LAB 3 PART 2

 loop:

  jsr readKeys

  jsr checkCollision

  jsr updateSnake

  jsr drawApple

  jsr drawSnake

  jsr spinWheels

  jmp loop



readKeys:

  lda sysLastKey

  cmp #ASCII_i

  beq upKey

  cmp #ASCII_l

  beq rightKey

  cmp #ASCII_k

  beq downKey

  cmp #ASCII_j

  beq leftKey

  rts

upKey:

  lda #movingDown

  bit snakeDirection

  bne illegalMove


  lda #movingUp

  sta snakeDirection

  rts

rightKey:

  lda #movingLeft

  bit snakeDirection

  bne illegalMove


  lda #movingRight

  sta snakeDirection

  rts

downKey:

  lda #movingUp

  bit snakeDirection

  bne illegalMove


  lda #movingDown

  sta snakeDirection

  rts

leftKey:

  lda #movingRight

  bit snakeDirection

  bne illegalMove


  lda #movingLeft

  sta snakeDirection

  rts

illegalMove:

  rts



checkCollision:

  jsr checkAppleCollision

  jsr checkSnakeCollision

  rts



checkAppleCollision:

  lda appleL

  cmp snakeHeadL

  bne doneCheckingAppleCollision

  lda appleH

  cmp snakeHeadH

  bne doneCheckingAppleCollision


  ;eat apple

  inc snakeLength

  inc snakeLength ;increase length

  jsr generateApplePosition

doneCheckingAppleCollision:

  rts



checkSnakeCollision:

  ldx #2 ;start with second segment

snakeCollisionLoop:

  lda snakeHeadL,x

  cmp snakeHeadL

  bne continueCollisionLoop


maybeCollided:

  lda snakeHeadH,x

  cmp snakeHeadH

  beq didCollide


continueCollisionLoop:

  inx

  inx

  cpx snakeLength          ;got to last section with no collision

  beq didntCollide

  jmp snakeCollisionLoop


didCollide:

  jmp gameOver

didntCollide:

  rts

Comments

Popular posts from this blog

SPO600 Lab1

SPO600(Project 3.2 FInal Post and thoughts on project and course)

SPO600(Project Part 2.1)