From 2c116d9f71e9667c395b13f5b4257b9c5c488eef Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 24 Aug 2021 14:32:04 -0400 Subject: [PATCH] peasant: collision sort of works --- games/peasant/gr_offsets.s | 5 ++ games/peasant/peasant_move.s | 120 ++++++++++++++++++++++++++++++++--- games/peasant/zp.inc | 1 + 3 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 games/peasant/gr_offsets.s diff --git a/games/peasant/gr_offsets.s b/games/peasant/gr_offsets.s new file mode 100644 index 00000000..d3af91f7 --- /dev/null +++ b/games/peasant/gr_offsets.s @@ -0,0 +1,5 @@ +gr_offsets: + .word $400,$480,$500,$580,$600,$680,$700,$780 + .word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8 + .word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0 + diff --git a/games/peasant/peasant_move.s b/games/peasant/peasant_move.s index 3b50f72c..542f92ae 100644 --- a/games/peasant/peasant_move.s +++ b/games/peasant/peasant_move.s @@ -6,7 +6,11 @@ move_peasant: lda PEASANT_XADD ora PEASANT_YADD - beq peasant_the_same + bne really_move_peasant + + jmp peasant_the_same + +really_move_peasant: ; restore bg behind peasant @@ -22,11 +26,28 @@ move_peasant: clc lda PEASANT_X - adc PEASANT_XADD - bmi peasant_x_negative + adc PEASANT_XADD ; A = new X + + bmi peasant_x_negative ; if newx <0, handle + cmp #40 - bcs peasant_x_toobig ; bge - bcc done_movex + bcs peasant_x_toobig ; if newx>=40, hanfle (bge) + + pha + + tay + ldx PEASANT_Y + jsr peasant_collide + + pla + + bcc done_movex ; no collide + + jsr stop_peasant ; stop moving + + lda PEASANT_X ; leave same + + jmp done_movex ;============================ peasant_x_toobig: @@ -59,12 +80,31 @@ done_movex: clc lda PEASANT_Y - adc PEASANT_YADD - cmp #45 + adc PEASANT_YADD ; newy in A + + cmp #45 ; if <45 then off screen bcc peasant_y_negative ; blt - cmp #150 + + cmp #150 ; if >=150 then off screen bcs peasant_y_toobig ; bge - bcc done_movey + + ; check collide + + pha + + ldy PEASANT_X + tax ; newy + jsr peasant_collide + + pla + + bcc done_movey ; no collide + + jsr stop_peasant ; stop moving + + lda PEASANT_Y ; leave same + + jmp done_movey ;============================ @@ -117,3 +157,65 @@ peasant_the_same: rts + + +; when peasants collide + + ;=================== + ; peasant_collide + ;=================== + ; newx/7 in Y + ; newy in X + ; returns C=0 if no collide + ; C=1 if collide +peasant_collide: + ; rrrr rtii top 5 bits row, bit 2 top/bottom + + ; add 28 to collide with feet + txa + clc + adc #28 + tax + + txa + and #$04 ; see if odd/even + beq peasant_collide_even + +peasant_collide_odd: + lda #$f0 + bne peasant_collide_mask ; bra + +peasant_collide_even: + lda #$0f +peasant_collide_mask: + + sta MASK + + txa + lsr + lsr ; need to divide by 8 then * 2 + lsr ; can't just div by 4 as we need to mask bottom bit + asl + tax + + lda gr_offsets,X + sta INL + lda gr_offsets+1,X + sta INH + + lda (INL),Y + and MASK + beq collide_true ; true if color 0 + ;bne collide_false + +collide_false: + clc + rts + +collide_true: + sec + rts + + + +.include "gr_offsets.s" diff --git a/games/peasant/zp.inc b/games/peasant/zp.inc index 02fdb726..9bd94476 100644 --- a/games/peasant/zp.inc +++ b/games/peasant/zp.inc @@ -11,6 +11,7 @@ HGR_BITS = $1C GBASL = $26 GBASH = $27 +MASK = $2E PEASANT_X = $60 PEASANT_Y = $61