From 6fd980e3427c27be3c7206003199c431f0eb4293 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 12 Sep 2024 14:18:39 -0400 Subject: [PATCH] climb: proper collision detection with bird --- games/peasant_mini/cliff/climb.s | 88 +++++++++++++++++++++++++++----- games/peasant_mini/cliff/zp.inc | 1 + 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/games/peasant_mini/cliff/climb.s b/games/peasant_mini/cliff/climb.s index b1452dc0..f84eef0e 100644 --- a/games/peasant_mini/cliff/climb.s +++ b/games/peasant_mini/cliff/climb.s @@ -280,19 +280,10 @@ new_bird_wider: move_bird: ;========================= - ; collision detect here? - - ; we're both 3 wide - ; be lazy and only see if they exactly match? - - lda PEASANT_X - cmp bird_x - bne no_bird_collision - - ; check height - ; we are 30 tall - ; bird is 15 or so + ; collision detect here + jsr bird_collide + bcc no_bird_collision ; collision happened! @@ -639,3 +630,76 @@ peasant_sprites_data_l = peasant_sprite_offset+68 peasant_sprites_data_h = peasant_sprite_offset+102 peasant_mask_data_l = peasant_sprite_offset+136 peasant_mask_data_h = peasant_sprite_offset+170 + + + ;=========================== + ; check for bird collisions + +bird_collide: + + ; bird is 3x16 + ; peasant is 3x30 + + ; doing a sort of Minkowski Sum collision detection here + ; with the rectangular regions + + ; might be faster to set it up so you can subtract, but that leads + ; to issues when we go negative and bcc/bcs are unsigned compares + + ; if (bird_x+1= bird_x+1) + + lda bird_x + sta TEMP_CENTER + inc TEMP_CENTER ; bird_x+1 + + sec + lda PEASANT_X + sbc #1 ; A is PEASANT_X-1 + cmp TEMP_CENTER ; compare with bird_x+1 + bcs bird_no_collide ; bge + + ; if (bird_x+1>=PEASANT_X+3) no collide + ; equivalent, if (bird_x-2>=PEASANT_X) + ; equivalent, if (PEASANT_X+3=bird_y+8) + + lda bird_y + clc + adc #8 + sta TEMP_CENTER + + lda PEASANT_Y + sec + sbc #8 ; A is now PEASANT_Y-8 + cmp TEMP_CENTER + bcs bird_no_collide ; blt + + ; if (bird_Y+8>=PEASANT_Y+38) no collide + ; equivalent, if (bird_y-30>=PEASANT_Y) + ; equivalent, if (PEASANT_Y+38