` *=---------------------------------------------------------------------=*
`
` >> 2 Player Simple Pong V0.01 <<
`
` By Kevin Picone
`
` 28th, May, 2002
`
` (c) Copyright 2002 Kevin Picone, All Rights Reserved.
`
`
` *=---------------------------------------------------------------------=*
` Email: picone@centercom.com.au URL: www.uwdesign.50megs.com
` *=---------------------------------------------------------------------=*
`
`
`
` So WHAT does this do ?:
` =======================
`
`
` This mini game re-creates a basic versions of the first arcade game
` "pong". A good learning exercise for new programmers to dig through
` it and see how a full mini game works. This one includes a basic intro
` the game and game over screen. Their pretty ugly to look at, so see
` if you can improve them..
`
` Well, good luck !
`
`
`
` Known bugs:
` ===========
`
` The ball rebound and get stuck on the player bats.. Can you fix it :)
`
`
`
` Free License Agreement.
` =========================
`
` * The user / developer agrees to include a visible credit to
` "Kevin Picone" and provide a link to Underware Design's web site,
` within your programs Documentation and or Web Site.
`
` * The user / developer agrees to NOT release derivative works in
` whole or in part of this source code, or Port this source code to
` other languages or platforms, without the prior written consent from
` the author "Kevin Picone"
`
` * The user / developer agrees to NOT offer this source code for Sale.
`
` * Providing the User / Developer agrees in full to the previous FREE
` license Agreement clauses, the user / developer may use this
` source code FREELY in all their products, commercial or otherwise.
`
`
`
` Cya,
` Kevin Picone
` picone@centercom.com.au
` www.uwdesign.50megs.com
` www.thedrummachine.50megs.com
` pub101.ezboard.com/buwdesign (uwdesign forum)
`
`
` *=---------------------------------------------------------------------=*
Sync on
Sync rate 60
Hide mouse
` Create Some GAME STATE Variables to make our code more readible
` These are used to allow us to easily determine what part of the
` games code to run, The INTRO, THE GAME, or the GAME OVER screen
`
i=1
GameState_Intro_FadeIn=i : inc I
GameState_Intro_HitKey=i : inc I
GameState_Intro_faDeOut=i : inc I
GameState_Game_in_play=i : inc I
GameState_GameOver=i : inc I
` Now Set The GAMESTATE variable to INTRO mode
GameState=GameState_Intro_FadeIn
Intro_Text_colour=Rgb(250,25,150)
Intro_Fade_Percent#=0
do
cls 0
ink rgb(55,55,55),0
print " "
print " "
print " "
print "Player 1 Wins: ",Victory_p2
print "Player 2 Wins: ",Victory_p1
`print " player1 overall*2:",player1_score
`print " player2 overall*2:",player2_score
` -------------------
` fade the intro IN
` -------------------
if GameState=GameState_intro_fadeIn
c=FadeColour24(Intro_Text_colour,Intro_Fade_Percent#)
ink c,0
Gosub Display_intro_text
inc Intro_Fade_Percent#,2
if Intro_Fade_Percent#>100
` When the fade is complete set game mode to HIT KEY
GameState=GameState_intro_hitKey
endif
Endif
` ----------------------------
` fade the intro OUT to Black
` -----------------------------
if GameState=GameState_intro_fadeout
c=FadeColour24(Intro_Text_colour,Intro_Fade_Percent#)
ink c,0
Gosub Display_intro_text
dec Intro_Fade_Percent#,2
if Intro_Fade_Percent#<0
`once the fade out is done now lets - Start the game
GameState=GameState_Game_in_play
endif
Endif
` ---------------------------------------
` IF Game State = Game State Intro then Were displaying the intro titles
` ---------------------------------------
if GameState=GameState_intro_hitKey
ink Intro_Text_colour,0
Gosub Display_intro_text
if inkey$()<>""
` Fade out the intro
GameState=GameState_intro_fadeout
` Init the players positions
Gosub Init_player_positions
` Init The ball Speed
BallXspeed#=Get_Random_Ball_Speed(-5,5)
BallYspeed#=Get_Random_Ball_Speed(-4,4)
` int the Balls starting position
BallX#=320
BallY#=240
endif
endif
` ---------------------------------------
` IF Game State = Game State GAME OVER then Were displaying game over
` screen
` ---------------------------------------
If GameState=GameState_Game_Over
ink GameOver_Colour,0
center Text 320,240,"Game Over"
dec GameOver_ShowFrames
if GameOver_ShowFrames<0
` Set Game back to intro mode
GameState=GameState_Intro_FadeIn
` Reste The gameover_frame counter for next time
Gosub Set_Display_game_over_Frames
endif
Endif
` -----------------------------------------------------
` IF Game STATE = GAME IN PLAY then the game is in PLAY
` ----------------------------------------------------------
if GameState=GameState_Game_in_play
` Player #1
BallxSpeed#=controls(0,30,44,10,10,50,20,Ballx#,Bally#,BallXspeed#)
` Player #2
Ballxspeed#=controls(1,200,208,640-20,10,50,470,Ballx#,Bally#,BallXspeed#)
` Check if the Ball the top or bottom of screen, if so, rebound it
` -----------------------------------------------------------------
if bally#<10 or Bally#>470 then BallySpeed#=BallySpeed#*-1
ballx#=ballx#+BallXspeed#
bally#=bally#+Ballyspeed#
` Check if Ball Passed Either player
` -----------------------------------
if ballx#<-20 or BallX#>660
GameState=GameState_GAME_OVER
Gosub Set_Display_game_over_Frames
endif
` ----------------
` draw the Ball
` ---------------
FilledCircle(int(ballx#),int(bally#),3,rgb(0,255,0))
Endif
sync
loop
` *=---------------------------------------------------------------------=*
` Display The Title Screen Information
` *=---------------------------------------------------------------------=*
Display_intro_text:
Y=100
center Text 320,y,"D B a n d P F ' s W a l l B o u n c e r G l i t c h e r "
y=y+20
center Text 320,y,"Formally 2 Player Pong By: Kevin Picone"
y=y+40
center Text 320,y,"Controls:"
y=y+30
center Text 320,y," Player 1 Keys: A=up ,Z=Down)"
y=y+20
center Text 320,y," Player 2 Keys: Up Arrow Key =up ,Down Arrow Key =Down)"
y=y+30
center Text 320,y,"(c) Copyright 2002 Kevin Picone, Underware design"
y=y+20
center Text 320,y+50,"Press Any Key To Play"
return
` *=---------------------------------------------------------------------=*
` Set up The Game Over Variables
` *=---------------------------------------------------------------------=*
Set_Display_game_over_Frames:
GameOver_Colour=Rgb(100,255,200)
GameOver_ShowFrames=100
if Players_Score(1)>players_score(player,1) then Victory_p1=Victory_p1+1
if Players_Score(1)<players_score(player,1) then Victory_p2=Victory_p2+1
player1_score=player1_score+players_score(player,1)
player2_score=Players_Score(1)+Players_Score(1)
return
` *=---------------------------------------------------------------------=*
` Init Players
` *=---------------------------------------------------------------------=*
Init_player_positions:
` Init Both Players
Dim Players_Ypos(2)
Dim Players_Score(2)
Dim Players_Colour(2)
players_ypos(0)=240
Players_Colour(0)=rgb(0,100,105)
players_ypos(1)=240
Players_Colour(1)=rgb(195,60,15)
return
` *=---------------------------------------------------------------------=*
` Control Players
` *=---------------------------------------------------------------------=*
`
` The Same routine is used to control both players.
`
` This routine also changes the direction of the Ball when a collision
` occurs.
`
`
` *=---------------------------------------------------------------------=*
Function controls(player,upkey,downkey,Xpos,width,height,Scorexpos,Ballx#,Bally#,BallXspeed#)
` Control The player
b4:
if keystate(upkey)=1 and players_ypos(player)>0 then players_ypos(player)=players_ypos(player)-5
if keystate(downkey)=1 and players_ypos(player)<(475-height) then players_ypos(player)=players_ypos(player)+5
if spacekey()=1
suspend for key
while scancode()=0
cls
ink rgb(255,0,0),0
print "PAUSE MENU"
ink rgb(255,255,255),0
print "Player one's score:",Players_Score(1)
print "Player two's score:",players_score(player,1)
print "Press a key to continue!"
sync
endwhile
goto b4
endif
` draw the players Bat
` ----------------------
ink Players_Colour(player),0
Box xpos,players_ypos(player),xpos+width,players_ypos(player)+height
` Handle Collision With the Ball and bat
` ----------------------------------------
if (players_ypos(player)+height)>BallY# and players_ypos(player)<(BallY#+5)
if (xpos+width)>BallX# and xpos<(BallX#+5)
` If the bat hit the Ball then reflex the ball's Direction
BallXspeed#=BallXspeed#*-1
` Add some score to the player
players_score(player)=players_score(player,1)+5
endif
Endif
text scorexpos,0,"Player "+str$(player+1)+" Score:"+Zero_Pad_Number(players_score(player),8)
Endfunction BallxSpeed#
` *=------------------------------------------------------------------=*
` Zero Pad Number
` *=------------------------------------------------------------------=*
`
` This function takes a number and returns it as a fixed length string
` padded with zero's
`
` *=------------------------------------------------------------------=*
Function Zero_Pad_Number(Number,digits)
S$=right$("0000000000000000"+str$(number),digits)
EndFunction s$
Function Get_Random_Ball_Speed(low,top)
d=top-low
repeat
speed=low+rnd(d)
until abs(speed)>2
endFunction Speed
` *=------------------------------------------------------------------=*
` Fade Colour 24
` *=------------------------------------------------------------------=*
`
` Fades a 24colour via a percentage. The colour clipped so it won't
` overflow.
`
` *=------------------------------------------------------------------=*
Function FadeColour24(Col,FadePercent#)
Scaler#=((255.0*FadePercent#)/100.0)/255.0
R=RGBR(Col)*Scaler#
G=RGBG(Col)*Scaler#
B=RGBB(Col)*Scaler#
If R<0 then R=0
If G<0 then G=0
If B<0 then B=0
If R>255 then R=255
If G>255 then G=255
If B>255 then B=255
NewColour=Rgb(r,g,b)
Endfunction NewColour
` *=----------------------------------------------------------------=*
` --------- Filled Circle ---------
` *=----------------------------------------------------------------=*
Function FilledCircle(bx,by,radius,colour)
ink rgb(0,255,0),0
WindowWidth=640
bytop=by
bybot=by
Radius2=Radius-1
WindowWidth2=WindowWidth-1
For Y=0 To RADIUS2
x=sqrt((Radius^2)-y^2)
LeftPixel=bx-x
RightPixel=bx+x
if LeftPixel<WindowWidth
if RightPixel>0
if LeftPixel<0 Then LeftPixel=0
if RightPixel>WindowWidth2 Then RightPixel=WindowWidth2
Box LeftPixel,BYTop,RightPixel,BYTop
Box LeftPixel,BYbot,RightPixel,BYbot
Endif
endif
inc ByTop
dec bybot
Next Y
EndFunction
This was on the internet. This isn't you?
I urge you to watch the film "Who killed the electric car". Support electric cars! Did you know their used to be more electric cars then gassoline cars?