Main Menu

2 Player Pong

Started by kevin, November 12, 2008, 09:18:29 PM

Previous topic - Next topic

kevin

2 PLayer Pong

 This is a quick port of an old DB mini game example, for those interesting in having a go at Clever Coders challenge 15.



PlayBASIC Code: [Select]
` *=---------------------------------------------------------------------=*
`
` >> 2 Player Simple Pong V0.01 <<
`
` By Kevin Picone
`
` 28th, May, 2002
`
` (c) Copyright 2002 Kevin Picone, All Rights Reserved.
`
` *=---------------------------------------------------------------------=*
`
`
` So WHAT does this do ?:
` =======================
`
`
` This mini game re-creates a basic versions of one the first arcade games
` "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 :)
`
` *=---------------------------------------------------------------------=*


setFps 60

` 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
`
acset =1
Constant GameState_Intro_FadeIn =ac(1)
Constant GameState_Intro_HitKey =ac(1)
Constant GameState_Intro_faDeOut =ac(1)
Constant GameState_Game_in_play =ac(1)
Constant GameState_GameOver =ac(1)


` 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

` -------------------
` fade the intro IN
` -------------------

if GameState=GameState_intro_fadeIn
ink RgbFade(Intro_Text_colour,Intro_Fade_Percent#)
Display_intro_text()
Intro_Fade_Percent#=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
ink RgbFade(Intro_Text_colour,Intro_Fade_Percent#)
Display_intro_text()
Intro_Fade_Percent#=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
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
centerText GetScreenWidth()/2,GetScreenHeight()*0.4,"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
Login required to view complete source code