From 35413e6ad036bc64e48df7cbdb633ba6efdaf219 Mon Sep 17 00:00:00 2001 From: blondie7575 Date: Sun, 23 Dec 2018 17:39:22 -0700 Subject: [PATCH] Added support for multiple active projectiles --- equates.s | 2 + fan.s | 7 +- gamemanager.s | 6 +- gameobject.s | 134 +++++++++--------- gscats.2mg | Bin 819264 -> 819264 bytes player.s | 29 +++- projectile.s | 379 ++++++++++++++++++++++++++++++++++++++------------ 7 files changed, 390 insertions(+), 167 deletions(-) diff --git a/equates.s b/equates.s index c9c06c9..9ae651b 100644 --- a/equates.s +++ b/equates.s @@ -63,3 +63,5 @@ JD_VY = 138 JD_TYPE = 140 JD_NEW = 142 +MAXPROJECTILES = 3 + diff --git a/fan.s b/fan.s index f020f49..f2c6fb6 100644 --- a/fan.s +++ b/fan.s @@ -30,12 +30,12 @@ deployFan: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; updateFan ; +; Y = Offset to projectile structure ; updateFan: - SAVE_AY + SAVE_AXY ; Wait for fan to collide with us as it falls from the sky - ldy #0 lda projectileData+GO_POSX,y sta rectParams lda projectileData+GO_POSY,y @@ -45,12 +45,13 @@ updateFan: lda #GAMEOBJECTHEIGHT sta rectParams+6 + ldx currentPlayer jsr playerIntersectRect cmp #0 beq updateFanDone updateFanDone: - RESTORE_AY + RESTORE_AXY rts diff --git a/gamemanager.s b/gamemanager.s index 4f40da5..fa2feef 100644 --- a/gamemanager.s +++ b/gamemanager.s @@ -130,12 +130,12 @@ gameplayLoopProjectiles: beq gameplayLoopProjectilesSkip jsr unrenderProjectiles - jsr updateProjectilePhysics + jsr updateProjectilesPhysics jsr protectProjectiles jsr renderProjectiles gameplayLoopProjectilesSkip: - jsr updateProjectileCollisions + jsr updateProjectilesCollisions lda inventoryDirty beq gameplayLoopVictoryCondition @@ -268,7 +268,7 @@ scrollMap: jsr unrenderPlayers jsr unrenderProjectiles - jsr updateProjectilePhysics ; Good idea? +; jsr updateProjectilePhysics ; Good idea? sta mapScrollPos asl diff --git a/gameobject.s b/gameobject.s index 02b9cbf..53d7aed 100644 --- a/gameobject.s +++ b/gameobject.s @@ -135,286 +135,284 @@ renderGameobjectDone: ; protectGameObject ; ; Saves background behind this game object -; A = Pointer to gameobject background data +; PARAML0 = Pointer to gameobject background data ; X = VRAM position of upper left of game object ; -; Trashes SCRATCHL +; Trashes PARAML0 ; protectGameObject: phy ldy #0 - sta SCRATCHL - lda SHADOWVRAMBANK,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*2+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*2+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*2+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*3,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*3+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*3+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*3+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*4+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*4+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*4+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*5,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*5+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*5+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*5+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*6+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*6+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*6+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*7,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*7+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*7+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*7+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*8,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*8+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*8+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*8+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*9,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*9+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*9+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*9+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*10,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*10+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*10+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*10+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*11,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*11+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*11+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*11+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*12,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*12+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*12+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*12+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*13,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*13+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*13+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*13+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*14,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*14+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*14+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*14+6,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*15,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*15+2,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*15+4,x - sta (SCRATCHL),y + sta (PARAML0),y iny iny lda SHADOWVRAMBANK+160*15+6,x - sta (SCRATCHL),y + sta (PARAML0),y ply rts diff --git a/gscats.2mg b/gscats.2mg index b332b082ebe2c3dd6c54a34d42047e07ef00f7b6..857dc3c3d51f5d26a6fec0ae5fa6e20c720dd99d 100644 GIT binary patch delta 3232 zcmZve3v5%@8OP7LPK;wa#8nw{LR(J5qp)?WSD0o9Rl}oMNF#b#OEyL7>XC#Td(KNL z((s0S1-N5{t5QYHO^5?|I=&{C((p*FElQN7kaT2nHEEh6tqUpYl96;S1qKnS_nmuB zNYd@f=l(wb&pF@u&if8Z&kst^Us#=4RpB>g()Ey=2ciYRT-gWa0zA!%?NC z0k6Z```&B7@8Gm+`_w#TLn9WIx-^_!?=gR-@;!h2X`6iCPoAinqaG^FjlXT>PpluxcZvNiR=HbL zp@yoz&xvG4obwcpm#WRykXd`qM#6j5W*al@UVGiy7IKGUDlN*tnO6yNAS+HAB(e> z6g7hP;T=jUg5ALgHA2Y?)vBo%SGiSt{_G_hZAU16!cnOHtGMZeV`N0Pf3qCyM)!0C zMW=2aJoS&{-}B^Vv8#3!kIkkcSK)W(J-D@IabqfLdKm)G53^#I1>MtS^vKD_@F-Wh zahBzTBV;~iAzjK?H+~9lQf9hwcFrcp)KovZ`;q0;w&d1%vp89#ZBkZ8@s`InIWkb8 zG^{b&q(6Y{jpCick&^m1WM|*iC|;KzY!NqposwHbRTA8@Eh1P^_iURew~5+W(LLKC z${k`H-5u)?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03R)I_d;)bDn5P%^>uv3*mDeJcQD8oU`4d z*Y>?v64^OLy#PCA=M**OSj^YHRlBG5NbRp`FV{}hez|UW-PXFsx=VHRmX%xH+0wto zwza1B*ng>&CdXzrY=$2PpQGfTMeaVNo(=k4vKPTp#!U{{OSe**pnZOthmYjp6Fcy8 zE*x~?2l+V3Vk-?loG7!(Db@wK;{Dr{80#_Ne{WM-Sk;7!S*1T89bfLjhATvmevB0bO9R+T#5smb+E>m-i z^(zWHZ-_?f0#RX)E3E1=RB;gURO*{MSU+fm?ldcG=$e*e6YIyTocQ;7MxX0#d4QX_(U8I|s8>EuPFD?TzhVK@ z#$y{gi9Cyv1AGV%oy@x2$w5B!gw`=f>#&AyYb+i5G$oYFd)puih5-|RH=DA z58_P7k4AV7;-8Iowz%gP+r9q@roh&d6I*Q8{&Ddn>wjE3#kn~P3Y%dudna5dY?-xB z_VWoWMm4!*@?aeMmEdN31lB2?aFd|$P#)Uh=wER%` zNS=}}O9zTnt5rB49S5`t$EDMNCgHSnw#aE^gtOA00n>u^KG^TcB%(f_FB3gm$~jSC zruqk&>S{wgcP?}6Tq&0aY&M&z$p-bFd`+o3lf9RDEnCXHiwfmUQQ@dOH7s0}P81>4 z8Z`+gq!B&PTf&HRr3g8#!)f7)G_G?~!nkx>vT#k>uV=nriUH;bF-d_OTLncrqi22wvVFBWv*z!Q zdx;a?N1t8tq!@?)>@D<^@d^;=L zm$MIH>|4Xqn4WvSFeXjuF+UKdB-O}4P^JHoUO=byoR&gV7#02^+!Qhp_*MC#bVLvR zh|~vY5&EQyddL^08-Quy22?6X6ZV#28kz}O4zyfoW@vMuS)f^=*`V3uW!T~WKg;2{ ACjbBd diff --git a/player.s b/player.s index 0eba894..017a6b6 100644 --- a/player.s +++ b/player.s @@ -70,6 +70,20 @@ PD_SIZE = 256 .endmacro +.macro PLAYERPTR_X + txa ; Pointer to player structure from index + asl + asl + asl + asl + asl + asl + asl + asl + tax +.endmacro + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; playerCreate ; @@ -204,17 +218,17 @@ playerFire_abort: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; playerIntersectRect ; -; Y = Player index +; X = Player index ; rectParams = Rectangle to intersect with us ; A => non zero if rectangle is intersecting player ; playerIntersectRect: - phy - PLAYERPTR_Y + phx + PLAYERPTR_X - lda playerData+GO_POSX,y + lda playerData+GO_POSX,x sta rectParams2+0 - lda playerData+GO_POSY,y + lda playerData+GO_POSY,x sta rectParams2+2 lda #GAMEOBJECTWIDTH sta rectParams2+4 @@ -222,7 +236,7 @@ playerIntersectRect: sta rectParams2+6 jsr intersectRectRect - ply + plx rts @@ -250,6 +264,7 @@ RESTORE_AXY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; protectPlayers ; +; Trashes PARAML0 ; protectPlayers: SAVE_AXY @@ -261,6 +276,7 @@ protectPlayers: bmi protectPlayerNext lda #playerData+GO_BACKGROUND + sta PARAML0 jsr protectGameObject protectPlayerNext: @@ -271,6 +287,7 @@ protectPlayerNext: bmi protectPlayerDone lda #playerData+GO_BACKGROUND+PD_SIZE + sta PARAML0 jsr protectGameObject protectPlayerDone: diff --git a/projectile.s b/projectile.s index 3bca1db..8ed0e16 100644 --- a/projectile.s +++ b/projectile.s @@ -26,7 +26,48 @@ projectileData: .byte 0 ; Padding to 256-byte boundary .endrepeat -; Byte offsets for that ^ data structure can be found in equates.s + + ; Gameobject data (we're a subclass, effectively) + .word -1 ; Pos X in pixels (from left terrain edge) + .word 0 ; Pos Y in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .word 0 ; Pos X (12.4 fixed point) + .word 0 ; Pos Y (12.4 fixed point) + .word 0 ; Velocity X (8.8 fixed point) + .word 0 ; Velocity Y (8.8 fixed point) + .word 0 ; Type + .word 1 ; New? + + .repeat 112 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + ; Gameobject data (we're a subclass, effectively) + .word -1 ; Pos X in pixels (from left terrain edge) + .word 0 ; Pos Y in pixels (from bottom terrain edge) + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + + .word 0 ; Pos X (12.4 fixed point) + .word 0 ; Pos Y (12.4 fixed point) + .word 0 ; Velocity X (8.8 fixed point) + .word 0 ; Velocity Y (8.8 fixed point) + .word 0 ; Type + .word 1 ; New? + + .repeat 112 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + +; Byte offsets for that-^ data structure can be found in equates.s GRAVITY = $ffff ; 8.8 fixed point @@ -104,7 +145,14 @@ PT_RENDER = 14 tay .endmacro - +.macro PROJECTILETYPEPTR_X + txa ; Pointer to projectile type structure from index + asl + asl + asl + asl + tax +.endmacro projectileParams: .word 0 ; Starting pos X @@ -114,6 +162,30 @@ projectileParams: .word 0 ; Type +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; allocProjectile +; +; Returns offset of projectile structure in Y, or -1 if none available +; +allocProjectile: + SAVE_AX + ldx #0 + +allocProjectileLoop: + txy + PROJECTILEPTR_Y + lda projectileData+GO_POSX,y + bmi allocProjectileDone + inx + cpx MAXPROJECTILES + bne allocProjectileLoop + ldy #-1 + +allocProjectileDone: + RESTORE_AX + rts + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; fireProjectile ; @@ -121,10 +193,12 @@ projectileParams: fireProjectile: SAVE_AXY - ; Set up projectile structure - ldy #0 ; Only one active at a time for now - PROJECTILEPTR_Y + ; Allocate a projectile + jsr allocProjectile + cpy #-1 + beq fireProjectileDone + ; Set up projectile structure lda projectileParams ; X pos sta projectileData+GO_POSX,y lda projectileParams+2 ; Y pos @@ -169,6 +243,7 @@ fireProjectileFinish: sta projectileData+JD_NEW,y stz projectileActive +fireProjectileDone: RESTORE_AXY rts @@ -217,27 +292,49 @@ prepareProjectilePhysics: rts +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; updateProjectilesPhysics +; +; +updateProjectilesPhysics: + SAVE_AXY + ldx #0 + +updateProjectilesPhysicsLoop: + txy + PROJECTILEPTR_Y + jsr updateProjectilePhysics + +updateProjectilesPhysicsSkip: + inx + cpx #MAXPROJECTILES + bne updateProjectilesPhysicsLoop + + RESTORE_AXY + rts + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; updateProjectilePhysics ; -; Trashes SCRATCHL +; Y = Offset to projectile structure ; updateProjectilePhysics: - SAVE_AY + SAVE_AXY - lda projectileData+GO_POSX + lda projectileData+GO_POSX,y bpl updateProjectilePhysicsActive jmp updateProjectilePhysicsDone updateProjectilePhysicsActive: ; Integrate gravity over velocity - lda projectileData+JD_VY + lda projectileData+JD_VY,y clc adc #GRAVITY - sta projectileData+JD_VY + sta projectileData+JD_VY,y ; Integrate X velocity over position - lda projectileData+JD_VX + lda projectileData+JD_VX,y ; Convert 8.8 to 12.4 cmp #$8000 ror @@ -248,22 +345,22 @@ updateProjectilePhysicsActive: cmp #$8000 ror clc - adc projectileData+JD_PRECISEX - sta projectileData+JD_PRECISEX + adc projectileData+JD_PRECISEX,y + sta projectileData+JD_PRECISEX,y ; Convert to integer for rendering lsr lsr lsr lsr - sta projectileData+GO_POSX + sta projectileData+GO_POSX,y bmi updateProjectilePhysicsDelete cmp #TERRAINWIDTH-GAMEOBJECTWIDTH-1 bpl updateProjectilePhysicsDelete updateProjectilePhysicsContinue: ; Integrate Y velocity over position - lda projectileData+JD_VY + lda projectileData+JD_VY,y ; Convert 8.8 to 12.4 cmp #$8000 ror @@ -274,58 +371,85 @@ updateProjectilePhysicsContinue: cmp #$8000 ror clc - adc projectileData+JD_PRECISEY - sta projectileData+JD_PRECISEY + adc projectileData+JD_PRECISEY,y + sta projectileData+JD_PRECISEY,y ; Convert to integer for rendering lsr lsr lsr lsr - sta projectileData+GO_POSY + sta projectileData+GO_POSY,y cmp #GAMEOBJECTHEIGHT bmi updateProjectilePhysicsDelete ; Check for special update code - ldy #0 + phy lda projectileData+JD_TYPE,y tay PROJECTILETYPEPTR_Y lda projectileTypes+PT_UPDATE,y - beq updateProjectilePhysicsDone + beq updateProjectilePhysicsNormalUpdate + ply JSRA updateProjectilePhysicsDone: - RESTORE_AY + RESTORE_AXY rts updateProjectilePhysicsDelete: jsr endProjectile bra updateProjectilePhysicsDone +updateProjectilePhysicsNormalUpdate: + ply + bra updateProjectilePhysicsDone + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; updateProjectilesCollisions +; +; +updateProjectilesCollisions: + SAVE_AXY + ldx #0 + +updateProjectilesCollisionsLoop: + txy + PROJECTILEPTR_Y + jsr updateProjectileCollisions + +updateProjectilesCollisionsSkip: + inx + cpx #MAXPROJECTILES + bne updateProjectilesCollisionsLoop + + RESTORE_AXY + rts + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; updateProjectileCollisions ; -; Trashes SCRATCHL +; Y = Offset to projectile structure ; updateProjectileCollisions: - SAVE_AY + SAVE_AXY ; Check for player collisions - ldy #0 - lda projectileData+GO_POSX + lda projectileData+GO_POSX,y bmi updateProjectileCollisionsDone ; Projectile not active sta rectParams - lda projectileData+GO_POSY + lda projectileData+GO_POSY,y sta rectParams+2 lda #GAMEOBJECTWIDTH sta rectParams+4 lda #GAMEOBJECTHEIGHT sta rectParams+6 + ldx #0 updateProjectileCollisionsPlayerLoop: - cpy currentPlayer + cpx currentPlayer beq updateProjectileCollisionsPlayerNext jsr playerIntersectRect @@ -333,16 +457,16 @@ updateProjectileCollisionsPlayerLoop: bne updateProjectileCollisionsPlayerHit updateProjectileCollisionsPlayerNext: - iny - cpy #NUMPLAYERS + inx + cpx #NUMPLAYERS bne updateProjectileCollisionsPlayerLoop ; Check for terrain collisions - lda projectileData+GO_POSX + lda projectileData+GO_POSX,y inc inc sta rectParams - lda projectileData+GO_POSY + lda projectileData+GO_POSY,y clc inc inc @@ -357,7 +481,7 @@ updateProjectileCollisionsPlayerNext: bne updateProjectileCollisionsTerrainHit updateProjectileCollisionsDone: - RESTORE_AY + RESTORE_AXY rts updateProjectileCollisionsPlayerHit: @@ -409,90 +533,145 @@ deleteProjectile: protectProjectiles: SAVE_AXY - lda projectileData - bmi protectProjectilesDone + ldx #0 - lda #projectileData +protectProjectilesLoop: + txy + PROJECTILEPTR_Y + lda projectileData+GO_POSX,y + bpl protectProjectilesGotOne + +protectProjectilesContinue: + inx + cpx #MAXPROJECTILES + beq protectProjectilesDone + bra protectProjectilesLoop + +protectProjectilesGotOne: + lda #projectileData+GO_POSX sta PARAML0 + clc + tya + adc PARAML0 + sta PARAML0 + phx jsr vramPtr - cpx #0 - bmi protectProjectilesDone + cpx #-1 + beq protectProjectilesOffscreen lda #projectileData+GO_BACKGROUND + sta PARAML0 + clc + tya + adc PARAML0 + sta PARAML0 jsr protectGameObject + plx + bra protectProjectilesContinue protectProjectilesDone: RESTORE_AXY rts +protectProjectilesOffscreen: + plx + bra protectProjectilesContinue UPANGLE = $00af DNANGLE = $ffaf + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; renderProjectiles ; ; renderProjectiles: - SAVE_AY + SAVE_AXY + ldx #0 - lda projectileData - bpl renderProjectilesDoIt - jmp renderProjectilesDone +renderProjectilesLoop: + txy + PROJECTILEPTR_Y + jsr renderProjectile -renderProjectilesDoIt: +renderProjectilesSkip: + inx + cpx #MAXPROJECTILES + bne renderProjectilesLoop - lda projectileData+JD_TYPE - tay - PROJECTILETYPEPTR_Y + RESTORE_AXY + rts - lda #projectileData + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; renderProjectile +; +; Y = Offset to projectile structure +; +renderProjectile: + SAVE_AXY + + PROJECTILEPTR_Y + lda projectileData+GO_POSX,y + bpl renderProjectileDoIt + jmp renderProjectileDone + +renderProjectileDoIt: + lda projectileData+JD_TYPE,y + tax + PROJECTILETYPEPTR_X + + lda #projectileData ; Calculate pointer for game object render + sta PARAML0 + clc + tya + adc PARAML0 sta PARAML0 ; Determine which sprite to use - lda projectileData+JD_VX - bmi renderProjectilesNegX + lda projectileData+JD_VX,y + bmi renderProjectileNegX - lda projectileData+JD_VY + lda projectileData+JD_VY,y - bmi renderProjectilesNegYPosX + bmi renderProjectileNegYPosX cmp #UPANGLE - bmi renderProjectilesFlat + bmi renderProjectileFlat -renderProjectilesUpAngle: - lda projectileTypes+PT_FRAME0,y ; Up angle - bra renderProjectilesGoSprite +renderProjectileUpAngle: + lda projectileTypes+PT_FRAME0,x ; Up angle + bra renderProjectileGoSprite -renderProjectilesNegYPosX: +renderProjectileNegYPosX: cmp #DNANGLE - bpl renderProjectilesFlat + bpl renderProjectileFlat -renderProjectilesDownAngle: - lda projectileTypes+PT_FRAME2,y ; Down angle - bra renderProjectilesGoSprite +renderProjectileDownAngle: + lda projectileTypes+PT_FRAME2,x ; Down angle + bra renderProjectileGoSprite -renderProjectilesNegX: - lda projectileData+JD_VY +renderProjectileNegX: + lda projectileData+JD_VY,y - bmi renderProjectilesNegYNegX + bmi renderProjectileNegYNegX cmp #UPANGLE - bmi renderProjectilesFlat - bra renderProjectilesDownAngle + bmi renderProjectileFlat + bra renderProjectileDownAngle -renderProjectilesNegYNegX: +renderProjectileNegYNegX: cmp #DNANGLE - bpl renderProjectilesFlat - bra renderProjectilesUpAngle + bpl renderProjectileFlat + bra renderProjectileUpAngle -renderProjectilesFlat: - lda projectileTypes+PT_FRAME1,y ; Flat +renderProjectileFlat: + lda projectileTypes+PT_FRAME1,x ; Flat -renderProjectilesGoSprite: +renderProjectileGoSprite: jsr renderGameObject -renderProjectilesDone: - RESTORE_AY +renderProjectileDone: + RESTORE_AXY rts @@ -501,23 +680,51 @@ renderProjectilesDone: ; ; unrenderProjectiles: + SAVE_AXY + ldx #0 + +unrenderProjectilesLoop: + txy + PROJECTILEPTR_Y + jsr unrenderProjectile + +unrenderProjectilesSkip: + inx + cpx #MAXPROJECTILES + bne unrenderProjectilesLoop + + RESTORE_AXY + rts + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; unrenderProjectile +; +; Y = Offset to projectile structure +; +unrenderProjectile: pha - lda projectileData - bpl unrenderProjectilesActive - jmp unrenderProjectilesDone + lda projectileData+GO_POSX,y + bpl unrenderProjectileActive + jmp unrenderProjectileDone -unrenderProjectilesActive: - lda projectileData+JD_NEW - beq unrenderProjectilesDoIt - stz projectileData+JD_NEW - jmp unrenderProjectilesDone +unrenderProjectileActive: + lda projectileData+JD_NEW,y + beq unrenderProjectileDoIt + lda #0 + sta projectileData+JD_NEW,y + jmp unrenderProjectileDone -unrenderProjectilesDoIt: +unrenderProjectileDoIt: lda #projectileData sta PARAML0 + clc + tya + adc PARAML0 + sta PARAML0 jsr unrenderGameObject -unrenderProjectilesDone: +unrenderProjectileDone: pla rts @@ -525,14 +732,12 @@ unrenderProjectilesDone: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; processPlayerImpact ; -; Y = Index of player that was hit +; X = Index of player that was hit +; Y = Offset to projectile structure ; processPlayerImpact: - PLAYERPTR_Y - tyx + PLAYERPTR_X - ldy #0 ; Assume projectile 0 - PROJECTILEPTR_Y lda projectileData+JD_TYPE,y tay PROJECTILETYPEPTR_Y