peasant: centralize move code

This commit is contained in:
Vince Weaver 2021-08-24 13:52:11 -04:00
parent 814d465eaa
commit d9b6fe05b3
6 changed files with 138 additions and 459 deletions

View File

@ -94,7 +94,8 @@ peasant1.o: peasant1.s zp.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 \
keyboard.s parse_input.s new_map_location.s
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
ca65 -o peasant1.o peasant1.s -l peasant1.lst
###
@ -107,7 +108,9 @@ peasant2.o: peasant2.s zp.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 \
keyboard.s parse_input.s new_map_location.s
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
ca65 -o peasant2.o peasant2.s -l peasant2.lst
###
@ -120,7 +123,8 @@ peasant3.o: peasant3.s zp.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 \
keyboard.s parse_input.s new_map_location.s
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
ca65 -o peasant3.o peasant3.s -l peasant3.lst
###
@ -133,7 +137,8 @@ peasant4.o: peasant4.s zp.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 \
keyboard.s parse_input.s new_map_location.s
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
ca65 -o peasant4.o peasant4.s -l peasant4.lst

View File

@ -118,119 +118,7 @@ new_location:
game_loop:
; redraw peasant if moved
lda PEASANT_XADD
ora PEASANT_YADD
beq peasant_the_same
; restore bg behind peasant
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr restore_bg_7x30
; move peasant
clc
lda PEASANT_X
adc PEASANT_XADD
bmi peasant_x_negative
cmp #40
bcs peasant_x_toobig ; bge
bcc done_movex
;============================
peasant_x_toobig:
inc MAP_X
jsr new_map_location
lda #0 ; new X location
jmp done_movex
;============================
peasant_x_negative:
dec MAP_X
jsr new_map_location
lda #39 ; new X location
jmp done_movex
; check edge of screen
done_movex:
sta PEASANT_X
; Move Peasant Y
clc
lda PEASANT_Y
adc PEASANT_YADD
cmp #45
bcc peasant_y_negative ; blt
cmp #150
bcs peasant_y_toobig ; bge
bcc done_movey
;============================
peasant_y_toobig:
inc MAP_Y
jsr new_map_location
lda #45 ; new X location
jmp done_movey
;============================
peasant_y_negative:
dec MAP_Y
jsr new_map_location
lda #150 ; new X location
jmp done_movey
; check edge of screen
done_movey:
sta PEASANT_Y
lda GAME_OVER
bne game_over
; save behind new position
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr save_bg_7x30
; draw peasant
jsr draw_peasant
peasant_the_same:
jsr move_peasant
inc FRAME
@ -292,6 +180,8 @@ score_text:
.include "new_map_location.s"
.include "peasant_move.s"
.include "parse_input.s"
.include "keyboard.s"

View File

@ -118,119 +118,7 @@ new_location:
game_loop:
; redraw peasant if moved
lda PEASANT_XADD
ora PEASANT_YADD
beq peasant_the_same
; restore bg behind peasant
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr restore_bg_7x30
; move peasant
clc
lda PEASANT_X
adc PEASANT_XADD
bmi peasant_x_negative
cmp #40
bcs peasant_x_toobig ; bge
bcc done_movex
;============================
peasant_x_toobig:
inc MAP_X
jsr new_map_location
lda #0 ; new X location
jmp done_movex
;============================
peasant_x_negative:
dec MAP_X
jsr new_map_location
lda #39 ; new X location
jmp done_movex
; check edge of screen
done_movex:
sta PEASANT_X
; Move Peasant Y
clc
lda PEASANT_Y
adc PEASANT_YADD
cmp #45
bcc peasant_y_negative ; blt
cmp #150
bcs peasant_y_toobig ; bge
bcc done_movey
;============================
peasant_y_toobig:
inc MAP_Y
jsr new_map_location
lda #45 ; new X location
jmp done_movey
;============================
peasant_y_negative:
dec MAP_Y
jsr new_map_location
lda #150 ; new X location
jmp done_movey
; check edge of screen
done_movey:
sta PEASANT_Y
lda GAME_OVER
bne game_over
; save behind new position
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr save_bg_7x30
; draw peasant
jsr draw_peasant
peasant_the_same:
jsr move_peasant
inc FRAME
@ -291,6 +179,7 @@ score_text:
.include "gr_copy.s"
.include "new_map_location.s"
.include "peasant_move.s"
.include "parse_input.s"

View File

@ -117,120 +117,7 @@ new_location:
game_loop:
; redraw peasant if moved
lda PEASANT_XADD
ora PEASANT_YADD
beq peasant_the_same
; restore bg behind peasant
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr restore_bg_7x30
; move peasant
clc
lda PEASANT_X
adc PEASANT_XADD
bmi peasant_x_negative
cmp #40
bcs peasant_x_toobig ; bge
bcc done_movex
;============================
peasant_x_toobig:
inc MAP_X
jsr new_map_location
lda #0 ; new X location
jmp done_movex
;============================
peasant_x_negative:
dec MAP_X
jsr new_map_location
lda #39 ; new X location
jmp done_movex
; check edge of screen
done_movex:
sta PEASANT_X
; Move Peasant Y
clc
lda PEASANT_Y
adc PEASANT_YADD
cmp #45
bcc peasant_y_negative ; blt
cmp #150
bcs peasant_y_toobig ; bge
bcc done_movey
;============================
peasant_y_toobig:
inc MAP_Y
jsr new_map_location
lda #45 ; new X location
jmp done_movey
;============================
peasant_y_negative:
dec MAP_Y
jsr new_map_location
lda #150 ; new X location
jmp done_movey
; check edge of screen
done_movey:
sta PEASANT_Y
lda GAME_OVER
bne game_over
; save behind new position
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr save_bg_7x30
; draw peasant
jsr draw_peasant
peasant_the_same:
jsr move_peasant
inc FRAME
@ -290,6 +177,7 @@ score_text:
.include "gr_copy.s"
.include "new_map_location.s"
.include "peasant_move.s"
.include "parse_input.s"

View File

@ -117,121 +117,7 @@ new_location:
game_loop:
; redraw peasant if moved
lda PEASANT_XADD
ora PEASANT_YADD
beq peasant_the_same
; restore bg behind peasant
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr restore_bg_7x30
; move peasant
clc
lda PEASANT_X
adc PEASANT_XADD
bmi peasant_x_negative
cmp #40
bcs peasant_x_toobig ; bge
bcc done_movex
;============================
peasant_x_toobig:
inc MAP_X
jsr new_map_location
lda #0 ; new X location
jmp done_movex
;============================
peasant_x_negative:
dec MAP_X
jsr new_map_location
lda #39 ; new X location
jmp done_movex
; check edge of screen
done_movex:
sta PEASANT_X
; Move Peasant Y
clc
lda PEASANT_Y
adc PEASANT_YADD
cmp #45
bcc peasant_y_negative ; blt
cmp #150
bcs peasant_y_toobig ; bge
bcc done_movey
;============================
peasant_y_toobig:
inc MAP_Y
jsr new_map_location
lda #45 ; new X location
jmp done_movey
;============================
peasant_y_negative:
dec MAP_Y
jsr new_map_location
lda #150 ; new X location
jmp done_movey
; check edge of screen
done_movey:
sta PEASANT_Y
lda GAME_OVER
bne game_over
; save behind new position
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr save_bg_7x30
; draw peasant
jsr draw_peasant
peasant_the_same:
jsr move_peasant
inc FRAME
@ -291,6 +177,8 @@ score_text:
.include "gr_copy.s"
.include "peasant_move.s"
.include "new_map_location.s"
.include "parse_input.s"

View File

@ -0,0 +1,119 @@
; Move that Peasant!
move_peasant:
; redraw peasant if moved
lda PEASANT_XADD
ora PEASANT_YADD
beq peasant_the_same
; restore bg behind peasant
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr restore_bg_7x30
; move peasant
clc
lda PEASANT_X
adc PEASANT_XADD
bmi peasant_x_negative
cmp #40
bcs peasant_x_toobig ; bge
bcc done_movex
;============================
peasant_x_toobig:
inc MAP_X
jsr new_map_location
lda #0 ; new X location
jmp done_movex
;============================
peasant_x_negative:
dec MAP_X
jsr new_map_location
lda #39 ; new X location
jmp done_movex
; check edge of screen
done_movex:
sta PEASANT_X
; Move Peasant Y
clc
lda PEASANT_Y
adc PEASANT_YADD
cmp #45
bcc peasant_y_negative ; blt
cmp #150
bcs peasant_y_toobig ; bge
bcc done_movey
;============================
peasant_y_toobig:
inc MAP_Y
jsr new_map_location
lda #45 ; new X location
jmp done_movey
;============================
peasant_y_negative:
dec MAP_Y
jsr new_map_location
lda #150 ; new X location
jmp done_movey
; check edge of screen
done_movey:
sta PEASANT_Y
; if we moved off screen, don't re-draw peasant
lda GAME_OVER
bne peasant_the_same
; save behind new position
lda PEASANT_X
sta CURSOR_X
lda PEASANT_Y
sta CURSOR_Y
jsr save_bg_7x30
; draw peasant
jsr draw_peasant
peasant_the_same:
rts