Code: Select all
EnableExplicit
Enumeration
#Win
#Sound0
#Sound1
#SpriteBorder
#SpriteBat
#SpriteBat1
#SpriteBall
#SpriteBorder1
EndEnumeration
InitSprite ()
InitKeyboard ()
InitMouse ()
InitSound ()
Global we.i
Global Score1.i
Global Score2.i
Global zieg.s = "C:\Program Files\ProgMaster\Pong\"
Global circlex.i
Global circley.i
Global movex.i
Global movey.i
Global PlayerTwo.i
Global pseudoy.i
Global Block.i
Global StartTime.i
Global pseudomovex.i
Global pseudomovey.i
Global Blocky.i
Global Timerlol.i
Score1 = 0
Score2 = 0
circlex = 320
circley = Random (480)
movex = 2
movey = 2
PlayerTwo = 2
Block = 0
Structure player
x.i
y.i
EndStructure
UsePNGImageDecoder ()
Global Dim Player.player(1)
Player(0)\x = 0
Player(0)\y = 200
Player(1)\x = 635
Player(1)\y = 200
Procedure Game ()
Shared Blocky
ClearScreen (0)
StartDrawing (ScreenOutput ())
DrawText (20,20,Str (Score1),RGB(255,255,255),0)
DrawText (500,20,Str (Score2),RGB(255,255,255),0)
DrawText (380,20,Str ((ElapsedMilliseconds () - StartTime) / 1000),RGB(255,255,255),0)
If PlayerTwo = -2
DrawText (300,20,"Player 2",RGB(255,255,255),0)
EndIf
StopDrawing ()
DisplayTransparentSprite (#SpriteBall,circlex,circley)
DisplayTransparentSprite (#SpriteBat,Player(0)\x,Player(0)\y)
DisplayTransparentSprite (#SpriteBat1,Player(1)\x,Player(1)\y)
DisplayTransparentSprite (#SpriteBorder,0,0)
DisplayTransparentSprite (#SpriteBorder1,0,475)
circlex + movex
circley + movey
If SpritePixelCollision (#SpriteBat,Player(0)\x,Player(0)\y,#SpriteBall,circlex,circley) Or SpritePixelCollision (#SpriteBat1,Player(1)\x,Player(1)\y,#SpriteBall,circlex,circley)
movex * -1
If Block < 1
PlaySound (#Sound1)
EndIf
Block = 30
EndIf
If SpritePixelCollision (#SpriteBall,circlex,circley,#SpriteBorder,0,0)
movey * -1
PlaySound (#Sound1)
ElseIf SpritePixelCollision (#SpriteBall,circlex,circley,#SpriteBorder1,0,475)
movey * -1
PlaySound (#Sound1)
EndIf
If KeyboardPushed (#PB_Key_Up)
Player(1)\y - 3
ElseIf KeyboardPushed (#PB_Key_Down)
Player(1)\y + 3
EndIf
If KeyboardPushed (#PB_Key_F2) And Block < 1
PlayerTwo * -1
Block = 30
EndIf
If Block > 0
Block - 1
EndIf
If PlayerTwo = 2
If KeyboardPushed (#PB_Key_W)
Player(0)\y - 3
ElseIf KeyboardPushed (#PB_Key_S)
Player(0)\y + 3
EndIf
If SpritePixelCollision (#SpriteBat1,Player(1)\x,Player(1)\y,#SpriteBorder1,0,475)
Player(1)\y - 3
EndIf
If SpritePixelCollision (#SpriteBat1,Player(1)\x,Player(1)\y,#SpriteBorder,0,0)
Player(1)\y + 3
EndIf
Else
If movex < 0
pseudoy = circley - 30
If Player(0)\y <> pseudoy
If Player(0)\y < pseudoy
Player(0)\y + 2
Else
Player(0)\y - 2
EndIf
EndIf
EndIf
EndIf
If SpritePixelCollision (#SpriteBat,Player(0)\x,Player(0)\y,#SpriteBorder,0,0)
Player(0)\y + 2
EndIf
If SpritePixelCollision (#SpriteBat,Player(0)\x,Player(0)\y,#SpriteBorder1,0,475)
Player(0)\y - 2
EndIf
If SpritePixelCollision (#SpriteBat1,Player(1)\x,Player(1)\y,#SpriteBorder,0,0)
Player(1)\y + 3
EndIf
If SpritePixelCollision (#SpriteBat1,Player(1)\x,Player(1)\y,#SpriteBorder1,0,475)
Player(1)\y - 3
EndIf
If circlex < 0
StartTime = ElapsedMilliseconds() ; record start time
PlaySound (#Sound0)
circlex = 320
circley = Random (475)
Score2 + 1
EndIf
If circlex > 635
StartTime = ElapsedMilliseconds() ; record start time
PlaySound (0)
circlex = 320
circley = Random (480)
EndIf
EndProcedure
OpenWindow (#Win,20,30,640,480,"Pong",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
OpenWindowedScreen (WindowID (#Win),0,0,WindowWidth (#Win),WindowHeight (#Win),0,0,0)
LoadSprite (#SpriteBat,zieg + "bat.png")
CopySprite (#SpriteBat,#SpriteBat1)
LoadSprite (#SpriteBall,zieg + "ball.png")
LoadSprite (#SpriteBorder,zieg + "Border.png")
CopySprite (#SpriteBorder,#SpriteBorder1)
LoadSound (#Sound0,zieg + "Explosion.wav")
LoadSound (#Sound1,zieg + "Lazer.wav")
Procedure Loop ()
Shared StartTime.i
Repeat
we = WindowEvent ()
ExamineKeyboard ()
Game()
Select we
Case #PB_Event_CloseWindow
End
EndSelect
FlipBuffers ()
Until KeyboardPushed (1)
EndProcedure
Loop ()