GSCats/gamemanager.s

584 lines
10 KiB
ArmAsm
Raw Permalink Normal View History

2017-08-16 02:04:22 +00:00
;
; gamemanager
; The manager for overall game logic
;
; Created by Quinn Dunki on 8/15/17
;
2017-09-03 00:31:12 +00:00
NUMPLAYERS = 2
initGameplay:
; Create players
lda #56
ldy #0
jsr playerCreate
lda #568
ldy #1
jsr playerCreate
jsr deleteAllProjectiles
rts
2017-08-16 02:04:22 +00:00
beginGameplay:
; Initialize random numbers
lda #1
jsr seedRandom
2023-07-21 02:41:06 +00:00
2017-08-16 02:04:22 +00:00
; Erase the screen
ldx #$0000
2018-06-08 19:55:22 +00:00
ldy #200
2017-08-16 02:04:22 +00:00
jsr colorFill
; Generate, compile, and clip terrain
stz mapScrollPos
2018-01-16 20:56:53 +00:00
stz leftScreenEdge
2024-02-01 16:53:38 +00:00
stz mapScrollRequested
lda #160-GAMEOBJECTWIDTH/4-2
sta rightScreenEdge
2017-08-16 02:04:22 +00:00
jsr generateTerrain
2018-01-16 20:56:53 +00:00
jsr initGameplay
jsr syncPlayerHeader
2017-08-16 02:04:22 +00:00
ldy #0
jsr renderPlayerHeader
2017-12-24 19:36:31 +00:00
jsr prepareRowRendering
2017-10-19 19:59:24 +00:00
2018-01-19 02:15:42 +00:00
jsr compileTerrain
jsr clipTerrain
jsr renderTerrain
jsr renderInventory
jsr protectPlayers
jsr renderPlayers
ldy #0
jsr updateCrosshair
2018-01-19 02:15:42 +00:00
; Fade in from menu
2023-07-21 02:41:06 +00:00
lda #basePalette
sta PARAML2
jsr paletteFade
2017-08-16 02:04:22 +00:00
gameplayLoop:
lda projectileActive
bpl gameplayLoopKeyboardSkip
jsr kbdScanGameplay
gameplayLoopKeyboardSkip:
jsr kbdScanDebug
; BORDER_COLOR #$F
jsr nextVBL
; BORDER_COLOR #$0
; Check for pause
lda paused
2023-06-22 03:07:30 +00:00
beq gameplayLoopBeginUpdate
jmp gameplayLoopEndFrame
gameplayLoopBeginUpdate:
2017-08-16 02:04:22 +00:00
;;;;;;;;;;;
; Update
;
lda #1
sta projectilesDirty
lda projectileActive ; Skip interactivity during shots, but still allow map scrolling
bpl gameplayLoopShotTracking
lda dirtExplosionActive
bne gameplayLoopRenderJump ; Skip interactivity during dirt explosions
bra gameplayLoopScroll
gameplayLoopRenderJump:
jmp gameplayLoopRender
gameplayLoopShotTracking:
jsr trackActiveShot
; BORDER_COLOR #$1
2017-10-22 20:37:06 +00:00
gameplayLoopScroll:
2017-08-16 02:04:22 +00:00
; Scroll map if needed
lda mapScrollRequested
bmi gameplayLoopAngleCheck
2017-08-16 02:04:22 +00:00
jsr scrollMap
ldy currentPlayer
jsr updateCrosshair
gameplayLoopAngleCheck:
lda projectileActive ; Skip interactivity during shots
bpl gameplayLoopRenderJmp
bra gameplayLoopAngle
gameplayLoopRenderJmp:
jmp gameplayLoopRender
gameplayLoopAngle:
; Update aim angle if needed
2017-08-16 02:04:22 +00:00
lda angleDeltaRequested
beq gameplayLoopPower
2017-08-16 02:04:22 +00:00
jsr changeAngle
2023-06-22 03:07:30 +00:00
gameplayLoopAim:
jsr unrenderCrosshair
ldy currentPlayer
jsr updateCrosshair
jsr protectCrosshair
2023-06-22 03:07:30 +00:00
jsr renderCrosshair
2017-09-05 19:55:27 +00:00
gameplayLoopPower:
; Update power if needed
lda powerDeltaRequested
beq gameplayLoopFire
jsr changePower
jsr unrenderCrosshair
ldy currentPlayer
jsr renderCrosshair
2017-09-05 19:55:27 +00:00
gameplayLoopFire:
lda fireRequested
2023-07-30 22:46:59 +00:00
beq gameplayLoopMove
jsr unrenderCrosshair
jsr fire
2023-06-22 03:07:30 +00:00
2023-07-30 22:46:59 +00:00
gameplayLoopMove:
lda playerMoveRequested
beq gameplayLoopRender
jsr move
; BORDER_COLOR #$2
gameplayLoopRender:
; sta KBDSTROBE
2017-08-23 03:33:07 +00:00
;;;;;;;;;;;
; Render
;
; Render the terrain if needed
2018-03-05 20:32:05 +00:00
lda terrainDirty
beq gameplayLoopExplosions
; jsl renderTerrainSpans ; Part of the now disabled fill-mode renderer
jsr renderTerrain
stz terrainDirty
; Render players
lda playersDirty ; Check if terrain moved since last protect
beq gameplayLoopRenderPlayersAnyway
jsr unrenderPlayers
jsr protectPlayers
lda dirtExplosionActive ; Crosshair is dirty if map scrolled and dirt is finished
bne gameplayLoopRenderPlayersAnyway
jsr protectCrosshair
ldy currentPlayer
jsr renderCrosshair
gameplayLoopRenderPlayersAnyway:
jsr renderPlayers
gameplayLoopExplosions:
; Render explosions
jsr renderDirtExplosion
gameplayLoopProjectiles:
; BORDER_COLOR #$3
lda projectilesDirty
beq gameplayLoopProjectilesSkip
jsr unrenderProjectiles
jsr updateProjectilesPhysics
jsr unrenderPlayers ; This extra unrender...
jsr protectProjectiles
jsr renderPlayers ; ... rerender cycle makes fan stands overlapping cats render properly. Messy, but the engine doesn't handle overlapping sprites well
jsr renderProjectiles
gameplayLoopProjectilesSkip:
jsr updateProjectilesCollisions
2018-06-11 00:05:20 +00:00
lda inventoryDirty
beq gameplayLoopVictoryCondition
stz inventoryDirty
jsr renderInventory
2017-08-16 02:04:22 +00:00
; BORDER_COLOR #$4
2017-09-04 00:20:24 +00:00
gameplayLoopVictoryCondition:
lda gameOver
bmi gameplayEndTurnCondition
2017-09-04 00:20:24 +00:00
jsr endGame
gameplayEndTurnCondition:
lda turnRequested
beq gameplayLoopEndFrame
lda dirtExplosionActive
bne gameplayLoopEndFrame
jsr endTurn
2017-09-03 00:31:12 +00:00
gameplayLoopEndFrame:
2019-02-22 23:52:07 +00:00
lda singleStep
beq gameplayLoopEndFrameCont
lda #1
sta paused
gameplayLoopEndFrameCont:
2017-08-16 02:04:22 +00:00
lda quitRequested
beq gameplayLoopContinue
; Transition back to menu
stz quitRequested
lda #skyPalette
sta PARAML2
jsr paletteFade
jmp titleScreen
gameplayLoopContinue:
jmp gameplayLoop
2017-08-16 02:04:22 +00:00
2017-10-22 20:37:06 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; trackActiveShot
;
; Handles tracking the projectile with the camera
;
; Trashes SCRATCHL
;
trackActiveShot:
ldy projectileActive
lda projectileData+JD_PRECISEX,y
2017-10-22 20:37:06 +00:00
lsr ; Convert to integer and divide by two for byte distance
lsr
lsr
lsr
lsr
sta SCRATCHL ; Save this for later
lda projectileData+JD_VX,y
2017-10-22 20:37:06 +00:00
bmi trackActiveShotNeg
; Left-to-right
lda mapScrollPos
cmp #VISIBLETERRAINWIDTH-VISIBLETERRAINWINDOW
beq trackActiveShotDone ; Logical-right edge clamp
lda SCRATCHL
sec
2018-07-29 00:33:56 +00:00
sbc #150 ; Check for moving close to right edge
2017-10-22 20:37:06 +00:00
cmp leftScreenEdge
2018-07-28 23:20:37 +00:00
bmi trackActiveShotDone
lda #80 ; Move screen right to see shot land
sta mapScrollRequested
2017-10-22 20:37:06 +00:00
trackActiveShotNeg:
; Right-to-left
lda mapScrollPos
beq trackActiveShotDone ; Logical-left edge clamp
lda SCRATCHL
clc
2018-07-29 00:33:56 +00:00
adc #150 ; Check for moving close to left edge
2017-10-22 20:37:06 +00:00
cmp rightScreenEdge
bpl trackActiveShotDone
2018-07-28 23:20:37 +00:00
stz mapScrollRequested ; Move screen left to see shot land
2017-10-22 20:37:06 +00:00
trackActiveShotDone:
rts
2017-08-16 02:04:22 +00:00
2017-09-03 00:31:12 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; endTurn
;
; Handles changing the active player
;
endTurn:
lda currentPlayer
inc
cmp #NUMPLAYERS
beq endTurnWrap
2017-09-03 00:31:12 +00:00
sta currentPlayer
endTurnRefresh:
jsr processTurnForProjectiles
2017-09-03 00:31:12 +00:00
ldy currentPlayer
2018-07-29 00:33:56 +00:00
beq endTurnFocusPlayer0
lda #VISIBLETERRAINWINDOW
sta mapScrollRequested
endTurnHeader:
jsr syncPlayerHeader
2017-09-03 00:31:12 +00:00
jsr renderPlayerHeader
2018-07-29 00:33:56 +00:00
jsr renderInventory
2017-09-03 00:31:12 +00:00
stz turnRequested
rts
2018-07-29 00:33:56 +00:00
endTurnFocusPlayer0:
stz mapScrollRequested
bra endTurnHeader
2017-09-03 00:31:12 +00:00
endTurnWrap:
stz currentPlayer
bra endTurnRefresh
2017-09-04 00:20:24 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; endGame
;
2024-02-01 16:53:38 +00:00
; Handles someone winning. Assumes "someone" is current player
2017-09-04 00:20:24 +00:00
;
endGame:
2024-01-28 19:12:58 +00:00
SAVE_AXY
lda currentPlayer
beq endGame0
lda #victoryText1
bra endGameRender
endGame0:
lda #victoryText0
endGameRender:
sta PARAML0
ldy #$48b7
lda #2
jsl renderStringFar
2024-02-01 16:53:38 +00:00
; Play pee animation under loser (non-current player)
lda currentPlayer
eor #1
tay
PLAYERPTR_Y
lda playerData+GO_POSX,y
sta endGamePeePos
lda playerData+GO_POSY,y
dec
dec
sta endGamePeePos+2
lda #endGamePeePos
sta PARAML0
ldy #40
ldx #5
lda #ANIMATION_SIZE_16x16
jsr renderAnimationFreeze
; Wait for keypress
2024-01-28 19:12:58 +00:00
jsr kbdWaitForAnyKey
2017-09-04 00:20:24 +00:00
lda #1
sta quitRequested
2024-01-28 19:12:58 +00:00
RESTORE_AXY
2017-09-04 00:20:24 +00:00
rts
2024-02-01 16:53:38 +00:00
endGamePeePos:
.word 0,0
2017-09-04 00:20:24 +00:00
2017-08-16 02:04:22 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; scrollMap
;
; Handles updating the state of the terrain in response to scrolling
;
; A = New map scroll position
;
2017-08-16 02:04:22 +00:00
scrollMap:
2018-01-19 02:15:42 +00:00
jsr unclipTerrain
; jsl unrenderTerrainSpans ; Part of the now disabled fill-mode renderer
jsr unrenderPlayers
jsr unrenderProjectiles
pha
lda projectileActive ; Crosshair is visible if projectile isn't
beq scrollMapApplyScrolling
jsr unrenderCrosshair
lda #1
sta crosshairBackgroundStale
scrollMapApplyScrolling:
pla
; jsr updateProjectilePhysics ; Good idea?
2017-08-16 02:04:22 +00:00
sta mapScrollPos
asl
sta leftScreenEdge
clc
adc #160-GAMEOBJECTWIDTH/4-2
sta rightScreenEdge
2017-08-16 02:04:22 +00:00
2018-01-19 02:15:42 +00:00
jsr clipTerrain
2017-08-16 02:04:22 +00:00
lda #$ffff
sta mapScrollRequested
lda #1
sta playersDirty
sta projectilesDirty
2017-08-16 02:04:22 +00:00
sta terrainDirty
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; changeAngle
;
; Handles changing a player's aim
;
changeAngle:
2017-09-03 00:31:12 +00:00
ldy currentPlayer
2017-08-16 02:04:22 +00:00
tax
jsr playerDeltaAngle
2023-07-25 21:45:29 +00:00
; ldy currentPlayer
; jsr renderPlayerHeader
2017-08-16 02:04:22 +00:00
stz angleDeltaRequested
rts
2017-09-05 19:55:27 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; changePower
;
; Handles changing a player's power
;
changePower:
ldy currentPlayer
tax
jsr playerDeltaPower
2023-07-25 21:45:29 +00:00
; ldy currentPlayer
; jsr renderPlayerHeader
2017-09-05 19:55:27 +00:00
stz powerDeltaRequested
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; fire
;
; Handles firing a player's weapon
;
fire:
stz fireRequested
2017-09-03 00:31:12 +00:00
ldy currentPlayer
jsr playerFire
jsr renderPlayerHeader
rts
2023-07-30 22:46:59 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; move
;
; Handles moving a player
;
move:
SAVE_AY
; Unrender everything
2023-07-30 22:46:59 +00:00
jsr unrenderCrosshair
jsr unrenderPlayers
; Find active player game object data
ldy currentPlayer
PLAYERPTR_Y
tya
clc
adc #playerData
2023-07-30 22:46:59 +00:00
sta PARAML0
; Prepare parameters of move
2023-07-30 22:46:59 +00:00
ldx playerMoveRequested
lda currentPlayer
beq moveParamsPlayer0
lda #-1
sta placeGameObjectRightOffset
2023-12-23 23:47:20 +00:00
lda #GAMEOBJECTWIDTH-(GAMEOBJECTWIDTH/2-1)
sta placeGameObjectLeftOffset
movePerformMove:
2023-07-30 22:46:59 +00:00
jsr moveGameObjectOnTerrain
bra moveCleanup
moveParamsPlayer0:
2023-12-23 23:47:20 +00:00
lda #-(GAMEOBJECTWIDTH/2-2)
sta placeGameObjectRightOffset
lda #GAMEOBJECTWIDTH-2
sta placeGameObjectLeftOffset
bra movePerformMove
moveCleanup:
; Handle side effects caused by move
2023-07-30 22:46:59 +00:00
stz playerMoveRequested
ldy currentPlayer
jsr updateCrosshair
; Re-render everything
jsr protectPlayers
2023-07-30 22:46:59 +00:00
jsr renderPlayers
jsr protectCrosshair
ldy currentPlayer
2023-07-30 22:46:59 +00:00
jsr renderCrosshair
RESTORE_AY
2023-07-30 22:46:59 +00:00
rts
2017-08-16 02:04:22 +00:00
basePalette:
2023-07-21 02:41:06 +00:00
.word $06af,$0072,$0072,$0861,$0c93,$0eb4,$0d66,$0f9a,$0777,$0d00,$0bbb,$ddd,$007b,$0a5b,$0000,$0fff
2017-08-16 02:04:22 +00:00
quitRequested:
.word $0000
mapScrollRequested:
.word $FFFF
angleDeltaRequested:
.word $0000
2017-09-05 19:55:27 +00:00
powerDeltaRequested:
.word $0000
fireRequested:
.word $0000
2017-09-03 00:31:12 +00:00
turnRequested:
.word $0000
2023-07-30 22:46:59 +00:00
playerMoveRequested:
.word $0000
2017-08-16 02:04:22 +00:00
terrainDirty:
.word 0
playersDirty:
.word 0
projectilesDirty:
.word 1
2018-06-11 00:05:20 +00:00
inventoryDirty:
.word 1
2017-09-03 00:31:12 +00:00
currentPlayer:
.word 0
2017-09-04 00:20:24 +00:00
gameOver:
.word -1 ; Player index of winner
2017-09-05 19:48:30 +00:00
projectileActive:
.word -1 ; Y offset of active shot
paused:
.word 0
2019-02-22 23:52:07 +00:00
singleStep:
.word 0
2018-12-29 18:33:08 +00:00
globalWind:
.word 0 ; 12.4 velocity
2017-08-16 02:04:22 +00:00
; Position of map viewing window. Can be visualized in two ways:
; a) Word-distance from right edge of terrain data (which is in memory right-to-left) to left edge of visible screen
; b) Byte-distance from left edge of logical terrain to left edge of visible screen
; c) Byte-distance from left edge of logical terrain to right edge of visible screen minus game object width in words
2017-08-16 02:04:22 +00:00
mapScrollPos:
.word 0
2018-01-16 20:56:53 +00:00
;leftScreenEdge = $6E ; Moved to zero page for speed and cross-bank convenience
; .word 0
rightScreenEdge: ; Right edge minus one game object width, for easy render clipping
.word 160-GAMEOBJECTWIDTH/4-2
2019-02-22 23:52:07 +00:00
2024-01-28 19:12:58 +00:00
victoryText0:
pstring "SPROCKET WINS!"
victoryText1:
pstring " TINKER WINS!"