TGC Codebase Backup



A Pong Game In Only 55 Lines by Anonymous Coder

29th Feb 2004 6:50
Summary

This is a simple game of pong in the minimum number of lines



Description

This is a short and simple version of the game Pong. This is my first game so it might be a bit buggy. If you find a bug, please contact me and i will hopefully sort it out. Hope you enjoy.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Hide the mouse
Hide mouse
Rem Make all the objects needed in the game
Make object box 1,1,3,0 : color object 1,rgb(255,0,0)
Make object box 2,1,3,0 : color object 2,rgb(255,0,0)
Make object sphere 3,1  : color object 3,rgb(0,255,0)
Rem Set up the camera so it looks 2D
Position camera 0,0,-10
Point camera 0,0,0
Rem Setup what the variables start as
ply1posx# = -7
ply2posx# = 7
Ballmove# = 0

sync on
Rem Enter the main loop
Do

   Position object 3,ballx#,bally#,0
Rem Setup the differant areas of the paddles and what they do
   If ballx# > ply2posx# - 1 and bally# < ply2pos# + 0.5 and bally# > ply2pos# - 0.5 Then ballmove# = 0
   If ballx# < ply1posx# + 1 and bally# < ply1pos# + 0.5 and bally# > ply1pos# - 0.5 Then ballmove# = 1

   If ballx# > ply2posx# - 1 and bally# < ply2pos# + 3.0 and bally# > ply2pos# + 0.5 Then ballmove# = 2
   If ballx# < ply1posx# + 1 and bally# < ply1pos# + 3.0 and bally# > ply1pos# + 0.5 Then ballmove# = 3

   If ballx# > ply2posx# - 1 and bally# < ply2pos# - 0.5 and bally# > ply2pos# - 3.0 Then ballmove# = 4
   If ballx# < ply1posx# + 1 and bally# < ply1pos# - 0.5 and bally# > ply1pos# - 3.0 Then ballmove# = 5
Rem Setup the differant ball movements
   If ballmove# = 2 and bally# > 5 Then ballmove# = 4
   If ballmove# = 3 and bally# > 5 Then ballmove# = 5

   If ballmove# = 4 and bally# < -5 Then ballmove# = 2
   If ballmove# = 5 and bally# < -5 Then ballmove# = 3

   If ballmove# = 1 Then ballx#=ballx# +0.05
   If ballmove# = 0 Then ballx#=ballx# -0.05

   If ballmove# = 2 Then ballx#=ballx# -0.05 : bally#=bally# + 0.05
   If ballmove# = 3 Then ballx#=ballx# +0.05 : bally#=bally# + 0.05

   If ballmove# = 4 Then ballx#=ballx# -0.05 : bally#=bally# - 0.05
   If ballmove# = 5 Then ballx#=ballx# +0.05 : bally#=bally# - 0.05
Rem Setup Player 1 and Player 2 controlls
   If upkey() = 1 and ply1pos# < 4 Then ply1pos#=ply1pos# + 0.05
   If Downkey() = 1 and ply1pos# > -4 Then ply1pos#=ply1pos# - 0.05

   If keystate(72) = 1 and ply2pos# < 4 Then ply2pos#=ply2pos# + 0.05
   If keystate(80) = 1 and ply2pos# > -4 Then ply2pos#=ply2pos# - 0.05
Rem Setup what happens if someone scores a point
   If ballx# < -8 Then Sleep 1000 : Ballx# = 0 : bally# = 0 : ballmove# = 0 : ply1pos# = 0 : ply2pos# = 0 : Ply2score# = ply2score# + 1
   If ballx# > 8  Then Sleep 1000 : ballx# = 0 : bally# = 0 : ballmove# = 1 : ply1pos# = 0 : ply1pos# = 0 : Ply1score# = ply1score# + 1
Rem Tell DBPro where the paddles are on the screen
   Position object 1,ply1posx#,ply1pos#,0
   Position object 2,ply2posx#,ply2pos#,0

sync
Loop