diff --git a/equates.s b/equates.s index 582fa32..d5d5f01 100644 --- a/equates.s +++ b/equates.s @@ -65,6 +65,7 @@ JD_NEW = 142 JD_STATIC = 144 JD_OWNER = 146 JD_FACING = 148 +JD_SCRATCH = 150 MAXPROJECTILES = 3 diff --git a/fan.s b/fan.s index 3d9d4ec..2647e1d 100644 --- a/fan.s +++ b/fan.s @@ -58,17 +58,26 @@ updateFan: beq updateFanDone ; Once fan is in place, make it static + lda projectileData+GO_POSY,y + inc + sta projectileData+GO_POSY,y lda #1 sta projectileData+JD_STATIC,y jsr endProjectile ; Now set up the stand + jsr allocGameObject + cpx #-1 +BREAK + beq updateFanDone + txa + sta projectileData+JD_SCRATCH,y ; Remember where our stand is lda projectileData+GO_POSX,y - sta standGameObjectData+GO_POSX + sta gameObjectPool+GO_POSX,x lda projectileData+GO_POSY,y sec sbc #GAMEOBJECTHEIGHT - sta standGameObjectData+GO_POSY,y + sta gameObjectPool+GO_POSY,x updateFanDone: RESTORE_AXY @@ -123,7 +132,11 @@ renderFan: beq renderFanDone ; Don't render the stand until we're static ; Render the stand under the fan - lda #standGameObjectData + lda projectileData+JD_SCRATCH,y + sta PARAML0 + clc + lda #gameObjectPool + adc PARAML0 sta PARAML0 lda #14 jsr renderGameObject @@ -131,13 +144,3 @@ renderFan: renderFanDone: RESTORE_AXY rts - - -; Fake game object for rendering the stand -standGameObjectData: - .word 40 ; X pos in pixels (from right terrain edge) - .word 38 ; Y pos 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 64 bytes - .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 diff --git a/gameobject.s b/gameobject.s index 53d7aed..7bf1940 100644 --- a/gameobject.s +++ b/gameobject.s @@ -7,12 +7,14 @@ GAMEOBJECTWIDTH = 16 GAMEOBJECTHEIGHT = 16 +MAXGAMEOBJECTS = 6 ; Size of general purpose object pool + ; Base class sample: ;gameobjectData: ; .word 40 ; X pos in pixels (from right terrain edge) ; .word 38 ; Y pos 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 64 bytes +; .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ; Saved background 128 bytes ; .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 @@ -712,3 +714,133 @@ unrenderGameobjectBackground: unrenderGameobjectDone: RESTORE_AXY rts + + +.macro GAMEOBJECTPTR_X + txa ; Pointer to game object type structure from index + asl + asl + asl + asl + asl + asl + asl + asl + tax +.endmacro + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; allocGameObject +; +; Returns offset of gameobject structure in X, or -1 if none available +; +allocGameObject: + SAVE_AY + ldy #0 + +allocGameObjectLoop: + tyx + GAMEOBJECTPTR_X + lda gameObjectPool+GO_POSX,x + bmi allocGameObjectDone + iny + cpy #MAXGAMEOBJECTS + bne allocGameObjectLoop + ldx #-1 + +allocGameObjectDone: + RESTORE_AY + rts + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; deleteGameObject +; +; Deletes the game object at offset X +; +deleteGameObject: + pha + lda #-1 + sta gameObjectPool+GO_POSX,x + pla + rts + + +; A general purpose pool allocator for game objects. Useful +; for those times you need an object, but not a full fledged +; Player, Projectile, or other subclass. +gameObjectPool: + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos 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 128 bytes + .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 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos 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 128 bytes + .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 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos 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 128 bytes + .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 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos 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 128 bytes + .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 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos 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 128 bytes + .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 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + .word -1 ; X pos in pixels (from right terrain edge) + .word 0 ; Y pos 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 64 bytes + .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 + + .repeat 124 + .byte 0 ; Padding to 256-byte boundary + .endrepeat + + + diff --git a/gscats.2mg b/gscats.2mg index d2c1b25..392534c 100644 Binary files a/gscats.2mg and b/gscats.2mg differ diff --git a/projectile.s b/projectile.s index 7c6a40c..97376ca 100644 --- a/projectile.s +++ b/projectile.s @@ -24,8 +24,9 @@ projectileData: .word 0 ; Static? .word 0 ; Owner (player index) .word 0 ; Facing (0,1) = (+X,-X) + .word 0 ; Scratch space for subclasses - .repeat 106 + .repeat 104 .byte 0 ; Padding to 256-byte boundary .endrepeat @@ -47,8 +48,9 @@ projectileData: .word 0 ; Static? .word 0 ; Owner (player index) .word 0 ; Facing (0,1) = (+X,-X) + .word 0 ; Scratch space for subclasses - .repeat 106 + .repeat 104 .byte 0 ; Padding to 256-byte boundary .endrepeat @@ -70,8 +72,9 @@ projectileData: .word 0 ; Static? .word 0 ; Owner (player index) .word 0 ; Facing (0,1) = (+X,-X) + .word 0 ; Scratch space for subclasses - .repeat 106 + .repeat 104 .byte 0 ; Padding to 256-byte boundary .endrepeat @@ -530,6 +533,8 @@ updateProjectileCollisionsTerrainHit: ; endDeleteProjectile: lda #projectileData + clc + adc projectileActive sta PARAML0 jsr unrenderGameObject ldy projectileActive