Sign in to follow this  
Followers 0
CodyBarrett

TRON (game)

37 posts in this topic

#1 ·  Posted (edited)

here is my take on the TRON game, old school. ;)

OLD VERSIONS OF TRON

however, i have only gotten the basic movements down, with only one player, it will need MANY more tweaks to get done right, here is what i've got so faar, yeah its crazy because i'm creating a label every time it moves a certain amount of pixels, but idk how to incorporate GDI drawings into this :idiot:

if anyone has any ideas for an AI if anyone has any ideas for a BETTER AI that would be cool :idiot: or if i've made mistakes somewhere :)

OLD VERSION WITH GDI+

;================================
;INCLUDES========================
;================================
#include <GDIPLUS.au3>
#include <GUICONSTANTSEX.AU3>
#include <WINDOWSCONSTANTS.AU3>
#include <STATICCONSTANTS.AU3>
#include <ARRAY.AU3>
#include <MISC.AU3>
#include <COLOR.AU3>
;================================
;GLOBAL VARS=====================
;================================
Global $nBUFFER_SPEED = 10
Global $nCYCLE_SLEEP = 25
Global $nLINE_THICKNESS = 5
Global $nPLAYER_COUNT = 4
Global $nPLAYER_SURVIVED_COUNT = -1
Global $nGAME_TYPE = 0
Global $nGAME_TYPE_NEW = 0
;================================
;ARRAYs==========================
;================================
Dim $aGAME_TYPE[3] = [0,1,2];NORMAL,LAST-MAN-STANDING,DOMINATION
Dim $aHOT_KEYS[1] = ['74']
Dim $aWINSIZE[2] = [400,400]
Dim $aGRID[$aWINSIZE[0]/$nLINE_THICKNESS][$aWINSIZE[1]/$nLINE_THICKNESS]
Dim $aPLAYER_DEFAULT_DIRECTION[$nPLAYER_COUNT+1]
Dim $aPLAYER_TYPE[$nPLAYER_COUNT+1]
Dim $aPLAYER_DIRECTION[$nPLAYER_COUNT+1]
Dim $aPLAYER_STATUS[$nPLAYER_COUNT+1]
Dim $aPLAYER_COLOR[$nPLAYER_COUNT+1]
Dim $aPLAYER_COLOR_HANDLE[$nPLAYER_COUNT+1]
Dim $aSTART_POS[$nPLAYER_COUNT+1][2]
Dim $aCURRENT_POS[$nPLAYER_COUNT+1][2]
Dim $aPLAYER_SCORE[$nPLAYER_COUNT+1]
Dim $aPLAYER_KEYPRESS[$nPLAYER_COUNT+1][4]
Dim $aDIRECTION[4] = [0,1,2,3]
Dim $aOPPOSITE_DIRECTION[4] = [$aDIRECTION[2],$aDIRECTION[3],$aDIRECTION[0],$aDIRECTION[1]]
Dim $aSCORE_LABEL[$nPLAYER_COUNT+1]
Dim $aMENUID[6]
;================================
;================================
;================================
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;================================
;START MAIN SCRIPT===============
;================================
_GDIPlus_Startup()
;================================
Opt ('GUIONEVENTMODE',1)
;================================
Global $hMAIN_WINDOW = GUICreate ('',$aWINSIZE[0],$aWINSIZE[1]+40,Default,Default,Default,Default,Default)
GUISetOnEvent (-3,'exitprogram',$hMAIN_WINDOW)
GUISetState (@SW_SHOW,$hMAIN_WINDOW)
;================================
    Global $hGRAPHIC_GUI = _GDIPlus_GraphicsCreateFromHWND($hMAIN_WINDOW)                               ;Graphics AREA
    Global $hBMP_BUFF = _GDIPlus_BitmapCreateFromGraphics($aWINSIZE[0], $aWINSIZE[1], $hGRAPHIC_GUI)    ;USED TO BUFFER
    Global $hGRAPHIC = _GDIPlus_ImageGetGraphicsContext($hBMP_BUFF)                                     ;AREA to draw new graphics on
    _GDIPlus_GraphicsClear($hGRAPHIC, 0xFF000000)
    Global $hBACKGROUND_BRUSH = _GDIPlus_BrushCreateSolid(0xFF000000)
;================================
    $aMENUID[0] = GUICtrlCreateMenu ('Menu [pause]')
    $aMENUID[1] = GUICtrlCreateMenuItem ('Start/Restart' & @TAB & @TAB & '[F5]',$aMENUID[0])
    GUICtrlSetOnEvent ($aMENUID[1],'start_game')
    $aMENUID[2] = GUICtrlCreateMenuItem ('Normal Mode' & @TAB & @TAB & '(requires restart)',$aMENUID[0])
    GUICtrlSetOnEvent ($aMENUID[2],'change_mode0')
    $aMENUID[3] = GUICtrlCreateMenuItem ('Last-Man-Standing Mode' & @TAB & @TAB & '(requires restart)',$aMENUID[0])
    GUICtrlSetOnEvent ($aMENUID[3],'change_mode1')
    $aMENUID[4] = GUICtrlCreateMenuItem ('Domination Mode' & @TAB & @TAB & '(requires restart)',$aMENUID[0])
    GUICtrlSetOnEvent ($aMENUID[4],'change_mode2')
    $aMENUID[5] = GUICtrlCreateMenuItem ('EXIT' & @TAB & @TAB & '[ESC]',$aMENUID[0])
    GUICtrlSetOnEvent ($aMENUID[5],'exitprogram')
;================================
    ProgressOn ('Loading...','Please Wait...','',Default,Default,1)
        For $nX = 0 To UBound ($aGRID,1)-1
            For $nY = 0 To UBound ($aGRID,2)-1
                $aGRID[$nX][$nY] = 0
            Next
            $nPERCENT = Round (($nX/(UBound ($aGRID,1)-1))*100,2)
            ProgressSet ($nPERCENT,$nPERCENT & '%','Please Wait...')
        Next
    ProgressOff ()
;================================
;PLAYER CREATION=================
;================================
;create_player(player_number,0 for ai OR 1 for user,x,y,[up,[right,[left,[down]]]])
create_player (1,1,1,1,1,'0xFF0000','57','44','53','41')                            ;PLAYER1 1 = user
create_player (2,0,3,(UBound ($aGRID,1)-1)-1,(UBound ($aGRID,2)-1)-1,'0x0000FF')    ;PLAYER2 0 = ai
create_player (3,0,1,1,(UBound ($aGRID,2)-1)-1,'0xFF00FF')                          ;PLAYER3 0 = ai
create_player (4,0,3,(UBound ($aGRID,1)-1)-1,1,'0x00FF00')                          ;PLAYER4 0 = ai
;================================
For $nPLAYER = 1 To $nPLAYER_COUNT
    $aSCORE_LABEL[$nPLAYER] = GUICtrlCreateLabel ('Player' & $nPLAYER & ' Score: ' & 0,($nPLAYER-1)*($aWINSIZE[0]/$nPLAYER_COUNT),$aWINSIZE[1],$aWINSIZE[0]/$nPLAYER_COUNT,20,$SS_CENTERIMAGE)
    GUICtrlSetBkColor ($aSCORE_LABEL[$nPLAYER],$aPLAYER_COLOR[$nPLAYER])
    GUICtrlSetColor ($aSCORE_LABEL[$nPLAYER],invert_colour($aPLAYER_COLOR[$nPLAYER]))
Next
;================================
;CONSTANT LOOPS==================
;================================
AdlibRegister ('BUFFER',$nBUFFER_SPEED)
AdlibRegister ('set_visuals',$nBUFFER_SPEED)
AdlibRegister ('hot_key_check',$nCYCLE_SLEEP)
AdlibRegister ('detect_user_direction',$nCYCLE_SLEEP)
AdlibRegister ('detect_ai_direction',$nCYCLE_SLEEP)
GUIRegisterMsg(0xF, 'WM_PAINT'); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3)
GUIRegisterMsg(0x85, 'WM_PAINT'); $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize.
;================================
;END MAIN SCRIPT=================
;================================
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;================================
;MAIN LOOP=======================
;================================
While True
    CYCLE ()
    Sleep ($nCYCLE_SLEEP)
WEnd
;================================
;================================
;================================
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;================================
;START FUNCTIONS=================
;================================
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;MISCELLANCIOUS--------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
Func BUFFER ()
    _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI, $hBMP_BUFF, 0, 0)
EndFunc
Func hot_key_check ()
    Local $n
    For $n = 0 To UBound ($aHOT_KEYS)-1
        If _IsPressed ($aHOT_KEYS[$n]) Then
            hot_key_action ($n)
            Return
        EndIf
    Next
EndFunc
Func hot_key_action ($nKEY)
    Switch $nKEY
        Case 0
            start_game ()
            Return
        Case Else
            Return
    EndSwitch
EndFunc
Func invert_colour ($bCOLOUR)
    Local $bRED = Hex (255-_ColorGetRed($bCOLOUR),2)
    Local $bGREEN = Hex (255-_ColorGetGreen($bCOLOUR),2)
    Local $bBLUE = Hex (255-_ColorGetBlue($bCOLOUR),2)
    Local $bINVERT = '0x' & $bRED & $bGREEN & $bBLUE
    Return $bINVERT
EndFunc
Func set_visuals ()
    Local $nPLAYER
    For $nPLAYER = 1 To $nPLAYER_COUNT
        If StringTrimLeft (GUICtrlRead ($aSCORE_LABEL[$nPLAYER]),StringLen ('player'&$nPLAYER  & ' score: ')) <> $aPLAYER_SCORE[$nPLAYER] Then
            GUICtrlSetData ($aSCORE_LABEL[$nPLAYER],'player'&$nPLAYER  & ' score: ' & $aPLAYER_SCORE[$nPLAYER])
        EndIf
    Next
EndFunc
Func WM_PAINT($hWND, $MSG, $wPARAM, $lPARAM)
    _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI, $hBMP_BUFF,0,0)
    _WinAPI_RedrawWindow($hWND,Default,Default, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)); , $RDW_ALLCHILDREN
EndFunc
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;USER INTERACTION FUNCTIONS--------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
Func change_mode0 ()
    $nGAME_TYPE_NEW = 0
EndFunc
Func change_mode1 ()
    $nGAME_TYPE_NEW = 1
EndFunc
Func change_mode2 ()
    $nGAME_TYPE_NEW = 2
EndFunc
Func detect_user_direction ()
    Local $nPLAYER = 1
    Local $nDIRECTION = 0
    For $nPLAYER = 1 To $nPLAYER_COUNT
        If $aPLAYER_STATUS[$nPLAYER] = True Then
            If $aPLAYER_TYPE[$nPLAYER] = 1 Then
                For $nDIRECTION = 0 To 3
                    If _IsPressed ($aPLAYER_KEYPRESS[$nPLAYER][$nDIRECTION]) Then
                        change_direction ($nPLAYER,$nDIRECTION)
                        Return
                    EndIf
                Next
            EndIf
        EndIf
    Next
EndFunc
Func exitprogram ()
    For $nPLAYER = 1 To $nPLAYER_COUNT
        _GDIPlus_BrushDispose ($aPLAYER_COLOR_HANDLE[$nPLAYER])
    Next
    _GDIPlus_BrushDispose($hBACKGROUND_BRUSH)
    _GDIPlus_GraphicsDispose($hGRAPHIC)
    _GDIPlus_BitmapDispose ($hBMP_BUFF)
    _GDIPlus_Shutdown()
    Exit
EndFunc
Func start_game ()
    If WinGetHandle ('[active]') = $hMAIN_WINDOW Then
        Local $nPLAYER = 1
        Local $nPERCENT
        ProgressOn ('Loading...','Please Wait...','',Default,Default,1)
        For $nPLAYER = 1 To $nPLAYER_COUNT
            reset_player ($nPLAYER)
            $aCURRENT_POS[$nPLAYER][0] = $aSTART_POS[$nPLAYER][0]
            $aCURRENT_POS[$nPLAYER][1] = $aSTART_POS[$nPLAYER][1]
            $aPLAYER_DIRECTION[$nPLAYER] = $aPLAYER_DEFAULT_DIRECTION[$nPLAYER]
            $aPLAYER_STATUS[$nPLAYER] = True
            $aPLAYER_SCORE[$nPLAYER] = 1
            $nPERCENT = Round (($nPLAYER/$nPLAYER_COUNT)*100,2)
            ProgressSet ($nPERCENT,$nPERCENT & '%','Please Wait...')
        Next
        ProgressOff ()
        $nGAME_TYPE = $nGAME_TYPE_NEW
        $nPLAYER_SURVIVED_COUNT = $nPLAYER_COUNT
    EndIf
EndFunc
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;AI FUNCTIONS----------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
Func detect_ai_direction ()
    Local $nX
    Local $nY
    Local $nCHOICE
    Local $nDIRECTION
    Local $nDIRECTION_PREVIOUS
    Local $nCTRLID
    Local $nPLAYER
    Local $nMAX
    For $nPLAYER = 1 To $nPLAYER_COUNT
        If $aPLAYER_STATUS[$nPLAYER] = True Then
            If $aPLAYER_TYPE[$nPLAYER] = 0 Then
                $nDIRECTION_PREVIOUS = $aPLAYER_DIRECTION[$nPLAYER]
                $nMAX = Floor (($nCYCLE_SLEEP*3)/2)-1
                $nCHOICE = Random (0,$nMAX,1)
                If $nCHOICE = 0 Then
                    For $n = 0 To 3
                        $nDIRECTION = get_random_direction ($aPLAYER_DIRECTION[$nPLAYER],$aOPPOSITE_DIRECTION[$aPLAYER_DIRECTION[$nPLAYER]])
                        change_direction ($nPLAYER,$nDIRECTION)
                        If check_for_crash (move_player (0,$nPLAYER,1),move_player(1,$nPLAYER,1)) = 0 Then
                            ExitLoop
                        Else
                            If $n = 3 Then
                                change_direction ($nPLAYER,$nDIRECTION_PREVIOUS)
                            EndIf
                        EndIf
                    Next
                Else
                    $nDIRECTION = search_sibling_squares ($nPLAYER)
                    change_direction ($nPLAYER,$nDIRECTION)
                    If check_for_crash (move_player (0,$nPLAYER,1),move_player(1,$nPLAYER,1)) <> 0 Then
                        change_direction ($nPLAYER,$nDIRECTION_PREVIOUS)
                    EndIf
                EndIf
            EndIf
        EndIf
    Next
EndFunc
Func search_sibling_squares ($nPLAYER)
    Local $nDIRECTION
    Local $nDIRECTION_PREVIOUS =  $aPLAYER_DIRECTION[$nPLAYER]
    If check_for_crash (move_player (0,$nPLAYER,1),move_player(1,$nPLAYER,1)) = 0 Then
        Return $nDIRECTION_PREVIOUS
    Else
        For $nDIRECTION = 0 To 3
            change_direction ($nPLAYER,$nDIRECTION)
            If check_for_crash (move_player (0,$nPLAYER,1),move_player(1,$nPLAYER,1)) = 0 Then
                Return $nDIRECTION
            EndIf
        Next
        Return $nDIRECTION_PREVIOUS
    EndIf
EndFunc
Func get_random_direction ($nDIRECTION_NO_GO_1,$nDIRECTION_NO_GO_2)
    Local $nDIRECTION = Random (0,3,1)
    If $nDIRECTION = $nDIRECTION_NO_GO_1 Or $nDIRECTION = $nDIRECTION_NO_GO_2 Then
        $nDIRECTION = get_random_direction ($nDIRECTION_NO_GO_1,$nDIRECTION_NO_GO_2)
    EndIf
    Return $nDIRECTION
EndFunc
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;BACKGROUND FUNCTIONS--------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
;----------------------------------------------------------
Func change_direction ($nPLAYER,$nDIRECTION)
    If  $aPLAYER_DIRECTION[$nPLAYER] =  $aDIRECTION[$nDIRECTION] Then
        Return
    Else
        If $aPLAYER_DIRECTION[$nPLAYER] = $aOPPOSITE_DIRECTION[$nDIRECTION] Then
            Return
        Else
            $aPLAYER_DIRECTION[$nPLAYER] =  $aDIRECTION[$nDIRECTION]
        EndIf
    EndIf
EndFunc
Func check_for_crash ($nX,$nY)
    If  $nX*$nLINE_THICKNESS < 0 Or $nY*$nLINE_THICKNESS < 0 Then
        Return -1
    ElseIf $nX*$nLINE_THICKNESS >= $aWINSIZE[0] Or $nY*$nLINE_THICKNESS >= $aWINSIZE[1] Then
        Return -1
    ElseIf $aGRID[$nX][$nY] <> 0 Then
        Return $aGRID[$nX][$nY]
    Else
        Return 0
    EndIf
EndFunc
Func create_player ($nPLAYER,$nTYPE,$nDIRECTION,$nX,$nY,$nCOLOR,$sUP=0,$sRIGHT=0,$sDOWN=0,$sLEFT=0)
    $aPLAYER_TYPE[$nPLAYER] = $nTYPE
    $aPLAYER_STATUS[$nPLAYER] = True
    $aPLAYER_DEFAULT_DIRECTION[$nPLAYER] = $nDIRECTION
    $aPLAYER_DIRECTION[$nPLAYER] = $nDIRECTION
    $aSTART_POS[$nPLAYER][0] = $nX
    $aSTART_POS[$nPLAYER][1] = $nY
    $aCURRENT_POS[$nPLAYER][0] = $nX
    $aCURRENT_POS[$nPLAYER][1] = $nY
    $aPLAYER_COLOR[$nPLAYER] = $nCOLOR
    $aPLAYER_COLOR_HANDLE[$nPLAYER] = _GDIPlus_BrushCreateSolid ('0xFF' & StringTrimLeft ($nCOLOR,2))
    $aPLAYER_KEYPRESS[$nPLAYER][0] = $sUP
    $aPLAYER_KEYPRESS[$nPLAYER][1] = $sRIGHT
    $aPLAYER_KEYPRESS[$nPLAYER][2] = $sDOWN
    $aPLAYER_KEYPRESS[$nPLAYER][3] = $sLEFT
EndFunc
Func CYCLE ()
    Local $nPLAYER = 1
    Local $nX
    Local $nY
    Local $nCRASH_VALUE
    If $nPLAYER_SURVIVED_COUNT > 1 Then
        For $nPLAYER = 1 To $nPLAYER_COUNT
            If $aPLAYER_STATUS[$nPLAYER] = True Then
                $aCURRENT_POS[$nPLAYER][0] = move_player (0,$nPLAYER,1)
                $aCURRENT_POS[$nPLAYER][1] = move_player (1,$nPLAYER,1)
                $nCRASH_VALUE = check_for_crash ($aCURRENT_POS[$nPLAYER][0],$aCURRENT_POS[$nPLAYER][1])
                If $nCRASH_VALUE = 0 Then
                    position_player ($nPLAYER)
                Else
                    delete_player ($nPLAYER,$nCRASH_VALUE)
                EndIf
            EndIf
        Next
    Else
        end_game()
    EndIf
EndFunc
Func delete_player ($nPLAYER,$nCRASH_VALUE)
    Local $nX = 0
    Local $nY = 0
    Switch $nGAME_TYPE
        Case $aGAME_TYPE[0]
            reset_player ($nPLAYER)
        Case $aGAME_TYPE[1]
            reset_player ($nPLAYER)
        Case $aGAME_TYPE[2]
            If $nCRASH_VALUE <> -1 And $nCRASH_VALUE <> $nPLAYER Then
                For $nX = 0 To UBound ($aGRID,1)-1
                    For $nY = 0 To UBound ($aGRID,2)-1
                        If GUICtrlRead ($aGRID[$nX][$nY]) = $nPLAYER Then
                            $aGRID[$nX][$nY] = $nCRASH_VALUE
                            draw_square ($nCRASH_VALUE,$nX,$nY)
                        EndIf
                    Next
                Next
                $aPLAYER_SCORE[$nCRASH_VALUE] =  $aPLAYER_SCORE[$nCRASH_VALUE]+$aPLAYER_SCORE[$nPLAYER]
            Else
                reset_player ($nPLAYER)
            EndIf
    EndSwitch
    $aPLAYER_STATUS[$nPLAYER] = False
    $nPLAYER_SURVIVED_COUNT = $nPLAYER_SURVIVED_COUNT-1
EndFunc
Func draw_square ($nPLAYER,$nX=-1,$nY=-1)
    If $nX = -1 Or $nY = -1 Then
        $nX = $aCURRENT_POS[$nPLAYER][0]
        $nY = $aCURRENT_POS[$nPLAYER][1]
    EndIf
    _GDIPlus_GraphicsFillRect($hGRAPHIC, $nX*$nLINE_THICKNESS, $nY*$nLINE_THICKNESS, $nLINE_THICKNESS, $nLINE_THICKNESS, $aPLAYER_COLOR_HANDLE[$nPLAYER])
    _GDIPlus_GraphicsDrawRect($hGRAPHIC, $nX*$nLINE_THICKNESS, $nY*$nLINE_THICKNESS, $nLINE_THICKNESS,$nLINE_THICKNESS)
EndFunc
Func end_game ()
    Local $nX = 0
    Local $nY = 0
    Local $nPLAYER = 1
    Local $nPLAYER_SCORE = 1
    Local $nWINNER = 0
    If $nPLAYER_SURVIVED_COUNT = 0 Then
        MsgBox (64,'GAME OVER','There Was ' & $nWINNER & ' Winners...',Default,WinGetHandle ('[active]'))
        $nPLAYER_SURVIVED_COUNT = -1
    ElseIf $nPLAYER_SURVIVED_COUNT > 0 Then
        For $nPLAYER = 1 To $nPLAYER_COUNT
            If $aPLAYER_STATUS[$nPLAYER] = True Then
                Switch $nGAME_TYPE
                    Case $aGAME_TYPE[0]
                        $nWINNER = _ArrayMaxIndex ($aPLAYER_SCORE,1)
                    Case $aGAME_TYPE[1]
                        $nWINNER = $nPLAYER
                    Case $aGAME_TYPE[2]
                        If $nPLAYER = _ArrayMaxIndex ($aPLAYER_SCORE,1) Then
                            $nWINNER = $nPLAYER
                        Else
                            $nWINNER = _ArrayMaxIndex ($aPLAYER_SCORE,1)
                        EndIf
                EndSwitch
                MsgBox (64,'GAME OVER','Player' & $nWINNER & ' WINS!' & @CRLF & @CRLF & 'Player' & $nWINNER & ' Has A Score Of ' & $aPLAYER_SCORE[$nWINNER],Default,WinGetHandle ('[active]'))
                $nPLAYER_SURVIVED_COUNT = -1
                Return
            EndIf
        Next
    Else
        Return
    EndIf
EndFunc
Func move_player ($nDIRECTION,$nPLAYER,$nDISTANCE)
    Switch $aPLAYER_DIRECTION[$nPLAYER]
        Case $aDIRECTION[0]
            If $nDIRECTION = 0 Then
                Return $aCURRENT_POS[$nPLAYER][0]
            ElseIf $nDIRECTION = 1 Then
                Return $aCURRENT_POS[$nPLAYER][1]-$nDISTANCE
            EndIf
        Case $aDIRECTION[1]
            If $nDIRECTION = 0 Then
                Return $aCURRENT_POS[$nPLAYER][0]+$nDISTANCE
            ElseIf $nDIRECTION = 1 Then
                Return $aCURRENT_POS[$nPLAYER][1]
            EndIf
        Case $aDIRECTION[2]
            If $nDIRECTION = 0 Then
                Return $aCURRENT_POS[$nPLAYER][0]
            ElseIf $nDIRECTION = 1 Then
                Return $aCURRENT_POS[$nPLAYER][1]+$nDISTANCE
            EndIf
        Case $aDIRECTION[3]
            If $nDIRECTION = 0 Then
                Return $aCURRENT_POS[$nPLAYER][0]-$nDISTANCE
            ElseIf $nDIRECTION = 1 Then
                Return $aCURRENT_POS[$nPLAYER][1]
            EndIf
    EndSwitch
EndFunc
Func position_player ($nPLAYER)
    Local $nX = $aCURRENT_POS[$nPLAYER][0]
    Local $nY = $aCURRENT_POS[$nPLAYER][1]
    $aGRID[$nX][$nY] = $nPLAYER
    draw_square ($nPLAYER,$nX,$nY)
    $aPLAYER_SCORE[$nPLAYER] = $aPLAYER_SCORE[$nPLAYER]+1
EndFunc
Func reset_player ($nPLAYER)
    Local $nX = 0
    Local $nY = 0
    For $nX = 0 To UBound ($aGRID,1)-1
        For $nY = 0 To UBound ($aGRID,2)-1
            If $aGRID[$nX][$nY] = $nPLAYER Then
                $aGRID[$nX][$nY] = 0
                _GDIPlus_GraphicsFillRect($hGRAPHIC, $nX*$nLINE_THICKNESS, $nY*$nLINE_THICKNESS, $nLINE_THICKNESS, $nLINE_THICKNESS)
            EndIf
        Next
    Next
EndFunc
;================================
;END FUNCTIONS===================
;================================

OLD VERSION remastered and rewritten WITH GDI+

image is recommended: (download and place in the same folder)

post-41162-0-87075500-1299171932_thumb.p

#NoTrayIcon
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <misc.au3>
#include <COLOR.AU3>
#include <Array.AU3>
_GDIPlus_Startup()
Global $aWINDOW_INFORMATION[2][3]
        $aWINDOW_INFORMATION[0][0] = 800;(width)
        $aWINDOW_INFORMATION[0][1] = 600 ;(height)
        $aWINDOW_INFORMATION[1][0] = $aWINDOW_INFORMATION[0][0]*0.8 ;(width)
        $aWINDOW_INFORMATION[1][1] = $aWINDOW_INFORMATION[0][1]*0.8 ;(height)
Global $nGAME_TYPE = 1
    ;1 = userVSai deathmatch 2 player
    ;2 = aiVSai deathmatch 2 player
    ;3 = userVSai free-for-all 4 player
    ;4 = aiVSai free-for-all 4 player
Global $nPREVIOUS_CTRLID = 1
Global $nPLAYER_COUNT = 2
Global $nCYCLE_SLEEP = 40
Global $nBUFFER_SPEED = 35
Global $nPLAYER_SIZE = 5
Global $nGAME_STATUS = False
    ;false = N\A
    ;true = running
Global $hTRON_LOGO = _GDIPlus_ImageLoadFromFile(@ScriptDir & '\TRON3.png')
Global $hGRAPHIC_GUI
Global $hMAIN_GRAPHIC
Global $aPLAYER_BMP_BUFF[5] = ['',False,False,False,False]
Global $aPLAYER_GRAPHIC[5] = ['',False,False,False,False]
Global $hBACKGROUND_BMP_BUFF
Global $bBUFFERING = True
Global $bPAINTING = True

Global $aGRID
Global $aOPPOSITE_DIRECTION[4] = [2,3,0,1]

GUIRegisterMsg(0xF, "MY_PAINT")
GUIRegisterMsg(0x85, "MY_PAINT")
AdlibRegister ('BUFFER',$nBUFFER_SPEED)
MAIN_MENU ()
Func MAIN_MENU ()
    Local $nGUI_CTRLID[6]
    Local $nCOUNT = 0
    Local $nMSG
    Local $nX = $aWINDOW_INFORMATION[0][0] / 4
    Local $nY = $aWINDOW_INFORMATION[0][1] / 1.5
    Local $nW = $aWINDOW_INFORMATION[0][0] / 2
    Local $nH = $aWINDOW_INFORMATION[0][1] / 30
    $aWINDOW_INFORMATION[0][2] = GUICreate (@ScriptName,$aWINDOW_INFORMATION[0][0],$aWINDOW_INFORMATION[0][1],Default,Default,$WS_POPUPWINDOW,$WS_EX_CLIENTEDGE,Default)
    GUISetBkColor (0x000000,$aWINDOW_INFORMATION[0][2])
    GUISetFont (8,999,'','Tahoma',$aWINDOW_INFORMATION[0][2])
    GUICtrlSetDefBkColor (0xFF0000,$aWINDOW_INFORMATION[0][2])
    GUICtrlSetDefColor (0xFFFFFF,$aWINDOW_INFORMATION[0][2])
        $hMAIN_GRAPHIC = _GDIPlus_GraphicsCreateFromHWND($aWINDOW_INFORMATION[0][2])
        $nGUI_CTRLID[0] = GUICtrlCreateLabel ('START',$nX*1.5,$nY,$nW/2,$nH,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
        $nY += $nH*1.5
        $nGUI_CTRLID[1] = GUICtrlCreateLabel ('2 Players' & @TAB & 'USER vs AI' & @TAB & 'Death-Match',$nX,$nY,$nW,$nH,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
        $nY += $nH*1.5
        $nGUI_CTRLID[2] = GUICtrlCreateLabel ('2 Players' & @TAB & 'AI vs AI' & @TAB & 'Death-Match',$nX,$nY,$nW,$nH,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
        $nY += $nH*1.5
        $nGUI_CTRLID[3] = GUICtrlCreateLabel ('4 Players' & @TAB & 'USER vs AI' & @TAB & 'Free-For-All',$nX,$nY,$nW,$nH,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
        $nY += $nH*1.5
        $nGUI_CTRLID[4] = GUICtrlCreateLabel ('4 Players' & @TAB & 'AI vs AI' & @TAB & 'Free-For-All' ,$nX,$nY,$nW,$nH,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
        $nY += $nH*1.5
        $nGUI_CTRLID[5] = GUICtrlCreateLabel ('QUIT',$nX*1.5,$nY,$nW/2,$nH,BitOR ($SS_CENTER,$SS_CENTERIMAGE))
        For $nCOUNT = 0 To 5
            GUICtrlSetCursor ($nGUI_CTRLID[$nCOUNT],0)
        Next
        GUICtrlSetBkColor ($nGUI_CTRLID[1],0x0000FF)
        $nPREVIOUS_CTRLID = $nGUI_CTRLID[1]
    GUISetState (@SW_SHOW,$aWINDOW_INFORMATION[0][2])
    $bBUFFERING = False
    $bPAINTING = False
    MY_PAINT (0,0,0,0)
    While True
        $nMSG = GUIGetMsg()
        If _IsPressed ('26') Then ;UP
            If $nGAME_TYPE > 1 Then
                $nMSG = $nGUI_CTRLID[$nGAME_TYPE-1]
            Else
                $nMSG = $nGUI_CTRLID[4]
            EndIf
        ElseIf _IsPressed ('28') Then ;DOWN
            If $nGAME_TYPE < 4 Then
                $nMSG = $nGUI_CTRLID[$nGAME_TYPE+1]
            Else
                $nMSG = $nGUI_CTRLID[1]
            EndIf
        ElseIf _IsPressed ('0D') Then ;ENTER
            $nMSG = $nGUI_CTRLID[0]
        EndIf
        Switch $nMSG
            Case $nGUI_CTRLID[0]
                START_GAME ()
            Case $nGUI_CTRLID[1]
                GUICtrlSetBkColor ($nPREVIOUS_CTRLID,0xFF0000)
                GUICtrlSetBkColor ($nGUI_CTRLID[1],0x0000FF)
                $nPREVIOUS_CTRLID = $nGUI_CTRLID[1]
                $nGAME_TYPE = 1
                $nPLAYER_COUNT = 2
            Case $nGUI_CTRLID[2]
                GUICtrlSetBkColor ($nPREVIOUS_CTRLID,0xFF0000)
                GUICtrlSetBkColor ($nGUI_CTRLID[2],0x0000FF)
                $nPREVIOUS_CTRLID = $nGUI_CTRLID[2]
                $nGAME_TYPE = 2
                $nPLAYER_COUNT = 2

            Case $nGUI_CTRLID[3]
                GUICtrlSetBkColor ($nPREVIOUS_CTRLID,0xFF0000)
                GUICtrlSetBkColor ($nGUI_CTRLID[3],0x0000FF)
                $nPREVIOUS_CTRLID = $nGUI_CTRLID[3]
                $nGAME_TYPE = 3
                $nPLAYER_COUNT = 4

            Case $nGUI_CTRLID[4]
                GUICtrlSetBkColor ($nPREVIOUS_CTRLID,0xFF0000)
                GUICtrlSetBkColor ($nGUI_CTRLID[4],0x0000FF)
                $nPREVIOUS_CTRLID = $nGUI_CTRLID[4]
                $nGAME_TYPE = 4
                $nPLAYER_COUNT = 4
            Case $nGUI_CTRLID[5]
                _GDIPlus_Shutdown()
                Exit
            Case $GUI_EVENT_CLOSE
                _GDIPlus_Shutdown()
                Exit
            Case Else
                ; do nothing
        EndSwitch
    WEnd
EndFunc







Func MY_PAINT($hWnd, $msg, $wParam, $lParam)
    If $bPAINTING = False Then
        $bPAINTING = True
        If $nGAME_STATUS = True Then
            Local $iX = 0
            Local $iY = 0
            _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI, $hBACKGROUND_BMP_BUFF,$iX,$iY)
            Local $nCOUNT
            For $nCOUNT = 1 To $nPLAYER_COUNT
                If $aPLAYER_BMP_BUFF[$nCOUNT] <> False Then
                    _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI, $aPLAYER_BMP_BUFF[$nCOUNT], $iX,$iY)
                EndIf
            Next
        Else
            Local $nScrX = 0
            Local $nScrY = 0
            Local $nDstX = 0
            Local $nDstY = 0
            Local $nW = _GDIPlus_ImageGetWidth($hTRON_LOGO)
            Local $nH = _GDIPlus_ImageGetHeight ($hTRON_LOGO)
            _GDIPlus_GraphicsDrawImageRectRect($hMAIN_GRAPHIC, $hTRON_LOGO,$nScrX,$nScrY,$nW,$nH,$nDstX,$nDstY,$aWINDOW_INFORMATION[0][0],$aWINDOW_INFORMATION[0][1]/2)
        EndIf
        $bPAINTING = False
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc
Func BUFFER ()
    If $bBUFFERING = False Then
        $bBUFFERING = True
        If $nGAME_STATUS = True Then
            Local $iX = 0
            Local $iY = 0
            _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI, $hBACKGROUND_BMP_BUFF,$iX, $iY)
            Local $nCOUNT
            For $nCOUNT = 1 To $nPLAYER_COUNT
                If $aPLAYER_BMP_BUFF[$nCOUNT] <> False Then
                    _GDIPlus_GraphicsDrawImage($hGRAPHIC_GUI, $aPLAYER_BMP_BUFF[$nCOUNT], $iX,$iY)
                EndIf
            Next
        EndIf
        $bBUFFERING = False
    EndIf
EndFunc














Func crash ($nX,$nY,$aGRID)
    If $nX*$nPLAYER_SIZE < 0 Or $nY*$nPLAYER_SIZE < 0 Then
        Return True
    ElseIf $nX*$nPLAYER_SIZE >= $aWINDOW_INFORMATION[1][0] Or $nY*$nPLAYER_SIZE >= $aWINDOW_INFORMATION[1][1]  Then
        Return True
    ElseIf $aGRID[$nX][$nY] <> 0 Then
        Return True
    Else
        Return False
    EndIf
EndFunc
Func move_pos ($nDIMENSION,$nDIRECTION,$nX,$nY,$bREVERT=False)
    Switch $nDIRECTION
        Case 0
            If $bREVERT = False Then
                $nY -= 1
            ElseIf $bREVERT = True Then
                $nY += 1
            EndIf
        Case 1
            If $bREVERT = False Then
                $nX += 1
            ElseIf $bREVERT = True Then
                $nX -= 1
            EndIf
        Case 2
            If $bREVERT = False Then
                $nY += 1
            ElseIf $bREVERT = True Then
                $nY -= 1
            EndIf
        Case 3
            If $bREVERT = False Then
                $nX -= 1
            ElseIf $bREVERT = True Then
                $nX += 1
            EndIf
    EndSwitch
    If $nDIMENSION = 0 Then
        Return $nX
    ElseIf $nDIMENSION = 1 Then
        Return $nY
    EndIf
EndFunc
Func invert_colour ($bCOLOUR)
    Local $bRED = Hex (255-_ColorGetRed($bCOLOUR),2)
    Local $bGREEN = Hex (255-_ColorGetGreen($bCOLOUR),2)
    Local $bBLUE = Hex (255-_ColorGetBlue($bCOLOUR),2)
    Local $bINVERT = '0x' & $bRED & $bGREEN & $bBLUE
    Return $bINVERT
EndFunc
Func ai_find_path ($nDIRECTION,$nXi,$nYi,$aGRID,$nDEPTH)
    Local $nCHOICE
    Local $nX
    Local $nY
    Local $nDIRECTION_TEMP = 0
    If $nDEPTH = 0 Then
        Return $nDIRECTION
    Else
        Local $nCHOICE = Random(1,50,1)
        Local $nX = move_pos(0,$nDIRECTION,$nXi,$nYi)
        Local $nY = move_pos(1,$nDIRECTION,$nXi,$nYi)
        If $nCHOICE = 1 Or crash ($nX,$nY,$aGRID) = True Then
            Do
                $nDIRECTION_TEMP = Random (0,3,1)
            Until $nDIRECTION_TEMP <> $nDIRECTION And $nDIRECTION_TEMP <> $aOPPOSITE_DIRECTION[$nDIRECTION]
            $nX = move_pos(0,$nDIRECTION_TEMP,$nX,$nY)
            $nY = move_pos(1,$nDIRECTION_TEMP,$nX,$nY)
            If crash ($nX,$nY,$aGRID) = True Then
                $nDIRECTION_TEMP = $aOPPOSITE_DIRECTION[$nDIRECTION_TEMP]
                $nX = move_pos(0,$nDIRECTION_TEMP,$nX,$nY)
                $nY = move_pos(1,$nDIRECTION_TEMP,$nX,$nY)
                If crash ($nX,$nY,$aGRID) = False Then
                    $nDIRECTION_TEMP = ai_find_path ($nDIRECTION_TEMP,$nX,$nY,$aGRID,$nDEPTH-1)
                EndIf
            Else
                $nDIRECTION_TEMP = ai_find_path ($nDIRECTION_TEMP,$nX,$nY,$aGRID,$nDEPTH-1)
            EndIf
        Else
            Return $nDIRECTION
        EndIf
    EndIf
    Return $nDIRECTION_TEMP
EndFunc















Func START_GAME ()
    Local $nDIRECTION
    Local $nGRIDxMAX = $aWINDOW_INFORMATION[1][0]/$nPLAYER_SIZE
    Local $nGRIDyMAX = $aWINDOW_INFORMATION[1][1]/$nPLAYER_SIZE
    Local $aGRID[$nGRIDxMAX+1][$nGRIDyMAX+1]
    Local $aPLAYER_TYPE[5]
    Local $aPLAYER_STATUS[5]
    Local $aPLAYER_X[5]
    Local $aPLAYER_Y[5]
    Local $aPLAYER_DIRECTION[5]
    Local $aPLAYER_COLOR[5]
    Local $aPLAYER_BRUSH_HWND[5]
    Local $aPLAYER_KEYS[5][4]
    Local $nX
    Local $nY
    Local $nCOUNT
    Local $nINDEX
    Local $sBACK_GROUND_COLOR = '0x' & Hex(Random (0x000000,0xFFFFFF,1),6)
    Global $aPLAYER_BMP_BUFF[5] = ['',False,False,False,False]
    Global $aPLAYER_GRAPHIC[5] = ['',False,False,False,False]
    $aWINDOW_INFORMATION[1][2] = GUICreate("GDIPlus Example", $aWINDOW_INFORMATION[1][0], $aWINDOW_INFORMATION[1][1],Default,Default,$WS_POPUPWINDOW,Default,$aWINDOW_INFORMATION[0][2])
    GUISetBkColor ($sBACK_GROUND_COLOR,$aWINDOW_INFORMATION[1][2])


    ;creating the drawing area
    $hGRAPHIC_GUI = _GDIPlus_GraphicsCreateFromHWND($aWINDOW_INFORMATION[1][2])

    ;creating the visual grid
    $hBACKGROUND_BMP_BUFF = _GDIPlus_BitmapCreateFromGraphics($aWINDOW_INFORMATION[1][0], $aWINDOW_INFORMATION[1][1], $hGRAPHIC_GUI)
    $hBACKGROUND_GRAPHIC = _GDIPlus_ImageGetGraphicsContext($hBACKGROUND_BMP_BUFF)
    $hGRID_BRUSH = _GDIPlus_BrushCreateSolid('0x20' & StringTrimLeft (invert_colour ($sBACK_GROUND_COLOR),2))
    For $nX = 1 To $aWINDOW_INFORMATION[1][0] Step 20
        _GDIPlus_GraphicsFillRect ($hBACKGROUND_GRAPHIC,$nX,0,1,$aWINDOW_INFORMATION[1][1],$hGRID_BRUSH)
    Next
    For $nY = 1 To $aWINDOW_INFORMATION[1][1] Step 20
        _GDIPlus_GraphicsFillRect ($hBACKGROUND_GRAPHIC,0,$nY,$aWINDOW_INFORMATION[1][0],1,$hGRID_BRUSH)
    Next
    ;defining GRID array
    For $nX = 0 To $nGRIDxMAX
        For $nY = 0 To $nGRIDyMAX
            $aGRID[$nX][$nY] = 0
        Next
    Next


    ;player 1
    If $nGAME_TYPE = 1 Then
        $aPLAYER_TYPE[1] = True
    Else
        If $nGAME_TYPE = 3 Then
            $aPLAYER_TYPE[1] = True
        Else
            $aPLAYER_TYPE[1] = False
        EndIf
    EndIf
    $aPLAYER_STATUS[1] = True
    $aPLAYER_X[1] = 1
    $aPLAYER_Y[1] = 1
    $aPLAYER_DIRECTION[1] = 1
    $aPLAYER_COLOR[1] = '0xFF0000'
    $aPLAYER_BRUSH_HWND[1] = ''
    $aPLAYER_KEYS[1][0] = '57'
    $aPLAYER_KEYS[1][1] = '44'
    $aPLAYER_KEYS[1][2] = '53'
    $aPLAYER_KEYS[1][3] = '41'
;player 2
    $aPLAYER_TYPE[2] = False
    $aPLAYER_STATUS[2] = True
    $aPLAYER_X[2] = $nGRIDxMAX-2
    $aPLAYER_Y[2] = $nGRIDyMAX-2
    $aPLAYER_DIRECTION[2] = 3
    $aPLAYER_COLOR[2] = '0x0000FF'
    $aPLAYER_BRUSH_HWND[2] = ''
    If $nPLAYER_COUNT > 2 Then
        ;player 3
        $aPLAYER_TYPE[3] = False
        $aPLAYER_STATUS[3] = True
        $aPLAYER_X[3] = $nGRIDxMAX-2
        $aPLAYER_Y[3] = 1
        $aPLAYER_DIRECTION[3] = 2
        $aPLAYER_COLOR[3] = '0x00FF00'
        $aPLAYER_BRUSH_HWND[3] = ''
        ;player 4
        $aPLAYER_TYPE[4] = False
        $aPLAYER_STATUS[4] = True
        $aPLAYER_X[4] = 1
        $aPLAYER_Y[4] = $nGRIDyMAX-2
        $aPLAYER_DIRECTION[4] = 0
        $aPLAYER_COLOR[4] = '0xFF00FF'
        $aPLAYER_BRUSH_HWND[4] = ''
    EndIf


    For $nCOUNT = 1 To $nPLAYER_COUNT
        $aPLAYER_BMP_BUFF[$nCOUNT] = _GDIPlus_BitmapCreateFromGraphics($aWINDOW_INFORMATION[1][0], $aWINDOW_INFORMATION[1][1], $hGRAPHIC_GUI)
        $aPLAYER_GRAPHIC[$nCOUNT] = _GDIPlus_ImageGetGraphicsContext($aPLAYER_BMP_BUFF[$nCOUNT])
        $aPLAYER_BRUSH_HWND[$nCOUNT] = _GDIPlus_BrushCreateSolid('0xFF' & StringTrimLeft ($aPLAYER_COLOR[$nCOUNT],2))
        _GDIPlus_GraphicsClear($aPLAYER_GRAPHIC[$nCOUNT],'0x20' & StringTrimLeft ($sBACK_GROUND_COLOR,2))
    Next



    GUISetState(@SW_SHOW,$aWINDOW_INFORMATION[1][2])
    $nGAME_STATUS = True
    While True
        ;##################################################
        ;=================================================
        ;------------------------------------------------
        ;CYCLE
        For $nCOUNT = 1 To $nPLAYER_COUNT
            If $aPLAYER_STATUS[$nCOUNT] = True Then
                If $aPLAYER_TYPE[$nCOUNT] = True Then
                    ;direction USER
                    For $nDIRECTION = 0 To 3
                        If _IsPressed ($aPLAYER_KEYS[$nCOUNT][$nDIRECTION]) Then
                            $aPLAYER_DIRECTION[$nCOUNT] = $nDIRECTION
                            ExitLoop
                        EndIf
                    Next
                Else
                    ;direction AI
                    $aPLAYER_DIRECTION[$nCOUNT] = ai_find_path ($aPLAYER_DIRECTION[$nCOUNT],$aPLAYER_X[$nCOUNT],$aPLAYER_Y[$nCOUNT],$aGRID,2)
                EndIf
                $aPLAYER_X[$nCOUNT] = move_pos (0,$aPLAYER_DIRECTION[$nCOUNT],$aPLAYER_X[$nCOUNT],$aPLAYER_Y[$nCOUNT])
                $aPLAYER_Y[$nCOUNT] = move_pos (1,$aPLAYER_DIRECTION[$nCOUNT],$aPLAYER_X[$nCOUNT],$aPLAYER_Y[$nCOUNT])
                If crash ($aPLAYER_X[$nCOUNT],$aPLAYER_Y[$nCOUNT],$aGRID) = False Then
                    $aGRID[$aPLAYER_X[$nCOUNT]][$aPLAYER_Y[$nCOUNT]] = $nCOUNT
                    _GDIPlus_GraphicsFillRect($aPLAYER_GRAPHIC[$nCOUNT], $aPLAYER_X[$nCOUNT]*$nPLAYER_SIZE,$aPLAYER_Y[$nCOUNT]*$nPLAYER_SIZE, $nPLAYER_SIZE, $nPLAYER_SIZE,$aPLAYER_BRUSH_HWND[$nCOUNT])
                    _GDIPlus_GraphicsDrawRect($aPLAYER_GRAPHIC[$nCOUNT], $aPLAYER_X[$nCOUNT]*$nPLAYER_SIZE,$aPLAYER_Y[$nCOUNT]*$nPLAYER_SIZE, $nPLAYER_SIZE,$nPLAYER_SIZE)
                Else
                    _GDIPlus_GraphicsClear($aPLAYER_GRAPHIC[$nCOUNT], '0x20' & StringTrimLeft ($sBACK_GROUND_COLOR,2))
                    _GDIPlus_GraphicsDispose($aPLAYER_GRAPHIC[$nCOUNT])
                    _GDIPlus_BitmapDispose ($aPLAYER_BMP_BUFF[$nCOUNT])
                    _GDIPlus_BrushDispose($aPLAYER_BRUSH_HWND[$nCOUNT])
                    $aPLAYER_BMP_BUFF[$nCOUNT] = False
                    $aPLAYER_BRUSH_HWND[$nCOUNT] = False
                    $aPLAYER_GRAPHIC[$nCOUNT] = False
                    $aPLAYER_STATUS[$nCOUNT] = False
                EndIf
            EndIf
        Next
        Sleep ($nCYCLE_SLEEP)
        ;------------------------------------------------
        ;=================================================
        ;##################################################
        ;::::::::::::::::::::::::::::::::::::::::::::::::::
        ;##################################################
        ;=================================================
        ;------------------------------------------------
        ;GUI functions
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then
            $nGAME_STATUS = False
            For $nCOUNT = 1 To $nPLAYER_COUNT
                _GDIPlus_BrushDispose($aPLAYER_BRUSH_HWND[$nCOUNT])
                _GDIPlus_GraphicsDispose($aPLAYER_GRAPHIC[$nCOUNT])
                _GDIPlus_BitmapDispose ($aPLAYER_BMP_BUFF[$nCOUNT])
                $aPLAYER_BMP_BUFF[$nCOUNT] = False
                $aPLAYER_GRAPHIC[$nCOUNT] = False
            Next
            _GDIPlus_BrushDispose($hGRID_BRUSH)
            _GDIPlus_GraphicsDispose($hBACKGROUND_GRAPHIC)
            _GDIPlus_BitmapDispose ($hBACKGROUND_BMP_BUFF)
            _GDIPlus_GraphicsDispose($hGRAPHIC_GUI)
            GUIDelete ($aWINDOW_INFORMATION[1][2])
            Return
        EndIf
        ;------------------------------------------------
        ;=================================================
        ;##################################################
    WEnd
EndFunc

Hey guys, i've reqritten (again) the script, cut out the AI (its too difficult to make it work properly without glitches.

NEW VERSION OF TRON

controls

ESC brings back to main screen, exits when on the main screen

ENTER is the action button for main screen & pick bike screen

P1:

up=w

down=s

left=a

right=d

P2:

up,down,left,right=arrow keys

this is the new version, from scratch, UEZ helped with my knowledge of GDI+

all images are required. place them all in the same folder.

Edited by CodyBarrett
1 person likes this

Share this post


Link to post
Share on other sites



here is my take on the TRON game, old school. :)

however, i have only gotten the basic movements down, with only one player, it will need MANY more tweaks to get done right, here is what i've got so faar, yeah its crazy because i'm creating a label every time it moves a certain amount of pixels, but idk how to incorporate GDI drawings into this :idiot:

if anyone has any ideas for an AI that would be cool ;)

or if i've made mistakes somewhere o.o

Like it!

But you're going way to much calculating.

I was interested and made my own little version. :idiot:

I can't think of a way to create a smart AI yet.

Global $iColumns                                                = 75
Global $iRows                                                   = 75
Global $iTileSize                                               = 5

Global Const $iTargetFPS                                    = 30

Global $aField                                                  [$iColumns][$iRows]
Global $aChecked                                            [$iColumns][$iRows]

Global $iPlayerX                                                = 2
Global $iPlayerY                                                = 2
Global $iSpeedX                                             = 1
Global $iSpeedY                                             = 0

Global $iPlayerColor                                            = 0xFF0000
Global $iIdleColor                                          = 0x000000

HotKeySet("{UP}", "MoveUp")
HotKeySet("{RIGHT}", "MoveRight")
HotKeySet("{DOWN}", "MoveDown")
HotKeySet("{LEFT}", "MoveLeft")

Global $hWnd = GUICreate("", $iColumns * $iTileSize, $iRows * $iTileSize)
InitializeField()
SetPlayer()

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch

    UpdatePlayer()
    Sleep(1000 / $iTargetFPS)
WEnd

Func InitializeField()
    For $x = 0 To UBound($aField) - 1
        For $y = 0 To UBound($aField, 2) - 1

            $aField[$x][$y] = GUICtrlCreateLabel("", $x * $iTileSize, $y * $iTileSize, $iTileSize, $iTileSize)
            $aChecked[$x][$y] = False

            GUICtrlSetBkColor($aField[$x][$y], $iIdleColor)
        Next
    Next
EndFunc

Func SetPlayer()
    GUICtrlSetBkColor($aField[$iPlayerX][$iPlayerY], $iPlayerColor)
    $aChecked[$iPlayerX][$iPlayerY] = True
EndFunc

Func UpdatePlayer()
    GUICtrlSetBkColor($aField[$iPlayerX][$iPlayerY], $iPlayerColor)
    $aChecked[$iPlayerX][$iPlayerY] = True

    CheckBounds()

    $iPlayerX += $iSpeedX
    $iPlayerY += $iSPeedY

    CheckCollision()
EndFunc

Func CheckBounds()
    If (($iPlayerX + $iSpeedX) < 0 Or ($iPlayerX + $iSpeedX) > (UBound($aField) - 1)) Then GameOver()
    If (($iPlayerY + $iSpeedY) < 0 Or ($iPlayerY + $iSpeedY) > (UBound($aField, 2) - 1)) Then GameOver()
EndFunc

Func CheckCollision()
    If ($aChecked[$iPlayerX][$iPlayerY]) Then
        GameOver()
    EndIf
EndFunc

Func GameOver()
    Exit MsgBox(0, "Game over", "Sorry, game over!")
EndFunc

Func MoveUp()
    If ($iSpeedY <> 1) Then
        $iSpeedX = 0
        $iSpeedY = -1
    EndIf
EndFunc

Func MoveRight()
    If ($iSpeedX <> -1) Then
        $iSpeedX = 1
        $iSPeedY = 0
    EndIf
EndFunc

Func MoveDown()
    If ($iSpeedY <> -1) Then
        $iSpeedX = 0
        $iSpeedY = 1
    EndIf
EndFunc

Func MoveLeft()
    If ($iSpeedX <> 1) Then
        $iSpeedX = -1
        $iSpeedY = 0
    EndIf
EndFunc

Good luck!


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

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

2D Hitbox Editor

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

Share this post


Link to post
Share on other sites

AWESOME!

i was wondering how to make the lagg less when i was creating a label for each new line!

solution? don't MAKE new labels, just use the GRID. :) thanks a bunch, OH and i have a 2player version nearly read (just gotta add the GRID thing) downside, its only 2players on a local machine, as in two people on one keyboard.

AI? still no luck ;)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Based on AlmarM's version I added a score. So you can compare each game with your previous.

Edit: By the way, if you make it 2-player, I will add network multiplayer. :)

Global $iColumns                                                = 75
Global $iRows                                                   = 75
Global $iTileSize                                               = 5

Global Const $iTargetFPS                                    = 30

Global $aField                                                  [$iColumns][$iRows]
Global $aChecked                                            [$iColumns][$iRows]

Global $iPlayerX                                                = 2
Global $iPlayerY                                                = 2
Global $iSpeedX                                             = 1
Global $iSpeedY                                             = 0

Global $iPlayerColor                                            = 0xFF0000
Global $iIdleColor                                          = 0x000000

Global $iScore = 0

HotKeySet("{UP}", "MoveUp")
HotKeySet("{RIGHT}", "MoveRight")
HotKeySet("{DOWN}", "MoveDown")
HotKeySet("{LEFT}", "MoveLeft")

Global $hWnd = GUICreate("", $iColumns * $iTileSize, $iRows * $iTileSize)
InitializeField()
SetPlayer()

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch

    UpdatePlayer()
    Sleep(1000 / $iTargetFPS)
WEnd

Func InitializeField()
    For $x = 0 To UBound($aField) - 1
        For $y = 0 To UBound($aField, 2) - 1

            $aField[$x][$y] = GUICtrlCreateLabel("", $x * $iTileSize, $y * $iTileSize, $iTileSize, $iTileSize)
            $aChecked[$x][$y] = False

            GUICtrlSetBkColor($aField[$x][$y], $iIdleColor)
        Next
    Next
EndFunc

Func SetPlayer()
    GUICtrlSetBkColor($aField[$iPlayerX][$iPlayerY], $iPlayerColor)
    $aChecked[$iPlayerX][$iPlayerY] = True
EndFunc

Func UpdatePlayer()
    GUICtrlSetBkColor($aField[$iPlayerX][$iPlayerY], $iPlayerColor)
    $aChecked[$iPlayerX][$iPlayerY] = True

    CheckBounds()

    $iPlayerX += $iSpeedX
    $iPlayerY += $iSPeedY
    $iScore += 1

    CheckCollision()
EndFunc

Func CheckBounds()
    If (($iPlayerX + $iSpeedX) < 0 Or ($iPlayerX + $iSpeedX) > (UBound($aField) - 1)) Then GameOver()
    If (($iPlayerY + $iSpeedY) < 0 Or ($iPlayerY + $iSpeedY) > (UBound($aField, 2) - 1)) Then GameOver()
EndFunc

Func CheckCollision()
    If ($aChecked[$iPlayerX][$iPlayerY]) Then
        GameOver()
    EndIf
EndFunc

Func GameOver()
    Exit MsgBox(0, "Game over", "Sorry, game over!" & @CRLF & @CRLF & "Your score: " & $iScore)
EndFunc

Func MoveUp()
    If ($iSpeedY <> 1) Then
        $iSpeedX = 0
        $iSpeedY = -1
    EndIf
EndFunc

Func MoveRight()
    If ($iSpeedX <> -1) Then
        $iSpeedX = 1
        $iSPeedY = 0
    EndIf
EndFunc

Func MoveDown()
    If ($iSpeedY <> -1) Then
        $iSpeedX = 0
        $iSpeedY = 1
    EndIf
EndFunc

Func MoveLeft()
    If ($iSpeedX <> 1) Then
        $iSpeedX = -1
        $iSpeedY = 0
    EndIf
EndFunc
Edited by Manadar

Share this post


Link to post
Share on other sites

Very useful script, thank you :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

UPDATED AT THE TOP

PROS:

cleaned up a bit

made more dynamic

2player 1 keyboard is now supported with each player having elements in an array for the ISPRESSED commands.

CONS:

ISPRESSED may not respond in time if the cycle is too slow.

LOTS of loops

LOTS of labels (however now there is a fixed amount thanks to AlmarM)

any bugs or anything i can work on please tell me!!! as for Networked, well id need a TRON server machine, i don't have one and UDP client to client is not reliable enough.

EDIT:

nice score Manadar! i'll add that for my next one! :) (but maybe a realtime updating Label for each user...)

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I had 15 minute spare time then I made it multiplayer. It works very poorly, but it works. Tested with my girlfriend on the machine next to me.

Basically it just sends TCP messages in XXYY format. If X or Y value is less than 10, it should be reported as 0X0Y. 8)

Global $iColumns                                                = 75
Global $iRows                                                   = 75
Global $iTileSize                                               = 5

Global Const $SleepTime = 50

Global $aField                                                  [$iColumns][$iRows]
Global $aChecked                                            [$iColumns][$iRows]

Global $iPlayerX                                                = Random(5, $iColumns-5, 1)
Global $iPlayerY                                                = Random(5, $iRows-5, 1)
Global $iSpeedX                                             = 1
Global $iSpeedY                                             = 0

Global $iOtherPlayerX = 0
Global $iOtherPlayerY = 0

Global $iPlayerColor                                            = 0xFF0000
Global $iOtherPlayerColor                                            = 0x0000FF
Global $iIdleColor                                          = 0x000000

Global $iScore = 0

HotKeySet("{UP}", "MoveUp")
HotKeySet("{RIGHT}", "MoveRight")
HotKeySet("{DOWN}", "MoveDown")
HotKeySet("{LEFT}", "MoveLeft")

TCPStartup()
Global $iSocketMode = "server"
$listen = TCPListen(@IPAddress1, 27015)
If @error Then
    $iSocketMode = "client"
    $ip = @IPAddress1
    $socket = TCPConnect($ip, 27015)
Else
    $hWnd = GUICreate("Waiting for other players.. You are: " & @IPAddress1)
    $button = GUICtrlCreateButton("Click to enter IP instead", 0, 0)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case -3
                Exit
            Case $button
                $iSocketMode = "client"

                $ip = InputBox("IP please", "Enter the IP please", @IPAddress1)
                If @error Then Exit

                $socket = TCPConnect($ip, 27015)
                If @error Then Exit

                ExitLoop
        EndSwitch

        $socket = TCPAccept($listen)
        If $socket <> -1 Then
            ExitLoop
        EndIf
    WEnd
    GUIDelete()
EndIf

Global $hWnd = GUICreate($iSocketMode, $iColumns * $iTileSize, $iRows * $iTileSize)
InitializeField()
SetPlayer()

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch

    $timeStarted = TimerInit()
    UpdatePlayer()
    UpdateOtherPlayer()

    $timeEnded = TimerDiff($timeStarted)
    While $timeEnded < $SleepTime
        Sleep(1)
        $timeEnded = TimerDiff($timeStarted)
    WEnd
WEnd

Func InitializeField()
    For $x = 0 To UBound($aField) - 1
        For $y = 0 To UBound($aField, 2) - 1

            $aField[$x][$y] = GUICtrlCreateLabel("", $x * $iTileSize, $y * $iTileSize, $iTileSize, $iTileSize)
            $aChecked[$x][$y] = False

            GUICtrlSetBkColor($aField[$x][$y], $iIdleColor)
        Next
    Next
EndFunc

Func SetPlayer()
    GUICtrlSetBkColor($aField[$iPlayerX][$iPlayerY], $iPlayerColor)
    $aChecked[$iPlayerX][$iPlayerY] = True
EndFunc

Func UpdateOtherPlayer()
    $myPos = ""
    If $iPlayerX < 10 Then
        $myPos &= "0" & String($iPlayerX)
    Else
        $myPos &= $iPlayerX
    EndIf
    If $iPlayerY < 10 Then
        $myPos &= "0" & $iPlayerY
    Else
        $myPos &= $iPlayerY
    EndIf

    TCPSend($socket, $myPos)
    If @error Then
        Exit
    EndIf
    
    While 1
        $data = TCPRecv($socket, 4)
        If @error Then
            Exit
        EndIf
        If StringLen($data) <> 4 Then
            ExitLoop
        EndIf
        $iOtherPlayerX = StringLeft($data, 2)
        $iOtherPlayerY = StringRight($data, 2)

        GUICtrlSetBkColor($aField[$iOtherPlayerX][$iOtherPlayerY], $iOtherPlayerColor)
        $aChecked[$iOtherPlayerX][$iOtherPlayerY] = True
    WEnd
EndFunc

Func UpdatePlayer()
    GUICtrlSetBkColor($aField[$iPlayerX][$iPlayerY], $iPlayerColor)
    $aChecked[$iPlayerX][$iPlayerY] = True

    CheckBounds()

    $iPlayerX += $iSpeedX
    $iPlayerY += $iSPeedY
    $iScore += 1

    CheckCollision()
EndFunc

Func CheckBounds()
    If (($iPlayerX + $iSpeedX) < 0 Or ($iPlayerX + $iSpeedX) > (UBound($aField) - 1)) Then GameOver()
    If (($iPlayerY + $iSpeedY) < 0 Or ($iPlayerY + $iSpeedY) > (UBound($aField, 2) - 1)) Then GameOver()
EndFunc

Func CheckCollision()
    If ($aChecked[$iPlayerX][$iPlayerY]) Then
        GameOver()
    EndIf
EndFunc

Func GameOver()
    Exit MsgBox(0, "Game over", "Sorry, game over!" & @CRLF & @CRLF & "Your score: " & $iScore)
EndFunc

Func MoveUp()
    If ($iSpeedY <> 1) Then
        $iSpeedX = 0
        $iSpeedY = -1
    EndIf
EndFunc

Func MoveRight()
    If ($iSpeedX <> -1) Then
        $iSpeedX = 1
        $iSPeedY = 0
    EndIf
EndFunc

Func MoveDown()
    If ($iSpeedY <> -1) Then
        $iSpeedX = 0
        $iSpeedY = 1
    EndIf
EndFunc

Func MoveLeft()
    If ($iSpeedX <> 1) Then
        $iSpeedX = -1
        $iSpeedY = 0
    EndIf
EndFunc

Edit: Added lag-synchronization. Things should now go more smoothly. There needs to be some kind of "loaded" indicator ... That, or the game should be loaded in the background ready to go.

Edited by Manadar

Share this post


Link to post
Share on other sites

interesting... i'll have to try and implement that too :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I might have an idea for an AI, but that would be a silly simple one.

I´ll try creating it on the single player game. :)

EDIT: Tried AI, but it's hard.

I stopped creating it. ;)

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

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

2D Hitbox Editor

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

Share this post


Link to post
Share on other sites

for my version, all i need for an AI is integrate a decision making algorithm, and then move up,right,down, or left. and the background Cycle will take care of the movement.

my problem. the actual algorithm for a decision making ai. :) minimax is one idea, however i wouldn't know how to implement it because for my tick tack toe i barely even used an algorithm...

any ideas how to make one?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

What I tried was making an AI that used the same functions like a player (only added 'Bot' before it, ex: BotCheckBounds, BotMoveUp, etc).

What I wrote as algoritme was:

  • Set a random timer
  • Start the bot as soon as the player starts
  • When the random timer hits its limit, the bot moves randomly to Up,Right,Down,Left (sets random timer again)
  • If the (BotX + BotSpeedX) (prediction) is out of the array range, change direction
  • Same as the previous step, but for (BotY + BotSpeedY)
  • If the bot predicts a "Checked" cell, move randomly to a direction

EDIT:

Tried making a SplashScreen while the game is initializing.

This is just an example, isn't working very well though.

Global $iColumns                                        = 100
Global $iRows                                           = 100
Global $iTileSize                                       = 5

Global $aField                                          [$iColumns][$iRows]

Global $WS_POPUP                                    = 0x80000000

MsgBox(0, "", "Press 'OK' to start the game.")

$hInitialize = _OpenSplash()

Global $hWnd = GUICreate("", $iColumns * $iTileSize, $iRows * $iTileSize)
InitializeField()

_CloseSplash($hInitialize)

GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch
WEnd

Func _OpenSplash()
    $hWnd = GUICreate("", 230, 70, -1, -1, $WS_POPUP)
    $hLabel = GUICtrlCreateLabel("Initializing game...", 10, 20, 250, 50)

    GUICtrlSetFont($hLabel, 20)

    GUISetState()

    Return $hWnd
EndFunc

Func _CloseSplash($hWnd)
    GUIDelete($hWnd)
EndFunc

Func InitializeField()
    For $x = 0 To UBound($aField) - 1
        For $y = 0 To UBound($aField, 2) - 1
            $aField[$x][$y] = GUICtrlCreateLabel("", $x * $iTileSize, $y * $iTileSize, $iTileSize, $iTileSize)

            GUICtrlSetBkColor($aField[$x][$y], 0x00)
        Next
    Next
EndFunc
Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

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

2D Hitbox Editor

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

Share this post


Link to post
Share on other sites

i tried making my ai check 1-5 squares in the direction it was going and if there is a crash it would check 1-5 squares in any other direction and the first one that didn't have a crash it would change into that direction, however when it was playing:

-ai starts off bottom right corner directiop:LEFT

-ai doesn't move until just before it hits the other side

-ai changes direction:UP

-and repeats process until it basically draws a circle. :)

Share this post


Link to post
Share on other sites

NEW VERSION

added:

-GAME TYPES

-BASIC (very basic) AI

-SCORE SYSTEM

fixed:

-miscellaneous bugs

any ideas for a better ai?

Share this post


Link to post
Share on other sites

You did great improvements! :)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

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

2D Hitbox Editor

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

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

You did great improvements! :)

any ideas for a smarter AI? :S

Have you looked at the other Tron game by monoceres? AutoiTRON. It could give you some ideas. Download from here (see his signature for why)

his link is broken, i'm posting on that topic right now for an update... hopefully i'll see what he has done soon.

EDIT:

just reread your post and you gave me the direct downloadlink haha thanks.

EDIT:

monoceres version is actually pretty awesome, fairly simplistic although i dont understand some of the GDI but its cool, and FAST! ;)

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

any ideas for a smarter AI? :S

Like I said earlier, set a random counter and keep track of how many steps the bot takes.

If the bot reaches the random timer, reset the random counter and do something like MoveRandom() wich will randomly choose from Up, Right, Down, Left. :)


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

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

2D Hitbox Editor

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

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I have a kind of random counter.. $nchoice in detect_ai_.... func.

EDIT

-added 7 more AIs total of 8 players on the grid

-fixed up some of the code

-fixed a few small bugs

CURRENTLY i'm working on a GDI+ version instead of GUI....Label creation. so far its exceptionally faster :)

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

NEW VERSION

GDI+ :) first time i used it, so i'm sure i've messed up somewhere...

any ideas how to do it more efficiently?

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

NEW VERSION!

check the top

CHANGES:

--everything. :)

----rewritten around GDI+

----changed different game styles

----player max, a max of 4

----cycle speed

----buffer speed

----gui layout

----ai movement (depth orientated)

----player movement (w,a,d,s)

----visual grid

----logo (still under maintenance)

----onevent now getmsg

----over all IS FASTER

what else... "EVERYTHING" seems to cover most of it

issues:

--ai is stupid ;)

--only 1 USER

----easy fix just gotta change a few things around

--no networked play

--ai decision laggs the CPU

----my 2.6GHz went up from 7% to 60% when game was playing

i'm sure there is some other issues, what do you guys think? :idiot:

EDIT

RIGHT i forgot to add.

does any one know how to erase the object for the brush of a certain player that doesn't involve deleting the entire object of the drawing area (just one players tail when they crash)

Edited by CodyBarrett

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0