Jump to content

SNAKE


CodyBarrett
 Share

Recommended Posts

my recent work on TRON inspired me to try my hand at the simple SNAKE game.

--however the first time it eats a block, for the life of me i can't figure out where i went wrong, it doesn't grow at all.

--i'm sure there is more bugs, anyone see any?

#NoTrayIcon
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <misc.au3>

_GDIPlus_Startup ()
Global $nNEXT_DIRECTION = 1
Global $bIS_TURNING = False
Global $nGRAPHICS_CLEAR = 0xFF000000
Global $nBUFFER_SPEED = 60
Global $nLOOP_SPEED = 70
Global $nCURRENT_DIRECTION = 1
Global $nLAST_DIRECTION = 1
Global $nCURRENT_X = 0
Global $nCURRENT_Y = 0
Global $nFOOD_X = 0
Global $nFOOD_Y = 0
Global $nSNAKE_LENGTH = 2
Global $nBLOCK_SIZE = 20
Global $nGUI_W = 20*$nBLOCK_SIZE
Global $nGUI_H = 20*$nBLOCK_SIZE
Global $nGRID_1_MAX = ($nGUI_W/$nBLOCK_SIZE)+1
Global $nGRID_2_MAX = ($nGUI_H/$nBLOCK_SIZE)+1
Dim $aGRID[$nGRID_1_MAX][$nGRID_2_MAX]
Dim $aTAIL[$nSNAKE_LENGTH][2]
$hHWND = GUICreate (@ScriptName,$nGUI_W,$nGUI_H)
GUISetState (@SW_SHOW,$hHWND)


$hGRAPHIC_GUI = _GDIPlus_GraphicsCreateFromHWND($hHWND)
$hBMP_BUFFER = _GDIPlus_BitmapCreateFromGraphics($nGUI_W, $nGUI_H, $hGRAPHIC_GUI)
$hGRAPHIC = _GDIPlus_ImageGetGraphicsContext($hBMP_BUFFER)
_GDIPlus_GraphicsClear($hGraphic, $nGRAPHICS_CLEAR)
$hBRUSH = _GDIPlus_BrushCreateSolid(0xFFFF0000)
$hFOOD_BRUSH = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)


GUIRegisterMsg(0xF, 'MY_PAINT')
GUIRegisterMsg(0x85, 'MY_PAINT')
AdlibRegister ('BUFFER',$nBUFFER_SPEED)
AdlibRegister ('INPUT',$nBUFFER_SPEED)

SET_FOOD ()


while True
    $nMSG = GUIGetMsg ()
    If $nMSG = -3 Then QUIT ()
    Sleep ($nLOOP_SPEED)
    LOOP ()
WEnd



Func SET_FOOD ()
    Do
        $nX = Random (0,$nGRID_1_MAX-2,1)
        $nY = Random (0,$nGRID_2_MAX-2,1)
    Until $aGRID[$nX][$nY] = 0
    $aGRID[$nX][$nY] = 2
    $nFOOD_X = $nX
    $nFOOD_Y = $nY
EndFunc
Func EAT_FOOD ()
    $nSNAKE_LENGTH += 1
    _GDIPlus_GraphicsFillRect($hGRAPHIC, $nFOOD_X*$nBLOCK_SIZE, $nFOOD_Y*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE)
    ReDim $aTAIL[$nSNAKE_LENGTH][2]
    SET_FOOD ()
EndFunc
Func Move ($nX_Y,$nX,$nY)
    Switch $nCURRENT_DIRECTION
        Case 0
            If $nX_Y = 1 Then
                $nY-=1
            EndIf
        Case 1
            If $nX_Y = 0 Then
                $nX+=1
            EndIf
        Case 2
            If $nX_Y = 1 Then
                $nY+=1
            EndIf
        Case 3
            If $nX_Y = 0 Then
                $nX-=1
            EndIf
    EndSwitch
    If $nX < 0 Then
        $nX = $nGRID_1_MAX-1
    ElseIf $nX >= $nGRID_1_MAX-1 Then
        $nX = 0
    EndIf
    If $nY < 0 Then
        $nY = $nGRID_2_MAX-1
    ElseIf $nY >= $nGRID_2_MAX-1 Then
        $nY = 0
    EndIf
    If $nX_Y = 0 Then
        Return $nX
    ElseIf $nX_Y = 1 Then
        Return $nY
    EndIf
EndFunc
Func LOOP ()
    $bIS_TURNING = True
    Local $nX = Move(0,$nCURRENT_X,$nCURRENT_Y)
    Local $nY = Move(1,$nCURRENT_X,$nCURRENT_Y)
    $bIS_TURNING = False
    TURN_SNAKE($nNEXT_DIRECTION)
    If $aGRID[$nX][$nY] = 2 Then
        EAT_FOOD ()
    ElseIf $aGRID[$nX][$nY] = 1 Then
        Return
    EndIf
    $nCURRENT_X = $nX
    $nCURRENT_Y = $nY
    _GDIPlus_GraphicsFillRect($hGRAPHIC, $aTAIL[0][0]*$nBLOCK_SIZE, $aTAIL[0][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE)
    $aGRID[$aTAIL[0][0]][$aTAIL[0][1]] = 0
    $aGRID[$nCURRENT_X][$nCURRENT_Y] = 1
    $aTAIL[$nSNAKE_LENGTH-1][0] = $nCURRENT_X
    $aTAIL[$nSNAKE_LENGTH-1][1] = $nCURRENT_Y
    For $nCOUNT = 0 To $nSNAKE_LENGTH-1
        If $nSNAKE_LENGTH > 0 Then
            If $nCOUNT+1 < $nSNAKE_LENGTH Then
                $aTAIL[$nCOUNT][0] = $aTAIL[$nCOUNT+1][0]
                $aTAIL[$nCOUNT][1] = $aTAIL[$nCOUNT+1][1]
            EndIf
        EndIf
    Next
    _GDIPlus_GraphicsFillRect($hGRAPHIC, $aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE, $aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE, $hBRUSH)
    _GDIPlus_GraphicsDrawRect($hGRAPHIC, $aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE, $aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE, $nBLOCK_SIZE,$nBLOCK_SIZE)
    _GDIPlus_GraphicsFillRect($hGRAPHIC, $nFOOD_X*$nBLOCK_SIZE, $nFOOD_Y*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE, $hFOOD_BRUSH)
EndFunc
Func INPUT ()
    $nLAST_DIRECTION = $nCURRENT_DIRECTION
    If _IsPressed ('57') And $nCURRENT_DIRECTION <> 2 Then
        TURN_SNAKE(0)
    ElseIf _IsPressed ('44') And $nCURRENT_DIRECTION <> 3  Then
        TURN_SNAKE(1)
    ElseIf _IsPressed ('53') And $nCURRENT_DIRECTION <> 0  Then
        TURN_SNAKE(2)
    ElseIf _IsPressed ('41') And $nCURRENT_DIRECTION <> 1  Then
        TURN_SNAKE(3)
    EndIf
EndFunc
Func TURN_SNAKE ($nDIRECTION)
    If $bIS_TURNING Then
        $nNEXT_DIRECTION = $nDIRECTION
    ElseIf Mod($nDIRECTION - $nCURRENT_DIRECTION, 2) <> 0 Then
        $nCURRENT_DIRECTION = $nDIRECTION
        $nNEXT_DIRECTION = $nDIRECTION
        $bIS_TURNING = True
    EndIf
EndFunc
Func BUFFER ()
    _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI,$hBMP_BUFFER, 0, 0)
EndFunc
Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI,$hBMP_BUFFER,0,0)
    _WinAPI_RedrawWindow($hWnd,Default,Default, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)); , $RDW_ALLCHILDREN
    Return $GUI_RUNDEFMSG
EndFunc
Func QUIT ()
    _GDIPlus_GraphicsDispose ($hGRAPHIC_GUI)
    _GDIPlus_BitmapDispose ($hBMP_BUFFER)
    _GDIPlus_GraphicsDispose ($hGRAPHIC)
    _GDIPlus_BrushDispose ($hBRUSH)
    _GDIPlus_BrushDispose ($hFOOD_BRUSH)
    _GDIPlus_Shutdown ()
    Exit
EndFunc
Edited by CodyBarrett
Link to comment
Share on other sites

I fixed the food problem.

Change:

Global $nSNAKE_LENGTH = 1

To:

Global $nSNAKE_LENGTH = 2

I have no idea why it works, but I have these problems a lot and usually it helps to just +1 on some initial value. So I tried this value and it worked.

Edit: Btw, you can disappear. :) Go to the bottom edge of the map, travel 1 block down so you should reappear on top of the map, you don't immediately reappear and then you go left or right.

Edit2: Badger. Badger. Badger. Badger.

Edited by Manadar
Link to comment
Share on other sites

I fixed the food problem.

Change:

Global $nSNAKE_LENGTH = 1

To:

Global $nSNAKE_LENGTH = 2

I have no idea why it works, but I have these problems a lot and usually it helps to just +1 on some initial value. So I tried this value and it worked.

Edit: Btw, you can disappear. :) Go to the bottom edge of the map, travel 1 block down so you should reappear on top of the map, you don't immediately reappear and then you go left or right.

THANKS manadar!

#1 FIXED

#2 and... thats strange :S gonna look into that one :)

EDIT

#2 fixed.

i also fixed something i found, hitting your own tail erased chunks. not anymore.

Edited by CodyBarrett
Link to comment
Share on other sites

Nice program. It's very concise and also fun.

I noticed it couldn't handle fast turning, though. If people have very nimble fingers you need to store the next direction before it has moved forward. I modified the part that handles turning as follows:

Func INPUT ()
    If _IsPressed ('57') Then
        TURN_SNAKE(0)
    ElseIf _IsPressed ('44') Then
        TURN_SNAKE(1)
    ElseIf _IsPressed ('53') Then
        TURN_SNAKE(2)
    ElseIf _IsPressed ('41') Then
        TURN_SNAKE(3)
    EndIf
EndFunc
Func TURN_SNAKE ($nDIRECTION)
    If $bIS_TURNING Then
        $nNEXT_DIRECTION = $nDIRECTION
    ElseIf Mod($nDIRECTION - $nCURRENT_DIRECTION, 2) <> 0 Then
        $nCURRENT_DIRECTION = $nDIRECTION
        $nNEXT_DIRECTION = $nDIRECTION
        $bIS_TURNING = True
    EndIf
EndFunc ;==>TURN_SNAKE

Then I added the following global variables:

Global $nNEXT_DIRECTION = 1
Global $bIS_TURNING = False

Finally I changed the LOOP function to turn to the next direction (if any):

Func LOOP ()
    Local $nX = Move(0,$nCURRENT_X,$nCURRENT_Y)
    Local $nY = Move(1,$nCURRENT_X,$nCURRENT_Y)
    $bIS_TURNING = False
    TURN_SNAKE($nNEXT_DIRECTION)
...
Link to comment
Share on other sites

interesting, i didn't notice any kind of lag, but i guess i am running it on a fairly speedy PC.

thanks its even faster now :)

Link to comment
Share on other sites

Are you supposed to be able to die? Because I can't seem to manage it.. You could add walls to make it more interesting.. not just on the sides but throughout the middle of the maze too..

You can't die exactly, you just get stopped by or stuck inside your tail.

BTW, I found another bug. There's actually a race condition that can occur if you change direction of the snake after $nX has been modified but before $nY has been modified. It's so rare you would almost never see it, but it did occur for me once. You can prevent this by setting the boolean that prevents changing direction before calling Move, like so:

Func LOOP ()
    $bIS_TURNING = True
    Local $nX = Move(0,$nCURRENT_X,$nCURRENT_Y)
    Local $nY = Move(1,$nCURRENT_X,$nCURRENT_Y)
    $bIS_TURNING = False
    TURN_SNAKE($nNEXT_DIRECTION)
...
Link to comment
Share on other sites

its nearly impossible to loze, i find the challenge is getting so big that you can barely avoid getting stuck, it takes some skill to move from multiple sides to avoid getting stuck. just me though, maybe i'm to slow to play this game :)

i've never noticed that glitch.. thanks for the heads up though. ive added that line.

Link to comment
Share on other sites

CodyBarrett this is good :)

I tried it out to see how far I can get

apparently, there is a bug, when I got to 1 line left, it created a white box on a red box, it's stuck on that same spot, i can't eat it i just go under it :)

i have a pic and i'll video it also lol

http://www.youtube.com/watch?v=B1wTkdIRfrg

EDIT: added video, removed picture

Edited by AoRaToS

s!mpL3 LAN Messenger

Current version 2.9.9.1 [04/07/2019]

s!mpL3 LAN Messenger.zip

s!mpL3

Link to comment
Share on other sites

simple fix for that, just add a conditional IF GRID[RANDOM][RANDOM] = 0 then use that pos. i'll add it in when i update it, i've also made a few more changes.

Link to comment
Share on other sites

I made a quick conversion to SDL. I commented the GDI+ code and put the SDL equivalent under as a comparison.

Biggest difference for this script seems to be about 30% less RAM usage.

Have fun!

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;~ #include <GDIPlus.au3>   ;Not needed anymore
;~ #include <WinAPI.au3>   ;Not needed anymore
;~ #include <GuiConstants.au3>   ;Not needed anymore
;~ #include <WindowsConstants.au3>   ;Not needed anymore
#include <misc.au3>
#include "SDL.AU3"
#include "SDL_sprig.AU3"

;~ _GDIPlus_Startup ()
;Must be done later

Global $nNEXT_DIRECTION = 1
Global $bIS_TURNING = False
;~ Global $nGRAPHICS_CLEAR = 0xFF000000   ;GDI+ uses ARGB
Global $nGRAPHICS_CLEAR = 0x000000   ;We only wants RGB here
Global $nBUFFER_SPEED = 60
Global $nLOOP_SPEED = 70
Global $nCURRENT_DIRECTION = 1
Global $nLAST_DIRECTION = 1
Global $nCURRENT_X = 0
Global $nCURRENT_Y = 0
Global $nFOOD_X = 0
Global $nFOOD_Y = 0
Global $nSNAKE_LENGTH = 2
Global $nBLOCK_SIZE = 20
Global $nGUI_W = 20*$nBLOCK_SIZE
Global $nGUI_H = 20*$nBLOCK_SIZE
Global $nGRID_1_MAX = ($nGUI_W/$nBLOCK_SIZE)+1
Global $nGRID_2_MAX = ($nGUI_H/$nBLOCK_SIZE)+1
Dim $aGRID[$nGRID_1_MAX][$nGRID_2_MAX]
Dim $aTAIL[$nSNAKE_LENGTH][2]
$hHWND = GUICreate (@ScriptName,$nGUI_W,$nGUI_H)
GUISetState (@SW_SHOW,$hHWND)


;~ $hGRAPHIC_GUI = _GDIPlus_GraphicsCreateFromHWND($hHWND)
;~ $hBMP_BUFFER = _GDIPlus_BitmapCreateFromGraphics($nGUI_W, $nGUI_H, $hGRAPHIC_GUI)
;~ $hGRAPHIC = _GDIPlus_ImageGetGraphicsContext($hBMP_BUFFER)
EnvSet("SDL_WINDOWID", $hHWND)   ;Must be before SDL_Init
_SDL_Init($_SDL_INIT_VIDEO)
_SDL_Startup_sprig()   ;SDL only draw a square, so we need some other UDF for the rectangles
$hSURFACE_GUI = _SDL_SetVideoMode($nGUI_W, $nGUI_H, 32, $_SDL_SWSURFACE)   ;32 is BPP (bits per pixel), can be 24 too (other BBP will break the script since we hardcoded 24-bit colors)

;~ _GDIPlus_GraphicsClear($hGraphic, $nGRAPHICS_CLEAR)
_SDL_FillRect($hSURFACE_GUI, 0, $nGRAPHICS_CLEAR)

;~ $hBRUSH = _GDIPlus_BrushCreateSolid(0xFFFF0000)
;~ $hFOOD_BRUSH = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)

;No brushes in SDL

;~ GUIRegisterMsg(0xF, 'MY_PAINT')
;~ GUIRegisterMsg(0x85, 'MY_PAINT')
;Not needed, SDL does this for us

AdlibRegister ('BUFFER',$nBUFFER_SPEED)
AdlibRegister ('INPUT',$nBUFFER_SPEED)

SET_FOOD ()


while True
    $nMSG = GUIGetMsg ()
    If $nMSG = -3 Then QUIT ()
    Sleep ($nLOOP_SPEED)
    LOOP ()
WEnd

Func SET_FOOD ()
    Do
        $nX = Random (0,$nGRID_1_MAX-2,1)
        $nY = Random (0,$nGRID_2_MAX-2,1)
    Until $aGRID[$nX][$nY] = 0
    $aGRID[$nX][$nY] = 2
    $nFOOD_X = $nX
    $nFOOD_Y = $nY
EndFunc

Func EAT_FOOD ()
    $nSNAKE_LENGTH += 1

;~     _GDIPlus_GraphicsFillRect($hGRAPHIC, $nFOOD_X*$nBLOCK_SIZE, $nFOOD_Y*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE)
    _SDL_FillRect($hSURFACE_GUI, _SDL_Rect_Create($nFOOD_X*$nBLOCK_SIZE, $nFOOD_Y*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE), 0)

    ReDim $aTAIL[$nSNAKE_LENGTH][2]
    SET_FOOD ()
EndFunc

Func Move ($nX_Y,$nX,$nY)
    Switch $nCURRENT_DIRECTION
        Case 0
            If $nX_Y = 1 Then
                $nY-=1
            EndIf
        Case 1
            If $nX_Y = 0 Then
                $nX+=1
            EndIf
        Case 2
            If $nX_Y = 1 Then
                $nY+=1
            EndIf
        Case 3
            If $nX_Y = 0 Then
                $nX-=1
            EndIf
    EndSwitch
    If $nX < 0 Then
        $nX = $nGRID_1_MAX-1
    ElseIf $nX >= $nGRID_1_MAX-1 Then
        $nX = 0
    EndIf
    If $nY < 0 Then
        $nY = $nGRID_2_MAX-1
    ElseIf $nY >= $nGRID_2_MAX-1 Then
        $nY = 0
    EndIf
    If $nX_Y = 0 Then
        Return $nX
    ElseIf $nX_Y = 1 Then
        Return $nY
    EndIf
EndFunc

Func LOOP ()
    $bIS_TURNING = True
    Local $nX = Move(0,$nCURRENT_X,$nCURRENT_Y)
    Local $nY = Move(1,$nCURRENT_X,$nCURRENT_Y)
    $bIS_TURNING = False
    TURN_SNAKE($nNEXT_DIRECTION)
    If $aGRID[$nX][$nY] = 2 Then
        EAT_FOOD ()
    ElseIf $aGRID[$nX][$nY] = 1 Then
        Return
    EndIf
    $nCURRENT_X = $nX
    $nCURRENT_Y = $nY

;~     _GDIPlus_GraphicsFillRect($hGRAPHIC, $aTAIL[0][0]*$nBLOCK_SIZE, $aTAIL[0][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE)
    _SDL_FillRect($hSURFACE_GUI, _SDL_Rect_Create($aTAIL[0][0]*$nBLOCK_SIZE, $aTAIL[0][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE), 0)

    $aGRID[$aTAIL[0][0]][$aTAIL[0][1]] = 0
    $aGRID[$nCURRENT_X][$nCURRENT_Y] = 1
    $aTAIL[$nSNAKE_LENGTH-1][0] = $nCURRENT_X
    $aTAIL[$nSNAKE_LENGTH-1][1] = $nCURRENT_Y
    For $nCOUNT = 0 To $nSNAKE_LENGTH-1
        If $nSNAKE_LENGTH > 0 Then
            If $nCOUNT+1 < $nSNAKE_LENGTH Then
                $aTAIL[$nCOUNT][0] = $aTAIL[$nCOUNT+1][0]
                $aTAIL[$nCOUNT][1] = $aTAIL[$nCOUNT+1][1]
            EndIf
        EndIf
    Next

;~     _GDIPlus_GraphicsFillRect($hGRAPHIC, $aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE, $aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE, $hBRUSH)
    _SDL_FillRect($hSURFACE_GUI, _SDL_Rect_Create($aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE, $aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE), 0xFF0000)
;~     _GDIPlus_GraphicsDrawRect($hGRAPHIC, $aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE, $aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE)
    _SPG_Rect($hSURFACE_GUI, $aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE, $aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE, ($aTAIL[$nSNAKE_LENGTH-1][0]*$nBLOCK_SIZE) +$nBLOCK_SIZE, ($aTAIL[$nSNAKE_LENGTH-1][1]*$nBLOCK_SIZE) +$nBLOCK_SIZE, 0x000000)
;~     _GDIPlus_GraphicsFillRect($hGRAPHIC, $nFOOD_X*$nBLOCK_SIZE, $nFOOD_Y*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE, $hFOOD_BRUSH)
    _SDL_FillRect($hSURFACE_GUI, _SDL_Rect_Create($nFOOD_X*$nBLOCK_SIZE, $nFOOD_Y*$nBLOCK_SIZE, $nBLOCK_SIZE, $nBLOCK_SIZE), 0xFFFFFF)

EndFunc

Func INPUT ()
    $nLAST_DIRECTION = $nCURRENT_DIRECTION
    If _IsPressed ('57') And $nCURRENT_DIRECTION <> 2 Then
        TURN_SNAKE(0)
    ElseIf _IsPressed ('44') And $nCURRENT_DIRECTION <> 3  Then
        TURN_SNAKE(1)
    ElseIf _IsPressed ('53') And $nCURRENT_DIRECTION <> 0  Then
        TURN_SNAKE(2)
    ElseIf _IsPressed ('41') And $nCURRENT_DIRECTION <> 1  Then
        TURN_SNAKE(3)
    EndIf
EndFunc

Func TURN_SNAKE ($nDIRECTION)
    If $bIS_TURNING Then
        $nNEXT_DIRECTION = $nDIRECTION
    ElseIf Mod($nDIRECTION - $nCURRENT_DIRECTION, 2) <> 0 Then
        $nCURRENT_DIRECTION = $nDIRECTION
        $nNEXT_DIRECTION = $nDIRECTION
        $bIS_TURNING = True
    EndIf
EndFunc

Func BUFFER ()
;~     _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI,$hBMP_BUFFER, 0, 0)
    _SDL_Flip($hSURFACE_GUI)
EndFunc

;~ Func MY_PAINT($hWnd, $msg, $wParam, $lParam)   ;Not needed, SDL does this for us
;~     _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI,$hBMP_BUFFER,0,0)
;~     _WinAPI_RedrawWindow($hWnd,Default,Default, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)); , $RDW_ALLCHILDREN
;~     Return $GUI_RUNDEFMSG
;~ EndFunc

Func QUIT ()
;~     _GDIPlus_GraphicsDispose ($hGRAPHIC_GUI)
;~     _GDIPlus_BitmapDispose ($hBMP_BUFFER)
;~     _GDIPlus_GraphicsDispose ($hGRAPHIC)
;~     _GDIPlus_BrushDispose ($hBRUSH)
;~     _GDIPlus_BrushDispose ($hFOOD_BRUSH)
    ;Not used

;~     _GDIPlus_Shutdown ()
    _SDL_Quit()

    Exit
EndFunc

Note: Needs SDL.au3, SDL.dll, SDL_sprig.au3, sprig.dll from HERE <-- link

Link to comment
Share on other sites

Hmmm... O.o interesting. Thanks for that different way Admiral, i'll look into it. :)

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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