Jump to content

Help me with my Pong game (Prospeed)


Marlo
 Share

Recommended Posts

Hellooooooo

Today i thought id have a bash at making my first ever game so i picked up a copy of Prospeed and downloaded some game examples of sing prospeed with AutoIt and now i intend to recreate pong as it seemed easy enough.

Now i've got as far as doing very basic graphics, making one of the paddles move and making the ball bounce off the walls (almost) but its the wall bounceing bit that has me stumped.

I have used this image as a mask to tell prospeed what my boundaries are:

Posted Image

and i have told the ball to move towards the wall upon program start-up. Now the ball does in fact bounce off as i hoped but it doesn't go in the direction that you would think it just seems to straigten out and then just bounce infinitely between the two walls.

here is what i've got so far:

#include <prospeed.au3>
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)

Global $MaskImg, $BGImg, $BallImg, $BallSprite, $PaddleImg, $RightPaddle, $LeftPaddle

Global $hGUI = GUICreate("UBER PONG!!1!", 491, 231)
GUISetOnEvent(-3, "_Exit")
GUISetState()
GUISetCursor(16)

$BGImg = Background("bg_pong.png", 0, 0, 491, 231)
$MaskImg = LoadImage("bg_mask.png", 0, 0, 491, 231, 4)
$BallImg = LoadSprite("pong_ball.png")
$PaddleImg = LoadSprite("pong_paddle.png")
$BallSprite = Sprite($BallImg, 0, 0, 15, 15, 1, 1, 1, 230, 115)
$LeftPaddle= Sprite($PaddleImg, 0, 0, 5, 50, 1, 1, 1, 6, 90)
$RightPaddle= Sprite($PaddleImg, 0, 0, 5, 50, 1, 1, 1, 480, 90)
SetSpriteSpeed($BallSprite, 3, 3)
SetSpriteSpeed($LeftPaddle, 0, 50)
SetSpriteSpeed($RightPaddle, 0, 50)
SetSpriteMovingMode($BallSprite, 1)
SetBackAutoCollision($BallSprite, $MaskImg, 2, 491, 231, "")
MoveSprite($BallSprite, 50, 1)


while True
    MoveSprite($LeftPaddle, 6, MouseGetPos(1)-25)
    sleep(9)
WEnd

Func _Exit()
    Exit
EndFunc

I have also uploaded my script and the files it needs here:

http://rapidshare.com/files/309329692/Pong.rar

any help is super appreciated.

Regards

Click here for the best AutoIt help possible.Currently Working on: Autoit RAT
Link to comment
Share on other sites

If it helps... Heres one I made earlier (a lot earlier). Its 2 player, the one on the right uses W and S, the one on the left uses UP and DOWN.

Opt ("GUIOnEventMode", 1)

#include<GDIPlus.au3>
#Include<Misc.au3>

Global $bPlaying = True

Local $hGameUI, $hLbl_Graph, $gr, $grb, $gro, $aPos, $User32 = DllOpen ("User32.dll")

$hGameUI = GUICreate ("Pong", @DesktopWidth, @DesktopHeight - 30, 0, 0, -2147483648, 136)
   GUISetOnEvent (-3, "_GUI_Event_Exit")
   GUISetBkColor (0)

$hLbl_Graph = GUICtrlCreateLabel ("", 0, 0, @DesktopWidth, @DesktopHeight - 100)
GUICtrlSetColor (-1,0x00FF00)
GUICtrlSetBkColor (-1,0x000000)

GUICtrlCreateLabel ("", 0, @DesktopHeight - 100, @DesktopWidth, 4)
GUICtrlSetBkColor (-1, 0xFF0000)

Local $StatLab[3]
$StatLab[2] = GUICtrlCreateLabel (0, 20, @DesktopHeight - 96, 200, 100)
GUICtrlSetColor (-1,0x00FF00)
GUICtrlSetBkColor (-1,0x000000)
GUICtrlSetFont (-1, 28, 700)

$StatLab[1] = GUICtrlCreateLabel (0, @DesktopWidth - 200, @DesktopHeight - 96, 200, 100)
GUICtrlSetColor (-1,0x00FF00)
GUICtrlSetBkColor (-1,0x000000)
GUICtrlSetFont (-1, 28, 700)

Local $aControlPos = ControlGetPos ($hGameUI, "", $hLbl_Graph)
_GDIPlus_Startup ()
$gro = _GDIPlus_GraphicsCreateFromHWND (GUICtrlGetHandle ($hLbl_Graph))
$grb = _GDIPlus_BitmapCreateFromGraphics ($aControlPos[2], $aControlPos[3], $gro)
$gr  = _GDIPlus_ImageGetGraphicsContext ($grb)

Global $Green_Brush = _GDIPlus_BrushCreateSolid (0xFF00FF00)
Global $Red_Brush   = _GDIPlus_BrushCreateSolid (0xFFFF0000)

Global $nSpeed = 30

Global $aPos[4][2] = [[0, 0], [@DesktopWidth - 20, 0], [50, 50], [$nSpeed, $nSpeed]]

$aPos[3][0] = random (5, $nSpeed - 5, 1)
$aPos[3][1] = random (5, $nSpeed - 5, 1)

GUISetstate ()

While $bPlaying
   If Random (1, 100, 1) = Random (1, 100, 1) Then
      If $aPos[3][0] > 0 Then
         $aPos[3][0] += 5
      Else
         $aPos[3][0] -= 5
      EndIf
      If $aPos[3][1] > 0 Then
         $aPos[3][1] += 5
      Else
         $aPos[3][1] -= 5
      EndIf
   EndIf
   $aPos[2][0] += $aPos[3][0]
   $aPos[2][1] += $aPos[3][1]
   If ($aPos[2][1] <= 0) Then
      $aPos[3][1] *= -1
      $aPos[2][1] = 0
   ElseIf ($aPos[2][1] >= $aControlPos[3] - 21) Then
      $aPos[3][1] *= -1
      $aPos[2][1] = $aControlPos[3] - 21
   EndIf

   If _IsPressed (26, $User32) Then
      If $aPos[0][1] > 10 Then $aPos[0][1] -= $nSpeed
   ElseIf _IsPressed (28, $User32) Then
      If $aPos[0][1] < $aControlPos[3] - 110 Then $aPos[0][1] += $nSpeed
   EndIf

   If _IsPressed (53, $User32) Then
      If $aPos[1][1] < $aControlPos[3] - 110 Then $aPos[1][1] += $nSpeed
   ElseIf _IsPressed (57, $User32) Then
      If $aPos[1][1] > 10 Then $aPos[1][1] -= $nSpeed
   EndIf

   If ($aPos[2][0] <= 20) Or ($aPos[2][0] >= $aControlPos[2] - 40) Then
      $i = 1
      If $aPos[2][0] >= $aControlPos[2] - 40 Then $i = 2
      If ($aPos[2][1] < $aPos[$i - 1][1]) Or ($aPos[2][1] > $aPos[$i - 1][1] + 100) then ; lose / win!!!
         GUICtrlSetData ($StatLab[$i], Int (GUICtrlRead ($StatLab[$i])) + 1)
         $aPos[3][0] = random (5, $nSpeed - 5, 1)
         $aPos[3][1] = random (5, $nSpeed - 5, 1)
         $aPos[2][0] = 50
         $aPos[2][1] = 50
      Else
         If ($aPos[2][0] <= 20) Then
            $aPos[2][0] = 20
         Else
            $aPos[2][0] = $aControlPos[2] - 40
         EndIf
         $aPos[3][0] *= -1
      EndIf
   EndIf

   _GDIPlus_GraphicsClear ($gr)
   _GDIPlus_GraphicsFillEllipse ($gr, $aPos[2][0], $aPos[2][1], 20, 20, $Green_Brush)
   _GDIPlus_GraphicsFillRect ($gr, $aPos[0][0], $aPos[0][1], 20, 100, $Red_Brush)
   _GDIPlus_GraphicsFillRect ($gr, $aPos[1][0], $aPos[1][1], 20, 100, $Red_Brush)
   _GDIPlus_GraphicsDrawImageRect ($gro, $grb, 0, 0, $aControlPos[2], $aControlPos[3])
WEnd
_GDIPlus_BrushDispose ($Red_Brush)
_GDIPlus_BrushDispose ($Green_Brush)
_GDIPlus_GraphicsDispose ($gr)
_GDIPlus_BitmapDispose ($grb)
_GDIPlus_GraphicsDispose ($gro)
_GDIPlus_Shutdown ()
Exit

Func _GUI_Event_Exit ()
   $bPlaying = False
EndFunc ; ==> _GUI_Event_Exit

Mat

Edit: Not in prospeed though :)

Edited by Mat
Link to comment
Share on other sites

this is a demo for sprite collisions

it's made for prospeed V2.8, but easy to convert to 3.0

i can send you the whole zip if you wish, just pm me with your mailadress.

jpam

#include <GUIConstants.au3>
#include <Prospeed.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{Esc}","_exit")

FileInstall("D:\snelheidscontrole\prospeed\Auto.jpg",@scriptdir & "\Auto.jpg",1)
FileInstall("D:\snelheidscontrole\prospeed\AutoMask.gif",@scriptdir & "\AutoMask.gif",1)
FileInstall("D:\snelheidscontrole\prospeed\FObjects2.gif",@scriptdir & "\FObjects2.gif",1)
FileInstall("D:\snelheidscontrole\prospeed\KlExplosion.wav",@scriptdir & "\KlExplosion.wav",1)

$GUI = GUICreate("Prospeed",800,600,-1,-1,$WS_POPUP)
GUISetState()

Background(@scriptdir & "\Auto.jpg", 0, 0)

$mask = LoadImage(@scriptdir & "\AutoMask.gif", 0, 0, 800,600,4)

$Sprite1 = @scriptdir & "\FObjects2.gif"
                    
$ball1 = sprite($Sprite1, 0, 24, 19, 19, 4, 1, 9, 600, 200)
$ball2 = sprite($Sprite1, 0, 24, 19, 19, 4, 1, 9, 600, 250)
$ball3 = sprite($Sprite1, 0, 24, 19, 19, 4, 1, 9, 600, 300)
$ball4 = sprite($Sprite1, 0, 24, 19, 19, 4, 1, 9, 600, 350)
$ball5 = sprite($Sprite1, 0, 24, 19, 19, 4, 1, 9, 600, 400)
$ball6 = sprite($Sprite1, 0, 24, 19, 19, 4, 1, 9, 600, 450)

DSoundInit()
$plop = @scriptdir & "KlExplosion.wav"
$load = DSoundLoad("Plopp.wav")

SetBackAutoCollision($ball1, $mask, 2, 800, 600, $load)
SetBackAutoCollision($ball2, $mask, 2, 800, 600, $load)
SetBackAutoCollision($ball3, $mask, 2, 800, 600, $load)
SetBackAutoCollision($ball4, $mask, 2, 800, 600, $load)
SetBackAutoCollision($ball5, $mask, 2, 800, 600, $load)
SetBackAutoCollision($ball6, $mask, 2, 800, 600, $load)

Movesprite($ball1, 810, 600)
Movesprite($ball2, 400, 600)
Movesprite($ball3, 810, 600)
Movesprite($ball4, 400, 600)
Movesprite($ball5, 810, 600)
Movesprite($ball6, 400, 600)

SetSpriteSpeed($ball1, 3, 3)
SetSpriteSpeed($ball2, 3, 3)
SetSpriteSpeed($ball3, 3, 3)
SetSpriteSpeed($ball4, 3, 3)
SetSpriteSpeed($ball5, 3, 3)
SetSpriteSpeed($ball6, 3, 3)

While 1
    $col = CollideUnknown()
    If $col > 0 Then 
        $c = GetSpriteX($S_A)
        $d = GetSpriteY($S_A)
        $e = GetSpriteX($S_B)
        $f = GetSpriteY($S_B)

        GetSpriteInfos($S_A)
        $g = $goal_PosX 
        $h = $goal_PosY

        GetSpriteInfos($S_B)
        $i = $goal_PosX
        $j = $goal_PosY
    If $c > $e Then 
        $g = 1024 
        $i = 0
    Else
        $g = 0
        $i = 1024
    EndIf                 
    If $d > $f Then
        $h = 768
        $j = 0
    Else
        $h = 0
        $j = 768
    EndIf                 
        MoveSprite($S_A, $g, $h)    
        MoveSprite($S_B, $i, $j)    
EndIf
WEnd

Func _exit()
    Exit
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...