GSCats/gamemanager.s

383 lines
6.8 KiB
ArmAsm
Raw 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
2017-08-16 02:04:22 +00:00
beginGameplay:
; Set up palette for terrain and players
lda #basePalette
sta PARAML0
lda #0
jsr setPalette
2018-06-06 20:23:00 +00:00
; Set up palette for status bar
lda #statusBarPalette
sta PARAML0
lda #1
jsr setPalette
lda #1
sta PARAML0
ldx #0
ldy #10
jsr setScanlinePalette
2017-10-06 19:28:18 +00:00
; Set up sprite rendering
BITS8
lda #3
sta SpriteBankBank00+3 ; Tell compiled sprites what bank they are in
2017-10-06 19:28:18 +00:00
BITS16
2018-06-08 19:55:22 +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
2018-01-16 20:56:53 +00:00
stz leftScreenEdge
2017-08-16 02:04:22 +00:00
jsr generateTerrain
2018-01-16 20:56:53 +00:00
; Create players
lda #56
2017-09-03 00:31:12 +00:00
ldy #0
jsr playerCreate
lda #568
2017-09-03 00:31:12 +00:00
ldy #1
jsr playerCreate
2017-08-16 02:04:22 +00:00
ldy #0
jsr renderPlayerHeader
2017-10-19 19:59:24 +00:00
jsr protectPlayers
jsr protectProjectiles
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
; jsl renderTerrainSpans ; Part of the now disabled fill-mode renderer
2018-01-19 02:15:42 +00:00
2017-08-16 02:04:22 +00:00
gameplayLoop:
jsr kbdScan
2017-08-16 02:04:22 +00:00
jsr syncVBL
BORDER_COLOR #$0
2017-08-16 02:04:22 +00:00
;;;;;;;;;;;
; Update
;
lda #1
sta projectilesDirty
lda projectileActive
bpl gameplayLoopShotTracking ; Skip input during shots
2017-09-05 19:48:30 +00:00
; Check for pause
; lda paused
; bne gameplayLoopEndFrame
bra gameplayLoopScroll
gameplayLoopShotTracking:
jsr trackActiveShot
2017-10-22 20:37:06 +00:00
gameplayLoopScroll:
2017-08-16 02:04:22 +00:00
; Scroll map if needed
lda mapScrollRequested
bmi gameplayLoopAngle
2017-08-16 02:04:22 +00:00
jsr scrollMap
gameplayLoopAngle:
; Update aim angle if needed
2017-08-16 02:04:22 +00:00
lda angleDeltaRequested
2017-09-05 19:55:27 +00:00
beq gameplayLoopPower
2017-08-16 02:04:22 +00:00
jsr changeAngle
2017-09-05 19:55:27 +00:00
gameplayLoopPower:
; Update power if needed
lda powerDeltaRequested
beq gameplayLoopFire
jsr changePower
gameplayLoopFire:
lda fireRequested
beq gameplayLoopRender
jsr fire
gameplayLoopRender:
2017-09-05 19:48:30 +00:00
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 gameplayLoopProjectiles
BORDER_COLOR #$3
; jsl renderTerrainSpans ; Part of the now disabled fill-mode renderer
jsr renderTerrain
stz terrainDirty
BORDER_COLOR #$1
; Render players
jsr renderPlayers
gameplayLoopProjectiles:
lda projectilesDirty
beq gameplayLoopProjectilesSkip
jsr unrenderProjectiles
jsr updateProjectilePhysics
jsr protectProjectiles
jsr renderProjectiles
gameplayLoopProjectilesSkip:
jsr updateProjectileCollisions
2018-06-11 00:05:20 +00:00
lda inventoryDirty
beq gameplayLoopVictoryCondition
stz inventoryDirty
jsr renderInventory
2017-08-16 02:04:22 +00:00
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
jsr endTurn
2017-09-03 00:31:12 +00:00
gameplayLoopEndFrame:
2017-08-16 02:04:22 +00:00
lda quitRequested
beq gameplayLoopContinue
2017-08-16 02:04:22 +00:00
jmp quitGame
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:
lda projectileData+JD_PRECISEX
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
bmi trackActiveShotNeg
; Left-to-right
lda mapScrollPos
cmp #VISIBLETERRAINWIDTH-VISIBLETERRAINWINDOW
beq trackActiveShotDone ; Logical-right edge clamp
lda SCRATCHL
sec
sbc #80 ; Check for moving past center
cmp leftScreenEdge
bpl trackActiveShotCameraMove
bra trackActiveShotDone
trackActiveShotNeg:
; Right-to-left
lda mapScrollPos
beq trackActiveShotDone ; Logical-left edge clamp
lda SCRATCHL
clc
adc #80 ; Check for moving past center
cmp rightScreenEdge
bpl trackActiveShotDone
trackActiveShotCameraMove:
lda SCRATCHL
sbc #80
lsr
and #$fffe ; Force even
sta mapScrollRequested
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
sta currentPlayer
endTurnRefresh:
ldy currentPlayer
jsr renderPlayerHeader
stz turnRequested
rts
endTurnWrap:
stz currentPlayer
bra endTurnRefresh
2017-09-04 00:20:24 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; endGame
;
; Handles someone winning
;
endGame:
lda #1
sta quitRequested
rts
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
jsr updateProjectilePhysics ; Good idea?
2017-08-16 02:04:22 +00:00
sta mapScrollPos
asl
sta leftScreenEdge
clc
2017-09-05 19:48:30 +00:00
adc #160-GAMEOBJECTWIDTH/4-1
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
jsr protectPlayers
jsr protectProjectiles
jsr renderPlayers
jsr renderProjectiles ; Prevents flicker, but ads jitter to shot tracking
2017-08-16 02:04:22 +00:00
lda #1
sta terrainDirty
stz projectilesDirty
2017-08-16 02:04:22 +00:00
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
2017-09-03 00:31:12 +00:00
ldy currentPlayer
2017-08-16 02:04:22 +00:00
jsr renderPlayerHeader
stz angleDeltaRequested
rts
2017-09-05 19:55:27 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; changePower
;
; Handles changing a player's power
;
changePower:
ldy currentPlayer
tax
jsr playerDeltaPower
ldy currentPlayer
jsr renderPlayerHeader
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
rts
2017-08-16 02:04:22 +00:00
basePalette:
2018-06-08 19:55:22 +00:00
; Color 0 and 1 must both be sky blue. Compiled rendering uses PHD (which must contain $0000),
; and span rendering uses fill mode, so 0 can't be used there
.word $0aef,$0080,$0080,$0861,$0c93,$0eb4,$0d66,$0f9a,$0777,$0f00,$0bbb,$ddd,$007b,$0ff0,$0000,$0fff
2018-06-06 20:23:00 +00:00
statusBarPalette:
.word $0888,$0aef,$0F00,$0861,$0c93,$0eb4,$0d66,$0f9a,$00f0,$0fff,$0bbb,$ddd,$007b,$0000,$0ff0,$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
2017-08-16 02:04:22 +00:00
terrainDirty:
.word 1
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
paused:
.word 0
2017-09-03 00:31:12 +00:00
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:
2017-09-05 19:48:30 +00:00
.word 160-GAMEOBJECTWIDTH/4-1