Looking for feedback / testing -- My miscellaneous programs
Reply | Flag | Categorize
Habstinat 08 Feb 2013 23:52
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

I'll add programs to this thread as I see fit. Feedback, optimization, and high scores to beat are welcomed (I always try to fit some sort of scoring system in most of my games).

-PONG.8Xp-
Notes:
This is a fully featured pong game, complete with multiplayer, a practice mode, and a "challenge" mode in which the player must hit the ball against a wall that continues to move closer to the paddle until the player misses the ball, at which point his score will be tallied and recorded.
Controls:
[7]: Move the left paddle up one pixel
[1]: Move the left paddle down one pixel
[9]: Move the right paddle up one pixel
[3]: Move the right paddle down one pixel
[CLEAR]: Pause the game, or exit the game if paused
[ENTER]: Resume the game if paused
Hacks:
- The "L" variable can be changed to alter the length of both paddles divided by two.
Catches:
- It's still not as fast as I'd like it to be.
- The two player mode is still kind of crippled by the fact that only one one key press can be caught by getKey at a time.
- Ball movement is rather simplistic, and once you hit a trick shot, there's no way to counter that except returning it.
- You have to mash the number pad to move the paddle because only the arrow keys can be held. I'm not sure if I like it that way or not.
My high score:
71 for Challenge Mode. I'll admit, I haven't tried that hard.

0->C
0->P
Menu("      PONG      ","TWO PLAYER",2,"PRACTICE",P,"CHALLENGE",C,"QUIT",Q)
Lbl C
1->C
2->U
Lbl P
1->P
Lbl 2
0->V
0->W
0->S
0->T
4->L
32->O
48->N
0->E
1->D
0->Q
StoreGDB 0
1->Xmin
95->Xmax
FnOff 
AxesOff
ClrDraw
If C or P
Then
Vertical 1
Vertical 2
End
Horizontal ~10
Horizontal 10
For(I,1,93,92)
For(J,~L+32,L+32,1)
Pxl-On(J,I)
End
End
While not(Q)
getKey->G
If G
Then
If G=72 and Y-L+32!=1
Then
Y-1->Y
Pxl-On(Y-L+32,1)
Pxl-Off(Y+L+33,1)
Else
If G=92 and Y+L+32!=61
Then
Y+1->Y
Pxl-On(Y+L+32,1)
Pxl-Off(Y-L+31,1)
Else
If G=45
Then
ClrHome
Disp "GAME PAUSED"
Disp "[ENTER]: RESUME"
Disp "[CLEAR]: QUIT"
While not(F)
getKey->G
If G=45
Then
1->Q
1->F
End
If G=105
1->F
End
0->G
0->F
Else
If G=74 and T-L+32!=1
Then
T-1->T
Pxl-On(T-L+32,93)
Pxl-Off(T+L+33,93)
Else
If G=94 and T+L+32!=61
Then
T+1->T
Pxl-On(T+L+32,93)
Pxl-Off(T-L+31,93)
End
End
End
End
End
End
N->A
O->B
If N=1 or N=93
Then
If not(C)
Then
ClrHome
If N=1
V+1->V
If N=93
W+1->W
Disp "LEFT SCORE:"
Output(1,13,V)
Disp "RIGHT SCORE:"
Output(2,14,W)
Pause 
If V>9
Then
Disp "LEFT WINS!"
1->Q
End
If W>9
Then
Disp "RIGHT WINS!"
1->Q
End
32->O
48->N
0->E
Else
ClrHome
Disp "YOU LOSE..."
Disp "YOUR SCORE:"
Output(2,13,U)
If U>|LPONG(1)
U->|LPONG(1)
Disp "HIGH SCORE:"
Output(3,13,|LPONG(1))
Pause 
1->Q
End
End
If pxl-Test(O,N+D)
Then
If C and U>2
Then
Vertical U-1
Vertical U
U+1->U
End
~D->D
Else
If pxl-Test(O+1,N+D)
Then
~1->E
If N=2 or N=92
Then
~D->D
If C
Then
Vertical U-1
Vertical U
U+1->U
End
End
End
If pxl-Test(O-1,N+D)
Then
1->E
If N=2 or N=92
~D->D
End
End
O+E->O
N+D->N
Pxl-Off(B,A)
Pxl-On(O,N)
End
Lbl Q
RecallGDB 0
ClrHome

My other games will be added shortly.

Attachment:

Habstinat 08 Feb 2013 23:59
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

Oh jeez, looks like you can't edit posts on this forum. Well, regardless, the PONG.8Xp file is attached. I didn't mean to cross it out in the previous post.

Attachment: PONG.8Xp

Silver Phantom 09 Feb 2013 00:31
Silver Phantom

Member


Guest

instead of 0→(variable) try delvar variable

Attachment:

Xeda Elnara 09 Feb 2013 01:47
Xeda Elnara

Moderator

FA

Guest

I am going through and optimising some of your code and I can tell a bunch of it was well thought out :D
There are a handful of common optimisations that I can suggest:

  • Instead of using ~L+32 (I am assuming ~ is negative), you can use 32-L to save a byte
  • You can drop ending quotes and parentheses
  • To elaborate on what Silver said, DelVar is two bytes, so 0→Q is the same size as DelVar Q. However, DelVar and the other memory functions have a cool trick where you don't need to use a newline for the next command, saving a byte! For example, instead of this:
0→Q
1→P
---or---
DelVar Q
1→P

(both are the same size) You can do this:
DelVar Q1→P

Which is one byte less and essentially does the same thing.
  • Disp has a cool trick like Text( where each additional argument is treated like a new Disp. For example:
Disp "YOU LOSE..."
Disp "YOUR SCORE:"

Can instead be:
Disp "YOU LOSE...","YOUR SCORE:

Pretty neat, right?
  • One random trick optimisation was with this line:
If G=72 and Y-L+32≠1

I changed it in my head to:
If G=72 and Y-L+32-1

Which can be optimised to save two bytes:
If G=72 and Y-L+31

I am weird, so my methods are awkward. If you want to do the more logical version of my solution:
If G=72 and Y-L+32≠1
---use some algebra---
If G=72 and Y-L+32-32≠1-32
If G=72 and Y-L≠~31
---get rid of that negtive sign, it is using an unnecessary byte D: ---
If G=72 and Y-L+L≠~31+L
If G=72 and Y≠L-31

Yay :3 (I am in a math optimisy mood, sorry).
  • Often Repeat is more useful than While (in my opinion) because you don't need to set the variables before the loop. When I started learning TI-BASIC, I actually never learned what While did until I joined this site and saw people using it. I just found Repeat and figured out how it worked and I like it .-.

Here is how I convoluted it:

DelVar CDelVar P"      ;6 spaces here
Menu(Ans+"PONG"+Ans,"TWO PLAYER",2,"PRACTICE",P,"CHALLENGE",C,"QUIT",Q
Lbl C
1→C
2→U
Lbl P
1→P
Lbl 2
DelVar VDelVar WDelVar SDelVar T4→L
32→O
48→N
DelVar EDelVar Q1→D
StoreGDB 0
1→Xmin
95→Xmax
FnOff 
AxesOff
ClrDraw
If C or P
Then
Vertical 1
Vertical 2
End
Horizontal (-)10
Horizontal 10
For(I,1,93,92
For(J,32-L,L+32,1
Pxl-On(J,I
End
End
Repeat Q
getKey→G
If G
Then
If G=72 and Y-L+31
Then
Y-1→Y
Pxl-On(Y-L+32,1
Pxl-Off(Y+L+33,1
Else
If G=92 and Y+L≠29
Then
Y+1→Y
Pxl-On(Y+L+32,1
Pxl-Off(Y-L+31,1
Else
If G=45
Then
ClrHome
Disp "GAME PAUSED","[ENTER]: RESUME","[CLEAR]: QUIT
Repeat 30=abs(Ans-75
getKey
End
If Ans=45
1→Q
Else
If G=74 and T-L+31
Then
T-1→T
Pxl-On(T-L+32,93
Pxl-Off(T+L+33,93
Else
If G=94 and T+L≠29
Then
T+1→T
Pxl-On(T+L+32,93
Pxl-Off(T-L+31,93
End
End
End
End
End
End
N→A
O→B
If N=1 or N=93
Then
If not(C
Then
ClrHome
If N=1
V+1→V
If N=93
W+1→W
Disp "LEFT SCORE:
Output(1,13,V
Disp "RIGHT SCORE:
Output(2,14,W
Pause 
If V>9
Then
Disp "LEFT WINS!
1→Q
End
If W>9
Then
Disp "RIGHT WINS!
1→Q
End
32→O
DelVar E48→N
Else
ClrHome
Disp "YOU LOSE...","YOUR SCORE:
Output(2,13,U
If U>|LPONG(1
U→|LPONG(1
Disp "HIGH SCORE:
Output(3,13,|LPONG(1
Pause 
1→Q
End
End
If pxl-Test(O,N+D
Then
If C and U>2
Then
Vertical U-1
Vertical U
U+1→U
End
~D→D
Else
If pxl-Test(O+1,N+D
Then
~1→E
If N=2 or N=92
Then
~D→D
If C
Then
Vertical U-1
Vertical U
U+1→U
End
End
End
If pxl-Test(O-1,N+D
Then
1→E
If N=2 or N=92
~D→D
End
End
O+E→O
N+D→N
Pxl-Off(B,A
Pxl-On(O,N
End
Lbl Q
RecallGDB 0
ClrHome

I gave it a try and I like how you implemented the two player mode. Also, should the pixel be moving at an angle or just back and forth? If you want, I can put together a simple Pong engine so that you can compare it :D

Attachment:

Habstinat 09 Feb 2013 03:38
Habstinat

Included page "member:habstinat" does not exist (create it now)


Guest

Thank you so much for your optimizations. I really can't express how much this means to me; I'm ecstatic to try them out.

I just realized I forgot to mention trick shots. The ball /does/ move at an angle, but you have to set it off first with a trick shot executed by moving the paddle exactly one pixel away from the ball when you hit the ball. It's kind of hard to explain but really easy to understand once you do it once. I made it this way purposefully to give skilled players an edge; once you start a trick shot ball it can't be undone until the next ball. It's also impossible to score anything in Challenge Mode without using trick shots. If you didn't know about them, you probably weren't having much fun :P

Attachment:

bsch2734 11 Feb 2013 19:20
bsch2734

Member


Guest

One small note:
"or" and "and" can be replaced with addition and multiplication, respectively

So
If G=72 and Y-L+31
becomes
If (G=72)(Y-L+31

and
If N=1 or N=93
becomes
If (N=1)+(N=93

These increase size but also offer a marginal increase in speed

If max(N={1,93
can also replace
If N=1 or N=93
for the same size, though I do not know which is faster

Attachment:

Make a reply:

To use the style buttons, click on the one you want, then press Ctrl+V.


Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.