` Created 1/15/07
` Pong 1.00 Finished 1/20/07
` Main Menu Tab
Main_Menu:
`Clear Screen
CLS
`Bold Text
set text to bold
set text size 60
` Make Pong
center text screen width()/2,screen height()/10, "Pong 1.00"
` Set Text Size Smaller
set text size 30
` Main Menu Loop
Do
if Highlight(screen width()/2-text width("Single Player")/2,screen height()*.4,"Single Player")=1
CLS : center text screen width()/2, screen height()/2.5, "No Single Player Currently." : wait 3000 : goto Main_Menu : endif
if Highlight(screen width()/2-text width("Multiplayer")/2,screen height()*.55,"Multiplayer")=1 then exit
if Highlight(screen width()/2-text width("Exit")/2,screen height()*.7,"Exit")=1 then end
loop
` Start a New Game Tab
New_Game:
` Reset Standard Ink and Text
set text size 12
ink rgb(255,255,255),0
` Reset Players' Scores
Player1Score=0
Player2Score=0
` No Mouse for Player 1
hide mouse
` No White in Sprites Appear
set image colorkey 255,255,255
` Load Images
load image "paddle.bmp" , 1
load image "ball.bmp" , 2
` Beginning of Game Tab
New_Round:
` Load Sprites to the Screen
sprite 1, screen width()/20 , screen height()/3 , 1
sprite 2, screen width()-screen width()/20 , screen height()/3 , 1
sprite 3, screen width()/2, screen height()/2 , 2 : rotate sprite 3,Rnd(360)
` Set the Initial Difficulty Factors
BallSpeed#=0.8
Barsize1#=100
Barsize2#=100
` Main Loop
Do
` Print Scores
center text screen width()/10,screen height()/24,"Player 1: "+Str$(Player1Score)
center text screen width()-screen width()/10,screen height()/24,"Player 2: "+Str$(Player2Score)
` Substitute Variables Used When Creating Sprites
` Substitute Angle Var
SpriteAngle=Sprite Angle(3)
` Sub Collision Paddle Vars
PaddlePosX=Sprite X(1)
BallPosY=sprite y(3)
SpriteWidth=Sprite Width(1)
SpriteHeight=((Sprite Height(3)*90)/Sprite Angle(3))
` Sub Collision Screen Var
BallPosX=Sprite X(3)
SpriteWidth3=Sprite Width(3)
````Controls````
PlayerControls()
````Controls````
` Ball Controls
` Start Ball Movement
if BallReflect1=0 and BallReflect2=0 and WallReflect=0
if returnkey()=1
BallActivate=1
endif
` Trigger For Constant Movement
if BallActivate=1
move sprite 3,BallSpeed#
endif
endif
` Collision: Paddle 1 - Ball
if sprite hit(1,3)=1
BallReflect1=1
BallReflect2=0
WallReflect=0
BallActivate=0
rotate sprite 3,Rnd(130)+25
sprite 3, PaddlePosX+2*SpriteWidth+5, BallPosY-SpriteHeight, 2
endif
if BallReflect1=1
move sprite 3,BallSpeed#
endif
` Collision: Paddle 2 - Ball
if sprite hit(2,3)=1
BallReflect2=1
BallReflect1=0
WallReflect=0
BallActivate=0
rotate sprite 3,Rnd(130)+205
sprite 3, screen width()-PaddlePosX-SpriteWidth-5, BallPosY+SpriteHeight, 2
endif
if BallReflect2=1
move sprite 3,BallSpeed#
endif
` Collision: Ball - Screen
` Top
if sprite y(3)<sprite height(3)/2
WallReflect=1
BallReflect1=0
BallReflect2=0
BallActivate=0
rotate sprite 3,180-SpriteAngle
sprite 3, BallPosX+SpriteWidth3, BallPosY+5, 2
endif
if WallReflect=1
move sprite 3,BallSpeed#/2
endif
` Bottom
if sprite y(3)>screen height()-sprite height(3)/2
WallReflect=1
BallReflect1=0
BallReflect2=0
BallActivate=0
rotate sprite 3,180-SpriteAngle
sprite 3, BallPosX-SpriteWidth3, BallPosY-5, 2
endif
if WallReflect=1
move sprite 3,BallSpeed#/2
endif
` When Player Scores
if sprite x(3)>screen width()
Player1Score=Player1Score+1
BallReflect1=0
BallReflect2=0
WallReflect=0
BallActivate=0
goto New_Round:
endif
if sprite x(3)<0
Player2Score=Player2Score+1
BallReflect1=0
BallReflect2=0
WallReflect=0
BallActivate=0
goto New_Round:
endif
` When Player Loses
if Player1Score=3
Loser$="Player 2 Loses. Game Over."
wait 500
exit
endif
if Player2Score=3
Loser$="Player 1 Loses. Game Over."
wait 1000
exit
endif
` Refresh Bar Sizes(Smaller)
if sprite scale x(1)>20
scale sprite 1,BarSize1#
endif
if sprite scale x(2)>20
scale sprite 2,BarSize2#
endif
` Dec/Inc Constants To Increase Difficulty
Barsize1#=Barsize1#-0.0008
Barsize2#=Barsize2#-0.0008
BallSpeed#=BallSpeed#+.0002
loop
` Game Over
` Make Ball Inflate
for t=101 to 8001 step 10
scale sprite 3,t
spriteheight=sprite height(3)/2
spritewidth=sprite width(3)/2
wait 1
delete sprite 3
sprite 3, screen width()/2-spritewidth, screen height()/2-spriteheight , 2
next t
` Red, Big Ink
ink rgb(255,0,0),rgb(255,0,0)
set text size 40
` End Text and New Game
Do
center text screen width()/2,screen height()/3, Loser$
center text screen width()/2,screen height()/2, "Press Enter To Play"
center text screen width()/2,screen height()/1.75, "Another Game"
if returnkey()=1
goto New_Game:
endif
Loop
`Prevent Going Onward
end
` Player Controls
function PlayerControls()
` Paddle 1 Move Up
if scancode()=17
move sprite 1,4
endif
` Paddle 1 Move Down
if scancode()=31
move sprite 1,-4
endif
` Paddle 1 Top Screen Collision
if sprite y(1)<0
delete sprite 1
sprite 1,screen width()/20,0,1
endif
` Paddle 1 Bottom Screen Collision
if sprite y(1)>screen height()-sprite height(2)
delete sprite 1
sprite 1,screen width()/20,screen height()-sprite height(2),1
endif
` Paddle 2 Up
if upkey()>0
move sprite 2,4
endif
` Paddle 2 Down
if downkey()>0
move sprite 2,-4
endif
` Paddle 2 Top Screen Collision
if sprite y(2)<0
delete sprite 2
sprite 2,screen width()-screen width()/20,0,1
endif
` Paddle 2 Bottom Screen Collision
if sprite y(2)>screen height()-sprite height(1)
delete sprite 2
sprite 2,screen width()-screen width()/20,screen height()-sprite height(1),1
endif
endfunction
` Button Highlighting Function
function Highlight(x1,y1,Option$)
Over=0
x2=Text Width(Option$)
y2=Text Height(Option$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1 and mousey()<y1+y2
Over=1
endif
endif
if Over=1 then ink rgb(255,0,0),0 else ink rgb(255,255,255),0
if Over=1
Over=Mouseclick()
else
Over=0
endif
text x1,y1,Option$
endfunction Over
This is my 2nd program so far...I really need help finding bugs like 2 bugs:
-When the ball hits the top of the screen often times the ball goes to like 200 speed for no reason(FIXED)
-Whenever the ball hits the paddles, well sometimes theres a bit of glitchy movement, im sure its b/c of the rotation
Other than that, have fun with it
thx