Fix bugs related to correctly detecting the floor underneath the runner when close to the left edge. General code cleanup.

This commit is contained in:
Jeremy Rand 2017-08-05 23:14:25 -04:00
parent eec795b42f
commit 1c735c547d
2 changed files with 82 additions and 47 deletions

View File

@ -53,6 +53,11 @@ GRID_HEIGHT=5
GRID_MAX_SHIFT=7 GRID_MAX_SHIFT=7
LEVEL_STRUCT_SIZE=5 LEVEL_STRUCT_SIZE=5
LEVEL_STRUCT_START=0
LEVEL_STRUCT_WIDTH=1
LEVEL_STRUCT_TOP=2
LEVEL_STRUCT_BOTTOM=3
LEVEL_STRUCT_COLOUR=4
LINE0 = $2000 LINE0 = $2000
LINE1 = LINE0 + 1024 LINE1 = LINE0 + 1024
@ -254,7 +259,7 @@ LINE191 = LINE190 + 1024
; Set up hires screen ; Set up hires screen
jsr clearScreen jsr clearScreen
jsr setLevelAddr jsr resetGame
@nextframe: @nextframe:
jsr _vblWait jsr _vblWait
@ -262,6 +267,11 @@ LINE191 = LINE190 + 1024
jsr drawCharacter jsr drawCharacter
jsr drawGrids jsr drawGrids
;@debugLoop:
; ldx KBD
; bpl @debugLoop
; ldx KBDSTRB
jsr updateGrid jsr updateGrid
jsr updateCharacter jsr updateCharacter
@ -297,11 +307,7 @@ LINE191 = LINE190 + 1024
lda #CHAR_STATE_FALLING lda #CHAR_STATE_FALLING
sta characterState sta characterState
jmp setLevelAddr @setLevelAddr:
.endproc
.proc setLevelAddr
ldx level ldx level
lda levelsLo,x lda levelsLo,x
sta LEVELADDR sta LEVELADDR
@ -312,7 +318,7 @@ LINE191 = LINE190 + 1024
; If the high byte of the level address is 0, then there are no more levels ; If the high byte of the level address is 0, then there are no more levels
; For now, just loop back to level 0. TODO - Something better. ; For now, just loop back to level 0. TODO - Something better.
sta level sta level
jsr setLevelAddr jmp @setLevelAddr
@notAtTheEnd: @notAtTheEnd:
rts rts
@ -364,6 +370,7 @@ freq: .BYTE $00
.proc gameOver .proc gameOver
jsr drawCharacter jsr drawCharacter
jsr drawGrids
lda #0 lda #0
ldx #36 ldx #36
@ -542,7 +549,7 @@ lastButtonState: .BYTE $00
adc #MAXXBYTE adc #MAXXBYTE
sta screenRight sta screenRight
ldy #$1 ldy #LEVEL_STRUCT_WIDTH
lda (ZPADDR6),y lda (ZPADDR6),y
beq @noneFound beq @noneFound
@ -550,7 +557,9 @@ lastButtonState: .BYTE $00
lda gridLeft lda gridLeft
cmp screenRight cmp screenRight
bcs @noneFound bcs @noneFound
ldy #$1
; Add the width of the grid to the current gridLeft
ldy #LEVEL_STRUCT_WIDTH
clc clc
adc (ZPADDR6),y adc (ZPADDR6),y
; If we got a carry, that means the width of the next grid plus ; If we got a carry, that means the width of the next grid plus
@ -560,42 +569,38 @@ lastButtonState: .BYTE $00
bcs @overflow bcs @overflow
cmp gridXPos cmp gridXPos
bcc @nextGrid bcc @nextGrid
sec
@overflow: @overflow:
sbc gridXPos sbc gridXPos
tax ldx gridXShift
lda gridXShift
beq @skipRightAdjust beq @skipRightAdjust
cmp #3 cpx #3
bcs @skipRightAdjust bcs @skipRightAdjust
dex sec
dex sbc #2
@skipRightAdjust: @skipRightAdjust:
cpx #MAXXBYTE cmp #MAXXBYTE
bcc @rightIsNotOffScreen bcc @rightIsNotOffScreen
ldx #MAXXBYTE lda #MAXXBYTE
@rightIsNotOffScreen: @rightIsNotOffScreen:
stx gridScreenRight sta gridScreenRight
lda gridLeft lda gridLeft
sec sec
sbc gridXPos sbc gridXPos
beq @skipLeftAdjust
bpl @leftIsOnScreen bpl @leftIsOnScreen
lda #$0 lda #$0
tax
jmp @skipLeftAdjust jmp @skipLeftAdjust
@leftIsOnScreen: @leftIsOnScreen:
tax ldx gridXShift
lda gridXShift
beq @skipLeftAdjust beq @skipLeftAdjust
cmp #4 sec
bcs @skipLeftAdjust sbc #1
dex
dex
@skipLeftAdjust: @skipLeftAdjust:
txa
cmp #CHAR_XPOS+1 cmp #CHAR_XPOS+1
bcs @noneFound bcs @noneFound
@ -612,11 +617,11 @@ lastButtonState: .BYTE $00
@doNotIncHiByte: @doNotIncHiByte:
sta ZPADDR6 sta ZPADDR6
ldy #$1 ldy #LEVEL_STRUCT_WIDTH
lda (ZPADDR6),y lda (ZPADDR6),y
beq @noneFound beq @noneFound
ldy #$0 ldy #LEVEL_STRUCT_START
lda gridLeft lda gridLeft
clc clc
adc (ZPADDR6),y adc (ZPADDR6),y
@ -646,19 +651,19 @@ gridLeft: .BYTE $00
@loop: @loop:
jsr nextGridAtCharacter jsr nextGridAtCharacter
bcs @floorGone bcs @floorGone
ldy #2 ldy #LEVEL_STRUCT_TOP
lda (ZPADDR6),y lda (ZPADDR6),y
cmp characterYBottom cmp characterYBottom
bne @loop bne @loop
ldy #4 ldy #LEVEL_STRUCT_COLOUR
lda (ZPADDR6),y lda (ZPADDR6),y
cmp characterColour cmp characterColour
beq @checkForWin beq @checkForWin
jmp gameOver jmp gameOver
@checkForWin: @checkForWin:
ldy #LEVEL_STRUCT_SIZE+1 ldy #LEVEL_STRUCT_SIZE+LEVEL_STRUCT_WIDTH
lda (ZPADDR6),y lda (ZPADDR6),y
bne @return bne @return
jmp levelWon jmp levelWon
@ -679,6 +684,8 @@ gridLeft: .BYTE $00
; For jumping, we need to calculate the top first and check ; For jumping, we need to calculate the top first and check
; for collisions ; for collisions
lda #$ff
sta didHitHead
lda characterY lda characterY
sec sec
@ -690,11 +697,11 @@ gridLeft: .BYTE $00
jsr nextGridAtCharacter jsr nextGridAtCharacter
bcs @didNotHitHead bcs @didNotHitHead
ldy #2 ldy #LEVEL_STRUCT_TOP
lda (ZPADDR6),y lda (ZPADDR6),y
sta gridTop sta gridTop
ldy #3 ldy #LEVEL_STRUCT_BOTTOM
lda (ZPADDR6),y lda (ZPADDR6),y
sta gridBottom sta gridBottom
@ -705,6 +712,9 @@ gridLeft: .BYTE $00
@wasBelowToStart: @wasBelowToStart:
cmp characterY cmp characterY
bcc @loop bcc @loop
ldy #0
sty didHitHead
jmp @startFalling jmp @startFalling
@hitCeiling: @hitCeiling:
@ -740,11 +750,24 @@ gridLeft: .BYTE $00
clc clc
adc #CHAR_HEIGHT adc #CHAR_HEIGHT
sta characterYBottom sta characterYBottom
lda didHitHead
bne @return
; Check that the colour matches
ldy #LEVEL_STRUCT_COLOUR
lda (ZPADDR6),y
cmp characterColour
beq @return
jmp gameOver
@return:
rts rts
; Locals ; Locals
gridTop: .BYTE $00 gridTop: .BYTE $00
gridBottom: .BYTE $00 gridBottom: .BYTE $00
didHitHead: .BYTE $ff
.endproc .endproc
@ -772,11 +795,11 @@ gridBottom: .BYTE $00
jsr nextGridAtCharacter jsr nextGridAtCharacter
bcs @didNotLand bcs @didNotLand
ldy #3 ldy #LEVEL_STRUCT_BOTTOM
lda (ZPADDR6),y lda (ZPADDR6),y
sta gridBottom sta gridBottom
ldy #2 ldy #LEVEL_STRUCT_TOP
lda (ZPADDR6),y lda (ZPADDR6),y
cmp characterOldYBottom cmp characterOldYBottom
@ -805,8 +828,8 @@ gridBottom: .BYTE $00
@dropToBottomOfGrid: @dropToBottomOfGrid:
lda gridBottom lda gridBottom
sec clc
sbc #CHAR_HEIGHT adc #CHAR_HEIGHT
sta characterYBottom sta characterYBottom
@didNotLand: @didNotLand:
@ -822,6 +845,18 @@ gridBottom: .BYTE $00
sec sec
sbc #CHAR_HEIGHT sbc #CHAR_HEIGHT
sta characterY sta characterY
lda characterState
cmp #CHAR_STATE_NONE
bne @return
ldy #LEVEL_STRUCT_COLOUR
lda (ZPADDR6),y
cmp characterColour
beq @return
jmp gameOver
@return:
rts rts
; Locals ; Locals
@ -965,7 +1000,7 @@ yPos: .BYTE $00
inc gridXPos inc gridXPos
@loop: @loop:
ldy #$1 ldy #LEVEL_STRUCT_WIDTH
lda gridXPos lda gridXPos
cmp (LEVELADDR),y cmp (LEVELADDR),y
bcc @return bcc @return
@ -973,7 +1008,7 @@ yPos: .BYTE $00
; At this point, we know that this grid is not visible ; At this point, we know that this grid is not visible
; Check to see if the start of the next grid is left justified ; Check to see if the start of the next grid is left justified
; or off screen. ; or off screen.
ldy #LEVEL_STRUCT_SIZE ldy #LEVEL_STRUCT_SIZE+LEVEL_STRUCT_START
cmp (LEVELADDR),y cmp (LEVELADDR),y
bcc @return bcc @return
@ -988,7 +1023,7 @@ yPos: .BYTE $00
inc LEVELADDR+1 inc LEVELADDR+1
@doNotIncHiByte: @doNotIncHiByte:
sta LEVELADDR sta LEVELADDR
ldy #$0 ldy #LEVEL_STRUCT_START
lda gridXPos lda gridXPos
sec sec
sbc (LEVELADDR),y sbc (LEVELADDR),y
@ -1017,7 +1052,7 @@ yPos: .BYTE $00
adc #MAXXBYTE adc #MAXXBYTE
sta screenRight sta screenRight
ldy #$1 ldy #LEVEL_STRUCT_WIDTH
lda (ZPADDR6),y lda (ZPADDR6),y
bne @gridLoop bne @gridLoop
rts rts
@ -1026,7 +1061,7 @@ yPos: .BYTE $00
lda gridLeft lda gridLeft
cmp screenRight cmp screenRight
bcs @return bcs @return
ldy #$1 ldy #LEVEL_STRUCT_WIDTH
clc clc
adc (ZPADDR6),y adc (ZPADDR6),y
; If we got a carry, that means the width of the next grid plus ; If we got a carry, that means the width of the next grid plus
@ -1100,11 +1135,11 @@ yPos: .BYTE $00
@doNotIncHiByte: @doNotIncHiByte:
sta ZPADDR6 sta ZPADDR6
ldy #$1 ldy #LEVEL_STRUCT_WIDTH
lda (ZPADDR6),y lda (ZPADDR6),y
beq @return beq @return
ldy #$0 ldy #LEVEL_STRUCT_START
lda gridLeft lda gridLeft
clc clc
adc (ZPADDR6),y adc (ZPADDR6),y
@ -1126,7 +1161,7 @@ gridLeft: .BYTE $00
.proc drawGrid .proc drawGrid
ldy #$2 ldy #LEVEL_STRUCT_TOP
lda (ZPADDR6),y lda (ZPADDR6),y
tay tay
lda loAddrs,y lda loAddrs,y
@ -1165,7 +1200,7 @@ gridLeft: .BYTE $00
sta ZPADDR5+1 sta ZPADDR5+1
ldx gridXShift ldx gridXShift
ldy #$4 ldy #LEVEL_STRUCT_COLOUR
lda (ZPADDR6),y lda (ZPADDR6),y
tay tay
lda colourEvenLookup,y lda colourEvenLookup,y
@ -1177,7 +1212,7 @@ gridLeft: .BYTE $00
and oddGrid,x and oddGrid,x
sta oddGridVal sta oddGridVal
ldy #LEVEL_STRUCT_SIZE+1 ldy #LEVEL_STRUCT_SIZE+LEVEL_STRUCT_WIDTH
lda (ZPADDR6),y lda (ZPADDR6),y
bne @notLastGrid bne @notLastGrid
lda evenVal lda evenVal

Binary file not shown.