climb: update keyboard handling

This commit is contained in:
Vince Weaver 2024-09-08 00:15:55 -04:00
parent 26f4d89f3e
commit e9822cfffc
7 changed files with 172 additions and 29 deletions

View File

@ -47,10 +47,16 @@ CLIMB: climb.o
climb.o: climb.s zx02_optim.s \ climb.o: climb.s zx02_optim.s \
move_peasant_climb.s draw_peasant_climb.s \ move_peasant_climb.s draw_peasant_climb.s \
keyboard_climb.s \
hgr_copy.s hgr_partial_restore.s \ hgr_copy.s hgr_partial_restore.s \
hgr_sprite.s hgr_sprite_bg_mask.s \ hgr_sprite.s hgr_sprite_bg_mask.s \
random16.s \ random16.s \
cliff_graphics/cliff_base.hgr.zx02 \ cliff_graphics/cliff_base.hgr.zx02 \
cliff_graphics/cliff2.hgr.zx02 \
cliff_graphics/cliff3.hgr.zx02 \
cliff_graphics/cliff_base_priority.zx02 \
cliff_graphics/cliff2_priority.zx02 \
cliff_graphics/cliff3_priority.zx02 \
sprites/enemy_sprites.inc \ sprites/enemy_sprites.inc \
zp.inc hardware.inc \ zp.inc hardware.inc \
climbing_sprites.zx02 climbing_sprites.zx02

View File

@ -37,6 +37,7 @@ cliff_climb:
sta ERASE_SPRITE_COUNT sta ERASE_SPRITE_COUNT
sta PEASANT_STEPS sta PEASANT_STEPS
sta FLAME_COUNT sta FLAME_COUNT
sta CLIMB_COUNT
lda #10 lda #10
sta PEASANT_X sta PEASANT_X
@ -411,7 +412,7 @@ done_cliff:
.include "zx02_optim.s" .include "zx02_optim.s"
.include "keyboard.s" .include "keyboard_climb.s"
.include "draw_peasant_climb.s" .include "draw_peasant_climb.s"
@ -426,11 +427,17 @@ done_cliff:
.include "random16.s" .include "random16.s"
.include "gr_offsets.s"
bg_data: bg_data:
.incbin "cliff_graphics/cliff_base.hgr.zx02" .incbin "cliff_graphics/cliff_base.hgr.zx02"
.incbin "cliff_graphics/cliff2.hgr.zx02"
.incbin "cliff_graphics/cliff3.hgr.zx02"
priority_data: priority_data:
.incbin "cliff_graphics/cliff_base_priority.zx02" .incbin "cliff_graphics/cliff_base_priority.zx02"
.incbin "cliff_graphics/cliff2_priority.zx02"
.incbin "cliff_graphics/cliff3_priority.zx02"
sprites: sprites:
.include "sprites/enemy_sprites.inc" .include "sprites/enemy_sprites.inc"

View File

@ -20,7 +20,7 @@ draw_peasant_climb:
ldx PEASANT_DIR ldx PEASANT_DIR
lda peasant_climb_offsets,X lda peasant_climb_offsets,X
clc clc
adc PEASANT_STEPS adc CLIMB_COUNT
tax tax
ldy #4 ; reserved for peasant ldy #4 ; reserved for peasant

View File

@ -0,0 +1,118 @@
;==========================
; check keyboard
; for climbig part
;==========================
; note, this is different from the rest of the game
; pushing l/r/u/d only does one 5-frame animation of movement
;
; pressing another key while movement underway does not
; cancel/override
;
; holding down key just restarts from scratch
check_keyboard:
lda KEYPRESS
bmi key_was_pressed
rts
key_was_pressed:
inc SEEDL ; ????
and #$5f ; strip off high bit and make uppercase
;===========================
; check moving
;===========================
; only start moving if currently not
check_moving:
ldx CLIMB_COUNT
beq check_left
done_check_moving:
jmp done_check_keyboard
;==========================
; Left
;==========================
check_left:
cmp #$8
beq left_pressed
cmp #'A'
bne check_right
left_pressed:
lda #PEASANT_DIR_LEFT
sta PEASANT_DIR
lda #$FF
sta PEASANT_XADD
bne done_keyboard_reset ; bra
check_right:
cmp #$15
beq right_pressed
cmp #'D'
bne check_up
right_pressed:
lda #PEASANT_DIR_RIGHT
sta PEASANT_DIR
lda #$1
sta PEASANT_XADD
bne done_keyboard_reset ; bra
check_up:
cmp #'W'
beq up_pressed
cmp #$0B
bne check_down
up_pressed:
lda #PEASANT_DIR_UP
sta PEASANT_DIR
lda #$FC
sta PEASANT_YADD
bne done_keyboard_reset ; bra
check_down:
cmp #'S'
beq down_pressed
cmp #$0A
bne check_enter
down_pressed:
lda #PEASANT_DIR_DOWN
sta PEASANT_DIR
lda #$4
sta PEASANT_YADD
bne done_keyboard_reset ; bra
check_enter:
cmp #13
beq enter_pressed
cmp #' '
bne done_check_keyboard
enter_pressed:
done_keyboard_reset:
lda #4
sta CLIMB_COUNT ; start climbing
bit KEYRESET
done_check_keyboard:
; bit KEYRESET ; should we?
rts

View File

@ -5,7 +5,7 @@ move_peasant:
; redraw peasant if moved ; redraw peasant if moved
lda PEASANT_XADD lda PEASANT_XADD
ora PEASANT_YADD ora PEASANT_YADD ; sneaky way to see if both nonzero
bne really_move_peasant bne really_move_peasant
jmp peasant_the_same jmp peasant_the_same

View File

@ -4,20 +4,22 @@ move_peasant:
; redraw peasant if moved ; redraw peasant if moved
lda PEASANT_XADD lda CLIMB_COUNT
ora PEASANT_YADD
bne really_move_peasant bne really_move_peasant
jmp peasant_the_same jmp peasant_the_same
really_move_peasant: really_move_peasant:
; increment step count, wrapping at 4 ; decrement climb count
inc PEASANT_STEPS dec CLIMB_COUNT
lda PEASANT_STEPS bne climb_continue
and #3 climb_stop:
sta PEASANT_STEPS
jsr stop_peasant
climb_continue:
; restore bg behind peasant ; restore bg behind peasant
@ -37,10 +39,12 @@ really_move_peasant:
lda PEASANT_X lda PEASANT_X
adc PEASANT_XADD ; A = new X adc PEASANT_XADD ; A = new X
bmi peasant_x_negative ; if newx <0, handle ; in theory this can't happen when climbing
cmp #40 ; bmi peasant_x_negative ; if newx <0, handle
bcs peasant_x_toobig ; if newx>=40, hanfle (bge)
; cmp #40
; bcs peasant_x_toobig ; if newx>=40, handle (bge)
;====================================== ;======================================
@ -68,28 +72,28 @@ really_move_peasant:
jmp do_move_peasant_y jmp do_move_peasant_y
;============================ ;============================
peasant_x_toobig: ;peasant_x_toobig:
jsr move_map_east ; jsr move_map_east
lda #0 ; new X location ; lda #0 ; new X location
jmp done_movex ; jmp done_movex
;============================ ;============================
peasant_x_negative: ;peasant_x_negative:
jsr move_map_west ; jsr move_map_west
lda #39 ; new X location ; lda #39 ; new X location
jmp done_movex ; jmp done_movex
; check edge of screen ; check edge of screen
done_movex: ;done_movex:
; if we get here we changed screens ; if we get here we changed screens
sta PEASANT_X ; update new location ; sta PEASANT_X ; update new location
jmp peasant_the_same ; skip checking for Y collision ; jmp peasant_the_same ; skip checking for Y collision
@ -100,9 +104,12 @@ do_move_peasant_y:
lda PEASANT_Y lda PEASANT_Y
adc PEASANT_YADD ; newy in A adc PEASANT_YADD ; newy in A
cmp #45 ; if <45 then off screen cmp #12 ; if <12 then off screen
bcc peasant_y_negative ; blt bcc peasant_y_negative ; blt
; FIXME: in theory can never go down
cmp #160 ; if >=150 then off screen cmp #160 ; if >=150 then off screen
bcs peasant_y_toobig ; bge bcs peasant_y_toobig ; bge
@ -130,7 +137,7 @@ peasant_y_toobig:
jsr move_map_south jsr move_map_south
lda #45 ; new X location lda #12 ; new Y location
jmp done_movey jmp done_movey
@ -140,7 +147,7 @@ peasant_y_negative:
jsr move_map_north jsr move_map_north
lda #160 ; new X location lda #160 ; new Y location
jmp done_movey jmp done_movey
@ -254,5 +261,9 @@ move_map_south:
rts rts
.include "gr_offsets.s" stop_peasant:
lda #0
sta PEASANT_XADD
sta PEASANT_YADD
sta PEASANT_DIR ; PEASANT_UP is 0
rts

View File

@ -271,6 +271,7 @@ CURRENT_DISK = $DC
HGR_COLOR = $E4 HGR_COLOR = $E4
HGR_PAGE = $E6 HGR_PAGE = $E6
CLIMB_COUNT = $ED
FLAME_COUNT = $EE FLAME_COUNT = $EE
CURRENT_ROCK = $EF CURRENT_ROCK = $EF
ERASE_SPRITE_COUNT = $F0 ERASE_SPRITE_COUNT = $F0