Jump to content

Recommended Posts

Posted (edited)

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

OLD VERSIONS OF TRON

  Reveal hidden contents

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+

OLD VERSION remastered and rewritten WITH GDI+

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

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

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
Posted

  On 2/8/2011 at 3:10 AM, 'CodyBarrett said:

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.

Posted

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 ;)

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
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
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
Posted

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

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.

Posted

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?

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.

Posted

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. :)

Posted

NEW VERSION

added:

-GAME TYPES

-BASIC (very basic) AI

-SCORE SYSTEM

fixed:

-miscellaneous bugs

any ideas for a better ai?

Posted (edited)

  On 2/15/2011 at 8:19 AM, 'AlmarM said:

You did great improvements! :)

any ideas for a smarter AI? :S

  Quote

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
Posted

  On 2/15/2011 at 4:41 PM, 'CodyBarrett said:

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.

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
Posted

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?

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

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
  • Recently Browsing   0 members

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