diff --git a/games/peasant_mini/cliff/climb.s b/games/peasant_mini/cliff/climb.s index d8c28c41..5950ff35 100644 --- a/games/peasant_mini/cliff/climb.s +++ b/games/peasant_mini/cliff/climb.s @@ -316,9 +316,27 @@ move_bird_done: ldx #0 stx CURRENT_ROCK + move_rock_loop: + ldx CURRENT_ROCK + lda PEASANT_FALLING + bne no_rock_collision + + ; collision detect + + jsr rock_collide + bcc no_rock_collision + + ; collision happened! + + lda #1 + sta PEASANT_FALLING + +no_rock_collision: + + lda rock_state,X beq move_rock_normal cmp #3 @@ -833,3 +851,158 @@ bird_no_collide: clc rts + + + + ;=========================== + ; check for rock collisions + ;=========================== + ; which rock in X + +rock_collide: + + ; 0 = bit, 1 = little + lda rock_type,X + bne little_rock_collide + + + ;=========================== + ; big rock collide + +big_rock_collide: + + ; big rock is 3x22 + ; little rock is 2x14 + ; 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 (rock_x+1= rock_x+1) + + lda rock_x,X + sta TEMP_CENTER + inc TEMP_CENTER ; rock_x+1 + + sec + lda PEASANT_X + sbc #1 ; A is PEASANT_X-1 + cmp TEMP_CENTER ; compare with rock_x+1 + bcs rock_no_collide ; bge + + ; if (rock_x+1>=PEASANT_X+3) no collide + ; equivalent, if (rock_x-2>=PEASANT_X) + ; equivalent, if (PEASANT_X+3=rock_y+11) + + lda rock_y,X + clc + adc #11 + sta TEMP_CENTER + + lda PEASANT_Y + sec + sbc #11 ; A is now PEASANT_Y-11 + cmp TEMP_CENTER + bcs rock_no_collide ; blt + + ; if (rock_Y+11>=PEASANT_Y+41) no collide + ; equivalent, if (rock_y-30>=PEASANT_Y) + ; equivalent, if (PEASANT_Y+41= rock_x+2) no collide + + ; rr + ; ppp + + lda rock_x,X + sta TEMP_CENTER + inc TEMP_CENTER ; rock_x+1 + inc TEMP_CENTER ; rock_x+2 + + sec + lda PEASANT_X ; A is PEASANT_X + cmp TEMP_CENTER ; compare with rock_x+1 + bcs rock_no_collide ; bge + + + ; if (PEASANT_X+3=rock_y+7) + + lda rock_y,X + clc + adc #7 + sta TEMP_CENTER + + lda PEASANT_Y + sec + sbc #7 ; A is now PEASANT_Y-7 + cmp TEMP_CENTER + bcs rock_no_collide ; blt + + ; if (rock_Y+7>=PEASANT_Y+37) no collide + ; equivalent, if (rock_y-30>=PEASANT_Y) + ; equivalent, if (PEASANT_Y+37