Author Topic: Snake: What’s wrong?  (Read 3868 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixilized

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 5
  • Rating: +0/-0
  • Dividing zero by zero…
    • View Profile
    • My Site
Snake: What’s wrong?
« on: December 05, 2023, 07:20:40 pm »
I’m making Snake in Axe as practice, but my code isn’t working and I can’t figure out what’s wrong. The Snake is supposed to be longer, but I can only make it be one segment. What did I do wrong? Here’s my code. Thanks in advance!

Quote from: SourceCoder 3 (thetaSNAKE)
:.SNAKE
:DiagnosticOff
:ClrHome
:
:.sprites
:[E0A0E00000000000]->Pic0BODY
:[1F1F1FFFFFFFFFFF]->Pic0FILL
:
:.v\ariable RAM
:|E9872->->^^oVR
:
:.create v\ars
:^^oVR->->^^oHeadX+2->->^^oHeadY+2->->^^oDir+2->->^^oTail+2->->^^oLength
:
:.set v\ars
:0->HeadX->HeadY
:1->Tail+6->Length
:3->Dir
:
:.set list
:Data(0,0,0,0,0,0)->GDB1SEGX
:Data(0,0,0,0,0,0)->GDB1SEGY
:
:.game loop
:Repeat getKey(15)
:   
:   .erase tail
:   Pt-And({Tail-1+GDB1SEGX},{Tail-1+GDB1SEGY},Pic0FILL)
:   
:   .draw head
:   Pt-On(HeadX,HeadY,Pic0BODY)
:   
:   .update list
:   HeadX->{Tail-1+GDB1SEGX}
:   HeadY->{Tail-1+GDB1SEGY}
:   
:   .get input
:   getKey->Ans
:   If Ans?Ans<=4
:      
:      Ans->Dir
:      
:   End
:   
:   .move
:   (Dir=3)-(Dir=2)+HeadX->HeadX
:   (Dir=1)-(Dir=4)+HeadY->HeadY
:   
:   .update tail
:   Tail+1-(Length*(Tail=Length))->Tail
:   
:   .draw screen
:   DispGraphClrDraw
:   
:End



Side note: what is the bbcode for a code box? I clicked the bbcode button on SourceCoder, but that makes it a quote with a bunch of styling. How do I make the code box that you can click "copy" on?



Never mind, I found out what was wrong with snake. I forgot DispGraphClrDraw cleared the current buffer.

Edit (Eeems): Merged triple post
« Last Edit: December 08, 2023, 02:32:31 pm by Eeems »

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: Snake: What’s wrong?
« Reply #1 on: December 07, 2023, 03:22:48 pm »
Ans in Axe is TI-Basic's Ans. That means that changing it lets you communicate with TI-Basic but it is also as slow as using Basic. Speed isn't a problem for your code but you should avoid it in the future. I usually use the letter variables for scratch space.
I'm still around... kind of.