peasant: can more or less walk around like in original

This commit is contained in:
Vince Weaver 2021-08-15 12:18:17 -04:00
parent 361b623763
commit 12beab8608
6 changed files with 468 additions and 71 deletions

View File

@ -87,9 +87,7 @@ peasant.o: peasant.s graphics/graphics.inc sprites/peasant_sprite.inc \
draw_box.s hgr_rectangle.s hgr_font.s hgr_input.s \
hgr_7x30_sprite.s hgr_1x5_sprite.s hgr_save_restore.s \
wait_a_bit.s draw_peasant.s hgr_text_box.s \
title.s directions.s \
intro_cottage.s intro_lake_w.s intro_lake_e.s \
intro_river.s intro_knight.s
keyboard.s
ca65 -o peasant.o peasant.s -l peasant.lst

View File

@ -11,6 +11,12 @@ draw_peasant:
lda PEASANT_DIR
cmp #PEASANT_DIR_RIGHT
beq peasant_right
cmp #PEASANT_DIR_LEFT
beq peasant_left
cmp #PEASANT_DIR_DOWN
beq peasant_down
; else we are up
;=====================
; up up up up
@ -33,6 +39,47 @@ peasant_up1:
lda #>peasant_up1_sprite
jmp done_pick_draw
;=====================
; down down down
peasant_down:
lda FRAME
and #1
beq peasant_down1
peasant_down2:
lda #<peasant_down2_sprite
sta INL
lda #>peasant_down2_sprite
jmp done_pick_draw
peasant_down1:
lda #<peasant_down1_sprite
sta INL
lda #>peasant_down1_sprite
jmp done_pick_draw
;=====================
; left left left
peasant_left:
lda CURSOR_X
and #1
bne draw_left1
draw_left2:
lda #<peasant_left2_sprite
sta INL
lda #>peasant_left2_sprite
jmp done_pick_draw
draw_left1:
lda #<peasant_left1_sprite
sta INL
lda #>peasant_left1_sprite
jmp done_pick_draw
peasant_right:
lda CURSOR_X

151
games/peasant/keyboard.s Normal file
View File

@ -0,0 +1,151 @@
;==========================
; check keyboard
; for main game
;==========================
; Movement
; Note in the game, pressing a key starts walking
; To stop you have to press the same direction again
; Text
; We require ENTER/RETURN pressed before entering text
; this is mildly annoying, but lets us use
; WASD to walk. The Apple II+ doesn't have
; up or down buttons
check_keyboard:
lda KEYPRESS
bmi key_was_pressed
rts
key_was_pressed:
and #$7f ; strip off high bit
;==========================
; Left
;==========================
check_left:
cmp #$8
beq left_pressed
cmp #'A'
bne check_right
left_pressed: ; if peasant_moving_left, stop
; otherwise clear all movement, move left
ldx PEASANT_XADD
jsr stop_peasant
cpx #$FF ; if not left, start moving left
beq continue_left
lda #$FF ; move left
sta PEASANT_XADD
continue_left:
lda #PEASANT_DIR_LEFT
sta PEASANT_DIR
jmp done_check_keyboard
check_right:
cmp #$15
beq right_pressed
cmp #'D'
bne check_up
right_pressed:
ldx PEASANT_XADD
jsr stop_peasant
cpx #$1 ; if already right, stop
beq continue_right
lda #$1
sta PEASANT_XADD
continue_right:
lda #PEASANT_DIR_RIGHT
sta PEASANT_DIR
jmp done_check_keyboard
check_up:
cmp #'W'
beq up_pressed
cmp #$0B
bne check_down
up_pressed:
ldx PEASANT_YADD
jsr stop_peasant
cpx #$FC ; if already up, stop
beq continue_up
lda #$FC
sta PEASANT_YADD
continue_up:
lda #PEASANT_DIR_UP
sta PEASANT_DIR
jmp done_check_keyboard
check_down:
cmp #'S'
beq down_pressed
cmp #$0A
bne check_enter
down_pressed:
ldx PEASANT_YADD
jsr stop_peasant
cpx #$04 ; if already down, stop
beq continue_down
lda #$4
sta PEASANT_YADD
continue_down:
lda #PEASANT_DIR_DOWN
sta PEASANT_DIR
jmp done_check_keyboard
check_enter:
cmp #13
beq enter_pressed
cmp #' '
bne done_check_keyboard
enter_pressed:
jsr clear_bottom
jsr hgr_input
jsr parse_input
jsr clear_bottom
done_check_keyboard:
bit KEYRESET
rts
stop_peasant:
lda #0
sta PEASANT_XADD
sta PEASANT_YADD
rts

View File

@ -189,74 +189,6 @@ exit_copy_check:
rts
check_keyboard:
lda KEYPRESS
bmi key_was_pressed
rts
key_was_pressed:
and #$7f ; strip off high bit
check_left:
cmp #$8
beq left_pressed
cmp #'A'
bne check_right
left_pressed:
lda #$FF ; move left
sta PEASANT_XADD
jmp done_check_keyboard
check_right:
cmp #$15
beq right_pressed
cmp #'D'
bne check_up
right_pressed:
lda #$1
sta PEASANT_XADD
jmp done_check_keyboard
check_up:
cmp #'W'
bne check_down
lda #$FF
sta PEASANT_YADD
jmp done_check_keyboard
check_down:
cmp #'S'
bne check_enter
lda #$1
sta PEASANT_YADD
jmp done_check_keyboard
check_enter:
cmp #13
beq enter_pressed
cmp #' '
bne done_check_keyboard
enter_pressed:
jsr clear_bottom
jsr hgr_input
jsr parse_input
jsr clear_bottom
done_check_keyboard:
bit KEYRESET
rts
peasant_text:
.byte 25,2,"Peasant's Quest",0
@ -326,6 +258,8 @@ done_parse_message:
.include "hgr_tables.s"
.include "hgr_text_box.s"
.include "keyboard.s"
.include "wait_a_bit.s"
.include "graphics/graphics.inc"

View File

@ -261,3 +261,270 @@ peasant_up2_mask:
.byte $4F
.byte $7F
.byte $7F
; 84 1 90 31
peasant_left1_sprite:
.byte $00
.byte $00
.byte $00
.byte $01
.byte $01
.byte $01
.byte $07
.byte $18
.byte $00
.byte $00
.byte $00
.byte $18
.byte $18
.byte $18
.byte $1C
.byte $07
.byte $AB
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $18
.byte $1E
.byte $78
.byte $78
.byte $78
.byte $1C
.byte $00
.byte $00
; 70 1 76 31
peasant_left1_mask:
.byte $60
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $67
.byte $07
.byte $07
.byte $07
.byte $07
.byte $07
.byte $07
.byte $03
.byte $00
.byte $00
.byte $07
.byte $07
.byte $60
.byte $60
.byte $60
.byte $60
.byte $61
.byte $07
.byte $07
.byte $07
.byte $63
.byte $7F
.byte $7F
; 84 34 90 65
peasant_left2_sprite:
.byte $80
.byte $80
.byte $80
.byte $81
.byte $81
.byte $81
.byte $87
.byte $18
.byte $00
.byte $00
.byte $00
.byte $18
.byte $18
.byte $58
.byte $5F
.byte $47
.byte $E8
.byte $00
.byte $00
.byte $00
.byte $80
.byte $80
.byte $98
.byte $1C
.byte $73
.byte $63
.byte $63
.byte $7B
.byte $00
.byte $00
; 70 34 76 65
peasant_left2_mask:
.byte $60
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $67
.byte $43
.byte $43
.byte $43
.byte $43
.byte $43
.byte $03
.byte $00
.byte $00
.byte $03
.byte $C3
.byte $C3
.byte $E3
.byte $E0
.byte $E0
.byte $E0
.byte $60
.byte $0C
.byte $1C
.byte $1C
.byte $04
.byte $7F
.byte $7F
; 84 68 90 99
peasant_down1_sprite:
.byte $00
.byte $00
.byte $1E
.byte $0C
.byte $1E
.byte $12
.byte $1E
.byte $0C
.byte $00
.byte $00
.byte $00
.byte $33
.byte $33
.byte $33
.byte $33
.byte $33
.byte $BB
.byte $03
.byte $00
.byte $00
.byte $00
.byte $00
.byte $30
.byte $33
.byte $33
.byte $33
.byte $33
.byte $03
.byte $00
.byte $00
; 70 68 76 99
peasant_down1_mask:
.byte $73
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $73
.byte $61
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $4C
.byte $4C
.byte $4C
.byte $4C
.byte $4C
.byte $7C
.byte $7F
.byte $7F
; 84 102 90 133
peasant_down2_sprite:
.byte $00
.byte $00
.byte $1E
.byte $0C
.byte $1E
.byte $12
.byte $1E
.byte $0C
.byte $00
.byte $00
.byte $00
.byte $33
.byte $33
.byte $33
.byte $33
.byte $33
.byte $BB
.byte $30
.byte $00
.byte $00
.byte $00
.byte $00
.byte $03
.byte $33
.byte $33
.byte $33
.byte $33
.byte $30
.byte $00
.byte $00
; 70 102 76 133
peasant_down2_mask:
.byte $73
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $73
.byte $61
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $40
.byte $4C
.byte $4C
.byte $4C
.byte $4C
.byte $4C
.byte $4F
.byte $7F
.byte $7F

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 13 KiB