Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: mrhoontar . on October 30, 2016, 01:37:48 pm

Title: Finished my first real project in Ti-Basic, looking for critique?
Post by: mrhoontar . on October 30, 2016, 01:37:48 pm
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 (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
Title: Re: Finished my first real project in Ti-Basic, looking for critique?
Post by: Sorunome 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:

Reasons for not using Lbl/Goto:



Edit: added optimization
Title: Re: Finished my first real project in Ti-Basic, looking for critique?
Post by: CalcMax 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.