Groundwork for moving characters

This commit is contained in:
blondie7575 2023-07-30 15:46:59 -07:00
parent fad2daa4d7
commit 4ddb742b5f
3 changed files with 166 additions and 17 deletions

View File

@ -125,10 +125,15 @@ gameplayLoopPower:
gameplayLoopFire:
lda fireRequested
beq gameplayLoopRender
beq gameplayLoopMove
jsr unrenderCrosshair
jsr fire
gameplayLoopMove:
lda playerMoveRequested
beq gameplayLoopRender
jsr move
; BORDER_COLOR #$2
gameplayLoopRender:
@ -397,6 +402,24 @@ fire:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; move
;
; Handles moving a player
;
move:
jsr unrenderCrosshair
jsr unrenderPlayers
lda #playerData
sta PARAML0
ldx playerMoveRequested
jsr moveGameObjectOnTerrain
stz playerMoveRequested
jsr renderPlayers
jsr renderCrosshair
rts
basePalette:
.word $06af,$0072,$0072,$0861,$0c93,$0eb4,$0d66,$0f9a,$0777,$0d00,$0bbb,$ddd,$007b,$0a5b,$0000,$0fff
@ -413,6 +436,8 @@ fireRequested:
.word $0000
turnRequested:
.word $0000
playerMoveRequested:
.word $0000
terrainDirty:
.word 1
projectilesDirty:

View File

@ -8,6 +8,7 @@
GAMEOBJECTWIDTH = 16
GAMEOBJECTHEIGHT = 16
MAXGAMEOBJECTS = 6 ; Size of general purpose object pool
MAXCLIMB = 16 ; Highest pixel cliff we can climb
; Base class sample:
@ -25,16 +26,15 @@ GO_BACKGROUND = 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; placeGameObjectOnTerrain
; terrainHeightAtGameObjectPos
;
; A = GameObject position (left-edge relative)
; A -> Terrain height at that position
;
; PARAML0 = Pointer to gameobject data
; Trashes SCRATCHL
;
placeGameObjectOnTerrain:
SAVE_AY
ldy #GO_POSX
lda (PARAML0),y
terrainHeightAtGameObjectPos:
phy
clc ; Map into reversed terrain X space
adc #GAMEOBJECTWIDTH
sta SCRATCHL
@ -45,7 +45,35 @@ placeGameObjectOnTerrain:
and #$fffe ; Force even
tay
lda terrainData,y
ply
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; placeGameObjectOnTerrain
;
; PARAML0 = Pointer to gameobject data
; Trashes SCRATCHL,SCRATCHL2
;
placeGameObjectOnTerrain:
SAVE_AY
; Check forwardmost position
ldy #GO_POSX
lda (PARAML0),y
jsr terrainHeightAtGameObjectPos
sta SCRATCHL2
; Check rearmost position
ldy #GO_POSX
lda (PARAML0),y
sec
sbc #GAMEOBJECTWIDTH
jsr terrainHeightAtGameObjectPos
cmp SCRATCHL2 ; Take higher value
bcc placeGameObjectOnTerrainRear
placeGameObjectOnTerrainDone:
clc
adc #GAMEOBJECTHEIGHT
ldy #GO_POSY
@ -54,6 +82,84 @@ placeGameObjectOnTerrain:
RESTORE_AY
rts
placeGameObjectOnTerrainRear:
lda SCRATCHL2
bra placeGameObjectOnTerrainDone
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; moveGameObjectOnTerrain
;
; PARAML0 = Pointer to gameobject data
; X = Delta in pixels
;
; Trashes SCRATCHL,SCRATCHL2
;
moveGameObjectOnTerrain:
SAVE_AY
stx SCRATCHL2
ldy #GO_POSX
lda (PARAML0),y
clc
adc SCRATCHL2 ; Apply X delta
clc ; Map into reversed terrain X space
adc #GAMEOBJECTWIDTH
sta SCRATCHL
lda #TERRAINWIDTH
sec
sbc SCRATCHL
sta SCRATCHL ; Desired X position
ldy #GO_POSY
lda (PARAML0),y
sec
sbc #GAMEOBJECTHEIGHT
sta SCRATCHL2 ; Current Y position
lda SCRATCHL ; Check terrain height at new position
pha
jsr terrainHeightAtGameObjectPos
sec
sbc SCRATCHL2
bmi moveGameObjectOnTerrainStepDown
moveGameObjectOnTerrainCheckHeight:
cmp #MAXCLIMB
bcs moveGameObjectOnTerrainTooFar
bra moveGameObjectOnTerrainStore
moveGameObjectOnTerrainStepDown:
dec
eor #$ffff
bra moveGameObjectOnTerrainCheckHeight
moveGameObjectOnTerrainStore:
pla
sta SCRATCHL
; Reverse X position again
lda #TERRAINWIDTH
sec
sbc #GAMEOBJECTWIDTH
sbc SCRATCHL
ldy #GO_POSX
sta (PARAML0),y
jsr placeGameObjectOnTerrain
moveGameObjectOnTerrainTooDone:
RESTORE_AY
rts
moveGameObjectOnTerrainTooFar:
pla
bra moveGameObjectOnTerrainTooDone
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; vramPtr

36
input.s
View File

@ -28,7 +28,7 @@ kbdScanTitle:
beq kbdScanEnterTitle
cmp #(32 + $80)
beq kbdScanSpaceTitle
bra kbdScanDebugPiggyback
jmp kbdScanDebugPiggyback
kbdScanTitleDone:
BITS16
@ -64,6 +64,22 @@ kbdScanSpaceTitle:
rts
;;;;;;;
kbdScanApostrophe:
BITS16
lda #2
sta playerMoveRequested
rts
kbdScanSemiColon:
BITS16
lda #-2
sta playerMoveRequested
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; kbdScanGameplay/Debug
; Processes keyboard input for gameplay
@ -93,6 +109,10 @@ kbdScanGameplay:
beq kbdScanPeriod
cmp #(' ' + $80)
beq kbdScanSpace
cmp #(';' + $80)
beq kbdScanSemiColon
cmp #(39 + $80)
beq kbdScanApostrophe
cmp #(9 + $80)
bne kbdScanDebugPiggyback
jmp kbdScanTab
@ -116,7 +136,6 @@ kbdScanDebugPiggyback:
beq kbdScanEquals
bra kbdScanDone
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Gameplay Key Handlers
;
@ -145,13 +164,6 @@ kbdScanComma:
sta mapScrollRequested
rts
kbdScanESC:
BITS16
lda #1
sta quitRequested
rts
kbdScanLeftArrow:
BITS16
lda #2
@ -176,6 +188,12 @@ kbdScanDownArrow:
sta powerDeltaRequested
rts
kbdScanESC:
BITS16
lda #1
sta quitRequested
rts
kbdScanSpace:
BITS16
lda #1