TheNorwegianUser

_GDIPlus collision

16 posts in this topic

#1 ·  Posted (edited)

Hey!

Yesterday I started making a small game just 4 fun, but it's very buggy. The way I made it check the collisions and jump off blocks etc is probably not the best way to do it, so it would be great if anyone got any suggestions as to how to improve the collision checks, and/or just what's making it buggy.

#Include <GuiconstantsEx.au3>
#Include <GDIPlus.au3>
HotKeySet("{ESC}", "Terminate")
HotKeySet("{SPACE}", "StartJump")


#Region Gui
$WinWidth=500
$WinHeight=400
$hGUI=GUICreate("", $WinWidth, $WinHeight)
GUISetState()
#EndRegion

#Region Graphics
$GDI_QUALITY=2
_GDIPlus_Startup()
$GDI_GRAPHICS=_GDIPlus_GraphicsCreateFromHWND($hGUI)
$GDI_BITMAP=_GDIPlus_BitmapCreateFromGraphics($WinWidth, $WinHeight, $GDI_GRAPHICS)
$GDI_BACKBUFFER=_GDIPlus_ImageGetGraphicsContext($GDI_BITMAP)
_GDIPlus_GraphicsSetSmoothingMode($GDI_BACKBUFFER, $GDI_QUALITY)
_GDIPlus_GraphicsClear($GDI_BACKBUFFER)

$GDI_BRUSH_BALL=_GDIPlus_BrushCreateSolid()
#EndRegion

#Region GraphicObjects
Dim $Obj[1][4]
$Obj_Num=0
$SolidBrush=_GDIPlus_BrushCreateSolid()
Solid(125, 375, 125)
Solid(200, 350, 50, 25)
Solid(300, 325, 50, 50)
Solid(375, 325, 25, 50)
Solid(425, 300, 75, 50)
Solid(300, 225, 150, 25)
Solid(450, 250)
#EndRegion

#Region GameVars
$BallDirection=1
$BallWidth=20
$BallHeight=20
$BallSpeed=1
$BallSpeedY=0
$BallPosX_0=0
$BallPosX=$BallPosX_0
$BallPosY_Start=$WinHeight-$BallHeight
$BallPosY_0=300
$BallPosY=$BallPosY_0
$SurfaceCount=0
$Jump=False
$JumpHeight=350
$JumpSoon=False
#EndRegion

#Region Quality
$QualityTimer=TimerInit()
$QualityCount=0
$QualityFPS=60
$QualitySleep=2000
#EndRegion


While 1
    GetNewBallPos()
    _GDIPlus_GraphicsClear($GDI_BACKBUFFER, 0xFFFFFFFF)
    DrawObjects()
    MoveBall()
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    Gravity()
    QualityCheck()
    USleep($QualitySleep)
WEnd

Func Solid($_SolidPosX, $_SolidPosY, $_SolidWidth=25, $_SolidHeight=25, $_SolidBrush=$SolidBrush)
    ReDim $Obj[$Obj_Num+1][4]
    $Obj[$Obj_Num][0]=$_SolidPosX
    $Obj[$Obj_Num][1]=$_SolidPosY
    $Obj[$Obj_Num][2]=$_SolidWidth
    $Obj[$Obj_Num][3]=$_SolidHeight
    _GDIPlus_GraphicsDrawRect($GDI_GRAPHICS, $_SolidPosX, $_SolidPosY, $_SolidWidth, $_SolidHeight, $_SolidBrush)
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    $Obj_Num+=1
EndFunc

Func DrawObjects()
    For $1=0 To $Obj_Num-1
        _GDIPlus_GraphicsFillRect($GDI_BACKBUFFER, $Obj[$1][0], $Obj[$1][1], $Obj[$1][2], $Obj[$1][3], $SolidBrush)
    Next
EndFunc

Func GetNewBallPos()
    If $BallDirection=1 And SurfaceRight() Then $BallDirection=2
    If $BallDirection=2 And SurfaceLeft() Then $BallDirection=1
    Switch $BallDirection
        Case 1
            $BallPosX+=$BallSpeed
        Case 2
            $BallPosX-=$BallSpeed
    EndSwitch
EndFunc

Func MoveBall()
    _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX, $BallPosY, $BallWidth, $BallHeight, $GDI_BRUSH_BALL)
EndFunc

Func SurfaceRight()
    If $BallPosX>=$WinWidth-$BallWidth Then Return True
    For $1=0 To $Obj_Num-1
        If $Obj[$1][0]+$Obj[$1][2]/10>$BallPosX+$BallWidth And $BallPosX+$BallWidth>=$Obj[$1][0] And $Obj[$1][1]<$BallPosY+$BallHeight And $BallPosY<$Obj[$1][1]+$Obj[$1][3] Then Return True
    Next
EndFunc

Func SurfaceLeft()
    If $BallPosX<=$BallPosX_0 Then Return True
    For $1=0 To $Obj_Num-1
        If $Obj[$1][0]+$Obj[$1][2]>=$BallPosX And $BallPosX>=$Obj[$1][0]+$Obj[$1][2]-$Obj[$1][2]/10 And $Obj[$1][1]<$BallPosY+$BallHeight And $BallPosY<$Obj[$1][1]+$Obj[$1][3] Then Return True
    Next
EndFunc

Func SurfaceUnder()
    If $Jump=True Then Return False
    If $BallPosY>=$WinHeight-$BallHeight Then
        $BallPosY=$WinHeight-$BallHeight
        $BallPosY_0=$WinHeight-$BallHeight
        Return True
    EndIf
    For $1=0 To $Obj_Num-1
        If $BallPosX+$BallWidth>=$Obj[$1][0] And $BallPosX<=$Obj[$1][0]+$Obj[$1][2] And $BallPosY+$BallHeight>=$Obj[$1][1] And $BallPosY+$BallHeight<$Obj[$1][1]+$Obj[$1][3]/10 Then
            $BallPosY_0=$BallPosY
            Return True
        EndIf
    Next
EndFunc

Func SurfaceOver()
    For $1=0 To $Obj_Num-1
        If $BallPosX+$BallWidth>=$Obj[$1][0] And $BallPosX<=$Obj[$1][0]+$Obj[$1][2] And $BallPosY<=$Obj[$1][1]+$Obj[$1][3] And $BallPosY>$Obj[$1][1]+$Obj[$1][3]-$Obj[$1][3]/10 Then Return True
    Next
EndFunc

Func StartJump()
    If SurfaceUnder() Then
        $Jump=True
        $BallPosY_0=$BallPosY
        $BallSpeedY=$JumpHeight
        $JumpSoon=False
    Else
        $JumpSoon=True
    EndIf
EndFunc

Func Gravity()
    If $BallSpeedY>0 And SurfaceOver() = True Then
        $BallSpeedY=0
        $SurfaceCount=0
        $BallPosY_0=$BallPosY
    EndIf
    If SurfaceUnder() Then
        $SurfaceCount=0
        $BallSpeedY=0
        $BallPosY_0=$BallPosY
        If Not $JumpSoon=True Then
            Return
        Else
            StartJump()
        EndIf
    EndIf
    $SurfaceCount+=1
    $Jump=False
    $BallPosY=$BallPosY_0-($BallSpeedY*$SurfaceCount+1/2*-9.81*$SurfaceCount^2)*0.01
EndFunc

Func QualityCheck()
    $QualityCount+=1
    If $QualityCount=$QualityFPS Then
        $QualitySleep+=(1000-TimerDiff($QualityTimer))/$QualityFPS*100
        $QualityCount=0
        $QualityTimer=TimerInit()
    EndIf
EndFunc

Func USleep($iUsec, $hDLL = "ntdll.dll")
    Local $hStruct = DllStructCreate("int64")
    DllStructSetData($hStruct, 1, -1 * ($iUsec * 10))
    DllCall($hDLL, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))
EndFunc

Func Terminate()
    _GDIPlus_BrushDispose($SolidBrush)
    _GDIPlus_BrushDispose($GDI_BRUSH_BALL)
    _GDIPlus_GraphicsDispose($GDI_GRAPHICS)
    _GDIPlus_ImageDispose($GDI_BITMAP)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

Edit: Current progress:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <WindowsConstants.au3>
#Include <GuiconstantsEx.au3>
#Include <GDIPlus.au3>
#include <WinAPIGdi.au3>
#include <Screencapture.au3>
#Include <ButtonConstants.au3>
#include <File.au3>
#include <GuiConstants.au3>
#Include <Crypt.au3>

HotKeySet("{ESC}", "Terminate")

#Region Gui
$PictureDir=@ScriptDir & "\JuegoData\"
$WinWidth=500
$WinHeight=400
$hGUI=GUICreate("", $WinWidth, $WinHeight, -1, -1, $WS_POPUPWINDOW)
GUISetState()
Dim $Button[17]
#EndRegion

#Region Graphics
$GDI_QUALITY=2
_GDIPlus_Startup()
$GDI_GRAPHICS=_GDIPlus_GraphicsCreateFromHWND($hGUI)
$GDI_BITMAP=_GDIPlus_BitmapCreateFromGraphics($WinWidth, $WinHeight, $GDI_GRAPHICS)
$GDI_BACKBUFFER=_GDIPlus_ImageGetGraphicsContext($GDI_BITMAP)
_GDIPlus_GraphicsSetSmoothingMode($GDI_BACKBUFFER, $GDI_QUALITY)
_GDIPlus_GraphicsClear($GDI_BACKBUFFER)

$GDI_BRUSH_BALL=_GDIPlus_BrushCreateSolid()
#EndRegion

#Region GraphicObjects
Dim $Obj[1][14]
Dim $Text[1][5]
$Text_Num=0
$Obj_Num=0
Dim $Obj_DirectionX[1]
Dim $Obj_DirectionY[1]
Dim $SolidBrush[20]
$SolidBrush[0]=_GDIPlus_BrushCreateSolid()
$SolidBrush[1]=_GDIPlus_BrushCreateSolid(0xFF00FF00)
$SolidBrush[2]=_GDIPlus_BrushCreateSolid(0xFFFF0000)
$SolidBrush[3]=_GDIPlus_BrushCreateSolid(0xFF00FFFF)
$SolidBrush[4]=_GDIPlus_BrushCreateSolid(0xFFddad19)
$SolidBrush[5]=_GDIPlus_BrushCreateSolid(0xFF004400)
$SolidBrush[11]=_GDIPlus_BrushCreateSolid(0xFFFF9900)
$SolidBrush[12]=_GDIPlus_BrushCreateSolid(0xFF00FFFF)
$SolidBrush[13]=_GDIPlus_BrushCreateSolid(0xFF0000FF)
$SolidBrush[14]=_GDIPlus_BrushCreateSolid(0xFF734021)

Dim $VanishBrush[1]

Dim $EpicBrush[3]
$Brush=1
$EpicBrush[0]=_GDIPlus_BrushCreateSolid(0xFFc03430)
$EpicBrush[1]=_GDIPlus_BrushCreateSolid(0xFFf8cf46)
$EpicBrush[2]=_GDIPlus_BrushCreateSolid(0xFF367341)
#EndRegion

#Region GameVars
Dim $FileLineData[0]
$TakeScreenshot=False
$GoToMenu=False
$WinActive=True
Dim $Vanish[1]
$BrownStopCount=0
$BrownStop=False
$BallDirection=1
$BallWidth=20
$BallHeight=20
$BallSpeed=1
$BallSpeedY=0
$BallPosX_0=0
$BallPosX=$BallPosX_0
$BallPosY_Start=$WinHeight-$BallHeight
$BallPosY_0=375
$BallPosY=$BallPosY_0
$SurfaceCount=0
$Jump=False
$JumpHeight=350
$JumpSoon=False
$JumpSoonTimer=TimerInit()
$IsSqueezed=0
$SurfaceMove=0
$Level=1
$BallPosYDiff=0
$LastBallPosY=$BallPosY
$ActivePowerup=0
$ExtraJumpActive=0
$TeleTimer=TimerInit()
Dim $VanishTimer[1]
#EndRegion

Menu()

#Region Quality
$QualityTimer=TimerInit()
$QualityCount=0
$QualityFPS=60
$QualitySleep=2000
$USleepTimer=TimerInit()
#EndRegion

While 1
    CheckActive()
    GetNewBallPos()
    _GDIPlus_GraphicsClear($GDI_BACKBUFFER, 0xFFFFFFFF)
    CheckVanish()
    DrawText()
    DrawObjects()
    MoveBall()
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    If $TakeScreenshot=True Then TakeSnapShot()
    Gravity()
    QualityCheck()
    $ScriptPos=0
    If $GoToMenu=True Then GoToMenu()
    USleep($QualitySleep)
    $ScriptPos=1
WEnd

;=================================================================================
;============================== OBJECT DESCRIPTION ===============================
;==============================--------------------===============================
;============ Solid( Type, X, Y, [Width, Height, X2, Y2, Speed) ==================
;==============================--------------------===============================
;==============================         TYPES       ==============================
;============================== 0 = Black Solid     ==============================
;============================== 1 = Green Goal      ==============================
;============================== 2 = Red Fail        ==============================
;============================== 3 = Cyan Lock       ==============================
;============================== 4 = Gold Sticky     ==============================
;============================== 5 = Green Vanish    ==============================
;============================== 11 = Extra Jump     ==============================
;============================== 12 = Cyan Key       ==============================
;============================== 13 = Blue Teleport  ==============================
;============================== 14 = Brown Stop     ==============================
;=================================================================================

Func LevelFromTxt($_Level)
    $Level=$_Level
    $FileDir=@ScriptDir & "\JuegoData\Level" & $_Level & ".txt"
    $FileLines=_FileCountLines($FileDir)
    $FileOpen=FileOpen($FileDir)
    For $1=1 To $FileLines
        $FileData=FileReadLine($FileOpen, $1)
        StringReplace($FileData, ",", ",")
        $FileDataLen=@extended
        If StringLeft($FileData, 5)="Solid" Then $FileMode=1
        If StringLeft($FileData, 4)="Text" Then $FileMode=0
        $FileData=StringTrimLeft($FileData, 5+$FileMode)
        ReDim $FileLineData[0]
        ReDim $FileLineData[9]
        For $2=0 To $FileDataLen
            $FileLen=StringInStr($FileData, ",")
            $FileLineData[$2]=StringLeft($FileData, $FileLen-1)
            $FileData=StringTrimLeft($FileData, $FileLen)
        Next
        $FileLineData[$FileDataLen]=StringTrimRight($FileData, 1)
        If $FileMode=1 Then
            If $FileLineData[3]="" Then $FileLineData[3]=25
            If $FileLineData[4]="" Then $FileLineData[4]=25
            If $FileLineData[5]="" Then $FileLineData[5]=$FileLineData[1]
            If $FileLineData[6]="" Then $FileLineData[6]=$FileLineData[2]
            If $FileLineData[7]="" Then $FileLineData[7]=100
            If $FileLineData[8]="" Then $FileLineData[8]=$SolidBrush[$FileLineData[0]]
            Solid($FileLineData[0], $FileLineData[1], $FileLineData[2], $FileLineData[3], $FileLineData[4], $FileLineData[5], $FileLineData[6], $FileLineData[7], $FileLineData[8])
        ElseIf $FileMode=0 Then
            If $FileLineData[3]="" Then $FileLineData[3]=10
            If $FileLineData[4]="" Then $FileLineData[4]="Arial"
            Text($FileLineData[0], $FileLineData[1], $FileLineData[2], $FileLineData[3], $FileLineData[4])
        EndIf
    Next
EndFunc

Func Level8()
    $Level=8
    Solid(0, 100, -50, 25, 450)
    Solid(0, 225, -50, 25, 425)
    Solid(0, 350, -50, 25, 425)
    Solid(3, 225, 375, 25)
    Solid(3, 350, 375, 25)
    Solid(13, 0, 310, 25, 15, 75, 310, 400)
    Solid(13, 0, 200, 25, 15, 75, 200, 200)
    Solid(2, 0, 290, 100, 15)
    Solid(13, 0, 270, 25, 15, 75)
    Solid(13, 0, 100, 25, 15)
    Solid(0, 0, 150, 50, 10, 50, 150, 80)
    Solid(0, 0, 85, 25, 15)
    Solid(13, 80, 0, 15, 25, 80, 25)
    Solid(13, 130, 0, 15, 25)
    Solid(2, 50, 75, 50, 15)
    Solid(2, 125, 50)
    Solid(0, 150, 50)
    Solid(2, 200, 50)
    Solid(0, 200, 128)
    Solid(2, 170, 128, 30)
    Solid(0, 125, 75, 10, 90)
    Solid(0, 150, 200, 50)
    Solid(2, 200, 200)
    Solid(0, 150, 250)
    Solid(11, 200, 275, 20, 20)
    Solid(2, 150, 275)
    Solid(2, 125, 300, 100)
    Solid(13, 125, 285, 25, 15)
    Solid(13, 250, 275, 25, 15)
    Solid(5, 250, 325, 50)
    Solid(2, 250, 350, 100)
    Solid(0, 275, 265, 25, 32)
    Solid(2, 250, 250, 50, 15)
    Solid(5, 325, 275)
    Solid(5, 250, 225)
    Solid(5, 250, 170)
    Solid(5, 325, 180)
    Solid(5, 300, 100)
    Solid(5, 325, 115)
    Solid(5, 250, 50)
    Solid(13, 335, 0, 15, 25)
    Solid(13, 375, 0, 15, 25)
    Solid(2, 375, 75, 40)
    Solid(5, 415, 75)
    Solid(2, 440, 75, 60)
    Solid(14, 425, 0, 20, 20)
    Solid(11, 450, 25, 20, 20)
    Solid(5, 375, 190, 25, 20)
    Solid(2, 400, 190, 40, 20)
    Solid(0, 440, 100, 20, 110)
    Solid(11, 417, 125, 20, 20)
    Solid(14, 375, 105, 20, 20)
    Solid(14, 375, 160, 20, 20)
    Solid(2, 375, 275)
    Solid(11, 400, 275, 20, 20)
    Solid(11, 450, 250, 20, 20)
    Solid(11, 472, 200, 20, 20)
    Solid(14, 472, 150, 20, 20)
    Solid(12, 472, 100, 20, 20)
    Solid(11, 472, 310, 20, 20)
    Solid(2, 425, 350, 75)
    Solid(1, 150, 350, 50)
EndFunc

Func Level7()
    $Level=7
;~  $BallPosX_0=0
;~  $BallPosX=225
;~  $BallPosY_0=0
;~  $BallPosY=$BallPosY_0
;~  $BallDirection=2


    Solid(2, 0, 225, 75)
    Solid(2, 75, 225, 25, 50)
    Solid(0, 75, 275, 25, 75)
    Solid(1, 0, 250, 75)
    Solid(2, 150, 325, 100)
    Solid(2, 275, 375)
    Solid(2, 250, 300)
    Solid(2, 275, 275, 50)
    Solid(2, 325, 300)
    Solid(2, 350, 375)
    Solid(2, 350, 275, 50)
    Solid(2, 400, 275, 25, 50)
    Solid(2, 450, 375)
    Solid(0, 475, 375)
    Solid(11, 475, 350, 20, 20)
    Solid(2, 425, 250, 75)
    Solid(3, 0, 325, 75)
    Solid(0, 150, 300, 100)
    Solid(2,100, 225, 125)
    Solid(0, 300, 250)
    Solid(0, 400, 250)
    Solid(2, 400, 125, 25, 75)
    Solid(0, 475, 200)
    Solid(0, 425, 150)
    Solid(0, 375, 125)
    Solid(11, 325, 125, 20, 20)
    Solid(2, 250, 75, 25, 75)
    Solid(2, 200, 150, 25, 75)
    Solid(0, 150, 200, 50)
    Solid(11, 50, 200, 20, 20)
    Solid(11, 0, 125, 20, 20)
    Solid(11, 50, 75, 20, 20)
    Solid(11, 100, 75, 20, 20)
    Solid(11, 225, 75, 20, 20)
    Solid(11, 300, 50, 20, 20)
    Solid(11, 450, 50, 20, 20)
    Solid(11, 450, 0, 20, 20)
    Solid(12, 475, 0, 20, 20)
    Solid(11, 400, 0, 20, 20)
EndFunc

Func Level6()
    $Level=6
    Solid(0, 100, 100, 25, 300)
    Solid(0, 75, 375)
    Solid(0, 0, 325)
    Solid(0, 50, 275)
    Solid(0, 50, 200)
    Solid(0, 0, 225)
    Solid(0, 50, 140)
    Solid(0, 50, 75, 75)
    Solid(0, 0, 75)
    Solid(2, 75, 0, 25, 75)
    Solid(13, 55, 25, 15, 25)
    Solid(13, 105, 25, 15, 25)
    Solid(0, 150, -25, 25, 375)
    Solid(0, 300, 50, 25, 350)
    Solid(4, 225, 300, 75, 25, 225, 400, 400)
    Solid(0, 175, 200, 50, 25, 175, 300, 200)
    Solid(0, 225, 225, 75)
    Solid(0, 175, 100, 50, 25, 175, 200, 200)
    Solid(0, 225, 50, 75, 25, 225, 125, 400)
    Solid(0, 325, 50, 150)
    Solid(2, 350, 25, 25, 25, 425, 25, 200)
    Solid(0, 375, 175, 75)
    Solid(4, 450, 175, 50)
    Solid(2, 325, 75, 25, 25, 425)
    Solid(2, 375, 150, 25, 25, 400)
    Solid(0, 450, 75, 25, 50)
    Solid(0, 325, 225, 50, 50)
    Solid(0, 375, 250, 50)
    Solid(4, 425, 250)
    Solid(0, 450, 250, 50)
    Solid(13, 425, 200, 25, 15)
    Solid(13, 325, 275, 25, 15, 475)
    Solid(2, 325, 385, 175, 15)
    Solid(1, 325, 365, 50, 15, 450, 365, 200)
EndFunc

Func Level5()
    $Level=5
    Solid(2, 100, 375)
    Solid(2, 225, 375)
    Solid(0, 250, 375, 50)
    Solid(2, 300, 375, 50)
    Solid(0, 350, 375)
    Solid(2, 375, 375)
    Solid(0, 400, 350, 100, 50)
    Solid(0, 450, 300, 25)
    Solid(0, 350, 250, 50)
    Solid(11, 363, 225, 20, 20)
    Solid(2, 300, 250, 50)
    Solid(0, 250, 275, 50)
    Solid(2, 175, 250, 75)
    Solid(2, 175, 225, 50)
    Solid(0, 125, 250, 50)
    Solid(2, 100, 100, 25, 100)
    Solid(11, 125, 225, 20, 20)
    Solid(11, 25, 225, 20, 20)
    Solid(11, 25, 175, 20, 20)
    Solid(11, 50, 125, 20, 20)
    Solid(11, 50, 75, 20, 20)
    Solid(0, 175, 100, 50)
    Solid(11, 300, 100, 20, 20)
    Solid(11, 375, 100, 20, 20)
    Solid(11, 425, 75, 20, 20)
    Solid(1, 475, 50)


EndFunc

Func Level4()
    $Level=4
    Solid(0, 0, 400, 500)
    Solid(0, 125, 375, 125)
    Solid(0, 200, 350, 50, 25)
    Solid(0, 300, 325, 50, 50)
    Solid(0, 375, 325, 25, 50)
    Solid(0, 425, 300, 75, 50)
    Solid(0, 300, 225, 150, 25)
    Solid(0, 450, 250)
    Solid(0, 225, 250)
    Solid(0, 150, 200)
    Solid(0, 0, 300, 100)
    Solid(0, 50, 150, 25, 100)
    Solid(0, 25, 250)
    Solid(0, 0, 200)
    Solid(0, 425, 175, 75)
    Solid(0, 425, 125)
    Solid(0, 350, 125, 50)
    Solid(0, 275, 125)
    Solid(0, 150, 100, 75)
    Solid(0, 0, 100)
    Solid(0, 50, 50)
    Solid(0, 100, 0, 50)
    Solid(0, 150, 25, 75)
    Solid(0, 275, 25, 50)
    Solid(0, 375, 25, 125)
    Solid(1, 475, 0)
EndFunc

Func Level3()
    $Level=3
    Text("Blocks can move!", 25, 300)
    Solid(4, 100, 375, 100)
    Solid(2, 200, 375, 175)
    Solid(0, 200, 350, 75, 25, 300, 350, 200)
    Solid(0, 375, 175, 125, 25, 375, 375, 200)
    Solid(0, 275, 175, 100)
    Solid(3, 75, 175, 200)
    Solid(0, 0, 175, 75)
    Solid(12, 0, 150, 20, 20)
    Solid(0, 100, 225, 75)
    Solid(1, 225, 200, 50)
EndFunc

Func Level2()
    $Level=2
    Solid(0, 50, 375, 50)
    Solid(0, 125, 325, 100, 50)
    Solid(0, 250, 325, 100, 50)
    Solid(0, 400, 325, 75, 50)
    Solid(0, 0, 275, 100)
    Solid(0, 150, 225, 50)
    Solid(0, 250, 175, 75)
    Solid(0, 400, 200, 75)
    Solid(1, 475, 200)
    Text("Hit enter to restart. Hit esc to exit.", 300, 0, 8)

EndFunc

Func Level1()
    $Level=1
    Solid(0, 100, 375, 100)
    Solid(2, 200, 375)
    Solid(0, 225, 375, 75)
    Solid(4, 300, 375, 125)
    Solid(13, 425, 385, 75, 15)
    Solid(13, 0, 125, 75, 15)
    Solid(0, 0, 250, 175)
    Solid(11, 100, 225, 20, 20)
    Solid(2, 175, 250, 75)
    Solid(0, 250, 250, 175)
    Solid(12, 320, 225, 20, 20)
    Solid(3, 375, 125, 50, 125)
    Solid(13, 425, 255, 75, 15)
    Solid(13, 0, 0, 75, 15)
    Solid(0, 0, 100, 125)
    Solid(5, 125, 100)
    Solid(5, 150, 100)
    Solid(5, 175, 100)
    Solid(5, 200, 100)
    Solid(0, 225, 100, 275)
    Solid(14, 300, 75, 20, 20)
    Solid(1, 450, 50, 50, 50)
    Text("Press up to jump", 0, 325, 8)
    Text("Avoid red", 180, 325, 8)
    Text("Sticky", 335, 325, 8)
    Text("Teleport", 435, 325, 8)
    Text("Jump in the air! Hit space to use", 15, 200, 8)
    Text("Lock and key", 285, 200, 8)
    Text("These vanish!", 130, 50, 8)
    Text("Use to pause moving", 240, 50, 8)
    Text("Hit to win!", 435, 20, 8)
EndFunc

Func Solid($_SolidType, $_SolidPosX, $_SolidPosY, $_SolidWidth=25, $_SolidHeight=25, $_SolidPosX_2=$_SolidPosX, $_SolidPosY_2=$_SolidPosY, $_SolidSpeed=100, $_SolidBrush=$SolidBrush[$_SolidType])
    ReDim $Obj[$Obj_Num+1][14]
    ReDim $VanishTimer[$Obj_Num+1]
    ReDim $VanishBrush[$Obj_Num+1]
    ReDim $Vanish[$Obj_Num+1]
    $Obj[$Obj_Num][0]=$_SolidPosX
    $Obj[$Obj_Num][1]=$_SolidPosY
    $Obj[$Obj_Num][2]=$_SolidWidth
    $Obj[$Obj_Num][3]=$_SolidHeight
    $Obj[$Obj_Num][4]=$_SolidPosX_2
    $Obj[$Obj_Num][5]=$_SolidPosY_2
    $Obj[$Obj_Num][6]=Sqrt(($_SolidPosX_2-$_SolidPosX)^2+($_SolidPosY_2-$_SolidPosY)^2)/$_SolidSpeed
    If $_SolidPosX_2<>$_SolidPosX Then $Obj[$Obj_Num][7]=1
    If $_SolidPosY_2<>$_SolidPosY Then $Obj[$Obj_Num][8]=1
    If $_SolidPosX_2<>$_SolidPosX Then $Obj[$Obj_Num][9]=$_SolidPosX
    If $_SolidPosY_2<>$_SolidPosY Then $Obj[$Obj_Num][10]=$_SolidPosY
    $Obj[$Obj_Num][11]=$_SolidBrush
    $Obj[$Obj_Num][12]=$_SolidType
    $Obj[$Obj_Num][13]=1
    If $_SolidType=5 Then $VanishBrush[$Obj_Num]=_GDIPlus_BrushCreateSolid(0xFF004400)
    If $_SolidType=5 Then $Vanish[$Obj_Num]=99
    ReDim $Obj_DirectionX[$Obj_Num+1]
    ReDim $Obj_DirectionY[$Obj_Num+1]
    $Obj_DirectionX[$Obj_Num]=1
    $Obj_DirectionY[$Obj_Num]=1
    $Obj_Num+=1
EndFunc

Func Text($_TextData, $_TextPosX, $_TextPosY, $_TextSize=10, $_TextFont="Arial")
    ReDim $Text[$Text_Num+1][5]
    $Text[$Text_Num][0]=$_TextData
    $Text[$Text_Num][1]=$_TextPosX
    $Text[$Text_Num][2]=$_TextPosY
    $Text[$Text_Num][3]=$_TextSize
    $Text[$Text_Num][4]=$_TextFont
    $Text_Num+=1
EndFunc

Func DrawText()
    For $1=0 To $Text_Num-1
        _GDIPlus_GraphicsDrawString($GDI_BACKBUFFER, $Text[$1][0], $Text[$1][1], $Text[$1][2], $Text[$1][4], $Text[$1][3])
    Next
EndFunc

Func DrawObjects()
    For $1=0 To $Obj_Num-1
        If $Obj[$1][7]=1 Then ;;;Turn Object Vertically
            $Obj[$1][0]+=$Obj[$1][6]*$Obj_DirectionX[$1]
            If $Obj[$1][0]=$Obj[$1][4] Then $Obj_DirectionX[$1]*=-1
            If $Obj[$1][0]=$Obj[$1][9] Then $Obj_DirectionX[$1]*=-1
        EndIf
        If $Obj[$1][8]=1 Then ;;;Turn Object Horisontally
            $Obj[$1][1]+=$Obj[$1][6]*$Obj_DirectionY[$1]
            If $Obj[$1][1]=$Obj[$1][5] Then $Obj_DirectionY[$1]*=-1
            If $Obj[$1][1]=$Obj[$1][10] Then $Obj_DirectionY[$1]*=-1
        EndIf
        If $Obj[$1][12]>10 Then
            If $Obj[$1][13]<>0 Then _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $Obj[$1][0], $Obj[$1][1], $Obj[$1][2], $Obj[$1][3], $Obj[$1][11])
        Else
            If $Obj[$1][13]<>0 Then _GDIPlus_GraphicsFillRect($GDI_BACKBUFFER, $Obj[$1][0], $Obj[$1][1], $Obj[$1][2], $Obj[$1][3], $Obj[$1][11])
        EndIf
    Next
EndFunc

Func GetNewBallPos()
    If $BrownStop=True Then ;;;Brown Stop
        $BrownStopCount+=1
        If $BrownStopCount>50 Then $BrownStop=False
        Return
    EndIf
    $IsSqueezed=0
    If SurfaceRight() Then $BallDirection=2
    If SurfaceLeft() Then $BallDirection=1
    If $IsSqueezed=2 Then LoseGame()
    Switch $BallDirection
        Case 1
            $BallPosX+=$BallSpeed
        Case 2
            $BallPosX-=$BallSpeed
    EndSwitch
EndFunc

Func CheckVanish()
    For $1=0 To $Obj_Num-1
        If $Obj[$1][12]=5 Then
            If $Obj[$1][13]=2 Then
                $Vanish[$1]-=2
                _GDIPlus_BrushSetSolidColor($VanishBrush[$1], '0x' & $Vanish[$1] & '004400')
                $Obj[$1][11]=$VanishBrush[$1]
                If $Vanish[$1]<10 Then
                    $Obj[$1][13]=0
                    $Vanish[$1]=99
                    $VanishTimer[$1]=TimerInit()
                EndIf
            ElseIf $Obj[$1][13]=0 And TimerDiff($VanishTimer[$1])>2000 Then
                $VanishTimer[$1]=TimerInit()
                If PointInSquare($BallPosX+$BallWidth, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                    If PointInSquare($BallPosX+$BallWidth, $BallPosY+$BallHeight, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                        If PointInSquare($BallPosX, $BallPosY+$BallHeight, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                            If PointInSquare($BallPosX, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                                _GDIPlus_BrushSetSolidColor($VanishBrush[$1], 0xFF004400)
                                $Obj[$1][13]=1
                                $Obj[$1][11]=$SolidBrush[5]
                            EndIf
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
EndFunc

Func MoveBall()
    Switch $Brush
        Case 1
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX, $BallPosY, $BallWidth, $BallHeight, $GDI_BRUSH_BALL)
        Case 2
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX, $BallPosY, $BallWidth, $BallHeight, $EpicBrush[0])
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX+$BallWidth/8, $BallPosY+$BallHeight/8, $BallWidth-$BallWidth/4, $BallHeight-$BallHeight/4, $EpicBrush[1])
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX+$BallWidth/4, $BallPosY+$BallHeight/4, $BallWidth-$BallWidth/2, $BallHeight-$BallHeight/2, $EpicBrush[2])
    EndSwitch
EndFunc

Func WinGame()
    $Level+=1
    $CryptKey="Juego"
    If $Level<9 And _Crypt_DecryptData(IniRead(@ScriptDir & "\JuegoData\CL.ini", "1", "1", ""), "Juego", $CALG_AES_256)<$Level Then IniWrite(@ScriptDir & "\JuegoData\CL.ini", "1", "1", _Crypt_EncryptData($Level, $CryptKey, $CALG_AES_256))
    $ActivePowerup=0
    $ExtraJumpActive=1
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
    $Jump=0
    $JumpSoon=0
    $SurfaceCount=0
    $BallPosY=$BallPosY_Start
    $BallPosX=$BallPosX_0
    ReDim $Obj[0][0]
    ReDim $Obj[1][14]
    ReDim $Text[0][0]
    ReDim $Text[1][5]
    $Obj_Num=0
    $Text_Num=0
    If $Level<9 Then
        RunLevel($Level)
    Else
        GoToMenu()
    EndIf
    $QualityCount=0
    $QualityTimer=TimerInit()
EndFunc

Func LoseGame()
    For $1=1 To $Obj_Num-1
        $Obj[$1][13]=1
        $Vanish[$1]=99
        _GDIPlus_BrushSetSolidColor($VanishBrush[$1], 0xFF004400)
    Next
    $ActivePowerup=0
    $ExtraJumpActive=1
    $Jump=0
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
    $BallPosY=$BallPosY_Start
    $BallPosX=$BallPosX_0
    $SurfaceCount=0
    $QualityCount=0
    $QualityTimer=TimerInit()
EndFunc

Func SurfaceRight()
    If $BallPosX>=$WinWidth-$BallWidth Then Return True
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX+$BallWidth, $BallPosY+$BallHeight/2, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            If $Obj[$1][7]=1 And $Obj[$1][6]>$BallSpeed Then $BallPosX=$Obj[$1][0]-$BallWidth
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][12]=1 Then WinGame()
            $IsSqueezed+=1
            Return True
        EndIf
    Next
EndFunc

Func SurfaceLeft()
    If $BallPosX<=$BallPosX_0 Then Return True
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX, $BallPosY+$BallHeight/2, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            If $Obj[$1][7]=1 And $Obj[$1][6]>$BallSpeed Then $BallPosX=$Obj[$1][0]+$Obj[$1][2]
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][12]=1 Then WinGame()
            $IsSqueezed+=1
            Return True
        EndIf
    Next
EndFunc

Func SurfaceUnder()
    If $ExtraJumpActive=1 Or $ExtraJumpActive=2 Then
        If $ExtraJumpActive=2 Then $ExtraJumpActive=-1
        $ExtraJumpActive+=1
        Return True
    EndIf
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX+$BallWidth-3, $BallPosY+$BallHeight+1, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Or PointInSquare($BallPosX+3, $BallPosY+$BallHeight+1, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            If $Obj[$1][12]=4 Then ;;;Gold Sticky
                If $BallDirection=1 Then $BallPosX-=0.75
                If $BallDirection=2 Then $BallPosX+=0.75
            EndIf
            $BallPosY=$Obj[$1][1]-$BallHeight
            $BallPosY_0=$BallPosY
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][12]=1 Then WinGame()
            Return True
        EndIf
    Next
    If $BallPosY+$BallHeight>=$WinHeight Then
        $BallPosY=$WinHeight-$BallHeight
        $BallPosY_0=$WinHeight-$BallHeight
        Return True
    EndIf
EndFunc

Func SurfaceOver()
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX+$BallWidth-5, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Or PointInSquare($BallPosX+5, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            $SurfaceMove=0
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][8]=1 Then
                $BallPosY=$Obj[$1][1]+$Obj[$1][3]
                $SurfaceMove=1
                $SurfaceCount=5
            ElseIf $BallPosY<$Obj[$1][1]+$Obj[$1][3]-2 Then
                $BallPosY=$Obj[$1][1]+$Obj[$1][3]
            EndIf
            If $Obj[$1][12]=1 Then WinGame()
            Return True
        EndIf
    Next
EndFunc

Func CheckForPowerup($__PowerupObjNum, $__PowerupObj, $__PowerupActive)
    If $__PowerupObj>10 Then
        If $__PowerupActive=0 Then Return True
        If $__PowerupObj<>13 Then $Obj[$__PowerupObjNum][13]=0
        ActivatePowerup($__PowerupObj, $__PowerupObjNum)
        Return True
    EndIf
    Return False
EndFunc

Func ActivatePowerup($_PowerupType, $_PowerupObjNum)
    Switch $_PowerupType
        Case 11;;Superjump
            _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFFFF9900)
        Case 12;;Cyan Key
            For $1=0 To $Obj_Num-1
                If $Obj[$1][12]=3 And $Obj[$1][13]=1 Then $Obj[$1][13]=0
            Next
            $_PowerupType=$ActivePowerup
        Case 13;;Teleport
            If TimerDiff($TeleTimer)>500 Then
                $TeleLink=-1
                If $Obj[$_PowerupObjNum-1][12]<>13 Then $TeleLink=1
                $TeleDiffY=$BallPosY-$BallPosY_0
                $BallPosX=$Obj[$_PowerupObjNum+$TeleLink][0]+$Obj[$_PowerupObjNum+$TeleLink][2]/2-$BallWidth/2
                $BallPosY=$Obj[$_PowerupObjNum+$TeleLink][1]+$Obj[$_PowerupObjNum+$TeleLink][3]/2-$BallHeight/2
                $BallPosY_0=$BallPosY-$TeleDiffY
                $TeleTimer=TimerInit()
            EndIf
            $_PowerupType=$ActivePowerup
        Case 14
            _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF734021)
    EndSwitch
    $ActivePowerup=$_PowerupType
EndFunc

Func SpendPowerup()

    Switch $ActivePowerup
        Case 0
            Return
        Case 11 ;;;EXTRA JUMP
            $ActivePowerup=0
            $ExtraJumpActive=1
            $SurfaceCount=0
            StartJump()
        Case 14 ;;;Brown Stop
            $BrownStop=True
            $BrownStopCount=0
    EndSwitch
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
EndFunc

Func StartJump()
    If SurfaceUnder() Then
        $Jump=True
        $BallPosY_0=$BallPosY
;~      $BallSpeedY=$JumpHeight
        $JumpSoon=False
    Else
        $JumpSoonTimer=TimerInit()
        $JumpSoon=True
    EndIf
EndFunc

Func Gravity()

    If SurfaceOver() = True Then
        $BallSpeedY=0
        If $SurfaceMove=0 Then $SurfaceCount=2
        $BallPosY_0=$BallPosY
    EndIf
    If SurfaceUnder() Then
        $SurfaceCount=0
        $BallSpeedY=0
        $BallPosY_0=$BallPosY
        If $JumpSoon=False And $Jump=False Then
            Return
        Else
            If $JumpSoon=True And TimerDiff($JumpSoonTimer)>150 Then Return
            $BallSpeedY=$JumpHeight
            StartJump()
            $Jump=False
        EndIf
    EndIf
    $SurfaceCount+=1
    $BallPosY=$BallPosY_0-($BallSpeedY*$SurfaceCount+1/2*-9.81*$SurfaceCount^2)*0.01
EndFunc

Func QualityCheck()
    $QualityCount+=1
    If $QualityCount=$QualityFPS Then
        $QualitySleep+=(950-TimerDiff($QualityTimer))/$QualityFPS*100
        $QualityCount=0
        $QualityTimer=TimerInit()
    EndIf
EndFunc

Func USleep($iUsec, $hDLL = "ntdll.dll")
    $iUsec-=TimerDiff($USleepTimer)*100
    If $iUsec<0 Then $iUsec=0
    Local $hStruct = DllStructCreate("int64")
    DllStructSetData($hStruct, 1, -1 * ($iUsec * 10))
    DllCall($hDLL, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))
    $USleepTimer=TimerInit()
EndFunc

Func PointInSquare($_PointX, $_PointY, $_SquareTopX, $_SquareTopY, $_SquareBottomX, $_SquareBottomY, $_SquareType, $_SquareActive, $_SquareObjNum)
    If $_SquareActive=0 Then Return False
    $_SquareDiff=0
    If $_SquareType=2 Then $_SquareDiff=2
    If $_SquareType>10 Then $_SquareDiff=2
    If $_PointX<$_SquareTopX+$_SquareDiff Then Return False
    If $_PointX>$_SquareBottomX-$_SquareDiff Then Return False
    If $_PointY<$_SquareTopY+$_SquareDiff Then Return False
    If $_PointY>$_SquareBottomY-$_SquareDiff Then Return False
    If $_SquareType = 5 Then $Obj[$_SquareObjNum][13]=2
    Return True
EndFunc

Func TakeSnapShot()
    If Not FileExists($PictureDir) Then DirCreate($PictureDir)
    _ScreenCapture_CaptureWnd($PictureDir & "\Temp.bmp", $hGUI, 0, 0, -1, -1, False)
    $___SnapShotImage = _GDIPlus_ImageLoadFromFile($PictureDir & "\Temp.bmp")
    $___GC = _GDIPlus_ImageGetGraphicsContext($___SnapShotImage)
    $___NewBmp = _GDIPlus_BitmapCreateFromGraphics(115,87,$___GC)
    $___newGC = _GDIPlus_ImageGetGraphicsContext($___NewBmp)
    _GDIPlus_GraphicsDrawImageRect($___newGC,$___SnapShotImage,0,0,115,87)
    _GDIPlus_ImageSaveToFile($___newBmp,$PictureDir & "\Level" & $Level & ".bmp")
    _GDIPlus_GraphicsDispose($___GC)
    _GDIPlus_GraphicsDispose($___newGC)
    _GDIPlus_BitmapDispose($___newBmp)
    _GDIPlus_ImageDispose($___SnapShotImage)
    FileDelete($PictureDir & "\Temp.bmp")
    $TakeScreenshot=False
EndFunc

Func Menu()
    $Level=0
    $ButtonPosX=2
    $ButtonPosY=2
    For $1=1 To 16
        $Button[$1]=GUICtrlCreateButton("", $ButtonPosX, $ButtonPosY, 120, 95, $BS_BITMAP)
        $ButtonPosX+=125
        If $ButtonPosX>500 Then
            $ButtonPosX=2
            $ButtonPosY+=100
        EndIf
        GUICtrlSetImage($Button[$1], $PictureDir & "\Level" & $1 & ".bmp")
        If _Crypt_DecryptData(IniRead(@ScriptDir & "\JuegoData\CL.ini", "1", "1", ""), "Juego", $CALG_AES_256)<$1 And $1<9 And $1>1 Then GUICtrlSetState($Button[$1], 128)
    Next
    While 1
        $msg=GUIGetMsg()
        For $1=1 To 16
            Switch $msg
;~              Case $Button[1]
;~                  DeleteMenu()
;~                  Level1()
;~                  Return
                    Case $Button[$1]

                    DeleteMenu()
                    RunLevel($1)
                    Return
            EndSwitch
        Next
    WEnd
EndFunc

Func RunLevel($_RunLevel)
    HotKeySet("{UP}", "StartJump")
    HotKeySet("{SPACE}", "SpendPowerup")
    HotKeySet("{PRINTSCREEN}", "TakeSnapShot")
    HotKeySet("{ENTER}", "LoseGame")
    Switch $_RunLevel
        Case 1
            Level1()
        Case 2
            Level2()
        Case 3
            Level3()
        Case 4
            Level4()
        Case 5
            Level5()
        Case 6
            Level6()
        Case 7
            Level7()
        Case 8
            Level8()
        Case 9 To 16
            $Level=-1
            LevelFromTxt($_RunLevel)
    EndSwitch
    $TakeScreenshot=True
EndFunc

Func DeleteMenu()
    For $1=1 To 16
        GUICtrlDelete($Button[$1])
    Next
    $QualityCount=0
    $QualityTimer=TimerInit()
EndFunc

Func GoToMenu()
    If $ScriptPos=1 Then
        $GoToMenu=True
        Return
    EndIf
    $GoToMenu=False
    HotKeySet("{UP}")
    HotKeySet("{SPACE}")
    HotKeySet("{PRINTSCREEN}")
    HotKeySet("{ENTER}")
    _GDIPlus_GraphicsClear($GDI_BACKBUFFER, 0xFFFFFFFF)
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    $ActivePowerup=0
    $ExtraJumpActive=1
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
    $Jump=0
    $JumpSoon=0
    $SurfaceCount=0
    $BallPosY=$BallPosY_Start
    $BallPosX=$BallPosX_0
    ReDim $Obj[0][0]
    ReDim $Obj[1][14]
    ReDim $Text[0][0]
    ReDim $Text[1][5]
    $Obj_Num=0
    $Text_Num=0
    $QualityCount=0
    $QualityTimer=TimerInit()
    Menu()
EndFunc

Func CheckActive()
    If WinActive($hGUI) Then
        If $WinActive=False Then
            HotKeySet("{UP}", "StartJump")
            HotKeySet("{SPACE}", "SpendPowerup")
            HotKeySet("{PRINTSCREEN}", "TakeSnapShot")
            HotKeySet("{ENTER}", "LoseGame")
        EndIf
        $WinActive=True
    Else
        If $WinActive=True Then
            HotKeySet("{UP}")
            HotKeySet("{SPACE}")
            HotKeySet("{PRINTSCREEN}")
            HotKeySet("{ENTER}")
        EndIf
        $WinActive=False
    EndIf
EndFunc

Func Terminate()
    If $Level<>0 Then
        GoToMenu()
        Return
    EndIf
    _GDIPlus_BrushDispose($SolidBrush[0])
    _GDIPlus_BrushDispose($SolidBrush[1])
    _GDIPlus_BrushDispose($SolidBrush[2])
    _GDIPlus_BrushDispose($SolidBrush[3])
    _GDIPlus_BrushDispose($SolidBrush[4])
    _GDIPlus_BrushDispose($SolidBrush[5])
    _GDIPlus_BrushDispose($SolidBrush[11])
    _GDIPlus_BrushDispose($SolidBrush[12])
    _GDIPlus_BrushDispose($SolidBrush[13])
    _GDIPlus_BrushDispose($GDI_BRUSH_BALL)
    _GDIPlus_BrushDispose($VanishBrush)
    _GDIPlus_GraphicsDispose($GDI_GRAPHICS)
    _GDIPlus_ImageDispose($GDI_BITMAP)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

Edited by TheNorwegianUser
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The walls are rectangles that means you can use _WinAPI_PtInRectEx to check for collision.

Or just have a look here for some ideas: https://www.autoitscript.com/forum/topic/173187-looking-for-a-gui-objects-and-lines-in-the-window

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

Nice game :), I wanted to post this, I don't know much about GDI+ :P

 

Keep it up, TD :)


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The walls are rectangles that means you can use _WinAPI_PtInRectEx to check for collision.

Or just have a look here for some ideas: https://www.autoitscript.com/forum/topic/173187-looking-for-a-gui-objects-and-lines-in-the-window

Tried using _WinAPI_PtInRectEx, and it's a lot less buggy, but it's making the game laggy.

 

I like this!

May I ask: why not use IrrLicht?

It have a simple algorithm colision.

@bogQ (re)write au3impact too, see: https://www.youtube.com/watch?v=D7eCB1cfOX8

I'll look into that when I have more time, lots to do this week.

#Include <GuiconstantsEx.au3>
#Include <GDIPlus.au3>
#include <WinAPIGdi.au3>
HotKeySet("{ESC}", "Terminate")
HotKeySet("{SPACE}", "StartJump")


#Region Gui
$WinWidth=500
$WinHeight=400
$hGUI=GUICreate("", $WinWidth, $WinHeight)
GUISetState()
#EndRegion

#Region Graphics
$GDI_QUALITY=2
_GDIPlus_Startup()
$GDI_GRAPHICS=_GDIPlus_GraphicsCreateFromHWND($hGUI)
$GDI_BITMAP=_GDIPlus_BitmapCreateFromGraphics($WinWidth, $WinHeight, $GDI_GRAPHICS)
$GDI_BACKBUFFER=_GDIPlus_ImageGetGraphicsContext($GDI_BITMAP)
_GDIPlus_GraphicsSetSmoothingMode($GDI_BACKBUFFER, $GDI_QUALITY)
_GDIPlus_GraphicsClear($GDI_BACKBUFFER)

$GDI_BRUSH_BALL=_GDIPlus_BrushCreateSolid()
#EndRegion

#Region GraphicObjects
Dim $Obj[1][13]
$Obj_Num=0
Dim $Obj_DirectionX[1]
Dim $Obj_DirectionY[1]
Dim $SolidBrush[2]
$SolidBrush[0]=_GDIPlus_BrushCreateSolid()
$SolidBrush[1]=_GDIPlus_BrushCreateSolid(0xFF00FF00)
#EndRegion

#Region GameVars
$BallDirection=1
$BallWidth=20
$BallHeight=20
$BallSpeed=1
$BallSpeedY=0
$BallPosX_0=0
$BallPosX=$BallPosX_0
$BallPosY_Start=$WinHeight-$BallHeight
$BallPosY_0=350
$BallPosY=$BallPosY_0
$SurfaceCount=0
$Jump=False
$JumpHeight=350
$JumpSoon=False
$JumpSoonTimer=TimerInit()
$IsSqueezed=0
$SurfaceMove=0
#EndRegion

#Region Quality
$QualityTimer=TimerInit()
$QualityCount=0
$QualityFPS=60
$QualitySleep=2000
$USleepTimer=TimerInit()
#EndRegion

Level2()

While 1
    GetNewBallPos()
    _GDIPlus_GraphicsClear($GDI_BACKBUFFER, 0xFFFFFFFF)
    DrawObjects()
    MoveBall()
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    Gravity()
    QualityCheck()
    USleep($QualitySleep)
WEnd

Func Level3()
    Solid(0, 100, 375)
EndFunc

Func Level2()
    Solid(0, 125, 375, 125)
    Solid(0, 200, 350, 50, 25)
    Solid(0, 300, 325, 50, 50)
    Solid(0, 375, 325, 25, 50)
    Solid(0, 425, 300, 75, 50)
    Solid(0, 300, 225, 150, 25)
    Solid(0, 450, 250)
    Solid(0, 225, 250)
    Solid(0, 150, 200)
    Solid(0, 0, 300, 100)
    Solid(0, 50, 150, 25, 100)
    Solid(0, 25, 250)
    Solid(0, 0, 200)
    Solid(0, 425, 175, 75)
    Solid(0, 425, 125)
    Solid(0, 350, 125, 50)
    Solid(0, 275, 125)
    Solid(0, 150, 100, 75)
    Solid(0, 0, 100)
    Solid(0, 50, 50)
    Solid(0, 100, 0, 50)
    Solid(0, 150, 25, 75)
    Solid(0, 275, 25, 50)
    Solid(0, 375, 25, 125)
    Solid(1, 475, 0)
EndFunc

Func Level1()
;~ Solid(0, 0, 375, 25, 25, 300, 375, 400)
Solid(0, 0, 200, 500, 25, 0, 400, 400)
;~ Solid(0, 0, 200, 500, 25, 0, 375, 200)
EndFunc

Func Solid($_SolidType, $_SolidPosX, $_SolidPosY, $_SolidWidth=25, $_SolidHeight=25, $_SolidPosX_2=$_SolidPosX, $_SolidPosY_2=$_SolidPosY, $_SolidSpeed=100, $_SolidBrush=$SolidBrush[$_SolidType])
    ReDim $Obj[$Obj_Num+1][13]
    $Obj[$Obj_Num][0]=$_SolidPosX
    $Obj[$Obj_Num][1]=$_SolidPosY
    $Obj[$Obj_Num][2]=$_SolidWidth
    $Obj[$Obj_Num][3]=$_SolidHeight
    $Obj[$Obj_Num][4]=$_SolidPosX_2
    $Obj[$Obj_Num][5]=$_SolidPosY_2
    $Obj[$Obj_Num][6]=Sqrt(($_SolidPosX_2-$_SolidPosX)^2+($_SolidPosY_2-$_SolidPosY)^2)/$_SolidSpeed
    If $_SolidPosX_2<>$_SolidPosX Then $Obj[$Obj_Num][7]=1
    If $_SolidPosY_2<>$_SolidPosY Then $Obj[$Obj_Num][8]=1
    If $_SolidPosX_2<>$_SolidPosX Then $Obj[$Obj_Num][9]=$_SolidPosX
    If $_SolidPosY_2<>$_SolidPosY Then $Obj[$Obj_Num][10]=$_SolidPosY
    $Obj[$Obj_Num][11]=$_SolidBrush
    $Obj[$Obj_Num][12]=$_SolidType
    ReDim $Obj_DirectionX[$Obj_Num+1]
    ReDim $Obj_DirectionY[$Obj_Num+1]
    $Obj_DirectionX[$Obj_Num]=1
    $Obj_DirectionY[$Obj_Num]=1
    _GDIPlus_GraphicsDrawRect($GDI_GRAPHICS, $_SolidPosX, $_SolidPosY, $_SolidWidth, $_SolidHeight, $_SolidBrush)
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    $Obj_Num+=1
EndFunc

Func DrawObjects()
    For $1=0 To $Obj_Num-1
        If $Obj[$1][7]=1 Then
            $Obj[$1][0]+=$Obj[$1][6]*$Obj_DirectionX[$1]
            If $Obj[$1][0]=$Obj[$1][4] Then $Obj_DirectionX[$1]*=-1
            If $Obj[$1][0]=$Obj[$1][9] Then $Obj_DirectionX[$1]*=-1
        EndIf
        If $Obj[$1][8]=1 Then
            $Obj[$1][1]+=$Obj[$1][6]*$Obj_DirectionY[$1]
            If $Obj[$1][1]=$Obj[$1][5] Then $Obj_DirectionY[$1]*=-1
            If $Obj[$1][1]=$Obj[$1][10] Then $Obj_DirectionY[$1]*=-1
        EndIf
        _GDIPlus_GraphicsFillRect($GDI_BACKBUFFER, $Obj[$1][0], $Obj[$1][1], $Obj[$1][2], $Obj[$1][3], $Obj[$1][11])
    Next
EndFunc

Func GetNewBallPos()
    $IsSqueezed=0
    If SurfaceRight() Then $BallDirection=2
    If SurfaceLeft() Then $BallDirection=1
    If $IsSqueezed=2 Then LoseGame()
    Switch $BallDirection
        Case 1
            $BallPosX+=$BallSpeed
        Case 2
            $BallPosX-=$BallSpeed
    EndSwitch
EndFunc

Func MoveBall()
    _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX, $BallPosY, $BallWidth, $BallHeight, $GDI_BRUSH_BALL)
EndFunc

Func WinGame()
    ReDim $Obj[0][0]
    ReDim $Obj[1][13]
    $Obj_Num=0
    If $Level=2 Then Level2()
    If $Level=3 Then Level3()

EndFunc

Func LoseGame()
;~  MsgBox(0, "", "You Lost!")
EndFunc

Func SurfaceRight()
    If $BallPosX>=$WinWidth-$BallWidth Then Return True
    For $1=0 To $Obj_Num-1
;~      If $Obj[$1][0]+$Obj[$1][2]/10>$BallPosX+$BallWidth And $BallPosX+$BallWidth>=$Obj[$1][0] And $Obj[$1][1]<$BallPosY+$BallHeight And $BallPosY<$Obj[$1][1]+$Obj[$1][3] Then
        If _WinAPI_PtInRectEx($BallPosX+$BallWidth, $BallPosY+$BallHeight/2, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3]) Then
            If $Obj[$1][7]=1 And $Obj[$1][6]>$BallSpeed Then $BallPosX=$Obj[$1][0]-$BallWidth
            If $Obj[$1][12]=1 Then WinGame()
            $IsSqueezed+=1
            Return True
        EndIf
    Next
EndFunc

Func SurfaceLeft()
    If $BallPosX<=$BallPosX_0 Then Return True
    For $1=0 To $Obj_Num-1
;~      If $Obj[$1][0]+$Obj[$1][2]>=$BallPosX And $BallPosX>=$Obj[$1][0]+$Obj[$1][2]-$Obj[$1][2]/10 And $Obj[$1][1]<$BallPosY+$BallHeight And $BallPosY<$Obj[$1][1]+$Obj[$1][3] Then
        If _WinAPI_PtInRectEx($BallPosX, $BallPosY+$BallHeight/2, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3]) Then
            If $Obj[$1][7]=1 And $Obj[$1][6]>$BallSpeed Then $BallPosX=$Obj[$1][0]+$Obj[$1][2]
            If $Obj[$1][12]=1 Then WinGame()
            $IsSqueezed+=1
            Return True
        EndIf
    Next
EndFunc

Func SurfaceUnder()
;~  If $Jump=True Then Return False
    For $1=0 To $Obj_Num-1
;~      If $BallPosX+$BallWidth>=$Obj[$1][0] And $BallPosX<=$Obj[$1][0]+$Obj[$1][2] And $BallPosY+$BallHeight>=$Obj[$1][1] And $BallPosY+$BallHeight<$Obj[$1][1]+$Obj[$1][3]/10 Then
        If _WinAPI_PtInRectEx($BallPosX+$BallWidth-3, $BallPosY+$BallHeight, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3]) Or _WinAPI_PtInRectEx($BallPosX+3, $BallPosY+$BallHeight, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3]) Then
            $BallPosY=$Obj[$1][1]-$BallHeight
            $BallPosY_0=$BallPosY
            If $Obj[$1][12]=1 Then WinGame()
            Return True
        EndIf
    Next
    If $BallPosY+$BallHeight>=$WinHeight Then
        $BallPosY=$WinHeight-$BallHeight
        $BallPosY_0=$WinHeight-$BallHeight
        Return True
    EndIf
EndFunc

Func SurfaceOver()
    For $1=0 To $Obj_Num-1
;~      If $BallPosX+$BallWidth>=$Obj[$1][0] And $BallPosX<=$Obj[$1][0]+$Obj[$1][2] And $BallPosY<=$Obj[$1][1]+$Obj[$1][3] And $BallPosY>$Obj[$1][1]+$Obj[$1][3]-$Obj[$1][3]/10 Then
        If _WinAPI_PtInRectEx($BallPosX+$BallWidth-5, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3]) Or _WinAPI_PtInRectEx($BallPosX+5, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3]) Then
            $SurfaceMove=0
            If $Obj[$1][12]=1 Then WinGame()
            If $Obj[$1][8]=1 Then
                $BallPosY=$Obj[$1][1]+$Obj[$1][3]
                $SurfaceMove=1
                $SurfaceCount=5
            EndIf
            Return True
        EndIf
    Next
EndFunc

Func StartJump()
    If SurfaceUnder() Then
        $Jump=True
        $BallPosY_0=$BallPosY
;~      $BallSpeedY=$JumpHeight
        $JumpSoon=False
    Else
        $JumpSoonTimer=TimerInit()
        $JumpSoon=True
    EndIf
EndFunc

Func Gravity()
    If SurfaceOver() = True Then
        $BallSpeedY=0
        If $SurfaceMove=0 Then $SurfaceCount=2
        $BallPosY_0=$BallPosY
    EndIf
    If SurfaceUnder() Then
        $SurfaceCount=0
        $BallSpeedY=0
        $BallPosY_0=$BallPosY
        If $JumpSoon=False And $Jump=False Then
            Return
        Else
            If $JumpSoon=True And TimerDiff($JumpSoonTimer)>300 Then Return
            $BallSpeedY=$JumpHeight
            StartJump()
            $Jump=False
        EndIf
    EndIf
    $SurfaceCount+=1
;~  $Jump=False
    $BallPosY=$BallPosY_0-($BallSpeedY*$SurfaceCount+1/2*-9.81*$SurfaceCount^2)*0.01
EndFunc

Func QualityCheck()
    $QualityCount+=1
    If $QualityCount=$QualityFPS Then
        $QualitySleep+=(1000-TimerDiff($QualityTimer))/$QualityFPS*100
        $QualityCount=0
        $QualityTimer=TimerInit()
    EndIf
EndFunc

Func USleep($iUsec, $hDLL = "ntdll.dll")
;~  $iUsec-=TimerDiff($USleepTimer)
;~  If $iUsec<0 Then $iUsec=0
    Local $hStruct = DllStructCreate("int64")
    DllStructSetData($hStruct, 1, -1 * ($iUsec * 10))
    DllCall($hDLL, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))
    $USleepTimer=TimerInit()
EndFunc

Func Terminate()
    _GDIPlus_BrushDispose($SolidBrush)
    _GDIPlus_BrushDispose($GDI_BRUSH_BALL)
    _GDIPlus_GraphicsDispose($GDI_GRAPHICS)
    _GDIPlus_ImageDispose($GDI_BITMAP)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

Edited by TheNorwegianUser

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

May I sugest a function? To see a FPS in your game? I use this.

 

While Z_RUN()

;loop

Wend

Func Z_RUN()
;~  Global $Z_RUN[3] = [TimerInit(), TimerInit(), 0] ; use at start....
    Do
    Until TimerDiff($Z_RUN[0]) > 11 ; time to sleep at every loop
    $Z_RUN[0] = TimerInit()
    $Z_RUN[2] += 1
    If TimerDiff($Z_RUN[1]) > 999 Then
;~      _IrrSetWindowCaption("FPS[" & $Z_RUN[2] & "]")
        WinSetTitle($hGui, "", "FPS[" & $Z_RUN[2] & "]")
        $Z_RUN[1] = TimerInit()
        $Z_RUN[2] = 0
    EndIf
    Return True
EndFunc   ;==>Z_RUN

 

Edited by Luigi

m(o.O)m

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well, thanks for all the help! I've gotten a lot further, and this is my progress so far. For pictures to be displayed in the buttons simply press the prnt scrn button while playing a level. 

Any further suggestion of any sort would be appreciated ;)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <WindowsConstants.au3>
#Include <GuiconstantsEx.au3>
#Include <GDIPlus.au3>
#include <WinAPIGdi.au3>
#include <Screencapture.au3>
#Include <ButtonConstants.au3>
#include <File.au3>
#include <GuiConstants.au3>
#Include <Crypt.au3>

HotKeySet("{ESC}", "Terminate")

#Region Gui
$PictureDir=@ScriptDir & "\JuegoData\"
$WinWidth=500
$WinHeight=400
$hGUI=GUICreate("", $WinWidth, $WinHeight, -1, -1, $WS_POPUPWINDOW)
GUISetState()
Dim $Button[17]
#EndRegion

#Region Graphics
$GDI_QUALITY=2
_GDIPlus_Startup()
$GDI_GRAPHICS=_GDIPlus_GraphicsCreateFromHWND($hGUI)
$GDI_BITMAP=_GDIPlus_BitmapCreateFromGraphics($WinWidth, $WinHeight, $GDI_GRAPHICS)
$GDI_BACKBUFFER=_GDIPlus_ImageGetGraphicsContext($GDI_BITMAP)
_GDIPlus_GraphicsSetSmoothingMode($GDI_BACKBUFFER, $GDI_QUALITY)
_GDIPlus_GraphicsClear($GDI_BACKBUFFER)

$GDI_BRUSH_BALL=_GDIPlus_BrushCreateSolid()
#EndRegion

#Region GraphicObjects
Dim $Obj[1][14]
Dim $Text[1][5]
$Text_Num=0
$Obj_Num=0
Dim $Obj_DirectionX[1]
Dim $Obj_DirectionY[1]
Dim $SolidBrush[20]
$SolidBrush[0]=_GDIPlus_BrushCreateSolid()
$SolidBrush[1]=_GDIPlus_BrushCreateSolid(0xFF00FF00)
$SolidBrush[2]=_GDIPlus_BrushCreateSolid(0xFFFF0000)
$SolidBrush[3]=_GDIPlus_BrushCreateSolid(0xFF00FFFF)
$SolidBrush[4]=_GDIPlus_BrushCreateSolid(0xFFddad19)
$SolidBrush[5]=_GDIPlus_BrushCreateSolid(0xFF004400)
$SolidBrush[11]=_GDIPlus_BrushCreateSolid(0xFFFF9900)
$SolidBrush[12]=_GDIPlus_BrushCreateSolid(0xFF00FFFF)
$SolidBrush[13]=_GDIPlus_BrushCreateSolid(0xFF0000FF)
$SolidBrush[14]=_GDIPlus_BrushCreateSolid(0xFF734021)

Dim $VanishBrush[1]

Dim $EpicBrush[3]
$Brush=1
$EpicBrush[0]=_GDIPlus_BrushCreateSolid(0xFFc03430)
$EpicBrush[1]=_GDIPlus_BrushCreateSolid(0xFFf8cf46)
$EpicBrush[2]=_GDIPlus_BrushCreateSolid(0xFF367341)
#EndRegion

#Region GameVars
Dim $FileLineData[0]
$TakeScreenshot=False
$GoToMenu=False
$WinActive=True
Dim $Vanish[1]
$BrownStopCount=0
$BrownStop=False
$BallDirection=1
$BallWidth=20
$BallHeight=20
$BallSpeed=1
$BallSpeedY=0
$BallPosX_0=0
$BallPosX=$BallPosX_0
$BallPosY_Start=$WinHeight-$BallHeight
$BallPosY_0=375
$BallPosY=$BallPosY_0
$SurfaceCount=0
$Jump=False
$JumpHeight=350
$JumpSoon=False
$JumpSoonTimer=TimerInit()
$IsSqueezed=0
$SurfaceMove=0
$Level=1
$BallPosYDiff=0
$LastBallPosY=$BallPosY
$ActivePowerup=0
$ExtraJumpActive=0
$TeleTimer=TimerInit()
Dim $VanishTimer[1]
#EndRegion

Menu()

#Region Quality
$QualityTimer=TimerInit()
$QualityCount=0
$QualityFPS=60
$QualitySleep=2000
$USleepTimer=TimerInit()
#EndRegion

While 1
    CheckActive()
    GetNewBallPos()
    _GDIPlus_GraphicsClear($GDI_BACKBUFFER, 0xFFFFFFFF)
    CheckVanish()
    DrawText()
    DrawObjects()
    MoveBall()
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    If $TakeScreenshot=True Then TakeSnapShot()
    Gravity()
    QualityCheck()
    $ScriptPos=0
    If $GoToMenu=True Then GoToMenu()
    USleep($QualitySleep)
    $ScriptPos=1
WEnd

;=================================================================================
;============================== OBJECT DESCRIPTION ===============================
;==============================--------------------===============================
;============ Solid( Type, X, Y, [Width, Height, X2, Y2, Speed) ==================
;==============================--------------------===============================
;==============================         TYPES       ==============================
;============================== 0 = Black Solid     ==============================
;============================== 1 = Green Goal      ==============================
;============================== 2 = Red Fail        ==============================
;============================== 3 = Cyan Lock       ==============================
;============================== 4 = Gold Sticky     ==============================
;============================== 5 = Green Vanish    ==============================
;============================== 11 = Extra Jump     ==============================
;============================== 12 = Cyan Key       ==============================
;============================== 13 = Blue Teleport  ==============================
;============================== 14 = Brown Stop     ==============================
;=================================================================================

Func LevelFromTxt($_Level)
    $Level=$_Level
    $FileDir=@ScriptDir & "\JuegoData\Level" & $_Level & ".txt"
    $FileLines=_FileCountLines($FileDir)
    $FileOpen=FileOpen($FileDir)
    For $1=1 To $FileLines
        $FileData=FileReadLine($FileOpen, $1)
        StringReplace($FileData, ",", ",")
        $FileDataLen=@extended
        If StringLeft($FileData, 5)="Solid" Then $FileMode=1
        If StringLeft($FileData, 4)="Text" Then $FileMode=0
        $FileData=StringTrimLeft($FileData, 5+$FileMode)
        ReDim $FileLineData[0]
        ReDim $FileLineData[9]
        For $2=0 To $FileDataLen
            $FileLen=StringInStr($FileData, ",")
            $FileLineData[$2]=StringLeft($FileData, $FileLen-1)
            $FileData=StringTrimLeft($FileData, $FileLen)
        Next
        $FileLineData[$FileDataLen]=StringTrimRight($FileData, 1)
        If $FileMode=1 Then
            If $FileLineData[3]="" Then $FileLineData[3]=25
            If $FileLineData[4]="" Then $FileLineData[4]=25
            If $FileLineData[5]="" Then $FileLineData[5]=$FileLineData[1]
            If $FileLineData[6]="" Then $FileLineData[6]=$FileLineData[2]
            If $FileLineData[7]="" Then $FileLineData[7]=100
            If $FileLineData[8]="" Then $FileLineData[8]=$SolidBrush[$FileLineData[0]]
            Solid($FileLineData[0], $FileLineData[1], $FileLineData[2], $FileLineData[3], $FileLineData[4], $FileLineData[5], $FileLineData[6], $FileLineData[7], $FileLineData[8])
        ElseIf $FileMode=0 Then
            If $FileLineData[3]="" Then $FileLineData[3]=10
            If $FileLineData[4]="" Then $FileLineData[4]="Arial"
            Text($FileLineData[0], $FileLineData[1], $FileLineData[2], $FileLineData[3], $FileLineData[4])
        EndIf
    Next
EndFunc

Func Level8()
    $Level=8
    Solid(0, 100, -50, 25, 450)
    Solid(0, 225, -50, 25, 425)
    Solid(0, 350, -50, 25, 425)
    Solid(3, 225, 375, 25)
    Solid(3, 350, 375, 25)
    Solid(13, 0, 310, 25, 15, 75, 310, 400)
    Solid(13, 0, 200, 25, 15, 75, 200, 200)
    Solid(2, 0, 290, 100, 15)
    Solid(13, 0, 270, 25, 15, 75)
    Solid(13, 0, 100, 25, 15)
    Solid(0, 0, 150, 50, 10, 50, 150, 80)
    Solid(0, 0, 85, 25, 15)
    Solid(13, 80, 0, 15, 25, 80, 25)
    Solid(13, 130, 0, 15, 25)
    Solid(2, 50, 75, 50, 15)
    Solid(2, 125, 50)
    Solid(0, 150, 50)
    Solid(2, 200, 50)
    Solid(0, 200, 128)
    Solid(2, 170, 128, 30)
    Solid(0, 125, 75, 10, 90)
    Solid(0, 150, 200, 50)
    Solid(2, 200, 200)
    Solid(0, 150, 250)
    Solid(11, 200, 275, 20, 20)
    Solid(2, 150, 275)
    Solid(2, 125, 300, 100)
    Solid(13, 125, 285, 25, 15)
    Solid(13, 250, 275, 25, 15)
    Solid(5, 250, 325, 50)
    Solid(2, 250, 350, 100)
    Solid(0, 275, 265, 25, 32)
    Solid(2, 250, 250, 50, 15)
    Solid(5, 325, 275)
    Solid(5, 250, 225)
    Solid(5, 250, 170)
    Solid(5, 325, 180)
    Solid(5, 300, 100)
    Solid(5, 325, 115)
    Solid(5, 250, 50)
    Solid(13, 335, 0, 15, 25)
    Solid(13, 375, 0, 15, 25)
    Solid(2, 375, 75, 40)
    Solid(5, 415, 75)
    Solid(2, 440, 75, 60)
    Solid(14, 425, 0, 20, 20)
    Solid(11, 450, 25, 20, 20)
    Solid(5, 375, 190, 25, 20)
    Solid(2, 400, 190, 40, 20)
    Solid(0, 440, 100, 20, 110)
    Solid(11, 417, 125, 20, 20)
    Solid(14, 375, 105, 20, 20)
    Solid(14, 375, 160, 20, 20)
    Solid(2, 375, 275)
    Solid(11, 400, 275, 20, 20)
    Solid(11, 450, 250, 20, 20)
    Solid(11, 472, 200, 20, 20)
    Solid(14, 472, 150, 20, 20)
    Solid(12, 472, 100, 20, 20)
    Solid(11, 472, 310, 20, 20)
    Solid(2, 425, 350, 75)
    Solid(1, 150, 350, 50)
EndFunc

Func Level7()
    $Level=7
;~  $BallPosX_0=0
;~  $BallPosX=225
;~  $BallPosY_0=0
;~  $BallPosY=$BallPosY_0
;~  $BallDirection=2


    Solid(2, 0, 225, 75)
    Solid(2, 75, 225, 25, 50)
    Solid(0, 75, 275, 25, 75)
    Solid(1, 0, 250, 75)
    Solid(2, 150, 325, 100)
    Solid(2, 275, 375)
    Solid(2, 250, 300)
    Solid(2, 275, 275, 50)
    Solid(2, 325, 300)
    Solid(2, 350, 375)
    Solid(2, 350, 275, 50)
    Solid(2, 400, 275, 25, 50)
    Solid(2, 450, 375)
    Solid(0, 475, 375)
    Solid(11, 475, 350, 20, 20)
    Solid(2, 425, 250, 75)
    Solid(3, 0, 325, 75)
    Solid(0, 150, 300, 100)
    Solid(2,100, 225, 125)
    Solid(0, 300, 250)
    Solid(0, 400, 250)
    Solid(2, 400, 125, 25, 75)
    Solid(0, 475, 200)
    Solid(0, 425, 150)
    Solid(0, 375, 125)
    Solid(11, 325, 125, 20, 20)
    Solid(2, 250, 75, 25, 75)
    Solid(2, 200, 150, 25, 75)
    Solid(0, 150, 200, 50)
    Solid(11, 50, 200, 20, 20)
    Solid(11, 0, 125, 20, 20)
    Solid(11, 50, 75, 20, 20)
    Solid(11, 100, 75, 20, 20)
    Solid(11, 225, 75, 20, 20)
    Solid(11, 300, 50, 20, 20)
    Solid(11, 450, 50, 20, 20)
    Solid(11, 450, 0, 20, 20)
    Solid(12, 475, 0, 20, 20)
    Solid(11, 400, 0, 20, 20)
EndFunc

Func Level6()
    $Level=6
    Solid(0, 100, 100, 25, 300)
    Solid(0, 75, 375)
    Solid(0, 0, 325)
    Solid(0, 50, 275)
    Solid(0, 50, 200)
    Solid(0, 0, 225)
    Solid(0, 50, 140)
    Solid(0, 50, 75, 75)
    Solid(0, 0, 75)
    Solid(2, 75, 0, 25, 75)
    Solid(13, 55, 25, 15, 25)
    Solid(13, 105, 25, 15, 25)
    Solid(0, 150, -25, 25, 375)
    Solid(0, 300, 50, 25, 350)
    Solid(4, 225, 300, 75, 25, 225, 400, 400)
    Solid(0, 175, 200, 50, 25, 175, 300, 200)
    Solid(0, 225, 225, 75)
    Solid(0, 175, 100, 50, 25, 175, 200, 200)
    Solid(0, 225, 50, 75, 25, 225, 125, 400)
    Solid(0, 325, 50, 150)
    Solid(2, 350, 25, 25, 25, 425, 25, 200)
    Solid(0, 375, 175, 75)
    Solid(4, 450, 175, 50)
    Solid(2, 325, 75, 25, 25, 425)
    Solid(2, 375, 150, 25, 25, 400)
    Solid(0, 450, 75, 25, 50)
    Solid(0, 325, 225, 50, 50)
    Solid(0, 375, 250, 50)
    Solid(4, 425, 250)
    Solid(0, 450, 250, 50)
    Solid(13, 425, 200, 25, 15)
    Solid(13, 325, 275, 25, 15, 475)
    Solid(2, 325, 385, 175, 15)
    Solid(1, 325, 365, 50, 15, 450, 365, 200)
EndFunc

Func Level5()
    $Level=5
    Solid(2, 100, 375)
    Solid(2, 225, 375)
    Solid(0, 250, 375, 50)
    Solid(2, 300, 375, 50)
    Solid(0, 350, 375)
    Solid(2, 375, 375)
    Solid(0, 400, 350, 100, 50)
    Solid(0, 450, 300, 25)
    Solid(0, 350, 250, 50)
    Solid(11, 363, 225, 20, 20)
    Solid(2, 300, 250, 50)
    Solid(0, 250, 275, 50)
    Solid(2, 175, 250, 75)
    Solid(2, 175, 225, 50)
    Solid(0, 125, 250, 50)
    Solid(2, 100, 100, 25, 100)
    Solid(11, 125, 225, 20, 20)
    Solid(11, 25, 225, 20, 20)
    Solid(11, 25, 175, 20, 20)
    Solid(11, 50, 125, 20, 20)
    Solid(11, 50, 75, 20, 20)
    Solid(0, 175, 100, 50)
    Solid(11, 300, 100, 20, 20)
    Solid(11, 375, 100, 20, 20)
    Solid(11, 425, 75, 20, 20)
    Solid(1, 475, 50)


EndFunc

Func Level4()
    $Level=4
    Solid(0, 0, 400, 500)
    Solid(0, 125, 375, 125)
    Solid(0, 200, 350, 50, 25)
    Solid(0, 300, 325, 50, 50)
    Solid(0, 375, 325, 25, 50)
    Solid(0, 425, 300, 75, 50)
    Solid(0, 300, 225, 150, 25)
    Solid(0, 450, 250)
    Solid(0, 225, 250)
    Solid(0, 150, 200)
    Solid(0, 0, 300, 100)
    Solid(0, 50, 150, 25, 100)
    Solid(0, 25, 250)
    Solid(0, 0, 200)
    Solid(0, 425, 175, 75)
    Solid(0, 425, 125)
    Solid(0, 350, 125, 50)
    Solid(0, 275, 125)
    Solid(0, 150, 100, 75)
    Solid(0, 0, 100)
    Solid(0, 50, 50)
    Solid(0, 100, 0, 50)
    Solid(0, 150, 25, 75)
    Solid(0, 275, 25, 50)
    Solid(0, 375, 25, 125)
    Solid(1, 475, 0)
EndFunc

Func Level3()
    $Level=3
    Text("Blocks can move!", 25, 300)
    Solid(4, 100, 375, 100)
    Solid(2, 200, 375, 175)
    Solid(0, 200, 350, 75, 25, 300, 350, 200)
    Solid(0, 375, 175, 125, 25, 375, 375, 200)
    Solid(0, 275, 175, 100)
    Solid(3, 75, 175, 200)
    Solid(0, 0, 175, 75)
    Solid(12, 0, 150, 20, 20)
    Solid(0, 100, 225, 75)
    Solid(1, 225, 200, 50)
EndFunc

Func Level2()
    $Level=2
    Solid(0, 50, 375, 50)
    Solid(0, 125, 325, 100, 50)
    Solid(0, 250, 325, 100, 50)
    Solid(0, 400, 325, 75, 50)
    Solid(0, 0, 275, 100)
    Solid(0, 150, 225, 50)
    Solid(0, 250, 175, 75)
    Solid(0, 400, 200, 75)
    Solid(1, 475, 200)
    Text("Hit enter to restart. Hit esc to exit.", 300, 0, 8)

EndFunc

Func Level1()
    $Level=1
    Solid(0, 100, 375, 100)
    Solid(2, 200, 375)
    Solid(0, 225, 375, 75)
    Solid(4, 300, 375, 125)
    Solid(13, 425, 385, 75, 15)
    Solid(13, 0, 125, 75, 15)
    Solid(0, 0, 250, 175)
    Solid(11, 100, 225, 20, 20)
    Solid(2, 175, 250, 75)
    Solid(0, 250, 250, 175)
    Solid(12, 320, 225, 20, 20)
    Solid(3, 375, 125, 50, 125)
    Solid(13, 425, 255, 75, 15)
    Solid(13, 0, 0, 75, 15)
    Solid(0, 0, 100, 125)
    Solid(5, 125, 100)
    Solid(5, 150, 100)
    Solid(5, 175, 100)
    Solid(5, 200, 100)
    Solid(0, 225, 100, 275)
    Solid(14, 300, 75, 20, 20)
    Solid(1, 450, 50, 50, 50)
    Text("Press up to jump", 0, 325, 8)
    Text("Avoid red", 180, 325, 8)
    Text("Sticky", 335, 325, 8)
    Text("Teleport", 435, 325, 8)
    Text("Jump in the air! Hit space to use", 15, 200, 8)
    Text("Lock and key", 285, 200, 8)
    Text("These vanish!", 130, 50, 8)
    Text("Use to pause moving", 240, 50, 8)
    Text("Hit to win!", 435, 20, 8)
EndFunc

Func Solid($_SolidType, $_SolidPosX, $_SolidPosY, $_SolidWidth=25, $_SolidHeight=25, $_SolidPosX_2=$_SolidPosX, $_SolidPosY_2=$_SolidPosY, $_SolidSpeed=100, $_SolidBrush=$SolidBrush[$_SolidType])
    ReDim $Obj[$Obj_Num+1][14]
    ReDim $VanishTimer[$Obj_Num+1]
    ReDim $VanishBrush[$Obj_Num+1]
    ReDim $Vanish[$Obj_Num+1]
    $Obj[$Obj_Num][0]=$_SolidPosX
    $Obj[$Obj_Num][1]=$_SolidPosY
    $Obj[$Obj_Num][2]=$_SolidWidth
    $Obj[$Obj_Num][3]=$_SolidHeight
    $Obj[$Obj_Num][4]=$_SolidPosX_2
    $Obj[$Obj_Num][5]=$_SolidPosY_2
    $Obj[$Obj_Num][6]=Sqrt(($_SolidPosX_2-$_SolidPosX)^2+($_SolidPosY_2-$_SolidPosY)^2)/$_SolidSpeed
    If $_SolidPosX_2<>$_SolidPosX Then $Obj[$Obj_Num][7]=1
    If $_SolidPosY_2<>$_SolidPosY Then $Obj[$Obj_Num][8]=1
    If $_SolidPosX_2<>$_SolidPosX Then $Obj[$Obj_Num][9]=$_SolidPosX
    If $_SolidPosY_2<>$_SolidPosY Then $Obj[$Obj_Num][10]=$_SolidPosY
    $Obj[$Obj_Num][11]=$_SolidBrush
    $Obj[$Obj_Num][12]=$_SolidType
    $Obj[$Obj_Num][13]=1
    If $_SolidType=5 Then $VanishBrush[$Obj_Num]=_GDIPlus_BrushCreateSolid(0xFF004400)
    If $_SolidType=5 Then $Vanish[$Obj_Num]=99
    ReDim $Obj_DirectionX[$Obj_Num+1]
    ReDim $Obj_DirectionY[$Obj_Num+1]
    $Obj_DirectionX[$Obj_Num]=1
    $Obj_DirectionY[$Obj_Num]=1
    $Obj_Num+=1
EndFunc

Func Text($_TextData, $_TextPosX, $_TextPosY, $_TextSize=10, $_TextFont="Arial")
    ReDim $Text[$Text_Num+1][5]
    $Text[$Text_Num][0]=$_TextData
    $Text[$Text_Num][1]=$_TextPosX
    $Text[$Text_Num][2]=$_TextPosY
    $Text[$Text_Num][3]=$_TextSize
    $Text[$Text_Num][4]=$_TextFont
    $Text_Num+=1
EndFunc

Func DrawText()
    For $1=0 To $Text_Num-1
        _GDIPlus_GraphicsDrawString($GDI_BACKBUFFER, $Text[$1][0], $Text[$1][1], $Text[$1][2], $Text[$1][4], $Text[$1][3])
    Next
EndFunc

Func DrawObjects()
    For $1=0 To $Obj_Num-1
        If $Obj[$1][7]=1 Then ;;;Turn Object Vertically
            $Obj[$1][0]+=$Obj[$1][6]*$Obj_DirectionX[$1]
            If $Obj[$1][0]=$Obj[$1][4] Then $Obj_DirectionX[$1]*=-1
            If $Obj[$1][0]=$Obj[$1][9] Then $Obj_DirectionX[$1]*=-1
        EndIf
        If $Obj[$1][8]=1 Then ;;;Turn Object Horisontally
            $Obj[$1][1]+=$Obj[$1][6]*$Obj_DirectionY[$1]
            If $Obj[$1][1]=$Obj[$1][5] Then $Obj_DirectionY[$1]*=-1
            If $Obj[$1][1]=$Obj[$1][10] Then $Obj_DirectionY[$1]*=-1
        EndIf
        If $Obj[$1][12]>10 Then
            If $Obj[$1][13]<>0 Then _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $Obj[$1][0], $Obj[$1][1], $Obj[$1][2], $Obj[$1][3], $Obj[$1][11])
        Else
            If $Obj[$1][13]<>0 Then _GDIPlus_GraphicsFillRect($GDI_BACKBUFFER, $Obj[$1][0], $Obj[$1][1], $Obj[$1][2], $Obj[$1][3], $Obj[$1][11])
        EndIf
    Next
EndFunc

Func GetNewBallPos()
    If $BrownStop=True Then ;;;Brown Stop
        $BrownStopCount+=1
        If $BrownStopCount>50 Then $BrownStop=False
        Return
    EndIf
    $IsSqueezed=0
    If SurfaceRight() Then $BallDirection=2
    If SurfaceLeft() Then $BallDirection=1
    If $IsSqueezed=2 Then LoseGame()
    Switch $BallDirection
        Case 1
            $BallPosX+=$BallSpeed
        Case 2
            $BallPosX-=$BallSpeed
    EndSwitch
EndFunc

Func CheckVanish()
    For $1=0 To $Obj_Num-1
        If $Obj[$1][12]=5 Then
            If $Obj[$1][13]=2 Then
                $Vanish[$1]-=2
                _GDIPlus_BrushSetSolidColor($VanishBrush[$1], '0x' & $Vanish[$1] & '004400')
                $Obj[$1][11]=$VanishBrush[$1]
                If $Vanish[$1]<10 Then
                    $Obj[$1][13]=0
                    $Vanish[$1]=99
                    $VanishTimer[$1]=TimerInit()
                EndIf
            ElseIf $Obj[$1][13]=0 And TimerDiff($VanishTimer[$1])>2000 Then
                $VanishTimer[$1]=TimerInit()
                If PointInSquare($BallPosX+$BallWidth, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                    If PointInSquare($BallPosX+$BallWidth, $BallPosY+$BallHeight, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                        If PointInSquare($BallPosX, $BallPosY+$BallHeight, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                            If PointInSquare($BallPosX, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], -2, 1, 0) = False Then
                                _GDIPlus_BrushSetSolidColor($VanishBrush[$1], 0xFF004400)
                                $Obj[$1][13]=1
                                $Obj[$1][11]=$SolidBrush[5]
                            EndIf
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
EndFunc

Func MoveBall()
    Switch $Brush
        Case 1
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX, $BallPosY, $BallWidth, $BallHeight, $GDI_BRUSH_BALL)
        Case 2
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX, $BallPosY, $BallWidth, $BallHeight, $EpicBrush[0])
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX+$BallWidth/8, $BallPosY+$BallHeight/8, $BallWidth-$BallWidth/4, $BallHeight-$BallHeight/4, $EpicBrush[1])
            _GDIPlus_GraphicsFillEllipse($GDI_BACKBUFFER, $BallPosX+$BallWidth/4, $BallPosY+$BallHeight/4, $BallWidth-$BallWidth/2, $BallHeight-$BallHeight/2, $EpicBrush[2])
    EndSwitch
EndFunc

Func WinGame()
    $Level+=1
    $CryptKey="Juego"
    If $Level<9 And _Crypt_DecryptData(IniRead(@ScriptDir & "\JuegoData\CL.ini", "1", "1", ""), "Juego", $CALG_AES_256)<$Level Then IniWrite(@ScriptDir & "\JuegoData\CL.ini", "1", "1", _Crypt_EncryptData($Level, $CryptKey, $CALG_AES_256))
    $ActivePowerup=0
    $ExtraJumpActive=1
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
    $Jump=0
    $JumpSoon=0
    $SurfaceCount=0
    $BallPosY=$BallPosY_Start
    $BallPosX=$BallPosX_0
    ReDim $Obj[0][0]
    ReDim $Obj[1][14]
    ReDim $Text[0][0]
    ReDim $Text[1][5]
    $Obj_Num=0
    $Text_Num=0
    If $Level<9 Then
        RunLevel($Level)
    Else
        GoToMenu()
    EndIf
    $QualityCount=0
    $QualityTimer=TimerInit()
EndFunc

Func LoseGame()
    For $1=1 To $Obj_Num-1
        $Obj[$1][13]=1
        $Vanish[$1]=99
        _GDIPlus_BrushSetSolidColor($VanishBrush[$1], 0xFF004400)
    Next
    $ActivePowerup=0
    $ExtraJumpActive=1
    $Jump=0
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
    $BallPosY=$BallPosY_Start
    $BallPosX=$BallPosX_0
    $SurfaceCount=0
    $QualityCount=0
    $QualityTimer=TimerInit()
EndFunc

Func SurfaceRight()
    If $BallPosX>=$WinWidth-$BallWidth Then Return True
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX+$BallWidth, $BallPosY+$BallHeight/2, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            If $Obj[$1][7]=1 And $Obj[$1][6]>$BallSpeed Then $BallPosX=$Obj[$1][0]-$BallWidth
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][12]=1 Then WinGame()
            $IsSqueezed+=1
            Return True
        EndIf
    Next
EndFunc

Func SurfaceLeft()
    If $BallPosX<=$BallPosX_0 Then Return True
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX, $BallPosY+$BallHeight/2, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            If $Obj[$1][7]=1 And $Obj[$1][6]>$BallSpeed Then $BallPosX=$Obj[$1][0]+$Obj[$1][2]
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][12]=1 Then WinGame()
            $IsSqueezed+=1
            Return True
        EndIf
    Next
EndFunc

Func SurfaceUnder()
    If $ExtraJumpActive=1 Or $ExtraJumpActive=2 Then
        If $ExtraJumpActive=2 Then $ExtraJumpActive=-1
        $ExtraJumpActive+=1
        Return True
    EndIf
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX+$BallWidth-3, $BallPosY+$BallHeight+1, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Or PointInSquare($BallPosX+3, $BallPosY+$BallHeight+1, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            If $Obj[$1][12]=4 Then ;;;Gold Sticky
                If $BallDirection=1 Then $BallPosX-=0.75
                If $BallDirection=2 Then $BallPosX+=0.75
            EndIf
            $BallPosY=$Obj[$1][1]-$BallHeight
            $BallPosY_0=$BallPosY
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][12]=1 Then WinGame()
            Return True
        EndIf
    Next
    If $BallPosY+$BallHeight>=$WinHeight Then
        $BallPosY=$WinHeight-$BallHeight
        $BallPosY_0=$WinHeight-$BallHeight
        Return True
    EndIf
EndFunc

Func SurfaceOver()
    For $1=0 To $Obj_Num-1
        If PointInSquare($BallPosX+$BallWidth-5, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Or PointInSquare($BallPosX+5, $BallPosY, $Obj[$1][0], $Obj[$1][1], $Obj[$1][0]+$Obj[$1][2], $Obj[$1][1]+$Obj[$1][3], $Obj[$1][12], $Obj[$1][13], $1) Then
            If CheckForPowerup($1, $Obj[$1][12], $Obj[$1][13])= True Then Return False
            $SurfaceMove=0
            If $Obj[$1][12]=2 Then LoseGame()
            If $Obj[$1][8]=1 Then
                $BallPosY=$Obj[$1][1]+$Obj[$1][3]
                $SurfaceMove=1
                $SurfaceCount=5
            ElseIf $BallPosY<$Obj[$1][1]+$Obj[$1][3]-2 Then
                $BallPosY=$Obj[$1][1]+$Obj[$1][3]
            EndIf
            If $Obj[$1][12]=1 Then WinGame()
            Return True
        EndIf
    Next
EndFunc

Func CheckForPowerup($__PowerupObjNum, $__PowerupObj, $__PowerupActive)
    If $__PowerupObj>10 Then
        If $__PowerupActive=0 Then Return True
        If $__PowerupObj<>13 Then $Obj[$__PowerupObjNum][13]=0
        ActivatePowerup($__PowerupObj, $__PowerupObjNum)
        Return True
    EndIf
    Return False
EndFunc

Func ActivatePowerup($_PowerupType, $_PowerupObjNum)
    Switch $_PowerupType
        Case 11;;Superjump
            _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFFFF9900)
        Case 12;;Cyan Key
            For $1=0 To $Obj_Num-1
                If $Obj[$1][12]=3 And $Obj[$1][13]=1 Then $Obj[$1][13]=0
            Next
            $_PowerupType=$ActivePowerup
        Case 13;;Teleport
            If TimerDiff($TeleTimer)>500 Then
                $TeleLink=-1
                If $Obj[$_PowerupObjNum-1][12]<>13 Then $TeleLink=1
                $TeleDiffY=$BallPosY-$BallPosY_0
                $BallPosX=$Obj[$_PowerupObjNum+$TeleLink][0]+$Obj[$_PowerupObjNum+$TeleLink][2]/2-$BallWidth/2
                $BallPosY=$Obj[$_PowerupObjNum+$TeleLink][1]+$Obj[$_PowerupObjNum+$TeleLink][3]/2-$BallHeight/2
                $BallPosY_0=$BallPosY-$TeleDiffY
                $TeleTimer=TimerInit()
            EndIf
            $_PowerupType=$ActivePowerup
        Case 14
            _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF734021)
    EndSwitch
    $ActivePowerup=$_PowerupType
EndFunc

Func SpendPowerup()

    Switch $ActivePowerup
        Case 0
            Return
        Case 11 ;;;EXTRA JUMP
            $ActivePowerup=0
            $ExtraJumpActive=1
            $SurfaceCount=0
            StartJump()
        Case 14 ;;;Brown Stop
            $BrownStop=True
            $BrownStopCount=0
    EndSwitch
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
EndFunc

Func StartJump()
    If SurfaceUnder() Then
        $Jump=True
        $BallPosY_0=$BallPosY
;~      $BallSpeedY=$JumpHeight
        $JumpSoon=False
    Else
        $JumpSoonTimer=TimerInit()
        $JumpSoon=True
    EndIf
EndFunc

Func Gravity()

    If SurfaceOver() = True Then
        $BallSpeedY=0
        If $SurfaceMove=0 Then $SurfaceCount=2
        $BallPosY_0=$BallPosY
    EndIf
    If SurfaceUnder() Then
        $SurfaceCount=0
        $BallSpeedY=0
        $BallPosY_0=$BallPosY
        If $JumpSoon=False And $Jump=False Then
            Return
        Else
            If $JumpSoon=True And TimerDiff($JumpSoonTimer)>150 Then Return
            $BallSpeedY=$JumpHeight
            StartJump()
            $Jump=False
        EndIf
    EndIf
    $SurfaceCount+=1
    $BallPosY=$BallPosY_0-($BallSpeedY*$SurfaceCount+1/2*-9.81*$SurfaceCount^2)*0.01
EndFunc

Func QualityCheck()
    $QualityCount+=1
    If $QualityCount=$QualityFPS Then
        $QualitySleep+=(950-TimerDiff($QualityTimer))/$QualityFPS*100
        $QualityCount=0
        $QualityTimer=TimerInit()
    EndIf
EndFunc

Func USleep($iUsec, $hDLL = "ntdll.dll")
    $iUsec-=TimerDiff($USleepTimer)*100
    If $iUsec<0 Then $iUsec=0
    Local $hStruct = DllStructCreate("int64")
    DllStructSetData($hStruct, 1, -1 * ($iUsec * 10))
    DllCall($hDLL, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))
    $USleepTimer=TimerInit()
EndFunc

Func PointInSquare($_PointX, $_PointY, $_SquareTopX, $_SquareTopY, $_SquareBottomX, $_SquareBottomY, $_SquareType, $_SquareActive, $_SquareObjNum)
    If $_SquareActive=0 Then Return False
    $_SquareDiff=0
    If $_SquareType=2 Then $_SquareDiff=2
    If $_SquareType>10 Then $_SquareDiff=2
    If $_PointX<$_SquareTopX+$_SquareDiff Then Return False
    If $_PointX>$_SquareBottomX-$_SquareDiff Then Return False
    If $_PointY<$_SquareTopY+$_SquareDiff Then Return False
    If $_PointY>$_SquareBottomY-$_SquareDiff Then Return False
    If $_SquareType = 5 Then $Obj[$_SquareObjNum][13]=2
    Return True
EndFunc

Func TakeSnapShot()
    If Not FileExists($PictureDir) Then DirCreate($PictureDir)
    _ScreenCapture_CaptureWnd($PictureDir & "\Temp.bmp", $hGUI, 0, 0, -1, -1, False)
    $___SnapShotImage = _GDIPlus_ImageLoadFromFile($PictureDir & "\Temp.bmp")
    $___GC = _GDIPlus_ImageGetGraphicsContext($___SnapShotImage)
    $___NewBmp = _GDIPlus_BitmapCreateFromGraphics(115,87,$___GC)
    $___newGC = _GDIPlus_ImageGetGraphicsContext($___NewBmp)
    _GDIPlus_GraphicsDrawImageRect($___newGC,$___SnapShotImage,0,0,115,87)
    _GDIPlus_ImageSaveToFile($___newBmp,$PictureDir & "\Level" & $Level & ".bmp")
    _GDIPlus_GraphicsDispose($___GC)
    _GDIPlus_GraphicsDispose($___newGC)
    _GDIPlus_BitmapDispose($___newBmp)
    _GDIPlus_ImageDispose($___SnapShotImage)
    FileDelete($PictureDir & "\Temp.bmp")
    $TakeScreenshot=False
EndFunc

Func Menu()
    $Level=0
    $ButtonPosX=2
    $ButtonPosY=2
    For $1=1 To 16
        $Button[$1]=GUICtrlCreateButton("", $ButtonPosX, $ButtonPosY, 120, 95, $BS_BITMAP)
        $ButtonPosX+=125
        If $ButtonPosX>500 Then
            $ButtonPosX=2
            $ButtonPosY+=100
        EndIf
        GUICtrlSetImage($Button[$1], $PictureDir & "\Level" & $1 & ".bmp")
        If _Crypt_DecryptData(IniRead(@ScriptDir & "\JuegoData\CL.ini", "1", "1", ""), "Juego", $CALG_AES_256)<$1 And $1<9 And $1>1 Then GUICtrlSetState($Button[$1], 128)
    Next
    While 1
        $msg=GUIGetMsg()
        For $1=1 To 16
            Switch $msg
;~              Case $Button[1]
;~                  DeleteMenu()
;~                  Level1()
;~                  Return
                    Case $Button[$1]

                    DeleteMenu()
                    RunLevel($1)
                    Return
            EndSwitch
        Next
    WEnd
EndFunc

Func RunLevel($_RunLevel)
    HotKeySet("{UP}", "StartJump")
    HotKeySet("{SPACE}", "SpendPowerup")
    HotKeySet("{PRINTSCREEN}", "TakeSnapShot")
    HotKeySet("{ENTER}", "LoseGame")
    Switch $_RunLevel
        Case 1
            Level1()
        Case 2
            Level2()
        Case 3
            Level3()
        Case 4
            Level4()
        Case 5
            Level5()
        Case 6
            Level6()
        Case 7
            Level7()
        Case 8
            Level8()
        Case 9 To 16
            $Level=-1
            LevelFromTxt($_RunLevel)
    EndSwitch
    $TakeScreenshot=True
EndFunc

Func DeleteMenu()
    For $1=1 To 16
        GUICtrlDelete($Button[$1])
    Next
    $QualityCount=0
    $QualityTimer=TimerInit()
EndFunc

Func GoToMenu()
    If $ScriptPos=1 Then
        $GoToMenu=True
        Return
    EndIf
    $GoToMenu=False
    HotKeySet("{UP}")
    HotKeySet("{SPACE}")
    HotKeySet("{PRINTSCREEN}")
    HotKeySet("{ENTER}")
    _GDIPlus_GraphicsClear($GDI_BACKBUFFER, 0xFFFFFFFF)
    _GDIPlus_GraphicsDrawImageRect($GDI_GRAPHICS, $GDI_BITMAP, 0, 0, $WinWidth, $WinHeight)
    $ActivePowerup=0
    $ExtraJumpActive=1
    _GDIPlus_BrushSetSolidColor($GDI_BRUSH_BALL, 0xFF000000)
    $Jump=0
    $JumpSoon=0
    $SurfaceCount=0
    $BallPosY=$BallPosY_Start
    $BallPosX=$BallPosX_0
    ReDim $Obj[0][0]
    ReDim $Obj[1][14]
    ReDim $Text[0][0]
    ReDim $Text[1][5]
    $Obj_Num=0
    $Text_Num=0
    $QualityCount=0
    $QualityTimer=TimerInit()
    Menu()
EndFunc

Func CheckActive()
    If WinActive($hGUI) Then
        If $WinActive=False Then
            HotKeySet("{UP}", "StartJump")
            HotKeySet("{SPACE}", "SpendPowerup")
            HotKeySet("{PRINTSCREEN}", "TakeSnapShot")
            HotKeySet("{ENTER}", "LoseGame")
        EndIf
        $WinActive=True
    Else
        If $WinActive=True Then
            HotKeySet("{UP}")
            HotKeySet("{SPACE}")
            HotKeySet("{PRINTSCREEN}")
            HotKeySet("{ENTER}")
        EndIf
        $WinActive=False
    EndIf
EndFunc

Func Terminate()
    If $Level<>0 Then
        GoToMenu()
        Return
    EndIf
    _GDIPlus_BrushDispose($SolidBrush[0])
    _GDIPlus_BrushDispose($SolidBrush[1])
    _GDIPlus_BrushDispose($SolidBrush[2])
    _GDIPlus_BrushDispose($SolidBrush[3])
    _GDIPlus_BrushDispose($SolidBrush[4])
    _GDIPlus_BrushDispose($SolidBrush[5])
    _GDIPlus_BrushDispose($SolidBrush[11])
    _GDIPlus_BrushDispose($SolidBrush[12])
    _GDIPlus_BrushDispose($SolidBrush[13])
    _GDIPlus_BrushDispose($GDI_BRUSH_BALL)
    _GDIPlus_BrushDispose($VanishBrush)
    _GDIPlus_GraphicsDispose($GDI_GRAPHICS)
    _GDIPlus_ImageDispose($GDI_BITMAP)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

Edited by TheNorwegianUser
2 people like this

Share this post


Link to post
Share on other sites

Thanks for share bro !

Share this post


Link to post
Share on other sites

I like the colision system! ^^

 


m(o.O)m

Share this post


Link to post
Share on other sites

Great Game! Just lacks a restart button and GUI Acceleration Keys (instead of Hotkeys which forced me to quit the game in the middle to write this) TD :thumbsup:


Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Great Game! Just lacks a restart button and GUI Acceleration Keys (instead of Hotkeys which forced me to quit the game in the middle to write this) TD :thumbsup:

The enter key was alredy set to restart, just wasn't written anywhere :)  I think the hotkey problem is fixed now ;)

1 person likes this

Share this post


Link to post
Share on other sites

To be able to play with friends, i set up a TCP connection, but TCPRecv seems to make it run very slow. Is there a faster way to recieve a message from the server than using TCPRecv? Tried searching, but the best I could find was this, which I can't get to work.

Share this post


Link to post
Share on other sites

I have never used dlls before, so I have no idea what I can do to get it to work. It seems to get stuck on DllCall.

Func _TCPRecv($iSock, $iLen)
    Local $structBuffer = DllStructCreate("char[" & $iLen & "]")
    Local $aRet = DllCall("Ws2_32.dll", "int", "recv", "int", $iSock, "ptr", DllStructGetPtr($structBuffer), "int", $iLen, "int", 0)
    If @error Then SetError(1, 0, "")
    Return SetError(0, $aRet[0], DllStructGetData($structBuffer, 1))
EndFunc

 

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