16
TI-BASIC / Re: My first TI-BASIC game
« on: August 29, 2016, 04:09:30 am »
* long post incoming *
For further programs: you may want to add comments what the Vars stand for since we can only guess here xD
So here is what your vars are used for:
A = Score *btw your code says gou got to score at least 150001 since it's > not >=
B = X-Position of the "cursor"
C = Lives
D = Speed (and direction) of Cursor's movements (by default 1)
E = Score of last round (to check if changed)
F = Lives of last round (to check if changed)
G = Counter for the slider (hom many "tries" left)
I = Just for the delay, its value doesn't matter
K = GetKey *you should always declare Variables BEFORE using them
But since the default value for a var is 0, in this case "Repeat K=45" won't make any problems:)
Now let's take the code apart
A) No lives left (lives=-1)
B) Score>15000 (You might want to change that to >14999 or >=15000)
C) NO more tries (wasted all 25)
It would make things easier for you if you made all your future programs end at 0 not at -1
By the way: since you use " " a couple of times, why dont you just store it as Str1 and display that? (or maybe Str0 since nothing (zero) is displayed? ^^)
But you might want to add at last the " at the end of a string (so we know there's no more spaces behind coming)
I like it how you used two lines to make the text move to the top
Also that For( is a good way to add a little delay
Why do you put the Output(6,2," " into the for-loop It will only cause a much longer delay and maybe make the screen flicker...
You may put this in one line, you know...? like ":For(I,1,10):End" that's good for readability of your source (as ling as the for-loop i only for delay)
Just do -D->D here (the negative-sign, not the subtract)
same as above
ok ^^
I'm not sure, but isn't an End missing here for the Repeat K=45 or C<0 or A>15000 or G<0 If you didnt put it because the program is running like this, too: Never do that! it's ik to leave out stuff like " and ) (still should avoid the first) but NEVER leave out a For - it's terrible for readability and it's gonna be a problem once you want to modify the program but can't remember you left out that End...
If It's just me and I made a mistake somewhere, just ignore it
Dont know if you're planning to add this later, but you set a parameter for the speed without ever changing it
And what you most likely didn't think about:
That speed parameter might be a problem since it' imposible to score a "9" at any speed paramater D where iPart(8/D)==(8/D) is not met since B is gonna change like that:
so at D=2 you can only do it in 13 out of 25 tries...
and for D=3 it's completely impossible ^^
*I didn't try any of the code out myself so I got no idea if it's working...
For further programs: you may want to add comments what the Vars stand for since we can only guess here xD
So here is what your vars are used for:
A = Score *btw your code says gou got to score at least 150001 since it's > not >=
B = X-Position of the "cursor"
C = Lives
D = Speed (and direction) of Cursor's movements (by default 1)
E = Score of last round (to check if changed)
F = Lives of last round (to check if changed)
G = Counter for the slider (hom many "tries" left)
I = Just for the delay, its value doesn't matter
K = GetKey *you should always declare Variables BEFORE using them
But since the default value for a var is 0, in this case "Repeat K=45" won't make any problems:)
Now let's take the code apart
Code: [Select]
0->A
1->B
3->C
1->D
0->E
0->F
25->G
ClrHome
Output(1,2,"SCORE
Output(2,2,0
Output(3,2,"LIVES
Output(4,2,3
Output(7,9,"V
Just declarations and display stuff (stuff that won't change during the program)Code: [Select]
Repeat K=45 or C<0 or A>15000 or G<0
Main loopthat got 3 possible criterias to stop:A) No lives left (lives=-1)
B) Score>15000 (You might want to change that to >14999 or >=15000)
C) NO more tries (wasted all 25)
It would make things easier for you if you made all your future programs end at 0 not at -1
Code: [Select]
If A!=E
Then
Output(2,2," "
Output(2,2,A
End
If C!=F
Then
Output(4,2," "
Output(4,2,C
End
Checks for changes in both lives and score. That's fine but is it really necessary? ^^ You could also just update this every round ^^ (but that might make the screen flicker a bit so just leave it like that)By the way: since you use " " a couple of times, why dont you just store it as Str1 and display that? (or maybe Str0 since nothing (zero) is displayed? ^^)
Code: [Select]
Output(8,1,"................
Output(8,B,"X
A->E
C->F
Display the ground and the "cursor", fine.But you might want to add at last the " at the end of a string (so we know there's no more spaces behind coming)
Code: [Select]
getKey->K
If K=105
Then
The kay was pressed, will now check if you missed or notCode: [Select]
25->G
Set number of tries to 25, okCode: [Select]
If B=9
Then
A+100->A
A perfect hit I guess...Code: [Select]
If rand>.75
A+150->A
Additional points depending on luckCode: [Select]
If fPart (A/1000)=0
Then
A+250->A
C+1->C
Output(2,7,"1 UP!
For(I,1,50
End
Output(2,7," "
Output(1,7,"1 UP!
For(I,1,50
End
Output(1,7," "
End
Score divisible by 1000: 1upI like it how you used two lines to make the text move to the top
Also that For( is a good way to add a little delay
Code: [Select]
Else
A-150->A
C-1->C
Output(5,2,"MISS!
For(I,1,50
End
Output(5,2," "
Output(6,2,"MISS!
For(I,1,50
Output(6,2," "
End
End
Code part if you didnt perfectly hit itWhy do you put the Output(6,2," " into the for-loop It will only cause a much longer delay and maybe make the screen flicker...
Code: [Select]
For(I,1,10
End
Another little delayYou may put this in one line, you know...? like ":For(I,1,10):End" that's good for readability of your source (as ling as the for-loop i only for delay)
Code: [Select]
B+D->B
Move the target again (speed and direction=D)Code: [Select]
If B>16
Then
16->B
0-D->D
End
Mustn't leace screen on the left sideJust do -D->D here (the negative-sign, not the subtract)
Code: [Select]
If B<1
Then
1->B
0-D->D
End
Mustn't leace screen on the right sidesame as above
Code: [Select]
G-1->G
You should put G-1->G into the two conditions above (leaving screen) instead of putting it here Else You won't have 25 chanzes - it's more like the target is gonna move a total of 25 times... (here the counter for left tries (G) gets reduced by 1 EVERY round no matter if it touched the borders or not, that's what you could call a bug) Code: [Select]
End
End the conditioned block for Key is pressedCode: [Select]
If C<0 or G<0
Then
Output(7,1," "
Output(8,1,"YOU LOSE! "
Pause
End
I lost... ok ^^
Code: [Select]
If A>15000
Then
Output(2,2,A
Output(7,1," "
Output(8,1,"YOU WIN! "
Pause
End
Same as before: This is triggered at 15001 instead of 15000, use >= here or simply use 14999 instead Code: [Select]
ClrHome
ok, program is going to endI'm not sure, but isn't an End missing here for the Repeat K=45 or C<0 or A>15000 or G<0 If you didnt put it because the program is running like this, too: Never do that! it's ik to leave out stuff like " and ) (still should avoid the first) but NEVER leave out a For - it's terrible for readability and it's gonna be a problem once you want to modify the program but can't remember you left out that End...
If It's just me and I made a mistake somewhere, just ignore it
Dont know if you're planning to add this later, but you set a parameter for the speed without ever changing it
And what you most likely didn't think about:
That speed parameter might be a problem since it' imposible to score a "9" at any speed paramater D where iPart(8/D)==(8/D) is not met since B is gonna change like that:
Speed | how B changes |
1 | 1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1-1-2-... |
2 | 1-3-5-7-9-11-13-15-16-14-12-10-8-6-4-2-1-3-... |
3 | 1-4-7-10-13-16-16-13-10-7-4-1-1-4-... |
and for D=3 it's completely impossible ^^
*I didn't try any of the code out myself so I got no idea if it's working...