'Pong Master v0.1
'Copyright c2005 Dark Mars Software
'written by Dark Mars Software
'Option Explicit
SuperStrict
'Load Libraries
'Framework BRL.D3D7Max2D
'Import BRL.System
'Import BRL.RamStream
'Import BRL.WAVLoader
'Import BRL.BMPLoader
'Import BRL.Win32MaxGUI
'Import BRL.FreeAudioAudio
'Import BRL.Timer
' modules which may be required:
' Import BRL.PNGLoader
' Import BRL.TGALoader
' Import BRL.JPGLoader
' Import BRL.OGGLoader
SetGraphicsDriver D3D7Max2DDriver()
'Include the Media Files
IncludeMedia()
'Define the Applications Title
AppTitle = "Pong Master 0.1"
'Define Global Variables
'Sprite Variables
Global Player_Image:Timage 'Player's Bat
Global Ball_Image:Timage 'Ball
'Sound Variables
Global Applause_Sound:TSound ' Applause
Global Boink1_Sound:TSound ' Boink 1
Global Boink2_Sound:TSound ' Boink 2
Global Explosion_Sound:TSound ' Explosion
'Player Type
Type Player
Field X_Position:Int,Score:Int
End Type
Global Player1:Player = New Player
Global Player2:Player = New Player
Type Ball
Field X_Position:Int,Y_Position:Int,X_Velocity:Int,Y_Velocity:Int
End Type
Global Balls:Ball = New Ball
TitleScreen()
Function BallBouncing()
End Function
Function CleanUp()
'Remove Graphics
Ball_Image = Null 'Ball
Player_Image = Null 'Player's Bat
'Remove Sounds
Applause_Sound = Null ' Applause
Boink1_Sound = Null ' Boink 1
Boink2_Sound = Null ' Boink 2
Explosion_Sound = Null ' Explosion
End Function
Function Credits()
Local Notif:String=""
Notif = "Pong Master" + Chr$(10)
Notif = Notif + "Copyright c2005 Dark Mars Software" + Chr$(10)
Notif = Notif + "" + Chr$(10)
Notif = Notif + "Written by" + Chr$(10)
Notif = Notif + "Dark Mars Software" + Chr$(10)
Notif = Notif + "" + Chr$(10)
Notif = Notif + "Ideas by" + Chr$(10)
Notif = Notif + "Dark Mars Software" + Chr$(10)
Notif = Notif + "" + Chr$(10)
Notif = Notif + "Tested by" + Chr$(10)
Notif = Notif + "Dark Mars Software" + Chr$(10)
Notif = Notif + "BlitzBASIC Community" + Chr$(10)
Notify Notif$
End Function
Function IncludeMedia()
'Load Sounds
Incbin "Sounds/applause.wav" ' Applause
Incbin "Sounds/boink1.wav" ' Boink 1
Incbin "Sounds/boink2.wav" ' Boink 2
Incbin "Sounds/explosion.wav" ' Explosion
'Load Graphics
Incbin "Sprites/ball.bmp" ' Ball
Incbin "Sprites/bat.bmp" ' Bat
End Function
Function Instructions()
'create all the required buttons
Local IWindow:TGadget=CreateWindow( "Instructions", ( ClientWidth( Desktop() )/2 )-105, ( ClientHeight( Desktop() )/2 )-230, 210, 460 )
Local AimButton:TGadget = CreateButton( "Aim of the game", 0, 0, 200, 40, IWindow )
Local ControlsButton:TGadget = CreateButton( "Controls", 0, 40, 200, 40, IWindow )
Local RequirementsButton:TGadget = CreateButton( "SystemRequirements", 0, 80, 200, 40, IWindow )
Local HintsButton:TGadget = CreateButton( "Helpful hints", 0, 120, 200, 40, IWindow )
Local BackButton:TGadget = CreateButton( "Back", 0, 350, 200, 40, IWindow )
Local check:Int=1
ShowGadget IWindow
While check=1
WaitEvent()
Select EventID() 'see what gadget has been clicked on
'if the window close button was clicked on end program
Case EVENT_WINDOWCLOSE
End
'if the user clicked on a button
Case EVENT_GADGETACTION
Select EventSource()
Case AimButton
InstructAim()
Case ControlsButton
InstructControls()
Case RequirementsButton
InstructRequirements()
Case HintsButton
InstructTips()
Case BackButton
check=0
End Select
End Select
Wend
'a little house cleaning to make sure the memory is released back to blitz for later use
'this just frees all the local gadgets that were created at the beginning of this functions
FreeGadget AimButton
FreeGadget ControlsButton
FreeGadget RequirementsButton
FreeGadget HintsButton
FreeGadget BackButton
FreeGadget IWindow
End Function
Function InstructAim()
Local Notif:String = ""
Notif$ = Notif$ + "Aim of the game" + Chr$(10)
Notif$ = Notif$ + "-------------------" + Chr$(10)
Notif$ = Notif$ + "The aim of Pong Master is to score 15 points first by getting the" + Chr$(10)
Notif$ = Notif$ + " ball past the other players paddle" + Chr$( 10 )
Notify Notif
End Function
Function InstructControls()
Local Notif:String=""
Notif = Notif + "Player 1 Controls" + Chr$(10)
Notif = Notif + "---------------------" + Chr$(10)
Notif = Notif + "Left Arrow Key - Move Paddle Left" + Chr$(10)
Notif = Notif + "Right Arrow Key - Move Paddle Right" + Chr$(10)
Notif = Notif + "" + Chr$(10)
Notif = Notif + "Player 2 Controls" + Chr$(10)
Notif = Notif + "-----------------" + Chr$(10)
Notif = Notif + "A - Move Paddle Left" + Chr$(10)
Notif = Notif + "S - Move Paddle Right" + Chr$(10)
Notify Notif
End Function
Function InstructRequirements()
Local Notif:String=""
Notif = Notif + "Requirements" + Chr$(10)
Notif = Notif + "-----------------" + Chr$(10)
Notif = Notif + "The minimum spec machines we could test it on is as follows:" + Chr$(10)
Notif = Notif + "Intel 233MMX" + Chr$(10)
Notif = Notif + "64Mb Ram (also 32Mb)" + Chr$(10)
Notif = Notif + "2Mb Harddisk space" + Chr$(10)
Notif = Notif + "Voodoo 2 and S3 Virge video cards" + Chr$(10)
Notif = Notif + "IMPORTANT PLEASE READ: Some of the larger maps will require" + Chr$(10)
Notif = Notif + "more memory, for the small maps 32Mb should suffice but for" + Chr$(10)
Notif = Notif + "medium to large maps I would recommend 64Mb-128Mb of ram." + Chr$(10)
Notif = Notif + "We have had reports of unexpected result from running the game" + Chr$(10)
Notif = Notif + "with insufficient memory." + Chr$(10)
Notify Notif
End Function
Function InstructTips()
Local Notif:String=""
Notif = Notif + "Helpful Tips" + Chr$(10)
Notif = Notif + "--------------" + Chr$(10)
Notif = Notif + "Always follow the ball, doing so will allow you" + Chr$(10)
Notif = Notif + "enough time to possition your paddle accordingly" + Chr$(10)
Notif = Notif + "" + Chr$(10)
Notif = Notif + "Learning the balls bounce angle will allow you" + Chr$(10)
Notif = Notif + "estimate the balls projected path" + Chr$(10)
Notify Notif
End Function
Function LoadSounds()
'Load Sounds
Applause_Sound:TSound = LoadSound("Incbin::Sounds/applause.wav") ' Applause
Boink1_Sound:TSound = LoadSound("Incbin::Sounds/boink1.wav") ' Boink 1
Boink2_Sound:TSound = LoadSound("Incbin::Sounds/boink2.wav") ' Boink 2
Explosion_Sound:TSound = LoadSound("Incbin::Sounds/explosion.wav") ' Explosion
End Function
Function LoadSprites()
'Load Graphics
Ball_Image:TImage = LoadImage("Incbin::Sprites/ball.bmp") ' Ball
Player_Image:TImage = LoadImage("Incbin::Sprites/bat.bmp") ' Players Bat
End Function
Function MoveBall()
End Function
Function Player1Movement()
If KeyDown(KEY_LEFT) Then Player1.X_Position = Player1.X_Position + 5
If KeyDown(KEY_RIGHT) Then Player1.X_Position = Player1.X_Position - 5
End Function
Function Player2Movement()
If KeyDown(KEY_A) Then Player2.X_Position = Player2.X_Position + 5
If KeyDown(KEY_S) Then Player2.X_Position = Player2.X_Position - 5
End Function
Function PositionObjects()
DrawImage(Player_Image, Player1.X_Position, 50)
DrawImage(Player_Image, Player2.X_Position, 560)
DrawImage(Ball_Image, Balls.X_Position, Balls.Y_Position)
End Function
Function ResetLevel()
Player1.X_Position = 240
Player2.X_Position = 240
Balls.X_Position = 240
Balls.Y_Position = 320
End Function
'starting sequence for system (included Title menu system)
Function TitleScreen()
'create all the buttons
Local TWindow:TGadget = CreateWindow( "Main Menu", ( ClientWidth( Desktop() )/2 )-105, ( ClientHeight( Desktop() )/2 )-165, 210, 330 )
Local TwoPlayersButton:TGadget = CreateButton( "2 Player Game", 0, 0, 200, 40, TWindow )
Local CreditsButton:TGadget = CreateButton( "Credits", 0, 40, 200, 40, TWindow )
Local InstructionsButton:TGadget = CreateButton( "Instructions", 0, 80, 200, 40, TWindow )
Local QuitButton:TGadget = CreateButton( "Quit", 0, 120, 200, 40, TWindow )
ShowGadget TWindow
Local check:Int=1
While check=1
WaitEvent()
Select EventID() 'check To see what gadget has been clicked on
'if the window close button was clicked on end program
Case EVENT_WINDOWCLOSE
End
'if a button was clicked on
Case EVENT_GADGETACTION
'see what gadget has been clicked on
Select EventSource()
Case TwoPlayersButton
check=1
TwoPlayersGame()
Case CreditsButton
Credits()
Case InstructionsButton
Instructions()
Case QuitButton
End
End Select
End Select
Wend
FreeGadget TwoPlayersButton
FreeGadget CreditsButton
FreeGadget InstructionsButton
FreeGadget QuitButton
FreeGadget TWindow
End Function
Function TrackScores()
End Function
Function TwoPlayersGame()
'Load Graphics
LoadSprites()
'Load Sounds
LoadSounds()
'Setup a Loop Variable
Local check:Int = 1
Local timer:TTimer = CreateTimer(60)
'Open A Game Window
Local GWindow:TGadget = CreateWindow( "Pong Master - 2 Player", ( ClientWidth( Desktop() )/2 )-105, ( ClientHeight( Desktop() )/2 )-165, 480, 640, Null, WINDOW_TITLEBAR )
Local GraphicsWindow:TGadget=CreateCanvas(0,0,480,640,GWindow)
ShowGadget GWindow
'Setup the Level
ResetLevel()
While check = 1
WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_TIMERTICK
RedrawGadget GraphicsWindow
Case EVENT_GADGETPAINT
SetGraphics CanvasGraphics (GraphicsWindow)
MoveBall()
BallBouncing()
Player1Movement()
Player2Movement()
PositionObjects()
TrackScores()
Flip
End Select
Wend
FreeGadget GWindow
FreeGadget GraphicsWindow
'The game is finished so cleanup
CleanUp()
End Function
Memory Exception Error, Any ideas?