aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-09 13:29:49 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-09 13:29:49 -0400
commit2cef3f08d11c40dfe755a98b13f1702e5a503e9a (patch)
tree987e8c66e7b3b4451c80c135821399425904310d
parentc892af763c8794ab0b3b8bccc2b5d409566b3c26 (diff)
downloadnes-snake-2cef3f08d11c40dfe755a98b13f1702e5a503e9a.tar.gz
nes-snake-2cef3f08d11c40dfe755a98b13f1702e5a503e9a.zip
let the snake eat the apple
-rw-r--r--main.s59
1 files changed, 41 insertions, 18 deletions
diff --git a/main.s b/main.s
index 55948b4..f5b4e2c 100644
--- a/main.s
+++ b/main.s
@@ -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