Jump to content

Real Snake


Markus
 Share

Recommended Posts

kcd-clan gave me the inspiration to write that: Pacmanand so here is the SNAKE. All files in one folder and start. I think its quite funny, because you can drive over whole desctop without any window limiting ur snake ;) Maybe you will notice that you cant eat ur tail, don't worry, next version will be available soon :(

With "q" u may speed up, but mind that u cant slow down, after 22 apples next round is starting.

PS: I just noticed that a snake script is already existing :) but anyway i hope that you will enjoy that nearly totally different version. Have fun with crashing desctop icons :think:

EDIT!!!: -removed several bugs as a missing part of the snake

-snake is now growing after eating an apple

-you die if you run into ur own tail

-you may pause/go on with "Pause" or with "p"

-restart possible after death

-level 2 got walls (the x_pos of the walls is dependant on your desktop width, the pos is calculated automatically, the y_pos isnt calculated yet, the value is always the same, so if your resolution is very low it might look strange)(hope more levels will come soon :D )

#include <GUIConstants.au3>

HotKeySet("{UP}","moveUP")
HotKeySet("{DOWN}","moveDOWN")
HotKeySet("{LEFT}","moveLEFT")
HotKeySet("{RIGHT}","moveRIGHT")
HotKeySet("{ESC}","_exit")
HotKeySet("{PAUSE}","_pause")
HotKeySet("p","_pause")
HotKeySet("q","speedup")
;HotKeySet("a","speeddown")
Global $direction="right"
Global $x=100
Global $y=100
Global $x_apfel=200
Global $y_apfel=200
Global $apfel=0
Global $sleep=60
Global $snake_gui[50]
Global $snake_gui_x_pos[50]
Global $snake_gui_y_pos[50]
Global $snake_teil_bild[50]
Global $snake_teil=1
Global $snake_teil_kopf=0
Global $snake_length=8
Global $richtungsaenderung=""
Global $pause=0
Global $level=1
Global $hindernis_gui[100]
Global $left_mauer, $right_mauer



Func SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc   
$gui=GUICreate("",20,20,200,200,$WS_POPUP)
GUICtrlCreatePic(@ScriptDir & "\Apfel.bmp",0,0,20,20)
$a = DLLCall(@ScriptDir & "\BMP2RGN.dll","int","BMP2RGN", "str",@ScriptDir & "\Apfel.bmp", "int",255,"int",255,"int",255 )
SetWindowRgn($gui, $a[0])
GUISetState(@sw_show)

$parent=GUICreate("",1,1,-99,-99)
For $i=1 To 29
$snake_gui[$i]=GUICreate("",15,15,-99,-99,$WS_POPUP,-1,$parent)
$snake_teil_bild[$i]=GUICtrlCreatePic(@ScriptDir & "\Snake.bmp",0,0,15,15)
$a = DLLCall(@ScriptDir & "\BMP2RGN.dll","int","BMP2RGN", "str",@ScriptDir & "\Snake.bmp", "int",255,"int",255,"int",255 )
SetWindowRgn($snake_gui[$i], $a[0])
GUISetState()
Next
$a = DLLCall(@ScriptDir & "\BMP2RGN.dll","int","BMP2RGN", "str",@ScriptDir & "\Hindernis.bmp", "int",255,"int",255,"int",255 )
For $i=1 To 80
    $hindernis_gui[$i]=GUICreate("",30,30,-99,-99,$WS_POPUP,-1,$parent)
    GUICtrlCreatePic(@ScriptDir & "\Hindernis.bmp",0,0,30,30)
    SetWindowRgn($hindernis_gui[$i], $a[0])
    GUISetState()
Next


Func speedup()
    $sleep=$sleep-10
    ToolTip(30-$snake_length & " apples remaining   Sleeptime: " & $sleep,0,0)
EndFunc
Func speeddown()
    $sleep=$sleep+10
EndFunc

Func moveUP()
    If $direction<>"up" And $direction<>"down" Then $richtungsaenderung="up"
EndFunc

Func moveDOWN()
    If $direction<>"down" And $direction<>"up" Then $richtungsaenderung="down"
EndFunc

Func moveLEFT()
    If $direction<>"right" Then $direction="left"
EndFunc

Func moveRIGHT()
    If $direction<>"left" Then $direction="right"
EndFunc

Func _level_baun($level)
If $level=2 Then    
    $left_mauer=Round(@DesktopWidth/40)*10
    $right_mauer=$left_mauer*3-30
;MsgBox(0,$left_mauer,"")
    For $i=1 To 12
        WinMove($hindernis_gui[$i],"",$left_mauer,30*$i-30)
    Next
    For $i=1 To 12
        WinMove($hindernis_gui[$i+12],"",$right_mauer,30*$i-30)
    Next
    For $i=1 To 20
        WinMove($hindernis_gui[$i+24],"",$left_mauer,30*$i+600)
    Next
    For $i=1 To 20
        WinMove($hindernis_gui[$i+44],"",$right_mauer,30*$i+600)
    Next
EndIf
If $level=3 Then
    For $i=1 To 80
        WinMove($hindernis_gui[$i],"",-99,-99)
    Next

EndIf
EndFunc

Func _pause()
    If $pause=0 Then 
        $pause=1
    Else
        $pause=0
    EndIf
    While 1
        If $pause=0 Then ExitLoop
    WEnd
EndFunc
Func _exit()
    If $apfel=1 Then 
        $restart=MsgBox(4,"Gameover","You got " & $apfel & " apple!" & @crlf & @crlf & "Restart?")
    Else
        $restart=MsgBox(4,"Gameover","You got " & $apfel & " apples!" & @crlf & @crlf & "Restart?")
    EndIf
    If $restart=7 Then 
        Exit
    Else 
        $snake_length=8
        $sleep=60 
        $snake_teil=1
        $erstellen=1
        $x=100
        $y=100
        $direction="right"
        For $i=1 To 29
            WinMove($snake_gui[$i],"",-99,-99)
        ;GUISetState(@SW_HIDE,$snake_gui[$i])
            $snake_gui_x_pos[$i]=-99
            $snake_gui_y_pos[$i]=-99
        Next
        ToolTip("22 apples remaining   Sleeptime: " & $sleep,0,0)
    EndIf
EndFunc
WinMinimizeAll ( )
ToolTip("22 apples remaining   Sleeptime: " & $sleep,0,0)
While 1
    If $direction="right" Then 
        If $richtungsaenderung="up" Then
            $direction="up"
            $richtungsaenderung=""
        ElseIf $richtungsaenderung="down" Then
            $direction="down"
            $richtungsaenderung=""
        Else
            $x=$x+15
            Sleep($sleep)
        EndIf
    EndIf
    If $direction="left" Then 
        If $richtungsaenderung="up" Then
            $direction="up"
            $richtungsaenderung=""
        ElseIf $richtungsaenderung="down" Then
            $direction="down"
            $richtungsaenderung=""
        Else
            $x=$x-15
            Sleep($sleep)
        EndIf
    EndIf
    If $direction="up" Then 
        $y=$y-15
        Sleep($sleep)
    EndIf
    If $direction="down" Then 
        $y=$y+15
        Sleep($sleep)
    EndIf
    
    WinMove($snake_gui[$snake_teil],"",$x,$y)
    $snake_gui_x_pos[$snake_teil]=$x
    $snake_gui_y_pos[$snake_teil]=$y
    
    If Not $snake_teil_kopf=0 Then GUICtrlSetImage($snake_teil_bild[$snake_teil_kopf],@ScriptDir & "\snake.bmp")
    If $direction="left" Then GUICtrlSetImage($snake_teil_bild[$snake_teil],@ScriptDir & "\snakekopfwest.bmp")
    If $direction="right" Then GUICtrlSetImage($snake_teil_bild[$snake_teil],@ScriptDir & "\snakekopfost.bmp")
    If $direction="up" Then GUICtrlSetImage($snake_teil_bild[$snake_teil],@ScriptDir & "\snakekopfnord.bmp")
    If $direction="down" Then GUICtrlSetImage($snake_teil_bild[$snake_teil],@ScriptDir & "\snakekopfsued.bmp")
    $snake_teil_kopf=$snake_teil
    For $i=1 To $snake_length
        If $i=$snake_teil Then ContinueLoop
        If $x=$snake_gui_x_pos[$i] And $y=$snake_gui_y_pos[$i] Then _exit()
    Next
    
    
    $snake_teil=$snake_teil+1
    If $snake_teil=$snake_length+1 Then $snake_teil=1
    
    If $x>=$x_apfel-15 And $x<=$x_apfel+20 And  $y>=$y_apfel-15 And $y<=$y_apfel+20 Then
        $leave=0
        While 1
            $x_vor=Random ( 0 ,(@DesktopWidth-20)/10 , 1 )
            $x_apfel=$x_vor*10
            $y_vor=Random ( 0 ,(@DesktopHeight-60)/10 , 1 )
            $y_apfel=$y_vor*10
            If $level=1 Or $level>2 Or $leave=1 Then ExitLoop
            If $level=2 Then 
                $leave=1
                If $x_apfel>$left_mauer-20 And $x_apfel<$left_mauer+30 Then $leave=0
                If $x_apfel>$right_mauer-20 And $x_apfel<$right_mauer+30 Then $leave=0
            EndIf
        WEnd
        WinMove($gui,"",$x_apfel,$y_apfel)
        $apfel=$apfel+1
        $snake_length=$snake_length+1
        ToolTip(30-$snake_length & " apples remaining   Sleeptime: " & $sleep,0,0)
    EndIf
    If $snake_length=30 Then
        MsgBox(0,"Runde geschafft","")
        $snake_length=8
        If Not $sleep=0 Then $sleep=$sleep-10
        $snake_teil=1
        $level=$level+1
        $x=100
        $y=100
        $direction="down"
        For $i=1 To 29
            WinMove($snake_gui[$i],"",-99,-99)
        Next
        ToolTip("22 apples remaining   Sleeptime: " & $sleep,0,0)
        _level_baun($level)
    EndIf
    If $level=2 Then
        If $x>$left_mauer-20 And $x<$left_mauer+30 And $y>600 Then _exit()
        If $x>$left_mauer-20 And $x<$left_mauer+30 And $y<360 Then _exit()
        If $x>$right_mauer-20 And $x<$left_mauer+30 And $y>600 Then _exit()
        If $x>$right_mauer-20 And $x<$left_mauer+30 And $y<360 Then _exit()
    EndIf
    If $x>@DesktopWidth Or $x<0 Or $y<0 Or $y>@DesktopHeight Then 
        _exit()
    EndIf
WEnd

snakefiles.zip

Edited by Markus

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Link to comment
Share on other sites

Ok, I downloaded and played this. Very cool! I really like it!

One thing though.. after the snake got so long, there was a gap of 1 segment in his body. He would always have the gap and I could even go through it without throwing off the detection.

It would also be nice to have an english version with english msgboxs :think:

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

Hi,

nice! But you should die, if the snake goes right and you are typing left (always the opposite)

So long,

Mega

P.S.: Langeweile gehabt, oder? :think:

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

this is very well done! I like it

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

nice! But you should die, if the snake goes right and you are typing left (always the opposite)

Had that in the last version, but then i thought, u shouldnt die. I dont know snake rules(are there any? :( ) Maybe i'll do an options menu, that u die/die not.

P.S.: Langeweile gehabt, oder?

Naja da wars halt so 1 Uhr nachts, wo ich noch bissl im Forum war, da hat man halt komische Ideen :think:

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Link to comment
Share on other sites

Wonderful but exactly how did you tell it when you hit the end of the desktop, like if the snake hits the very top of the screen how did you tell it game was over, that could really help me

I'm guessing it has something to do with :

If $x>@DesktopWidth Or $x<0 Or $y<0 Or $y>@DesktopHeight Then
_exit()
EndIf
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

If $x>@DesktopWidth Or $x<0 Or $y<0 Or $y>@DesktopHeight Then
_exit()
EndIf
That's it^^

Thank you for your feedback, that's a great motivation to write level 3 - XX

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Link to comment
Share on other sites

Cool! Some suggestions for future versions:

Make it work for multi-monitors.

Add a "run" button to make the snake go faster - when the apple is on the far side of the screen it takes a long time to get there!

Make realative controls, so that you only need to use the left and right keys to control the snake.

Make the snake turn less than 90 degrees (like try 60 or 45 or 30, or even 15)

Or if you want to get crazy, forget about the keyboard altogether and make the snake always go towards the mouse pointer. :think:

Link to comment
Share on other sites

  • 2 weeks later...

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