Jump to content

Recommended Posts

Posted

Hello,

Im trying to create my own version of Pong. I took LimeSeed's pong as an example.

Now, I can't get this part to work in my own script. Can anyone help me?

LimeSeed's part.

If ($xball > 180) Then $boundaries = False
    If ($xball < 0) Then $boundaries = True
    If (($yball >= 244) And ($direction)) Then

        $contact = Execute($xball - $xp1)
        If (($contact > 68) And ($contact < 130)) Then
            $direction = False
        Else
            $points[1] += 1
            Sleep(100)
            $gf = $g
            GUICtrlSetData($scoreboard[0], $points[1])
            $yball = 50
            $direction = False
        EndIf
    EndIf
    
    If (($yball <= 17) And (Not ($direction))) Then
        $contact = Execute($xball - $aipos)
        If (($contact < (60 + $gf + 3)) And ($contact > 0)) Then
            $direction = True
        Else
            $points[0] += 1
            Sleep(100)
            $gf = $g
            GUICtrlSetData($scoreboard[1], $points[0])
            $yball = 50
            $direction = True
        EndIf
    EndIfoÝ÷ Ù³2±Êâ¦ßÛjëh×6; Constants
Global $B_S
Global $ScoreLabel
Global $L_x = 10, $L_y = 10
Global $R_x = 10, $R_y = 660
Global $B_x = 100, $B_y = 100
Global $Direction = False, $Bounce = True
Global $Score_Left = 0, $Score_Right = 0
Global Const $GUI_GR_CLOSE = 1
Global Const $GUI_GR_COLOR = 8
Global Const $GUI_GR_RECT = 10
Global Const $GUI_GR_PIE = 14
Global Const $GUI_GR_REFRESH = 22
Global Const $_Red = 0xFF0000, $_Yellow = 0xFFFF00
Global Const $_Green = 0x00FF00, $_Blue = 0x00FFF0
Global Const $_Purple = 0xFF00FF, $_Orange = 0xFFA900

; Main GUI
$GUI = GUICreate("2Player Pong", 700, 400)
$ScoreLabel = GUICtrlCreateLabel($Score_Left & " - " & $Score_Right, 310, 10, 85, 30)

; Player LEFT
$P_L = GUICtrlCreateGraphic(10, 20, 15, 75)
GUICtrlSetGraphic($P_L, $GUI_GR_COLOR, $_Red, $_Red)
GUICtrlSetGraphic($P_L, $GUI_GR_RECT, 10, 20, 15, 75)
GUICtrlSetGraphic($P_L, $GUI_GR_REFRESH)
GUICtrlSetGraphic($P_L, $GUI_GR_CLOSE)

; Player RIGHT
$P_R = GUICtrlCreateGraphic(660, 20, 15, 75)
GUICtrlSetGraphic($P_R, $GUI_GR_COLOR, $_Red, $_Red)
GUICtrlSetGraphic($P_R, $GUI_GR_RECT, 10, 20, 15, 75)
GUICtrlSetGraphic($P_R, $GUI_GR_REFRESH)
GUICtrlSetGraphic($P_R, $GUI_GR_CLOSE)

; Ball
$Ball = GUICtrlCreateGraphic(100, 100, 20, 20)
GUICtrlSetGraphic($Ball, $GUI_GR_COLOR, $_Red, $_Red)
GUICtrlSetGraphic($Ball, $GUI_GR_PIE, 100, 100, 5, 5, 360)
GUICtrlSetGraphic($Ball, $GUI_GR_REFRESH)
GUICtrlSetGraphic($Ball, $GUI_GR_CLOSE)

GUISetState()
GUISetBkColor(0x000000, $GUI)
GUICtrlSetColor($ScoreLabel, $_Red)
GUICtrlSetFont($ScoreLabel, 20, "", "", "Comic Sans MS")
While 1
    If GUIGetMsg() = -3 Then Exit
    GUICtrlSetGraphic($Ball, $GUI_GR_REFRESH)
    Sleep(10)
    $B_S += .001
    
    If _IsPressed(57, "user32.dll") And $L_x > 20 Then ; Left Player UP (W)
        $L_x -= 4
        GUICtrlSetPos($P_L, $L_y, $L_x)
    EndIf
    
    If _IsPressed(53, "user32.dll") And $L_x < 280 Then ; Left Player DOWN (S)
        $L_x += 4
        GUICtrlSetPos($P_L, $L_y, $L_x)
    EndIf
    
    If _IsPressed(26, "user32.dll") And $R_x > 20 Then ; Right Player UP (UP ARROW)
        $R_x -= 4
        GUICtrlSetPos($P_R, $R_y, $R_x)
    EndIf
    
    If _IsPressed(28, "user32.dll") And $R_x < 280 Then ; Right Player DOWN (DOWN ARROW)
        $R_x += 4
        GUICtrlSetPos($P_R, $R_y, $R_x)
    EndIf
    
    If $Direction Then
        $B_x += $B_S * 2
        GUICtrlSetPos($Ball, $B_x, $B_y)
    Else
        $B_x -= $B_S * 2
        GUICtrlSetPos($Ball, $B_x, $B_y)
    EndIf
    
    If $Bounce Then
        $B_x -= $B_S * 2
        GUICtrlSetPos($Ball, $B_x, $B_y)
    Else
        $B_x += $B_S * 2
        GUICtrlSetPos($Ball, $B_x, $B_y)
    EndIf
    
    If $B_y > 280 Then $Bounce = False
    If $B_y < 20 Then $Bounce = True
WEnd

Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
    Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc

If you still don't know what I mean, I want LimeSeed's part to build in mine.

I can't get it working!

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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
×
×
  • Create New...