base:duo_blast
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:duo_blast [2015-04-17 04:31] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== Duo Blast ===== | ||
+ | You will need to use sprite pad to draw 3 sprites. Actually, just draw two triangles. One that points up and another that points down. Finally draw a small square or a dot then save the lot. Now try this Acme Cross Assembler routine. | ||
+ | === source === | ||
+ | Creating your first game | ||
+ | < | ||
+ | ;This is an example tutorial for you to | ||
+ | ;learn how to create your own 2 player | ||
+ | ;Shot 'em Up, which includes joystick | ||
+ | ;control, a score system, etc. | ||
+ | ;Let's setup the perameters for our | ||
+ | ;game. These are the player positions. | ||
+ | |||
+ | plr1_x | ||
+ | plr1_y | ||
+ | plr2_x | ||
+ | plr2_y | ||
+ | |||
+ | ;Our parameters for the player bullets | ||
+ | |||
+ | plr1b_x | ||
+ | plr1b_y | ||
+ | plr2b_x | ||
+ | plr2b_y | ||
+ | |||
+ | ;Collisions parameters | ||
+ | |||
+ | plr1col | ||
+ | plr2col | ||
+ | |||
+ | ;bullet lockup routines | ||
+ | |||
+ | plr1lockup = $0360 ;Lockup for players | ||
+ | plr2lockup = $0361 ; | ||
+ | | ||
+ | |||
+ | ;We need to create a jump start for this | ||
+ | ;example, so we will create our own jump | ||
+ | ;address where it does not overlap data | ||
+ | ;which had been loaded. | ||
+ | |||
+ | !to " | ||
+ | *= $1000-2 | ||
+ | | ||
+ | *= $2000-2 | ||
+ | | ||
+ | *= $2400 | ||
+ | |||
+ | start sei ;Set irq flag | ||
+ | |||
+ | ;Clear the screen without JSR $E544 | ||
+ | |||
+ | ldx #$00 ;Calls a routine | ||
+ | clear lda #$20 ;to fill the whole | ||
+ | sta $0400,x ;screen with #$20, | ||
+ | sta $0500,x ;which is the | ||
+ | sta $0600,x ;blank space | ||
+ | sta $06e8,x ; | ||
+ | | ||
+ | bne clear ; | ||
+ | |||
+ | ;You should be familiar with the next | ||
+ | ;example code. If not then look at the | ||
+ | ;earlier chapters of A$$EMBLE IT! | ||
+ | |||
+ | lda #$00 | ||
+ | sta $d020 | ||
+ | sta $d021 | ||
+ | |||
+ | lda #$16 | ||
+ | sta $d018 | ||
+ | |||
+ | lda #$1b | ||
+ | sta $d011 | ||
+ | |||
+ | lda #$ff | ||
+ | sta $d015 | ||
+ | |||
+ | ;Now here we create the sprite objects | ||
+ | |||
+ | lda #$81 | ||
+ | sta $07f8 ;Player 1 ship | ||
+ | lda #$82 | ||
+ | sta $07f9 ;Player 1 bullet | ||
+ | lda #$80 | ||
+ | sta $07fa ;Player 2 ship | ||
+ | lda #$82 | ||
+ | sta $07fb ;Player 2 bullet | ||
+ | |||
+ | ;This is where we setup the colours of | ||
+ | ;the two players and bullets. | ||
+ | |||
+ | lda #$02 ;Colour red | ||
+ | sta $d027 ;Player 1 | ||
+ | sta $d028 ;Player 1 bullet | ||
+ | |||
+ | lda #$07 ;Colour yellow | ||
+ | sta $d029 ;Player 2 | ||
+ | sta $d02a ;Player 2 bullet | ||
+ | |||
+ | ;This is a different routine, as now the | ||
+ | ;default sprite positions are copied to | ||
+ | ;the declared parameters. | ||
+ | |||
+ | lda $d000 ;This is a method | ||
+ | sta plr1_x | ||
+ | lda $d001 ; | ||
+ | sta plr1_y | ||
+ | lda $d002 ;you can use this | ||
+ | sta plr1b_x ;to program the | ||
+ | lda $d003 ; | ||
+ | sta plr1b_y ;later on in the | ||
+ | lda $d004 ; | ||
+ | sta plr2_x | ||
+ | lda $d005 ;and decent | ||
+ | sta plr2_y | ||
+ | lda $d006 ;the sprites in | ||
+ | sta plr2b_x ;this game. | ||
+ | lda $d007 | ||
+ | sta plr2b_y | ||
+ | |||
+ | ;Now we reposition the two players and | ||
+ | ;put the bullets into zero | ||
+ | |||
+ | lda #$42 ;All this is the | ||
+ | sta plr1_y | ||
+ | lda #$18 ;two player ships, | ||
+ | sta plr1_x | ||
+ | lda #$e0 ;positions and the | ||
+ | sta plr2_y | ||
+ | lda #$98 ;as simple as that | ||
+ | sta plr2_x | ||
+ | |||
+ | lda #$00 ;All bullets are | ||
+ | sta plr1b_x ; | ||
+ | sta plr1b_y ;the zero value | ||
+ | sta plr2b_x ;yet again ' | ||
+ | sta plr2b_y ;' | ||
+ | |||
+ | ;Setup the scoreboard | ||
+ | |||
+ | lda #$30 ;We put zero on: | ||
+ | sta $0400 ;first line | ||
+ | lda #$02 ;paint first line | ||
+ | sta $d800 ;red | ||
+ | lda #$30 ;zero put on | ||
+ | sta $0427 ;first line as last | ||
+ | lda #$07 ;paint character | ||
+ | sta $d827 ; | ||
+ | |||
+ | ;Now for the main body of this program | ||
+ | ;the Interrupt flag, but we wont use | ||
+ | ;JMP $EA81 or JMP $EA31, as no keyboard | ||
+ | ;control will be required | ||
+ | |||
+ | lda #<int ; Call INT values | ||
+ | ldx #>int ; into an IRQ raster | ||
+ | ldy #$00 ; interrupt value and | ||
+ | sta $0314 ; zero the rasterline | ||
+ | stx $0315 ; | ||
+ | sty $d012 | ||
+ | lda #$7f ; Keep the screen on | ||
+ | ldx #$1b ; and continue the | ||
+ | sta $dc0d ; main interrupt | ||
+ | stx $d011 ; read | ||
+ | |||
+ | lda #$00 ;Initialise music | ||
+ | | ||
+ | | ||
+ | jsr $1000 ; | ||
+ | |||
+ | lda #$01 | ||
+ | sta $d019 ;IRQ is turned on | ||
+ | sta $d01a ; | ||
+ | |||
+ | lda $dc0d ;Copy $DC0D to $DD0D | ||
+ | sta $dd0d ;to have the IRQ | ||
+ | ; | ||
+ | |||
+ | | ||
+ | loop jmp loop ;Jump to the loop | ||
+ | | ||
+ | |||
+ | ;Our main interrupt | ||
+ | |||
+ | int asl $d019 ;Keep $D019 running | ||
+ | | ||
+ | |||
+ | ;Call routine to expand and reconvert | ||
+ | ;the sprite positions | ||
+ | |||
+ | jsr expand | ||
+ | |||
+ | ;Call routine to read joystick port 2 | ||
+ | ;for player 1 and player 2 | ||
+ | |||
+ | jsr read1up | ||
+ | jsr read2up | ||
+ | |||
+ | ;Call routine for bullet movements | ||
+ | |||
+ | jsr bullmove | ||
+ | |||
+ | ;Call routine for collision detection | ||
+ | ;and player 1 and player 2 bullet to | ||
+ | ;player collision. | ||
+ | |||
+ | jsr detect | ||
+ | jsr p1col | ||
+ | jsr p2col | ||
+ | |||
+ | ;And finally play the music | ||
+ | |||
+ | jsr $1003 ;Play music | ||
+ | |||
+ | pla ; An IRQ loop routine. | ||
+ | tay ; | ||
+ | pla ; This will keep all the | ||
+ | tax ; jsr routines playing | ||
+ | pla ; without using JMP $EA81 | ||
+ | rti ; or JMP $EA31 | ||
+ | |||
+ | ;Expand and reconver the sprite position | ||
+ | |||
+ | expand | ||
+ | sta $d001 ;to exact position | ||
+ | lda plr1b_y | ||
+ | sta $d003 ;to exact position | ||
+ | lda plr2_y | ||
+ | sta $d005 ;with this routine | ||
+ | lda plr2b_y | ||
+ | sta $d007 ;works with p2. | ||
+ | |||
+ | lda plr1_x | ||
+ | asl a ;calculate 64 | ||
+ | ror $d010 ;Expand x pos. | ||
+ | sta $d000 ;put at exact xpos | ||
+ | lda plr1b_x | ||
+ | asl a ;and do the same | ||
+ | ror $d010 ;as with the | ||
+ | sta $d002 ; | ||
+ | lda plr2_x | ||
+ | asl a ;All this is the | ||
+ | ror $d010 ;same except that | ||
+ | sta $d004 ;it will work with | ||
+ | lda plr2b_x | ||
+ | asl a ;Player 2 bullet | ||
+ | ror $d010 ; | ||
+ | sta $d006 ; | ||
+ | | ||
+ | |||
+ | ;Read joystick control for player1 | ||
+ | |||
+ | read1up | ||
+ | lsr a ;Joystick up | ||
+ | lsr a ;Joystick down | ||
+ | left1 lsr a ;Joystick left | ||
+ | bcs right1 | ||
+ | ldx plr1_x ;Move player 1 | ||
+ | | ||
+ | | ||
+ | cpx #$0e ;does the player | ||
+ | bcs set1 ;move further than | ||
+ | ldx #$0e ;$0e, if so then | ||
+ | set1 stx plr1_x ;stop. Else continue | ||
+ | right1 | ||
+ | bcs fire1 | ||
+ | ldx plr1_x ;Move player 1 | ||
+ | | ||
+ | | ||
+ | cpx #$9a ; | ||
+ | bcc set2 ; | ||
+ | ldx #$9a ;make the player | ||
+ | set2 stx plr1_x ; | ||
+ | |||
+ | fire1 lsr a ; | ||
+ | bcs nojoy1 | ||
+ | lda plr1lockup ;Is player fire | ||
+ | cmp #$00 ; | ||
+ | bne nojoy1 | ||
+ | lda #$01 ;then lock fire | ||
+ | sta plr1lockup ;and position | ||
+ | ldx plr1_x | ||
+ | stx plr1b_x | ||
+ | ldx plr1_y | ||
+ | stx plr1b_y | ||
+ | ;the player. | ||
+ | nojoy1 | ||
+ | |||
+ | ;Read joystick control for Player 2 | ||
+ | ;(joystick port 1) | ||
+ | |||
+ | read2up | ||
+ | lsr a ;up | ||
+ | lsr a ;down ;Please read the | ||
+ | left2 lsr a ;left ;player 1 | ||
+ | bcs right2 | ||
+ | ldx plr2_x | ||
+ | | ||
+ | | ||
+ | cpx #$0e ; | ||
+ | bcs set1_1 | ||
+ | ldx #$0e ; | ||
+ | set1_1 | ||
+ | right2 | ||
+ | bcs fire2 | ||
+ | ldx plr2_x | ||
+ | | ||
+ | | ||
+ | cpx #$9a | ||
+ | bcc set1_2 | ||
+ | ldx #$9a | ||
+ | set1_2 | ||
+ | fire2 lsr a | ||
+ | bcs nojoy2 | ||
+ | lda plr2lockup | ||
+ | cmp #$00 | ||
+ | bne nojoy2 | ||
+ | lda #$01 | ||
+ | sta plr2lockup | ||
+ | ldx plr2_x | ||
+ | stx plr2b_x | ||
+ | ldx plr2_y | ||
+ | stx plr2b_y | ||
+ | nojoy2 | ||
+ | |||
+ | ;call bullet routines | ||
+ | |||
+ | bullmove ldx plr1b_y | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | cpx #$f6 ; | ||
+ | bcc repsbul1 | ||
+ | lda #$00 ;Turn off the | ||
+ | sta plr1lockup ;fire lockup | ||
+ | ldx #$f6 | ||
+ | repsbul1 stx plr1b_y | ||
+ | |||
+ | ldx plr2b_y | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | cpx #$06 ; | ||
+ | bcs repsbul2 | ||
+ | lda #$00 ;Turn off the | ||
+ | sta plr2lockup ;fire lockup | ||
+ | ldx #$06 | ||
+ | repsbul2 stx plr2b_y | ||
+ | | ||
+ | |||
+ | ;Setup collision detection for player 1 | ||
+ | ;and player 2 | ||
+ | |||
+ | detect | ||
+ | | ||
+ | sbc #$06 ; | ||
+ | sta plr1col+$00 | ||
+ | | ||
+ | adc #$0c ; | ||
+ | sta plr1col+$01 | ||
+ | lda plr1_y | ||
+ | | ||
+ | sbc #$0c ;the player, | ||
+ | sta plr1col+$02 | ||
+ | | ||
+ | adc #$18 ; | ||
+ | sta plr1col+$03 | ||
+ | |||
+ | lda plr2_x | ||
+ | | ||
+ | sbc #$06 ;for player 2 | ||
+ | sta plr2col+$00 | ||
+ | | ||
+ | adc #$0c ; | ||
+ | sta plr2col+$01 | ||
+ | lda plr2_y | ||
+ | | ||
+ | sbc #$0c | ||
+ | sta plr2col+$02 | ||
+ | | ||
+ | adc #$18 | ||
+ | sta plr2col+$03 | ||
+ | | ||
+ | |||
+ | ;Check player 1 bullet collision on | ||
+ | ;player 2 ship | ||
+ | |||
+ | p2col lda plr1b_x | ||
+ | cmp plr2col+$00 ;at the correct | ||
+ | bcc missp2 | ||
+ | cmp plr2col+$01 ;the player is? | ||
+ | bcs missp2 | ||
+ | lda plr1b_y | ||
+ | cmp plr2col+$02 ;the bullet | ||
+ | bcc missp2 | ||
+ | cmp plr2col+$03 ; | ||
+ | bcs missp2 | ||
+ | lda #$f6 ;Else move | ||
+ | sta plr1b_y | ||
+ | lda #$00 ;screen, turn | ||
+ | sta plr1lockup | ||
+ | inc $0400 ;add 1 point | ||
+ | lda $0400 ; | ||
+ | cmp #$3a ;is it over 9? | ||
+ | bne missp2 | ||
+ | ; | ||
+ | jmp victory1 | ||
+ | missp2 | ||
+ | |||
+ | ;Check player2 bullet on player 1 ship | ||
+ | |||
+ | p1col lda plr2b_x | ||
+ | cmp plr1col+$00 ;bullet hit | ||
+ | bcc missp1 | ||
+ | cmp plr1col+$01 ;exact position | ||
+ | bcs missp1 | ||
+ | lda plr2b_y | ||
+ | cmp plr1col+$02 ;then continue | ||
+ | bcc missp1 | ||
+ | cmp plr1col+$03 ; | ||
+ | bcs missp1 | ||
+ | lda #$06 | ||
+ | sta plr2b_y | ||
+ | lda #$00 | ||
+ | sta plr2lockup | ||
+ | inc $0427 ;Add 1 point | ||
+ | lda $0427 ; | ||
+ | cmp #$3a ;is it over ' | ||
+ | bne missp1 | ||
+ | jmp victory2 | ||
+ | missp1 | ||
+ | |||
+ | victory1 sei ;Stop all IRQs | ||
+ | lda #$00 ;Turn off all | ||
+ | sta $d015 ;the sprites | ||
+ | |||
+ | ldx #$00 ;Call a routine | ||
+ | win1 lda vic1, | ||
+ | sta $0400, | ||
+ | lda #$01 ;message and | ||
+ | sta $d800, | ||
+ | | ||
+ | cpx #$28 ;and display | ||
+ | bne win1 ;as 40 chars | ||
+ | |||
+ | jmp space ;Jump to space | ||
+ | ; | ||
+ | |||
+ | victory2 sei ; | ||
+ | lda #$00 ; ' | ||
+ | sta $d015 ;same function | ||
+ | |||
+ | ldx #$00 ;This routine | ||
+ | win2 lda vic2, | ||
+ | sta $0400, | ||
+ | lda #$01 ;it reads the | ||
+ | sta $d800, | ||
+ | | ||
+ | cpx #$28 ;player 2 wins | ||
+ | bne win2 ;the game | ||
+ | |||
+ | jmp space ;You know this | ||
+ | ;if not then | ||
+ | ;look at the | ||
+ | ; | ||
+ | ;' | ||
+ | ; | ||
+ | |||
+ | space ldx #$00 ;Another text | ||
+ | setspc | ||
+ | sta $07c0, | ||
+ | lda #$03 ;time position | ||
+ | sta $dbc0, | ||
+ | | ||
+ | cpx #$28 ;the screen as | ||
+ | bne setspc | ||
+ | |||
+ | ;Lame hit space routine :) | ||
+ | |||
+ | hitspace lda #$80 ;Create a | ||
+ | raster | ||
+ | bne raster | ||
+ | jsr $1003 ; | ||
+ | |||
+ | lda $dc01 ;Read SPACEBAR | ||
+ | cmp #$ef ;if not pressed | ||
+ | bne raster | ||
+ | ;the raster to | ||
+ | ; | ||
+ | ;the SPACE read | ||
+ | ; | ||
+ | ;play music | ||
+ | |||
+ | jmp start ; | ||
+ | | ||
+ | |||
+ | ;Our text display data tables. | ||
+ | |||
+ | ; | ||
+ | |||
+ | vic1 !scr " | ||
+ | !scr " player 2 is a loser" | ||
+ | |||
+ | ; | ||
+ | |||
+ | vic2 !scr " | ||
+ | !scr " player 1 is a loser" | ||
+ | |||
+ | ; | ||
+ | |||
+ | spc !scr " | ||
+ | !scr " for another game! " | ||
+ | </ |
base/duo_blast.txt · Last modified: 2015-04-17 04:31 by 127.0.0.1