Author Topic: Finished my first real project in Ti-Basic, looking for critique?  (Read 4014 times)

0 Members and 1 Guest are viewing this topic.

Offline mrhoontar .

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +0/-0
    • View Profile
First off, hi! I'm new to the forums and I'm still very much a beginner to Ti-Basic, and even moreso of a beginner with assembly, so I don't expect this project to be fully optimized as I've written it, so I've come looking for some critique.

It's a basic Pokemon battle simulator, with the following features:
-Four randomly generated moves for both you and your enemy
-Moves can be either Physical or Special
-Moves have PP (Higher PP for lower damaging moves)
-Once you run out of PP, you're forced to use Struggle
-Moves have Accuracy (Higher Accuracy for lower damaging moves)
-Random Critical Hits

Stats are randomly generated using random base stats that aren't unrealistic.
The only thing the user really chooses in the battle is what level your pokemon should be, what level the enemy should be, and what move to use.

http://i.imgur.com/vVfWE2i.gifv
Here's a gif of a quick runthrough of the program.

Code: [Select]
Lbl ZZ
AxesOff
ClrDraw
DelVar {Y1}

ClrHome
DelVar [C]
DelVar [D]
{2,6}->dim([C]
Fill(0,[C]
{8,4}->dim([D]
Fill(0,[D]
//C is used for your stats, as well as the enemies
//D is used for the move data, in order, from left to right, being: Base Power, Physical/Special, Accuracy, and PP.

0->X
Lbl X1
X+1->X
If X=9
Goto X2
randInt(20,130)->[D](X,1)
Goto X1

Lbl X2
0->K
Lbl 5A
K+1->K
If K=9
Goto 5B
randInt(1,2)->[D](K,2)
Goto 5A

Lbl 5B
1->N
Text(0,21,"Welcome to my"
Text(6,18,"Battle Simulator"
Text(13,2,"First we will"
Text(13,45,"make a random"
Text(19,20,"enemy Pokemon."
Text(30,19,"ENTER to advance"
Pause
ClrDraw
Text(1,1,"Before we begin, when you"
Text(7,1,"select a move to use, it will"
Text(13,1,"be shown in this format"
Text(20,10,"Base Power, Type"
Text(27,1,"As an example:
Text(34,32,"77, Phys."
Text(40,1,"77 Base Power, Physical Atk"
Text(47,19,"ENTER to advance"
Pause

ClrHome
Disp "What should the","enemys level be?",""
Input "",X

{0,1->L1
{0,[D](1,1)->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str1
sub(Str1,1,length(Str1)-3->Str1

{0,1->L1
{0,[D](2,1)->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str2
sub(Str2,1,length(Str2)-3->Str2

{0,1->L1
{0,[D](3,1)->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str3
sub(Str3,1,length(Str3)-3->Str3

{0,1->L1
{0,[D](4,1)->L2
LinReg(ax+b) {Y1}
Equ>String({Y1},Str4
sub(Str4,1,length(Str4)-3->Str4

If [D](1,2)=1
Str1+", Phys."->Str1
If [D](2,2)=1
Str2+", Phys."->Str2
If [D](3,2)=1
Str3+", Phys."->Str3
If [D](4,2)=1
Str4+", Phys."->Str4
If [D](1,2)=2
Str1+", Spec."->Str1
If [D](2,2)=2
Str2+", Spec."->Str2
If [D](3,2)=2
Str3+", Spec."->Str3
If [D](4,2)=2
Str4+", Spec."->Str4

DelVar {Y1}

X->L

randInt(0,31)->I
randInt(0,255)->E
randInt(1,255)->B
iPart((((2B+I+(E/4))*L)/(100))+L+10)->[C](2,1)

1->A

Lbl Q3
A+1->A
If A=7
Goto Q4
randInt(0,31)->I
randInt(0,255)->E
randInt(6,130)->X
randInt(5,X)->B
iPart((((((2B+I+(E/4))*L)/(100))+5)*N))->[C](2,A)
Goto Q3

Lbl Q4
ClrHome
Text(1,38,"Stats"
Text(57,19,"ENTER to advance"
Text(3,4,"Enemy's"
Text(9,36,"Health"
Text(16,36,"Attack"
Text(23,30,"Sp. Attack"
Text(30,35,"Defense"
Text(37,29,"Sp. Defense"
Text(44,37,"Speed"

Pause
Text(9,12,[C](2,1)
Pause
Text(16,12,[C](2,2)
Pause
Text(23,12,[C](2,3)
Pause
Text(30,12,[C](2,4)
Pause
Text(37,12,[C](2,5)
Pause
Text(44,12,[C](2,6)
Pause

ClrHome
Disp "Now we make","your Pokemon!"
Pause "ENTER to advance"

ClrHome
Disp "What should","your level be?",""
Input "",X

"Health"
X->L

randInt(0,31)->I
randInt(0,255)->E
randInt(1,255)->B
iPart((((2B+I+(E/4))*L)/(100))+L+10)->[C](1,1)

1->A

Lbl Q1
A+1->A
If A=7
Goto Q2
randInt(0,31)->I
randInt(0,255)->E
randInt(6,130)->X
randInt(5,X)->B
iPart((((((2B+I+(E/4))*L)/(100))+5)*N))->[C](1,A)
Goto Q1

Lbl Q2
ClrHome

Text(3,70,"Yours"
Pause
Text(9,78,[C](1,1)
Pause
Text(16,78,[C](1,2)
Pause
Text(23,78,[C](1,3)
Pause
Text(30,78,[C](1,4)
Pause
Text(37,78,[C](1,5)
Pause
Text(44,78,[C](1,6)
Pause

0->Y
Lbl G1
Y+1->Y
If Y=9
Goto G2
If [D](Y,1)>=5 and [D](Y,1)<80
Then
100->[D](Y,3)
5->[D](Y,4)
End
If [D](Y,1)>80 and [D](Y,1)<100
Then
95->[D](Y,3)
4->[D](Y,4)
End
If [D](Y,1)>=100 and [D](Y,1)<110
Then
90->[D](Y,3)
3->[D](Y,4)
End
If [D](Y,1)>=110 and [D](Y,1)<120
Then
85->[D](Y,3)
2->[D](Y,4)
End
If [D](Y,1)>=120 and [D](Y,1)<=130
Then
80->[D](Y,3)
1->[D](Y,4)
End

Goto G1

Lbl G2
If [C](1,6)>[C](2,6)
Goto A
If [C](1,6)<[C](2,6)
Goto B
If [C](1,6)=[C](2,6)
randInt(1,2)->X
If X=1
Goto A
If X=2
Goto B

Lbl A
If [C](1,1)<=0
Then
ClrHome
Disp "You lost!"
Pause "ENTER to advance"
Menu("Try again?","Yes",ZZ,"No",Z1)
Else
ClrHome
Disp "Your turn","to attack!"
Pause "ENTER to advance"
ClrHome
Lbl A8
If [D](1,4)=0 and [D](2,4)=0 and [D](3,4)=0 and [D](4,4)=0
Then
Disp "Youre out of PP!"
Disp "You struggled!"
[C](1,2)->A
[C](2,4)->D
50->B
iPart(([C](1,1)*.25))->J
iPart([C](1,1)-[C](1,1)*.25)->[C](1,1)
Goto F1
End
Menu("What move?",Str1,A1,Str2,A2,Str3,A3,Str4,A4,"View Stats",A7)
Lbl A1
If [D](1,4)=0
Goto FF
[D](1,4)-1->[D](1,4)
1->X
If [D](1,2)=1
Goto A5
If [D](1,2)=2
Goto A6
Lbl A2
If [D](2,4)=0
Goto FF
[D](2,4)-1->[D](2,4)
2->X
If [D](2,2)=1
Goto A5
If [D](2,2)=2
Goto A6
Lbl A3
If [D](3,4)=0
Goto FF
[D](3,4)-1->[D](3,4)
3->X
If [D](3,2)=1
Goto A5
If [D](3,2)=2
Goto A6
Lbl A4
If [D](4,4)=0
Goto FF
[D](4,4)-1->[D](4,4)
4->X
If [D](4,2)=1
Goto A5
If [D](4,2)=2
Goto A6

Lbl A7
Pxl-On(4,4)
Pause
Goto A8

Lbl A5
[C](1,2)->A
[C](2,4)->D
Goto B1
Lbl A6
[C](1,3)->A
[C](2,5)->D
Goto B1
End

Lbl B1
[D](X,1)->B
randInt(1,100)->S
If S>75
Then
1.5->S
Else
1->S
End
Goto ST

Lbl FF
ClrHome
Disp "Your move is"
Disp "out of PP!"
Disp ""
Disp "Choose a"
Disp "different move!"
Pause "Enter to advance"
Goto A8

Lbl ST
X->Y
If [D](Y,3)<=randInt(0,100)
Then
ClrHome
Disp "You missed"
Disp "the Pokemon!"
Pause "ENTER to advance"
Goto B
Else
randInt(1,100)->C
If C>94
Then
2->C
Else
1->C
End
End

randInt(85,100)/100->R
Goto GI
Lbl F1
Pause
ClrHome
Disp "You took"
Disp J
Disp "recoil damage!"
Lbl GI
SCR->M
iPart(((((2L+10)/(250))*((A)/(D))*B+2)*M))->Q

[C](2,1)-Q->[C](2,1)
If C=2
Disp "Critical hit!"
Disp "You dealt",Q,"Damage!"
Pause ""
ClrHome
Disp "Your enemy has"
If [C](2,1)<=0
0->[C](2,1)
Disp [C](2,1),"Health left."
Pause "ENTER to advance"
Goto B

Lbl B
If [C](2,1)<=0
Then
ClrHome
Disp "You won!"
Pause "ENTER to advance"
Menu("Battle again?","Yes",ZZ,"No",Z1)
Else
ClrHome
Disp "Enemy's turn","to attack!"
Pause "ENTER to advance"
randInt(5,8)->X
If X=[D](X,2)=1
[C](2,2)->A
[C](1,4)->D
Goto D1
If X=[D](X,2)=2
[C](2,3)->A
[C](1,5)->D
Goto D1
End
Lbl D1
[D](X,1)->B
randInt(1,100)->S
If S>75
Then
1.5->S
Else
1->S
End

X->Y
If [D](Y,3)<=randInt(0,100)
Then
ClrHome
Disp "The enemy"
Disp "missed!"
Pause "ENTER to advance"
Goto A
Else
randInt(1,100)->C
If C>94
Then
2->C
Else
1->C
End
End



randInt(85,100)/100->R

SCR->M
iPart(((((2L+10)/(250))*((A)/(D))*B+2)*M))->Q
[C](1,1)-Q->[C](1,1)
ClrHome
If C=2
Disp "Critical hit!"
Disp "You were dealt",Q,"Damage!"
Pause ""
ClrHome
Disp "You have"
If [C](1,1)<=0
0->[C](1,1)
Disp [C](1,1)
Disp "Health left."
Pause "ENTER to advance"
Goto A

Lbl Z1
Stop

Here's the source code that I'm looking to have critiqued.
I'm particularly proud of the section that generates random moves, but I'd like to know what you all think of my code

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Finished my first real project in Ti-Basic, looking for critique?
« Reply #1 on: October 30, 2016, 01:42:48 pm »
Hi there, welcome to the forums!

I didn't read the code, i just skimmed it, but here are the few things i already noticed:
  • You can leave away the trailing quote (that way you save a few bytes), so that you only have like Disp "blah
  • Try to use less Lbl/Goto, yes, that means not using the built-in Menu( command, the reson is:
  • You can also leave away " and ) before the -> arrow (i think)

Reasons for not using Lbl/Goto:
  • Results in spaghetti-code, try using While and Repeat loops and thelike instead
  • The TI-Basic interpreter has a bug where if you Goto away while you are inside of a While/Repeat or an If that requires an End it'll still be looking for the end of that loop even though it jumped out --> eventually you'll get an Error:Memory



Edit: added optimization
« Last Edit: October 30, 2016, 01:46:14 pm by Sorunome »

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline CalcMax

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +0/-0
  • TI-84+SE for play, NSpire CX CAS for hard work
    • View Profile
Re: Finished my first real project in Ti-Basic, looking for critique?
« Reply #2 on: January 19, 2017, 01:00:58 pm »
I completely agree with Sorunome about the memory leak issue.  When I write something, I watch out for such issues. There are just way too many spaghetti code (aka TI-spaghetti-basic) games on ticalc.org.
Feel free to download any of my programs:
http://www.ticalc.org/archives/files/authors/115/11518.html