From d9b6fe05b381dac783cca95719a609aa69135a77 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 24 Aug 2021 13:52:11 -0400 Subject: [PATCH] peasant: centralize move code --- games/peasant/Makefile | 13 ++-- games/peasant/peasant1.s | 116 +--------------------------------- games/peasant/peasant2.s | 115 +-------------------------------- games/peasant/peasant3.s | 116 +--------------------------------- games/peasant/peasant4.s | 118 +--------------------------------- games/peasant/peasant_move.s | 119 +++++++++++++++++++++++++++++++++++ 6 files changed, 138 insertions(+), 459 deletions(-) create mode 100644 games/peasant/peasant_move.s diff --git a/games/peasant/Makefile b/games/peasant/Makefile index 97a85cd8..dbe020a3 100644 --- a/games/peasant/Makefile +++ b/games/peasant/Makefile @@ -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 diff --git a/games/peasant/peasant1.s b/games/peasant/peasant1.s index 24dfa431..414c2378 100644 --- a/games/peasant/peasant1.s +++ b/games/peasant/peasant1.s @@ -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" diff --git a/games/peasant/peasant2.s b/games/peasant/peasant2.s index e2d851f3..7a00fd37 100644 --- a/games/peasant/peasant2.s +++ b/games/peasant/peasant2.s @@ -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" diff --git a/games/peasant/peasant3.s b/games/peasant/peasant3.s index c291ea26..1266eca2 100644 --- a/games/peasant/peasant3.s +++ b/games/peasant/peasant3.s @@ -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" diff --git a/games/peasant/peasant4.s b/games/peasant/peasant4.s index 2b8312a6..e270bf3c 100644 --- a/games/peasant/peasant4.s +++ b/games/peasant/peasant4.s @@ -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" diff --git a/games/peasant/peasant_move.s b/games/peasant/peasant_move.s new file mode 100644 index 00000000..3b50f72c --- /dev/null +++ b/games/peasant/peasant_move.s @@ -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 +