diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-10-10 16:04:35 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-10-10 16:04:35 -0400 |
commit | 0408674c94433e250363fc2b37a8be791cf4ac80 (patch) | |
tree | 3a0a2185160ca1757255a2e79c25875657344f3b | |
parent | f878e71db1f84259f899961a9e0341c6dac625b0 (diff) | |
download | nes-snake-0408674c94433e250363fc2b37a8be791cf4ac80.tar.gz nes-snake-0408674c94433e250363fc2b37a8be791cf4ac80.zip |
implement collisions with the snake body
-rw-r--r-- | main.s | 72 |
1 files changed, 70 insertions, 2 deletions
@@ -46,6 +46,8 @@ rand_out DB apple INSTANCEOF point vram_addr_low DB vram_addr_high DB +body_test_x DB +body_test_y DB .ENDE ; }}} ; }}} @@ -276,9 +278,10 @@ handle_frame: INX STX frame_count CPX frame_skip - BMI end_game_loop + BPL + + JMP end_game_loop - LDA #$00 ++ LDA #$00 STA frame_count set_offset: @@ -331,6 +334,18 @@ check_collisions CPY #$BD BCS collision + STX body_test_x + STY body_test_y + DEC head_x + DEC head_y + JSR test_body_collision + INC head_x + INC head_y + LDX body_test_x + LDY body_test_y + CMP #$01 + BEQ collision + CPX apple.x BEQ maybe_eat_apple @@ -574,6 +589,59 @@ draw_sprite_at_head: ; {{{ STA $2007 RTS ; }}} +test_body_collision ; {{{ + LDA head_x + PHA + LDA head_y + PHA + + LDA head_x + SEC + SBC length + TAX + INX + TXA + STA head_x + + LDA head_y + SEC + SBC length + TAX + INX + TXA + STA head_y + + LDY length + +- DEY + LDA (head_x), y + CMP body_test_x + BEQ maybe_collision_found + CPY #$00 + BNE - + JMP collision_not_found + +maybe_collision_found: + LDA (head_y), y + CMP body_test_y + BEQ collision_found + CPY #$00 + BNE - + JMP collision_not_found + +collision_found: + LDX #$01 + JMP test_body_collision_end +collision_not_found: + LDX #$00 + +test_body_collision_end: + PLA + STA head_y + PLA + STA head_x + TXA + RTS ; }}} rand4: ; {{{ JSR rand1 LDX rand_out |