Sign in to follow this  
Followers 0
LimeSeed

Finally Slime Volleyball With GDI+

18 posts in this topic

It's finally here, slime volleyball written entirely in autoit!!

To Do List:

-Make Circles and balls smoother (anyone know how to do this?)

-Double Buffer

-Bask In My Awesomeness :P

#NoTrayIcon
;this is a project that i have been working on for months, and have finally finished :) whew!
;major thanks go to my Uncle Steve for helping me with the physics aspects of the game!
;click to play, and press spacebar to exit! Enjoy! I tried to make this as much like the oneslime.net game as possible!
;Also major thanks to Wedgey for making the original game!


#include "guiconstants.au3"
#include "misc.au3"
#include "gdiplus.au3"

;creates gui
$hWnd = GUICreate("Slime Volleyball by: Isaac Flaum", 750, 400)

;variables that make game function
$vDll = DllOpen("user32.dll")
$nWidth = 750
$nHeight = 400
$p1Diam = 100
$p2Diam = 100
$p1X = 200
$i = 0
$ballXPix = 0
$ballYPix = 0
$Winner = False
$p1OldX = 0
$p1s = 5
$p2s = 5
$p1OldY = 0
$leftbound = 0
$ballRad = 25
$start = True
$jump = False
$nclick = True
$jump2 = False
$fudge = 5
$maxXV = 15
$maxYV = 22
$dx = 0
$p1Y = 0
$p2X = 800
$p2Y = 0
$p1XV = 0
$p1YV = 0
$p2XV = 0
$p2YV = 0
$ballX = 200
$ballY = 400
$ballVX = 0
$ballVY = 0

GUISetState()

;create gdi+ environment and create different paint brushes and pens for slime and ball colors
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$brush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
$yellowbrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)
$greenbrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)
$redbrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$whitebrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$blackbrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$greybrush = _GDIPlus_BrushCreateSolid(0xFF808080)
$bluebrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)
$green = _GDIPlus_PenCreate(0xFF00FF00, 1, 2)
$blue = _GDIPlus_PenCreate(0xFF0000FF, 1, 2)
$red = _GDIPlus_PenCreate(0xFFFF0000, 1, 2)
$yellow = _GDIPlus_PenCreate(0xFFFFFF00, 1, 2)

;draw the net, floor, and background
_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)
_GDIPlus_GraphicsFillRect($hGraphic, $nWidth / 2 - 2, (7 * $nHeight) / 10, 4, $nHeight / 10 + 5, $whitebrush)
_GDIPlus_GraphicsFillRect($hGraphic, 0, (4 * $nHeight) / 5, $nWidth, $nHeight / 5, $greybrush)
DrawScores()
Sleep(1000)

;loop until spacebar is pressed, i did not want to make it listen for the 'x' button on the top to be pressed, as that slows down the script alot :-(
While (Not (_IsPressed(20, $vDll)))
    Sleep(20);50 fps
    If ($start) Then StartScreen()
    ;get old coordinates to black out old slime positions
    $p1OldX = $p1X
    $p1OldY = $p1Y
    $p2OldX = $p2X
    $p2oldy = $p2Y
    $ballOldX = $ballX
    $ballOldY = $ballY
    
    ;restart function
    If (_IsPressed(52, $vDll)) Then Restart()
    
    ;instructions function
    If (_IsPressed(49, $vDll)) Then Instructions()
    
    ;if pressed 'A', 'W', or 'D', move ball across x and y axis' for p1
    If (_IsPressed(41, $vDll)) Then $p1XV = -8
    If (_IsPressed(44, $vDll)) Then $p1XV = 8
    ;jump!
    If ((_IsPressed(57, $vDll)) And ($jump = False)) Then
        $p1YV = 20
        $jump = True
    EndIf
    If (Not (_IsPressed(44, $vDll)) And Not (_IsPressed(41, $vDll))) Then $p1XV = 0
    
    ;arrow keys for p2
    If (_IsPressed(25, $vDll)) Then $p2XV = -8
    If (_IsPressed(27, $vDll)) Then $p2XV = 8
    If ((_IsPressed(26, $vDll)) And ($jump2 = False)) Then
        $p2YV = 20
        $jump2 = True
    EndIf
    If (Not (_IsPressed(25, $vDll)) And Not (_IsPressed(27, $vDll))) Then $p2XV = 0
    
    ;draw slimes and move balls
    DrawSlimes()
    MoveBall()
    $i += 1
    $j = ($i / 3)
    ;draw net and floor but only every 3 loops
    If (IsInt($j)) Then
        _GDIPlus_GraphicsFillRect($hGraphic, 0, (4 * $nHeight) / 5, $nWidth, $nHeight / 5, $greybrush)
        _GDIPlus_GraphicsFillRect($hGraphic, $nWidth / 2 - 2, (7 * $nHeight) / 10, 4, $nHeight / 10 + 5, $whitebrush)
    EndIf
    
    ;if ball hits floor
    If ($ballY < 25) Then
        If ($ballX <= 500) Then
            Sleep(100)
            $p2s += 1
            $p1s -= 1
            $ballX = 800
            $ballY = 400
            $ballVX = 0
            $ballVY = 0
            _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)
            $p1X = 200
            $p2X = 800
            DrawScores()
            If ($p2s = 10) Then $Winner = True
        ElseIf ($ballX > 500) Then
            Sleep(100)
            $p1s += 1
            $p2s -= 1
            $ballX = 200
            $ballY = 400
            $ballVX = 0
            $ballVY = 0
            _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)
            $p1X = 200
            $p2X = 800
            DrawScores()
            If ($p1s = 10) Then $Winner = True
        EndIf
    EndIf
    
    ;if someone wins
    If ($Winner) Then
        If ($p1s = 10) Then ;if player one wins then do this
            _GDIPlus_GraphicsDrawString($hGraphic, "Player 1 Wins!", 250, 150, "Times New Roman", 30)
            While ($Winner)
                _GDIPlus_GraphicsDrawString($hGraphic, "Press 'R' to restart, or 'SpaceBar' to exit", 120, 200, "Times New Roman", 26)
                If (_IsPressed(52, $vDll)) Then
                    Restart()
                    $Winner = False
                EndIf
                If (_IsPressed(20, $vDll)) Then Exit
            WEnd
        Else ;if player 2 wins
            _GDIPlus_GraphicsDrawString($hGraphic, "Player 2 Wins!", 250, 150, "Times New Roman", 30)
            While ($Winner)
                _GDIPlus_GraphicsDrawString($hGraphic, "Press 'R' to restart, or 'SpaceBar' to exit", 120, 200, "Times New Roman", 26)
                If (_IsPressed(52, $vDll)) Then
                    Restart()
                    $Winner = False
                EndIf
                If (_IsPressed(20, $vDll)) Then Exit
            WEnd
        EndIf
    EndIf
WEnd

;Clean up resources when exited
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
DllClose($vDll)

Func DrawSlimes()
    ;black out old slime p1
    $sWidth = $nWidth * $p1Diam / 1000
    $sHeight = $nHeight * $p1Diam / 1000
    $leftbound = $p1OldX * $nWidth / 1000 - $sWidth / 2
    $topbound = 4 * $nHeight / 5 - $sHeight - $p1OldY * $nHeight / 1000
    _GDIPlus_GraphicsFillRect($hGraphic, $leftbound, $topbound, $sWidth, $sHeight, $brush)
    
    ;black out p2
    $sWidth = $nWidth * $p2Diam / 1000
    $sHeight = $nHeight * $p2Diam / 1000
    $leftbound = $p2OldX * $nWidth / 1000 - $sWidth / 2
    $topbound = 4 * $nHeight / 5 - $sHeight - $p2oldy * $nHeight / 1000
    _GDIPlus_GraphicsFillRect($hGraphic, $leftbound, $topbound, $sWidth, $sHeight, $brush)
    
    ;move it according to its velocity
    $p1X += $p1XV
    
    ;jump function for p1
    If ($p1YV <> 0) Then
        $p1YV -= 1.4
        $p1Y += $p1YV
        If ($p1Y < 0) Then
            $p1Y = 0
            $p1YV = 0
            $jump = False
        EndIf
    EndIf
    
    ;p1 boundaries
    If ($p1X < 50) Then $p1X = 50
    If ($p1X > 445) Then $p1X = 445
    
    ;draw new p1
    $sWidth = $nWidth * $p1Diam / 1000
    $sHeight = $nHeight * $p1Diam / 1000
    $leftbound = $p1X * $nWidth / 1000 - $sWidth / 2
    $topbound = 4 * $nHeight / 5 - $sHeight - $p1Y * $nHeight / 1000
    _GDIPlus_GraphicsFillPie($hGraphic, $leftbound, $topbound, $sWidth, 2 * $sHeight, 0, -180, $greenbrush)
    
    ;slimes eye
    $eyeLeft = $p1X + 38 * $p1Diam / 100
    $eyeTop = $p1Y - 60 * $p1Diam / 100
    $leftbound = $eyeLeft * $nWidth / 1000
    $topbound = 4 * $nHeight / 5 - $sHeight - $eyeTop * $nHeight / 1000
    $bedx = $leftbound - $ballXPix
    $bedy = $topbound - $ballYPix
    $bedist = Int(Sqrt($bedx * $bedx + $bedy * $bedy))
    $eyeWidthPix = $nWidth / 50 * $p1Diam / 100
    $eyeHeightPix = $nHeight / 25 * $p1Diam / 100
    $p1Blink = Random(0, 30, 1)
    If ($p1Blink < 29) Then
        _GDIPlus_GraphicsFillEllipse($hGraphic, $leftbound - $eyeWidthPix, $topbound - $eyeHeightPix, $eyeWidthPix, $eyeHeightPix, $whitebrush)
        _GDIPlus_GraphicsFillEllipse($hGraphic, $leftbound - 4 * $bedx / $bedist - 3 * $eyeWidthPix / 4, $topbound - 4 * $bedy / $bedist - 3 * $eyeHeightPix / 4, $eyeWidthPix / 2, $eyeHeightPix / 2, $blackbrush)
    EndIf
    
    ;draw p2
    $p2X += $p2XV
    
    ;jump function
    If ($p2YV <> 0) Then
        $p2YV -= 1.4
        $p2Y += $p2YV
        If ($p2Y < 0) Then
            $p2Y = 0
            $p2YV = 0
            $jump2 = False
        EndIf
    EndIf
    
    ;boundaries
    If ($p2X > 950) Then $p2X = 950
    If ($p2X < 555) Then $p2X = 555
    
    ;draw new p2
    $sWidth = $nWidth * $p2Diam / 1000
    $sHeight = $nHeight * $p2Diam / 1000
    $leftbound = $p2X * $nWidth / 1000 - $sWidth / 2
    $topbound = 4 * $nHeight / 5 - $sHeight - $p2Y * $nHeight / 1000
    _GDIPlus_GraphicsFillPie($hGraphic, $leftbound, $topbound, $sWidth, 2 * $sHeight, 0, -180, $redbrush)
    
    ;p2's eye
    $eyeLeft = $p2X - 18 * $p2Diam / 100
    $eyeTop = $p2Y - 60 * $p2Diam / 100
    $leftbound = $eyeLeft * $nWidth / 1000
    $topbound = 4 * $nHeight / 5 - $sHeight - $eyeTop * $nHeight / 1000
    $bedx = $leftbound - $ballXPix
    $bedy = $topbound - $ballYPix
    $bedist = Int(Sqrt($bedx * $bedx + $bedy * $bedy))
    $eyeWidthPix = $nWidth / 50 * $p2Diam / 100
    $eyeHeightPix = $nHeight / 25 * $p2Diam / 100
    $p2Blink = Random(0, 30, 1)
    If ($p2Blink < 29) Then
        _GDIPlus_GraphicsFillEllipse($hGraphic, $leftbound - $eyeWidthPix, $topbound - $eyeHeightPix, $eyeWidthPix, $eyeHeightPix, $whitebrush)
        _GDIPlus_GraphicsFillEllipse($hGraphic, $leftbound - 4 * $bedx / $bedist - 3 * $eyeWidthPix / 4, $topbound - 4 * $bedy / $bedist - 3 * $eyeHeightPix / 4, $eyeWidthPix / 2, $eyeHeightPix / 2, $blackbrush)
    EndIf
    
EndFunc   ;==>DrawSlimes

Func MoveBall()
    
    ;makes ball bounce off of net
    If ($ballX > 480 And $ballX < 520 And $ballY < 140) Then
        If ($ballVY < 0 And $ballY > 130) Then
            $ballVY *= -1
            $ballY = 130
        ElseIf ($ballX < 500) Then
            $ballX = 480
            $ballVX *= -1
        Else
            $ballX = 520
            $ballVX *= -1
        EndIf
    EndIf
    
    ;makes ball bounce off of walls
    If ($ballX < 15) Then
        $ballX = 15
        $ballVX = -$ballVX
    EndIf

    If ($ballX > 985) Then
        $ballX = 985
        $ballVX = -$ballVX
    EndIf
    
    ;black out old ball
    $ballXPix = $ballOldX * $nWidth / 1000
    $ballYPix = 4 * $nHeight / 5 - $ballOldY * $nHeight / 1000
    $ballRadPix = ($ballRad + $fudge) * $nHeight / 1000
    _GDIPlus_GraphicsFillRect($hGraphic, $ballXPix - $ballRadPix, $ballYPix - $ballRadPix, 2 * $ballRadPix, 2 * $ballRadPix, $brush)
    
    
    ;p1 collision detection
    $dx = 2 * ($ballX - $p1X)
    $dy = $ballY - $p1Y
    $dist = Int(Sqrt($dx * $dx + $dy * $dy))
    $dvx = $ballVX - $p1XV
    $dvy = $ballVY - $p1YV
    If ($dy > 0 And $dist < $p1Diam + $ballRad And $dist > $fudge) Then
        $something = Int(($dx * $dvx + $dy * $dvy) / $dist)
        $ballX = $p1X + ($p1Diam + $ballRad) / 2 * $dx / $dist
        $ballY = $p1Y + ($p1Diam + $ballRad) * $dy / $dist
        If ($something <= 0) Then
            $ballVX += $p1XV - 2 * $dx * $something / $dist
            $ballVY += $p1YV - 2 * $dy * $something / $dist
            If ($ballVX < -$maxXV) Then $ballVX = -$maxXV
            If ($ballVX > $maxXV) Then
                $ballVX = $maxXV
                $ballVY += $p1YV - 2 * $dy * $something / $dist
            EndIf
            If ($ballVY < -$maxYV) Then $ballVY = -$maxYV
            If ($ballVY > $maxYV) Then $ballVY = $maxYV
        EndIf
    EndIf
    
    ;p2 collision detection
    $dx = 2 * ($ballX - $p2X)
    $dy = $ballY - $p2Y
    $dist = Int(Sqrt($dx * $dx + $dy * $dy))
    $dvx = $ballVX - $p2XV
    $dvy = $ballVY - $p2YV
    If ($dy > 0 And $dist < $p2Diam + $ballRad And $dist > $fudge) Then
        $something = Int(($dx * $dvx + $dy * $dvy) / $dist)
        $ballX = $p2X + ($p2Diam + $ballRad) / 2 * $dx / $dist
        $ballY = $p2Y + ($p2Diam + $ballRad) * $dy / $dist
        If ($something <= 0) Then
            $ballVX += $p2XV - 2 * $dx * $something / $dist
            $ballVY += $p1YV - 2 * $dy * $something / $dist
            If ($ballVX < -$maxXV) Then $ballVX = -$maxXV
            If ($ballVX > $maxXV) Then
                $ballVX = $maxXV
                $ballVY += $p1YV - 2 * $dy * $something / $dist
            EndIf
            If ($ballVY < -$maxYV) Then $ballVY = -$maxYV
            If ($ballVY > $maxYV) Then $ballVY = $maxYV
        EndIf
    EndIf
    
    ;makes ball fall
    $ballVY -= 1
    
    ;makes ball move on x and y axis' according to balls x and y velocity
    $ballY += $ballVY
    $ballX += $ballVX
    
    ;converts ball pixels into autoit friendly coordinates
    $ballRadPix = ($ballRad + $fudge) * $nHeight / 1000
    $ballXPix = $ballX * $nWidth / 1000
    $ballYPix = 4 * $nHeight / 5 - $ballY * $nHeight / 1000
    _GDIPlus_GraphicsFillEllipse($hGraphic, $ballXPix - $ballRadPix, $ballYPix - $ballRadPix, 2 * $ballRadPix, 2 * $ballRadPix, $yellowbrush)
    
EndFunc   ;==>MoveBall

Func DrawScores()
    ;draw the score
    For $s = 1 To ($p1s) Step 1
        $xx = $s * 30
        _GDIPlus_GraphicsFillEllipse($hGraphic, $xx, 10, 25, 25, $whitebrush)
    Next
    For $s = 1 To ($p2s) Step 1
        $xx = 720 - ($s * 30)
        _GDIPlus_GraphicsFillEllipse($hGraphic, $xx, 10, 25, 25, $whitebrush)
    Next
EndFunc   ;==>DrawScores

Func Restart()
    $p1X = 200
    $p1Y = 0
    $p2X = 800
    $p2Y = 0
    $ballVX = 0
    $ballVY = 0
    $ballX = 200
    $ballY = 400
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)
    $p1s = 5
    $p2s = 5
    Sleep(100)
    DrawScores()
EndFunc   ;==>Restart

Func StartScreen()
    ;button to start game
    $startgame = GUICtrlCreateButton("Click Here To Start 2 Player Game ('I' = Instructions)", 230, 200, 260, 40)
    _GDIPlus_GraphicsDrawString($hGraphic, "Slime Volleyball By: Isaac Flaum", 170, 150, "Times New Roman", 20)
    While ($nclick)
        Sleep(20)
        If (_IsPressed(49, $vDll)) Then Instructions()
        $msg = GUIGetMsg()
        If ($msg = -3) Then Exit
        If ($msg = $startgame) Then
            GUICtrlDelete($startgame)
            $start = False
            $nclick = False
            Restart()
        EndIf
    WEnd
EndFunc   ;==>StartScreen

Func Instructions()
    MsgBox(0, "Slime Volleyball Instructions", "Slime Volleyball is a simple game in which 2 players battle" & Chr(13) & Chr(10) & "to get the ball on their opponents side. Once you get 10 points, you win!" & Chr(13) & Chr(10) & "The controls are as follows:" & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "Player 1:" & Chr(13) & Chr(10) & "Move Left: 'A'" & Chr(13) & Chr(10) & "Move Right: 'D'" & Chr(13) & Chr(10) & "Jump: 'W'" & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "Player 2:" & Chr(13) & Chr(10) & "Move Left: 'Left Arrow Key'" & Chr(13) & Chr(10) & "Move Right: 'Right Arrow Key'" & Chr(13) & Chr(10) & "Jump: 'Up Arrow Key'" & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "Spacebar: Exit" & Chr(13) & Chr(10) & "Instructions: 'I'" & Chr(13) & Chr(10) & "Restart: 'R'")
EndFunc   ;==>Instructions

global $warming = true

Share this post


Link to post
Share on other sites



Way cool! I totally lack any skill to play it but very nice coding...

Share this post


Link to post
Share on other sites

it looks good. a little buggy, like some flashing, and the window doesnt repaint if you minimize it or drag another on top of it. i like it.

Share this post


Link to post
Share on other sites

great job. GL on finishing.

Rental

Share this post


Link to post
Share on other sites

Wow this is awesome! One of my all time online favorites in AutoIt :mellow:

I fixed #1 & #2. Hope you don't mind:

CODE

#NoTrayIcon

;this is a project that i have been working on for months, and have finally finished smile.gif whew!

;major thanks go to my Uncle Steve for helping me with the physics aspects of the game!

;click to play, and press spacebar to exit! Enjoy! I tried to make this as much like the oneslime.net game as possible!

;Also major thanks to Wedgey for making the original game!

#include <guiconstants.au3>

#include <misc.au3>

#include <gdiplus.au3>

;creates gui

$hWnd = GUICreate("Slime Volleyball by: Isaac Flaum", 750, 400)

;variables that make game function

$vDll = DllOpen("user32.dll")

$nWidth = 750

$nHeight = 400

$p1Diam = 100

$p2Diam = 100

$p1X = 200

$i = 0

$ballXPix = 0

$ballYPix = 0

$Winner = False

$p1OldX = 0

$p1s = 5

$p2s = 5

$p1OldY = 0

$leftbound = 0

$ballRad = 25

$start = True

$jump = False

$nclick = True

$jump2 = False

$fudge = 5

$maxXV = 15

$maxYV = 22

$dx = 0

$p1Y = 0

$p2X = 800

$p2Y = 0

$p1XV = 0

$p1YV = 0

$p2XV = 0

$p2YV = 0

$ballX = 200

$ballY = 400

$ballVX = 0

$ballVY = 0

GUISetState()

;create gdi+ environment and create different paint brushes and pens for slime and ball colors

_GDIPlus_Startup()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)

;;; New

$bitmap=_GDIPlus_BitmapCreateFromGraphics($nWidth,$nHeight,$hGraphic)

$backbuffer=_GDIPlus_ImageGetGraphicsContext($bitmap)

_AntiAlias($backbuffer,4)

$brush = _GDIPlus_BrushCreateSolid(0xFF0000FF)

$yellowbrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)

$greenbrush = _GDIPlus_BrushCreateSolid(0xFF00FF00)

$redbrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)

$whitebrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

$blackbrush = _GDIPlus_BrushCreateSolid(0xFF000000)

$greybrush = _GDIPlus_BrushCreateSolid(0xFF808080)

$bluebrush = _GDIPlus_BrushCreateSolid(0xFF0000FF)

$green = _GDIPlus_PenCreate(0xFF00FF00, 1, 2)

$blue = _GDIPlus_PenCreate(0xFF0000FF, 1, 2)

$red = _GDIPlus_PenCreate(0xFFFF0000, 1, 2)

$yellow = _GDIPlus_PenCreate(0xFFFFFF00, 1, 2)

;draw the net, floor, and background

_GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)

_GDIPlus_GraphicsFillRect($hGraphic, $nWidth / 2 - 2, (7 * $nHeight) / 10, 4, $nHeight / 10 + 5, $whitebrush)

_GDIPlus_GraphicsFillRect($hGraphic, 0, (4 * $nHeight) / 5, $nWidth, $nHeight / 5, $greybrush)

DrawScores()

Sleep(1000)

;loop until spacebar is pressed, i did not want to make it listen for the 'x' button on the top to be pressed, as that slows down the script alot :-(

While (Not (_IsPressed(20, $vDll)))

;;; New

_GDIPlus_GraphicsClear($backbuffer,0xFF0000FF)

Sleep(20);50 fps

If ($start) Then StartScreen()

;get old coordinates to black out old slime positions

$p1OldX = $p1X

$p1OldY = $p1Y

$p2OldX = $p2X

$p2oldy = $p2Y

$ballOldX = $ballX

$ballOldY = $ballY

;restart function

If (_IsPressed(52, $vDll)) Then Restart()

;instructions function

If (_IsPressed(49, $vDll)) Then Instructions()

;if pressed 'A', 'W', or 'D', move ball across x and y axis' for p1

If (_IsPressed(41, $vDll)) Then $p1XV = -8

If (_IsPressed(44, $vDll)) Then $p1XV = 8

;jump!

If ((_IsPressed(57, $vDll)) And ($jump = False)) Then

$p1YV = 20

$jump = True

EndIf

If (Not (_IsPressed(44, $vDll)) And Not (_IsPressed(41, $vDll))) Then $p1XV = 0

;arrow keys for p2

If (_IsPressed(25, $vDll)) Then $p2XV = -8

If (_IsPressed(27, $vDll)) Then $p2XV = 8

If ((_IsPressed(26, $vDll)) And ($jump2 = False)) Then

$p2YV = 20

$jump2 = True

EndIf

If (Not (_IsPressed(25, $vDll)) And Not (_IsPressed(27, $vDll))) Then $p2XV = 0

;draw slimes and move balls

DrawSlimes()

MoveBall()

$i += 1

$j = ($i / 3)

;draw net and floor but only every 3 loops

; removed if

;~ If (IsInt($j)) Then

_GDIPlus_GraphicsFillRect($backbuffer, 0, (4 * $nHeight) / 5, $nWidth, $nHeight / 5, $greybrush)

_GDIPlus_GraphicsFillRect($backbuffer, $nWidth / 2 - 2, (7 * $nHeight) / 10, 4, $nHeight / 10 + 5, $whitebrush)

;~ EndIf

DrawScores()

;if ball hits floor

If ($ballY < 25) Then

If ($ballX <= 500) Then

Sleep(100)

$p2s += 1

$p1s -= 1

$ballX = 800

$ballY = 400

$ballVX = 0

$ballVY = 0

;~ _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)

$p1X = 200

$p2X = 800

DrawScores()

If ($p2s = 10) Then $Winner = True

ElseIf ($ballX > 500) Then

Sleep(100)

$p1s += 1

$p2s -= 1

$ballX = 200

$ballY = 400

$ballVX = 0

$ballVY = 0

;~ _GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)

$p1X = 200

$p2X = 800

DrawScores()

If ($p1s = 10) Then $Winner = True

EndIf

EndIf

;if someone wins

If ($Winner) Then

If ($p1s = 10) Then ;if player one wins then do this

_GDIPlus_GraphicsDrawString($backbuffer, "Player 1 Wins!", 250, 150, "Times New Roman", 30)

While ($Winner)

_GDIPlus_GraphicsDrawString($backbuffer, "Press 'R' to restart, or 'SpaceBar' to exit", 120, 200, "Times New Roman", 26)

If (_IsPressed(52, $vDll)) Then

Restart()

$Winner = False

EndIf

If (_IsPressed(20, $vDll)) Then Exit

WEnd

Else ;if player 2 wins

_GDIPlus_GraphicsDrawString($backbuffer, "Player 2 Wins!", 250, 150, "Times New Roman", 30)

While ($Winner)

_GDIPlus_GraphicsDrawString($backbuffer, "Press 'R' to restart, or 'SpaceBar' to exit", 120, 200, "Times New Roman", 26)

If (_IsPressed(52, $vDll)) Then

Restart()

$Winner = False

EndIf

If (_IsPressed(20, $vDll)) Then Exit

WEnd

EndIf

EndIf

;;; New

_GDIPlus_GraphicsDrawImageRect($hGraphic,$bitmap,0,0,$nWidth,$nHeight)

WEnd

;Clean up resources when exited

_GDIPlus_GraphicsDispose($hGraphic)

_GDIPlus_Shutdown()

DllClose($vDll)

Func DrawSlimes()

;black out old slime p1

$sWidth = $nWidth * $p1Diam / 1000

$sHeight = $nHeight * $p1Diam / 1000

$leftbound = $p1OldX * $nWidth / 1000 - $sWidth / 2

$topbound = 4 * $nHeight / 5 - $sHeight - $p1OldY * $nHeight / 1000

_GDIPlus_GraphicsFillRect($backbuffer, $leftbound, $topbound, $sWidth, $sHeight, $brush)

;black out p2

$sWidth = $nWidth * $p2Diam / 1000

$sHeight = $nHeight * $p2Diam / 1000

$leftbound = $p2OldX * $nWidth / 1000 - $sWidth / 2

$topbound = 4 * $nHeight / 5 - $sHeight - $p2oldy * $nHeight / 1000

_GDIPlus_GraphicsFillRect($backbuffer, $leftbound, $topbound, $sWidth, $sHeight, $brush)

;move it according to its velocity

$p1X += $p1XV

;jump function for p1

If ($p1YV <> 0) Then

$p1YV -= 1.4

$p1Y += $p1YV

If ($p1Y < 0) Then

$p1Y = 0

$p1YV = 0

$jump = False

EndIf

EndIf

;p1 boundaries

If ($p1X < 50) Then $p1X = 50

If ($p1X > 445) Then $p1X = 445

;draw new p1

$sWidth = $nWidth * $p1Diam / 1000

$sHeight = $nHeight * $p1Diam / 1000

$leftbound = $p1X * $nWidth / 1000 - $sWidth / 2

$topbound = 4 * $nHeight / 5 - $sHeight - $p1Y * $nHeight / 1000

_GDIPlus_GraphicsFillPie($backbuffer, $leftbound, $topbound, $sWidth, 2 * $sHeight, 0, -180, $greenbrush)

;slimes eye

$eyeLeft = $p1X + 38 * $p1Diam / 100

$eyeTop = $p1Y - 60 * $p1Diam / 100

$leftbound = $eyeLeft * $nWidth / 1000

$topbound = 4 * $nHeight / 5 - $sHeight - $eyeTop * $nHeight / 1000

$bedx = $leftbound - $ballXPix

$bedy = $topbound - $ballYPix

$bedist = Int(Sqrt($bedx * $bedx + $bedy * $bedy))

$eyeWidthPix = $nWidth / 50 * $p1Diam / 100

$eyeHeightPix = $nHeight / 25 * $p1Diam / 100

$p1Blink = Random(0, 30, 1)

If ($p1Blink < 29) Then

_GDIPlus_GraphicsFillEllipse($backbuffer, $leftbound - $eyeWidthPix, $topbound - $eyeHeightPix, $eyeWidthPix, $eyeHeightPix, $whitebrush)

_GDIPlus_GraphicsFillEllipse($backbuffer, $leftbound - 4 * $bedx / $bedist - 3 * $eyeWidthPix / 4, $topbound - 4 * $bedy / $bedist - 3 * $eyeHeightPix / 4, $eyeWidthPix / 2, $eyeHeightPix / 2, $blackbrush)

EndIf

;draw p2

$p2X += $p2XV

;jump function

If ($p2YV <> 0) Then

$p2YV -= 1.4

$p2Y += $p2YV

If ($p2Y < 0) Then

$p2Y = 0

$p2YV = 0

$jump2 = False

EndIf

EndIf

;boundaries

If ($p2X > 950) Then $p2X = 950

If ($p2X < 555) Then $p2X = 555

;draw new p2

$sWidth = $nWidth * $p2Diam / 1000

$sHeight = $nHeight * $p2Diam / 1000

$leftbound = $p2X * $nWidth / 1000 - $sWidth / 2

$topbound = 4 * $nHeight / 5 - $sHeight - $p2Y * $nHeight / 1000

_GDIPlus_GraphicsFillPie($backbuffer, $leftbound, $topbound, $sWidth, 2 * $sHeight, 0, -180, $redbrush)

;p2's eye

$eyeLeft = $p2X - 18 * $p2Diam / 100

$eyeTop = $p2Y - 60 * $p2Diam / 100

$leftbound = $eyeLeft * $nWidth / 1000

$topbound = 4 * $nHeight / 5 - $sHeight - $eyeTop * $nHeight / 1000

$bedx = $leftbound - $ballXPix

$bedy = $topbound - $ballYPix

$bedist = Int(Sqrt($bedx * $bedx + $bedy * $bedy))

$eyeWidthPix = $nWidth / 50 * $p2Diam / 100

$eyeHeightPix = $nHeight / 25 * $p2Diam / 100

$p2Blink = Random(0, 30, 1)

If ($p2Blink < 29) Then

_GDIPlus_GraphicsFillEllipse($backbuffer, $leftbound - $eyeWidthPix, $topbound - $eyeHeightPix, $eyeWidthPix, $eyeHeightPix, $whitebrush)

_GDIPlus_GraphicsFillEllipse($backbuffer, $leftbound - 4 * $bedx / $bedist - 3 * $eyeWidthPix / 4, $topbound - 4 * $bedy / $bedist - 3 * $eyeHeightPix / 4, $eyeWidthPix / 2, $eyeHeightPix / 2, $blackbrush)

EndIf

EndFunc ;==>DrawSlimes

Func MoveBall()

;makes ball bounce off of net

If ($ballX > 480 And $ballX < 520 And $ballY < 140) Then

If ($ballVY < 0 And $ballY > 130) Then

$ballVY *= -1

$ballY = 130

ElseIf ($ballX < 500) Then

$ballX = 480

$ballVX *= -1

Else

$ballX = 520

$ballVX *= -1

EndIf

EndIf

;makes ball bounce off of walls

If ($ballX < 15) Then

$ballX = 15

$ballVX = -$ballVX

EndIf

If ($ballX > 985) Then

$ballX = 985

$ballVX = -$ballVX

EndIf

;black out old ball

$ballXPix = $ballOldX * $nWidth / 1000

$ballYPix = 4 * $nHeight / 5 - $ballOldY * $nHeight / 1000

$ballRadPix = ($ballRad + $fudge) * $nHeight / 1000

;~ _GDIPlus_GraphicsFillRect($backbuffer, $ballXPix - $ballRadPix, $ballYPix - $ballRadPix, 2 * $ballRadPix, 2 * $ballRadPix, $brush)

;p1 collision detection

$dx = 2 * ($ballX - $p1X)

$dy = $ballY - $p1Y

$dist = Int(Sqrt($dx * $dx + $dy * $dy))

$dvx = $ballVX - $p1XV

$dvy = $ballVY - $p1YV

If ($dy > 0 And $dist < $p1Diam + $ballRad And $dist > $fudge) Then

$something = Int(($dx * $dvx + $dy * $dvy) / $dist)

$ballX = $p1X + ($p1Diam + $ballRad) / 2 * $dx / $dist

$ballY = $p1Y + ($p1Diam + $ballRad) * $dy / $dist

If ($something <= 0) Then

$ballVX += $p1XV - 2 * $dx * $something / $dist

$ballVY += $p1YV - 2 * $dy * $something / $dist

If ($ballVX < -$maxXV) Then $ballVX = -$maxXV

If ($ballVX > $maxXV) Then

$ballVX = $maxXV

$ballVY += $p1YV - 2 * $dy * $something / $dist

EndIf

If ($ballVY < -$maxYV) Then $ballVY = -$maxYV

If ($ballVY > $maxYV) Then $ballVY = $maxYV

EndIf

EndIf

;p2 collision detection

$dx = 2 * ($ballX - $p2X)

$dy = $ballY - $p2Y

$dist = Int(Sqrt($dx * $dx + $dy * $dy))

$dvx = $ballVX - $p2XV

$dvy = $ballVY - $p2YV

If ($dy > 0 And $dist < $p2Diam + $ballRad And $dist > $fudge) Then

$something = Int(($dx * $dvx + $dy * $dvy) / $dist)

$ballX = $p2X + ($p2Diam + $ballRad) / 2 * $dx / $dist

$ballY = $p2Y + ($p2Diam + $ballRad) * $dy / $dist

If ($something <= 0) Then

$ballVX += $p2XV - 2 * $dx * $something / $dist

$ballVY += $p1YV - 2 * $dy * $something / $dist

If ($ballVX < -$maxXV) Then $ballVX = -$maxXV

If ($ballVX > $maxXV) Then

$ballVX = $maxXV

$ballVY += $p1YV - 2 * $dy * $something / $dist

EndIf

If ($ballVY < -$maxYV) Then $ballVY = -$maxYV

If ($ballVY > $maxYV) Then $ballVY = $maxYV

EndIf

EndIf

;makes ball fall

$ballVY -= 1

;makes ball move on x and y axis' according to balls x and y velocity

$ballY += $ballVY

$ballX += $ballVX

;converts ball pixels into autoit friendly coordinates

$ballRadPix = ($ballRad + $fudge) * $nHeight / 1000

$ballXPix = $ballX * $nWidth / 1000

$ballYPix = 4 * $nHeight / 5 - $ballY * $nHeight / 1000

_GDIPlus_GraphicsFillEllipse($backbuffer, $ballXPix - $ballRadPix, $ballYPix - $ballRadPix, 2 * $ballRadPix, 2 * $ballRadPix, $yellowbrush)

EndFunc ;==>MoveBall

Func DrawScores()

;draw the score

For $s = 1 To ($p1s) Step 1

$xx = $s * 30

_GDIPlus_GraphicsFillEllipse($backbuffer, $xx, 10, 25, 25, $whitebrush)

Next

For $s = 1 To ($p2s) Step 1

$xx = 720 - ($s * 30)

_GDIPlus_GraphicsFillEllipse($backbuffer, $xx, 10, 25, 25, $whitebrush)

Next

EndFunc ;==>DrawScores

Func Restart()

$p1X = 200

$p1Y = 0

$p2X = 800

$p2Y = 0

$ballVX = 0

$ballVY = 0

$ballX = 200

$ballY = 400

_GDIPlus_GraphicsFillRect($backbuffer, 0, 0, $nWidth, (4 * $nHeight) / 5, $bluebrush)

$p1s = 5

$p2s = 5

Sleep(100)

DrawScores()

EndFunc ;==>Restart

Func StartScreen()

;button to start game

$startgame = GUICtrlCreateButton("Click Here To Start 2 Player Game ('I' = Instructions)", 230, 200, 260, 40)

_GDIPlus_GraphicsDrawString($backbuffer, "Slime Volleyball By: Isaac Flaum", 170, 150, "Times New Roman", 20)

While ($nclick)

Sleep(20)

If (_IsPressed(49, $vDll)) Then Instructions()

$msg = GUIGetMsg()

If ($msg = -3) Then Exit

If ($msg = $startgame) Then

GUICtrlDelete($startgame)

$start = False

$nclick = False

Restart()

EndIf

WEnd

EndFunc ;==>StartScreen

Func Instructions()

MsgBox(0, "Slime Volleyball Instructions", "Slime Volleyball is a simple game in which 2 players battle" & Chr(13) & Chr(10) & "to get the ball on their opponents side. Once you get 10 points, you win!" & Chr(13) & Chr(10) & "The controls are as follows:" & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "Player 1:" & Chr(13) & Chr(10) & "Move Left: 'A'" & Chr(13) & Chr(10) & "Move Right: 'D'" & Chr(13) & Chr(10) & "Jump: 'W'" & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "Player 2:" & Chr(13) & Chr(10) & "Move Left: 'Left Arrow Key'" & Chr(13) & Chr(10) & "Move Right: 'Right Arrow Key'" & Chr(13) & Chr(10) & "Jump: 'Up Arrow Key'" & Chr(13) & Chr(10) & "" & Chr(13) & Chr(10) & "Spacebar: Exit" & Chr(13) & Chr(10) & "Instructions: 'I'" & Chr(13) & Chr(10) & "Restart: 'R'")

EndFunc ;==>Instructions

Func _AntiAlias($hGraphics, $iMode)

Local $aResult

$aResult = DllCall($ghGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", $iMode)

If @error Then Return SetError(@error, @extended, False)

Return SetError($aResult[0], 0, $aResult[0] = 0)

EndFunc ;==>_AntiAlias


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

LimeSeed

Very nice game, I like how their eyes spinning after ball.

@monoceres

Have been useful your changes.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I love it :mellow: I remember a game called boom boom volley with two precious ladies.

Add an online multiplayer version and it beat WoW :(

Edited by toonboon

[right]~What can I say, I'm a Simplistic person[/right]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Might be a little bug. The red slime can't move backwards while jumping or jump while moving backwards.

Uhm, appears randomly.

Great game! :mellow:

Edited by walle

Share this post


Link to post
Share on other sites

@monoceres thanks alot! it looks great! and thanks everyone else for the positive comments!


global $warming = true

Share this post


Link to post
Share on other sites

Is it just me or does it bounce of greens head a lot better then it does of reds?


Giggity

Share this post


Link to post
Share on other sites

OMG..

The first fun game made with autoit (for me)..

Very good!!

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I like to play it against myself.

A few things I found that could be adjusted:

Like I said, it doesn't seem to bounce off red as good as green

If you hit the ball while moving backwards it doesn't travel far

The characters move just too slow. If you sped them up a little it would still be challenging but also able to volly longer

I would turn up the power of the hits and speed up the characters personally. And make the losing slime cry when they lost.

Edit: I caught the ball

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

dont know if its just me but when holding down WASD (one at a time) it plays a beeping noise and slows the speed of the game =\

Share this post


Link to post
Share on other sites

LimeSeed

Hey! Very nice work! 5 stars from me! :mellow:

Share this post


Link to post
Share on other sites

LimeSeed

Hey! Very nice work! 5 stars from me! :mellow:

Ditto!!!

Reallly Good!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

great game, i didn't even realize something like this was possible with autoit

Share this post


Link to post
Share on other sites

I didn't know the ball could be caught! I think I may use that image as an icon. Glad u all like it! I'll fix more bugs when I get back from vacation :mellow:


global $warming = true

Share this post


Link to post
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
Sign in to follow this  
Followers 0