diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-10-09 13:29:49 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-10-09 13:29:49 -0400 |
commit | 2cef3f08d11c40dfe755a98b13f1702e5a503e9a (patch) | |
tree | 987e8c66e7b3b4451c80c135821399425904310d | |
parent | c892af763c8794ab0b3b8bccc2b5d409566b3c26 (diff) | |
download | nes-snake-2cef3f08d11c40dfe755a98b13f1702e5a503e9a.tar.gz nes-snake-2cef3f08d11c40dfe755a98b13f1702e5a503e9a.zip |
let the snake eat the apple
-rw-r--r-- | main.s | 59 |
1 files changed, 41 insertions, 18 deletions
@@ -291,23 +291,43 @@ apply_direction: check_collisions LDY #$00 LDA (head), y - CMP #$40 + TAX + LDY #$01 + LDA (head), y + TAY + + CPX #$40 BCC collision - CMP #$C0 + CPX #$C0 BCS collision - LDY #$01 - LDA (head), y - CMP #$3D + CPY #$3D BCC collision - CMP #$BD + CPY #$BD BCS collision + CPX apple.x + BEQ maybe_eat_apple + JMP end_game_loop collision: JSR end_game + JMP end_game_loop + +maybe_eat_apple: + CPY apple.y + BEQ eat_apple + + JMP end_game_loop + +eat_apple: + LDX length + INX + STX length + JSR new_apple + end_game_loop: RTS ; }}} read_controller1: ; {{{ @@ -344,18 +364,7 @@ start_game: ; {{{ LDY #$01 STA (head), y - JSR rand - LDA rand_state - AND #%01111000 - CLC - ADC #$40 - STA apple.x - JSR rand - LDA rand_state - AND #%01111000 - CLC - ADC #$3D - STA apple.y + JSR new_apple - BIT $2002 BPL - @@ -463,6 +472,20 @@ end_game: ; {{{ LDA #$00 STA game_state RTS ; }}} +new_apple: ; {{{ + JSR rand + LDA rand_state + AND #%01111000 + CLC + ADC #$40 + STA apple.x + JSR rand + LDA rand_state + AND #%01111000 + CLC + ADC #$3D + STA apple.y + RTS ; }}} rand: ; {{{ ; linear feedback shift register with taps at 8, 6, 5, and 4 LDY rand_state |