FANDOM


Pong
Pong!

I was challenged by a friend to create pong.

NOTE: Before playing, make sure you set up a list for pong. Type in your calculator:

SetUpEditor LPONG

NOTE: If you typed in the code above, also make sure you type:

{0,0,0} →LPONG

This can be done on the main screen.

How to PlayEdit

Move up and down to try and rally back and forth either by yourself or with a friend! Only the player in which the ball is traveling towards may move their paddle. The ball appears as a sqaure with the missing center. The paddles are sticks each 10 pixels long on the side.

ControlsEdit

7 is the up arrow for Player 1, while 1 is the corresponding down arrow.

9 is the up arrow for Player 2, while 3 is the corresponding down arrow.

As states above, only the player in which the ball is traveling towards may move their paddle.

Other NotesEdit

I have a sub-program which will choose speed and ball angle based on the length of the game and the last movement of the paddle.

Also, there are some times when the ball will glitch out in the bottom screen (I'm fairly certain I know why)

Occasionally, an error will occur because the ball is too far out of the screen. I took a lot of shortcuts here to make the game run as smoothly as possible, so feel free to clean up some areas.

CodeEdit

:ClrHome
:Menu("OPTIONS","PLAY!",AA,"VIEW STATS",BB,"LEAVE",CC
:Lbl BB
 :Output(1,1,"PLAYER 1:
:Output(2,1,LPONG(1)
:Output(2,5,"WINS
:Output(4,1,"PLAYER 2:
:Output(5,1,LPONG(2)
:Output(5,5,"WINS
:Output(7,1,"HIGH SCORE:
:Output(7,13,LPONG(3)
:Lbl CC
 :Stop
 :Lbl AA
 :Menu("-----CHOOSE-----","1 PLAYER",BCwrg,"2 PLAYER",BD
:Lbl BC
 :0→E
:Goto F
 :Lbl BD
 :1→E
:Lbl F 
 :prgmGRAPH       //all this does is clear graph and take out X&Y axis
:0→Xmin
:-62→Ymin
:1→ΔX
:1→ΔY
:-23→A
:-23→B
:47→C
:-30→D
:-2→M
:0→N
:Line(91,B,91,B+9
:Lbl A
 :While M=-2
 :Pt-On(C,D,2
 :Line(3,A,3,A+9
 :getKey→K
:A+4(K=72)-4(K=92→A
:For(X,A-4,A-1
 :Pt-Off(3,X
 :End
 :For(X,A+9,A+13
 :Pt-Off(3,X
 :End
 :Pt-Off(C,D,2
 :C+M→C
:D+N→D
:If D≥-2 or D≤-60
:-N→N
:If C<2
 :Goto P2
 :If pxl-Test(-D,C-2
:2→M
:End
 :T+1→T
:randInt(-3,3→N
:While M=2
 :Pt-On(C,D,2
 :Line(91,B,91,B+9
:getKey→K
:B+4(K=74)-4(K=94→B
:For(X,B-4,B-1
 :Pt-Off(91,X
 :End
 :For(X,B+10,B+13
:Pt-Off(91,X
 :End
 :Pt-Off(C,D,2
 :C+M→C
:D+N→D
:If D≥-2 or D≤-60
:-N→N
:If C>92
 :Goto P1
 :If pxl-Test(-D,C+2)
:-2→M
:End
 :randInt(-3,3→N
:T+.01→T
:Goto A
 :Lbl P1
 :If E=1
 :Then
 :Disp "PLAYER 1 WINS!
:LPONG(1)+1→LPONG(1)
:End
 :If E=0
 :Then
 :Disp iPart(T)+100fPart(T)
:If iPart(T)+100fPart(T)>LPONG(3)
:iPart(T)+100fPart(T)→LPONG(3)
:End
 :Stop
 :Lbl P2
 :If E=1
 :Then
 :Disp "PLAYER 2 WINS!
:LPONG(2)+1→LPONG(2)
:End
 :If E=0
 :Then
 :iPart(T)+100fPart(T)→H
:Disp H
 :If H>LPONG(3)
:H→LPONG(3)
:End

Assuming this is all copied correctly, this should work like a charm!

ExplanationEdit

:ClrHome
:Menu("OPTIONS","PLAY!",AA,"VIEW STATS",BB,"LEAVE",CC

Main Menu, pretty self explanatory.

:Lbl BB
:Output(1,1,"PLAYER 1:
:Output(2,1,LPONG(1)
:Output(2,5,"WINS
:Output(4,1,"PLAYER 2:
:Output(5,1,LPONG(2)
:Output(5,5,"WINS
:Output(7,1,"HIGH SCORE:
:Output(7,13,LPONG(3)

This is the VIEW STATS option and it will show the number of wins for Player 1, Player 2, and the high score for playing alone.

:Lbl CC
:Stop

This will stop the program for the previous menu option, and the option, LEAVE

:Lbl AA
:Menu("-----CHOOSE-----","1 PLAYER",BC,"2 PLAYER",BD

Before starting the game, this menu will ask if you are playing by yourself, or with a friend.

:Lbl BC
:0→E
:Goto F

If you are playing by yourself, the calculator will store 0 into E in order to be able to recall this information later.

:Lbl BD
:1→E

Same deal here; if you're playing with a friend, this information will be stored into E

:Lbl F 
:prgmGRAPH

A program I made which deletes the X axis, Y axis, and sets the Zoom to default

:0→Xmin
:-62→Ymin

Sets the X & Y min. These are found under the VARS > Window menu

:1→ΔX
:1→ΔY

Sets the value of one pixel to one point. Found in the same place

:-23→A
:-23→B

A is the location of the left paddle, B is the location of the right paddle. This sets both coordinates to -23.

:47→C
:-30→D

C and D are the X & Y coordinates of the "ball".

:-2→M
:0→N

M and N are the slope of the ball. M is the direction (left or right) that the ball is traveling. N is the degree (up or down). for example, -2,3 would mean that in every tick, the ball will move left 2, up 3.

:Line(91,B,91,B+9

Since there are two loops based on the direction the ball is traveling, this plots the right paddle and makes the first loop run faster.

:Lbl A
:While M=-2

Beginning of the Player 1 loop. "While M=-2" stays to end the loop when the ball is no longer moving left.

:Pt-On(C,D,2
:Line(3,A,3,A+9

Draws the left paddle and the ball. The Pt-On( command takes 3 arguments. the first two are the coordinates, the third is what makes it look like a square with a hole in the center.

:getKey→K

gets a key and stores it in K

:A+4(K=72)-4(K=92→A

Complicated movement sequence which moves the paddle based on keypress.

:For(X,A-4,A-1
:Pt-Off(3,X
 :End
 :For(X,A+9,A+13
 :Pt-Off(3,X
 :End

These "for" loops delete the points to the top and bottom of the paddle. If this weren't here, the paddle wouldnt erase as it moved, and would draw a line on the left.

:Pt-Off(C,D,2
:C+M→C
:D+N→D

Erases the ball, then moves it based on the M & N.

:If D≥-2 or D≤-60
:-N→N

This makes the ball bounce off the top and bottom boundaries. Since the slope is reversed, (N turns into -N) the ball will ricochet in the exact angle it hit the boundary.

:If C<2
:Goto P2
 :If pxl-Test(-D,C-2
:2→M
:End

This determines if the ball hit the paddle. If so, the loop will end, if not, the program will go to label P2 which you will see later.

:T+1→T

In 1 player mode, this is your score.

:randInt(-3,3→N

When the ball hits the paddle, this is the line of code that will cause it to come off at a random angle.

:While M=2

Start of the second loop

:Pt-On(C,D,2
:Line(91,B,91,B+9

Draws the ball and right paddle

:getKey→K
:B+4(K=74)-4(K=94→B
:For(X,B-4,B-1
 :Pt-Off(91,X
 :End
 :For(X,B+10,B+13
:Pt-Off(91,X
 :End
 :Pt-Off(C,D,2

Like the first loop, this gets a key, moves the paddle, and deletes the pixels to the top and bottom.

:C+M→C
:D+N→D
:If D≥-2 or D≤-60
:-N→N

Moves the ball. Again, if it hits the top or bottom, it will bounce off.

:If C>92
:Goto P1
 :If pxl-Test(-D,C+2)
:-2→M
:End

Checks to see if the ball hit the paddle

:randInt(-3,3→N
:T+.01→T
:Goto A

random angle of the ball off the paddle, adds a number to your score, and moves to the beginning of the first loop. I chose to add .01 to the score for personal reasons. When you play single player, it will display your score as an integer.

:Lbl P1
:If E=1
 :Then
 :Disp "PLAYER 1 WINS!
:LPONG(1)+1→LPONG(1)
:End

When player 1 wins, it will say so and update the player statistics.

:If E=0
:Then
 :Disp iPart(T)+100fPart(T)
:If iPart(T)+100fPart(T)>LPONG(3)
:iPart(T)+100fPart(T)→LPONG(3)
:End
 :Stop

If in single player, it will display your score and update the high score chart respectively.

:Lbl P2
:If E=1
 :Then
 :Disp "PLAYER 2 WINS!
:LPONG(2)+1→LPONG(2)
:End
 :If E=0
 :Then
 :iPart(T)+100fPart(T)→H
:Disp H
 :If H>LPONG(3)
:H→LPONG(3)
:End

Same as above. It reads whether you are in single- or multi-player and will update the statistics accordingly.

Rianbay812 22:25, February 12, 2012 (UTC)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.