Author Topic: My first TI-BASIC game  (Read 5660 times)

0 Members and 2 Guests are viewing this topic.

Offline SopaXorzTaker

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • I like electronics.
    • View Profile
    • GitHub
My first TI-BASIC game
« on: August 27, 2016, 03:48:57 pm »
Literally a week after getting my TI-82, I wrote this simple game for it.
The objective of the game is to stop the slider ("X") at the right time so that it matches up with the target ("V")
You have four lives (including when zero are remaining), and a hit will yield either 100 and additional 150 score points if you are lucky (3/4 and 1/4 probability).
If you get a score divisible by 1000, you get additional 250 points and one more life.
However, if you miss, 150 points get deduced from your score and you lose one life.
To win, you must score 15000 or more points.
You lose the game if either you lose all of your lives, or if you don't stop the slider in 26 steps (more than enough to stop it from any position).
The controls are simple: Enter to stop the slider and Clear to clean-up the screen and exit the game.
Please report all the bugs encountered so that I can fix them  ^-^

Screenshot:


Also published on GitHub Gist: https://gist.github.com/SopaXorzTaker/48f9dc824a907f35112fb940b6e21440.

Update 2016/08/28: Update the displayed score upon victory
Code: [Select]
# Comment: -> is the STO command, >= is the greater than or equal sign (≥), <= is the less than or equal sign (≤), and != is the not equal sign (≠).
# SopaXorzTaker, 2016
# Good luck typing that in (or use the TI utility if you have a link cable).

0->A
1->B
3->C
1->D
0->E
0->F
25->G
0->K
ClrHome
Output(1,2,"SCORE
Output(2,2,0
Output(3,2,"LIVES
Output(4,2,3
Output(7,9,"V
Repeat K=45 or C<0 or A>=15000 or G<0
If A!=E
Then
Output(2,2,"               "
Output(2,2,A
End
If C!=F
Then
Output(4,2,"               "
Output(4,2,C
End
Output(8,1,"................
Output(8,B,"X
A->E
C->F
getKey->K
If K=105
Then
25->G
If B=9
Then
A+100->A
If rand>.75
A+150->A
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
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
End
Output(6,2,"     "
End
For(I,1,10
End
B+D->B
If B>16
Then
16->B
0-D->D
End
If B<1
Then
1->B
0-D->D
End
G-1->G
End
If C<0 or G<0
Then
Output(7,1,"                "
Output(8,1,"YOU LOSE!       "
Pause
End
If A>=15000
Then
Output(2,2,A
Output(7,1,"                "
Output(8,1,"YOU WIN!        "
Pause
End
ClrHome
« Last Edit: August 29, 2016, 04:31:48 am by SopaXorzTaker »

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: My first TI-BASIC game
« Reply #1 on: August 28, 2016, 07:21:54 am »
Is there any chance of the program or a screenshot? (IDK how possible such things for the 82 are...)
Anyhow, i'd recommend leaving away the trailing quotes on your output lines, this way you save bytes!
Also, any reason why there are so many spaces after "YOU LOSE!" and "YOU WIN!" ?

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

Offline SopaXorzTaker

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • I like electronics.
    • View Profile
    • GitHub
Re: My first TI-BASIC game
« Reply #2 on: August 28, 2016, 07:48:03 am »
Is there any chance of the program or a screenshot? (IDK how possible such things for the 82 are...)
Anyhow, i'd recommend leaving away the trailing quotes on your output lines, this way you save bytes!
Also, any reason why there are so many spaces after "YOU LOSE!" and "YOU WIN!" ?

The quotes at the end of some lines are not required, but are used to show that there should be spaces.
The spacing of the last two strings is needed to clear the rest  of the lines they are printed to, making the screen look tidier.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: My first TI-BASIC game
« Reply #3 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 :)

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<0Main 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 not

Code: [Select]
25->GSet number of tries to 25, ok

Code: [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 luck

Code: [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: 1up
I like it how you used two lines to make the text move to the top ;D
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 it
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...

Code: [Select]
For(I,1,10
End
Another little delay
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)

Code: [Select]
B+D->BMove 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 side
Just 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 side
same as above :)

Code: [Select]
G-1->GYou 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]
EndEnd the conditioned block for Key is pressed

Code: [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]
ClrHomeok, program is going to end

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 ;D

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
11-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-...
21-3-5-7-9-11-13-15-16-14-12-10-8-6-4-2-1-3-...
31-4-7-10-13-16-16-13-10-7-4-1-1-4-...
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... ;D
*insert supercool signature*

Offline SopaXorzTaker

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • I like electronics.
    • View Profile
    • GitHub
Re: My first TI-BASIC game
« Reply #4 on: August 29, 2016, 04:26:37 am »
Thank you!
The Output in a delay For certainly was a bug, and I replaced >15000 to >=15000 just to clarify it. Let me update the post.

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: My first TI-BASIC game
« Reply #5 on: August 29, 2016, 04:28:26 am »
dont forget the G-1->G or your program should end after 2 tries if you dont press  key ;) (at least I think so ^^)
*insert supercool signature*

Offline SopaXorzTaker

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • I like electronics.
    • View Profile
    • GitHub
Re: My first TI-BASIC game
« Reply #6 on: August 29, 2016, 04:30:58 am »
dont forget the G-1->G or your program should end after 2 tries if you dont press  key ;) (at least I think so ^^)
You already have a 25 step timeout, which I believe to be more than enough (I was able to complete this game :))

Offline SopaXorzTaker

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 6
  • Rating: +0/-0
  • I like electronics.
    • View Profile
    • GitHub
Re: My first TI-BASIC game
« Reply #7 on: August 29, 2016, 04:33:19 am »
As in the Str part, TI-82 does not support string manipulation :(

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: My first TI-BASIC game
« Reply #8 on: August 29, 2016, 04:39:36 am »
*try to avoid double posting (replying to your own post within less than 24 hours) :)

Ok then I just misunderstood you ^^ I thought it was ment like the target should pass by 25 times ;D f it was ment like 20 steps, then it's all right ^^

As in the Str part, TI-82 does not support string manipulation :(
didnt know that since I dont have a TI-82 sorry :/
*insert supercool signature*