Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Corresponds to the following YouTube video:
- http://www.youtube.com/watch?v=HcyTeswIKZo
- Code was copied manually from my calculator and typed to pastebin about midnight of Mar 2, 2014 Central.
- As per request of Justin Martone and Tazorac or CreeperKid43
- I also decided to add comments.
- In the following code, Underscore "_" means subscript.
- :CLRHOME // Clear 8 x 16 Screen
- :4->X // Starting head coordinates
- :4->Y
- :{8,16->dim([A] // Matrix data structure for checking intersection
- :Fill(0,[A]
- :DelVar L_1 // List data structure for deleting tail
- :DelVar L_2
- :15->L // Initial Length
- :For(A,1,L // Snake will begin compressed into one square
- :X->L_1(A
- :Y->L_2(A
- :End
- :L->M // 'L' is length available to data structures,
- :0->D // while 'M' is the ideal or actual snake length.
- :1->C // Index counter for list data structure
- :While 1 // Game loop beings (Quits upon death)
- :randInt(0,9->B
- :If not(B // 1 in 10 chance
- :Then
- :randInt(1,8->T
- :randInt(1,16->S
- :If [A](T,S)=0 // If there is nothing at the randomly chosen position
- :Then
- :2->[A](T,S // 2 is value for food in the matrix data structure
- :Output(T,S,". // . is character for food
- :End
- :End
- :Output(Y,X,"O // Draw snake head
- :1->[A](Y,X // 1 is value for snake body in matrix data structure
- :getkey->A // We get keyboard input (0 if no key is pressed)
- :If A=26 // RIGHT ARROW (2nd row, 6th column)
- :0->D
- :If A=24 // LEFT ARROW (2nd row, 4th column)
- :1->D
- :If A=34 // DOWN ARROW (3rd row, 4th column)
- :2->D
- :If A=25 // UP ARROW (2nd row, 5th column)
- :3->D
- :If D=0 // Update head coordinates
- :X+1->X
- :If D=1
- :X-1->X
- :If D=2
- :Y+1->Y
- :If D=3
- :Y-1->Y
- :If X=17 // Check for screen wrap
- :1->X
- :If X=0
- :16->X
- :If Y=9
- :1->Y
- :If Y=0
- :8->Y
- :X->L_1(C // Update head in list data structure
- :Y->L_2(C
- :If [A](Y,X)=1 // Check for intersection with body
- :Then
- :Disp "DEATH
- :Disp "LENGTH:
- :Disp M // Can you figure out how to make a high score counter?
- :Stop // For more 'permanent' variables, name a custom list
- :End // something like L_theta (L with a subscript theta)
- :If [A](Y,X)=2 // If you reach a food particle
- :Then
- :M+1->M // Add one to your ideal length (Mass? If you want an 'm' word)
- :End
- // Remove this redundant line of code since we already have it above: ":1->[A](Y,X]"
- :If C>L // If counter exceeds current available list length
- :C->L // Then we force the length to increase to fit
- :C+1->C // Increment counter once per cycle
- :C->F // F is used temporarily to remember where we need to erase the tail
- :If F>L // We cannot erase something outside our list size
- :1->F // So we wrap the index
- :If C>M // Our counter is limited by our ideal length
- :1->C
- :Output(L_2(F),L_1(F)," " // Don't need 2nd quote, but you need the space.
- :0->[A](L_2(F),L_1(F) // 0 is value for empty space in matrix data structure
- :End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement