Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: T3kN1c on January 12, 2012, 05:27:40 pm

Title: Snake Source Code
Post by: T3kN1c on January 12, 2012, 05:27:40 pm
I am pretty interested in calculator programming simply because I have no connector cable, so I have to program everything I want to be on my calculator. By hand... Anyway, I was wondering if anyone could post a TI-BASIC snake program, and explain it a little.
Title: Re: Snake Source Code
Post by: saintrunner on January 12, 2012, 05:29:45 pm
I don't know of any TI basics, but I do know of Axe (like Basic) ones! you don't have a connector? where do you live? I have like six lol! there pretty cheap
Title: Re: Snake Source Code
Post by: saintrunner on January 12, 2012, 05:33:50 pm
Code: [Select]
:Lbl 1
:AxesOff
:FnOff
:0→Xmin
:94→Xmax
:0→Ymax
:‾62→Ymin
:ClrHome
:ClrDraw
:RecallPic 0
:For(X,2,500
:End
:ClrDraw
:Lbl MN
:0→P
:Menu("     SNAKE     ","PLAY",P,"HIGH SCORE",S,"QUIT",Q
:Lbl P
:Menu("   DIFFICULTY   ","EASY",E,"MEDIUM",M,"HARD",H
:Lbl E:25→T
:1→D:Goto C
:Lbl M:50→T
:2→D:Goto C
:Lbl H:100→T
:3→D:Goto C
:0→Q
:Lbl C
:ClrDraw
:DelVar L
:If P=0:Then
:Output(4,5,"PREPARE"
:Output(5,4,"TO QUALIFY"
:Else
:ClrHome
:Output(4,6,"READY"
:End
:Pause
:ClrHome
:Output(4,6,"1"
:For(X,2,250
:End
:Output(4,8,"2"
:For(X,2,250
:End
:Output(4,10,"3"
:For(X,2,250
:End
:ClrHome
:Output(4,7,"GO!!"
:For(X,2,100
:End
:ClrDraw
:For(X,0,Q
:Pxl-On(randInt(1,61),randInt(1,93
:End
:Horizontal 0
:Horizontal ‾62
:Vertical 0
:Vertical 94
:26→R
:48→B
:32→A
:While 1
:Repeat pxl-Test(A,B) or L=320
:Pxl-On(A,B
:L+1→L
:getKey
:If Ans:Ans→R
:B+(R=26)-(R=24→B
:A-(R=25)+(R=34→A
:End
:If L=320:Then
:P+1→P
:PT→Q
:ClrHome
:Output(3,4,"CONGRATS!!"
:Output(4,6,"GO TO"
:Output(5,5,"LEVEL"
:Output(5,11,P
:Pause
:Goto C
:End
:ClrHome
:Output(3,4,"YOU'RE DEAD"
:Output(4,5,"SCORE:"
:P*320+L→S
:Output(4,11,S
:Pause
:If S>H and D=3
:Then:S→H
:Input "NAME:",Str0:End
:If S>M and D=2
:Then:S→M
:Input "NAME:",Str9:End
:If S>E and D=1
:Then:S→E
:Input "NAME:",Str8:End
:ClrHome
:Lbl S
:{E,M,H}→∟SNHS
:Output(2,2,"HIGH SCORES"
:Output(4,1,"E"
:Output(4,3,Str8
:Output(5,1,"M"
:Output(5,3,Str9
:Output(6,1,"H"
:Output(6,3,Str0
:Output(4,10,∟SNHS(1)
:Output(5,10,∟SNHS(2)
:Output(6,10,∟SNHS(3)
:Pause
:ClrHome
:DelVar P
:DelVar Q
:DelVar L
:Goto MN
:Lbl Q

heres one..I assume since it came with the game it is free to , and you'll need to make a pic (it's just the title screen)
Title: Re: Snake Source Code
Post by: ztrumpet on January 12, 2012, 06:12:33 pm
Here's the one that I would personally recommend: http://tibasicdev.wikidot.com/archives:nibbles  It bases collision detection and everything off the graph screen, so it produces some interesting and fast code.

If you'd like a homescreen version, you could try this one: http://tibasicdev.wikidot.com/snake
Title: Re: Snake Source Code
Post by: DJ Omnimaga on January 12, 2012, 06:50:30 pm
By the way welcome to the forums. :)

I would have shared some extra examples of snake games, but unfortunately all 5 snake games I made, back in 2002, were lost due to broken floppy disk and their code were pretty poor anyway.
Title: Re: Snake Source Code
Post by: Xeda112358 on January 12, 2012, 07:01:57 pm
Welcome to Omni! If you want to view the source of programs that you have downloaded, an excellent tool to use is SourceCoder (http://sc.cemetech.net/). All you need to do is load the program from your computer and it will make it into text. It can also do the reverse (text to program), but that won't help your situation XD
Title: Re: Snake Source Code
Post by: TIfanx1999 on January 12, 2012, 08:29:24 pm
/me is shocked Xeda didn't suggest hex. :P
Title: Re: Snake Source Code
Post by: T3kN1c on January 13, 2012, 12:39:36 pm
Thanks for all the help everyone! I'll look into everything and try it out.
Title: Re: Snake Source Code
Post by: MGOS on January 13, 2012, 03:07:05 pm
If you'd like a homescreen version, you could try this one: http://tibasicdev.wikidot.com/snake

Wow, that's a lot of optimization...

This is my (I know, less optimized, but without Lbls and Gotos) Snake code I wrote a while ago when I was new to programming. It turned out quite well, with a decent, but constant speed:

Code: [Select]
:128→dim(L1)
:128→dim(L2)
:{16,8}→dim([A])
:Fill(0,[A])
:1→L:1→O
:2→N:1→X:2→Y
:1→H:0→V:0→B
:X→L1(O):Y→L2(O)
:ClrHome
:randInt(1,8)→G
:randInt(1+[A](1,G)+[A](2,G),16)→F
:Output(G,F,"*")
:Repeat B
:getKey→A
:If A
:Then
:If A=105
:Pause
:If V((A=24)+(A=26))
:Then
:0→V
:A-25→H
:End
:If H((A=25)+(A=34))
:Then
:0→H
:(A=34)-(A=25)→V
:End
:End
:H+X→X
:V+Y→Y
:If (X=0)+(X=17)+(Y=0)+(Y=9)
:Then
:If X=0 :16→X
:If X=17:1→X
:If Y=0 :8→Y
:If Y=9 :1→Y
:End
:If [A](X,Y)
:1→B
:If not(B)
:Then
:Output(Y,X,"O")
:1→[A](X,Y)
:X→L1(N)
:Y→L2(N)
:N+1-128(N=128)→N
:If (X=F)(Y=G)
:Then
:randInt(1,16)→F
:randInt(1,8)→G
:While [A](F,G)
:randInt(1,16)→F
:randInt(1,8)→G
:End
:L+1→L
:Output(G,F,"*")
:Else
:0→[A](L1(O),L2(O))
:Output(L2(O),L1(O)," ")
:O+1-128(O=128)→O
:End
:End
:End
:ClrHome
:Output(2,4,"Game Over!")
:Output(5,4,"Score:")
:Output(5,11,L)
:DelVar L1
:DelVar L2
:DelVar [A]
Title: Re: Snake Source Code
Post by: meishe91 on April 18, 2012, 02:24:33 am
Incredibly late post...again. But I am actually writing a tutorial/helper that involves a snake program I wrote. I was supposed to make this like a year ago but then life, school, and work took over...so I'm still working on it but it should be coming out hopefully in the next few weeks.
Title: Re: Snake Source Code
Post by: DJ Omnimaga on April 18, 2012, 02:26:22 am
Nice to see you again Meishe91, are you planning a return eventually? Also good luck with the tutorial. :)
Title: Re: Snake Source Code
Post by: meishe91 on April 18, 2012, 02:28:37 am
I have no idea. I was just kinda thinking about Axe the other day and was like "I wonder how far that's gotten now..."
I would like to start doing some things again but I don't know really. I mean I started the tutorial like two months ago and haven't gotten a chance to finish it :P Really need to though. We shall see.
Title: Re: Snake Source Code
Post by: Brownie on March 12, 2013, 12:35:06 pm
what is the tail of the snakes code
Title: Re: Snake Source Code
Post by: Keoni29 on March 12, 2013, 12:38:26 pm
Which kind of cable do you need? Which calculator do you own? If it's just a mini usb cable: They are everywhere. Look around the house and I'm sure you'll find one. If it's an oldskool 2,5mm jack I/O cable you can buy it on ebay or make one yourself. There are some tutorials out there on how to build your own cable.