LAB 3 PART 3
Now that was a lot of code! as you can see I have had to separate the code into three posts. This program works by first executing two sub routines that are going to initialize the memory (init, loop) which will set the game state and the loop is going to call the subroutines of the program and execute them in order before looping back and and repeating. I like the way this program is broken down into different sub routines like functions it makes it easier to follow.
I Changed the controls from the original and also added a way to add a second value called SnakeLengthTwo it increased the size by double but the issue was that when it was added is that from where the last apple was that was eaten the tail value stays at that location in memory and the snake moves but just grows at a rapid rate.
updateSnake:
ldx snakeLength
ldx snakeLengthTwo //this will make the snake tail stay at the same spot
dex
txa
updateloop:
lda snakeHeadL,x
sta snakeBodyStart,x
dex
bpl updateloop
lda snakeDirection
lsr
bcs up
lsr
bcs right
lsr
bcs down
lsr
bcs left
up:
lda snakeHeadL
sec
sbc #$20
sta snakeHeadL
bcc upup
rts
upup:
dec snakeHeadH
lda #$1
cmp snakeHeadH
beq collision
rts
right:
inc snakeHeadL
lda #$1f
bit snakeHeadL
beq collision
rts
down:
lda snakeHeadL
clc
adc #$20
sta snakeHeadL
bcs downdown
rts
downdown:
inc snakeHeadH
lda #$6
cmp snakeHeadH
beq collision
rts
left:
dec snakeHeadL
lda snakeHeadL
and #$1f
cmp #$1f
beq collision
rts
collision:
jmp gameOver
drawApple:
ldy #0
lda sysRandom
sta (appleL),y
rts
drawSnake:
ldx snakeLength
lda #0
sta (snakeHeadL,x) ; erase end of tail
ldx #0
lda #5
sta (snakeHeadL,x) ; paint head
rts
spinWheels:
ldx #0
spinloop:
nop
nop
dex
bne spinloop
rts
gameOver:
Comments
Post a Comment