Restarting game now resets data properly

This commit is contained in:
blondie7575 2023-12-24 13:42:19 -07:00
parent c2dde9a4b7
commit f0a53d6964
3 changed files with 87 additions and 19 deletions

View File

@ -7,6 +7,18 @@
NUMPLAYERS = 2 NUMPLAYERS = 2
initGameplay:
; Create players
lda #56
ldy #0
jsr playerCreate
lda #568
ldy #1
jsr playerCreate
jsr deleteAllProjectiles
rts
beginGameplay: beginGameplay:
; Initialize random numbers ; Initialize random numbers
@ -19,18 +31,14 @@ beginGameplay:
jsr colorFill jsr colorFill
; Generate, compile, and clip terrain ; Generate, compile, and clip terrain
stz mapScrollPos
stz leftScreenEdge stz leftScreenEdge
lda #160-GAMEOBJECTWIDTH/4-2
sta rightScreenEdge
jsr generateTerrain jsr generateTerrain
; Create players jsr initGameplay
lda #56
ldy #0
jsr playerCreate
lda #568
ldy #1
jsr playerCreate
jsr syncPlayerHeader jsr syncPlayerHeader
ldy #0 ldy #0
jsr renderPlayerHeader jsr renderPlayerHeader
@ -125,6 +133,8 @@ gameplayLoopPower:
lda powerDeltaRequested lda powerDeltaRequested
beq gameplayLoopFire beq gameplayLoopFire
jsr changePower jsr changePower
jsr unrenderCrosshair
jsr renderCrosshair
gameplayLoopFire: gameplayLoopFire:
lda fireRequested lda fireRequested
@ -489,9 +499,9 @@ turnRequested:
playerMoveRequested: playerMoveRequested:
.word $0000 .word $0000
terrainDirty: terrainDirty:
.word 1 .word 0
playersDirty: playersDirty:
.word 1 .word 0
projectilesDirty: projectilesDirty:
.word 1 .word 1
inventoryDirty: inventoryDirty:

View File

@ -6,6 +6,8 @@
; ;
MAX_ANGER = 100 MAX_ANGER = 100
START_POWER = 2
START_TREATS = 7
playerData: playerData:
;;;;;;;;;;;; PLAYER 1 ;;;;;;;;;;;;;; ;;;;;;;;;;;; PLAYER 1 ;;;;;;;;;;;;;;
@ -17,14 +19,14 @@ playerData:
.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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 24 ; Angle in degrees from +X .word 0 ; Angle in degrees from +X
.word 2 ; Power .word 0 ; Power
.word MAX_ANGER ; Anger .word 0 ; Anger
.byte 8,"SPROCKET " ; Name .byte 8,"SPROCKET " ; Name
.word 29 ; Base Sprite .word 29 ; Base Sprite
.word 0,5,7,0,0,0,0,0 ; Prices .word 0,5,7,0,0,0,0,0 ; Prices
.word 0 ; Current weapon .word 0 ; Current weapon
.word 7 ; Treats .word 0 ; Treats
.repeat 86 .repeat 86
.byte 0 ; Padding to 256-byte boundary .byte 0 ; Padding to 256-byte boundary
.endrepeat .endrepeat
@ -38,14 +40,14 @@ playerData:
.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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 154 ; Angle in degrees from +X .word 0 ; Angle in degrees from +X
.word 2 ; Power .word 0 ; Power
.word MAX_ANGER ; Anger .word 0 ; Anger
.byte 8,"TINKER " ; Name .byte 8,"TINKER " ; Name
.word 20 ; Base Sprite .word 20 ; Base Sprite
.word 0,5,7,0,0,0,0,0 ; Prices .word 0,5,7,0,0,0,0,0 ; Prices
.word 0 ; Current weapon .word 0 ; Current weapon
.word 7 ; Treats .word 0 ; Treats
.repeat 86 .repeat 86
.byte 0 ; Padding to 256-byte boundary .byte 0 ; Padding to 256-byte boundary
@ -105,6 +107,7 @@ playerCreate:
sty SCRATCHL sty SCRATCHL
pla pla
; Starting position
sta playerData+GO_POSX,y sta playerData+GO_POSX,y
lda #playerData lda #playerData
clc clc
@ -112,6 +115,39 @@ playerCreate:
sta PARAML0 sta PARAML0
jsr placeGameObjectOnTerrainDefault jsr placeGameObjectOnTerrainDefault
; Starting aim
lda playerData+GO_POSX,y
cmp #TERRAINWIDTH/2
bcc playerCreateLeft
lda #154
bra playerCreateInit
playerCreateLeft:
lda #24
playerCreateInit:
sta playerData+PD_ANGLE,y
; Initialize standard values
lda #START_POWER
sta playerData+PD_POWER,y
lda #START_TREATS
sta playerData+PD_TREATS,y
lda #MAX_ANGER
sta playerData+PD_ANGER,y
lda #0
sta playerData+PD_CURRWEAPON,y
lda #1
sta playersDirty
sta terrainDirty
sta projectilesDirty
sta inventoryDirty
lda #-1
sta gameOver
sta projectileActive
stz currentPlayer
jsr createProgressBar jsr createProgressBar
rts rts

View File

@ -630,6 +630,9 @@ endProjectile:
; Trashes A ; Trashes A
; ;
deleteProjectile: deleteProjectile:
lda projectileData+GO_POSX,y
bmi deleteProjectileDone ; Already deleted
lda #-1 lda #-1
sta projectileData+GO_POSX,y sta projectileData+GO_POSX,y
@ -646,6 +649,25 @@ deleteProjectileDone:
rts rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; deleteAllProjectiles
;
deleteAllProjectiles:
SAVE_AXY
ldx #0
deleteAllProjectilesLoop:
txy
PROJECTILEPTR_Y
jsr deleteProjectile
inx
cpx #4
bne deleteAllProjectilesLoop
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; protectProjectiles ; protectProjectiles
; ;