blindwig Posted May 1, 2006 Share Posted May 1, 2006 (edited) Everyone's played that snake game in one form or another - you start with a small snake, eating bugs or bird or apples or whatever, and everytime you do, your snake grows a little longer. Try to keep going as long as you can without biting your own tail.Well something I've always noticed is that snake games usually only let you turn your snake at 90 degree angles. I once saw a snake game where you turn 60 degrees (a hex board instead of a check board) but it was badly written and hard to control. So, inspired by Marcus's Real Snake I wrote a snake that could turn 45 degrees, then I tried 30 degrees, and then 15.The thing with turning 15 degrees is that it takes 6 turns to turn 90 degrees, and 12 turns to do a full 180. Too much button-mashing for my pleasure! So I decided to make a more smooth control - give the snake full freedom to follow the mouse cursor! I limit the snake to a maxium of 90 degree turns (so that he doesn't double back and bite himself in the neck!) so he effectively has 180 degrees of freedom.In the attached ZIP are 2 versions of the game engine - one uses a graph control, and the other uses a bunch of always-on-top transparent-region forms, inspired by postings in kcd-clan's Pacman thread.EDITAdded new version, uses thick lines instead of segments(previous version had 72 downloads - cool!)EDITAdded new version of Snake_4 - snake gains thickness as well as length, added eyes and nose, added status display, fixed the 90-degree rule code(previous version had 45 downloads!)EDITA new version - snake_5 - Added control panel, fixed memory leaks, added "string mode" - cool!(pervious version had 57 downloads)MWR_Snake_20060511.zip Edited May 12, 2006 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Simucal Posted May 1, 2006 Share Posted May 1, 2006 Great Script blindwig, I really like it. You should put the snake head on the second version of the game. This looks really sick. 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 More sharing options...
rakudave Posted May 1, 2006 Share Posted May 1, 2006 very nice work! yeah, a head would be nice... Pangaea Ruler new, UDF: _GUICtrlCreateContainer(), Pangaea Desktops, Pangaea Notepad, SuDoku, UDF: Table Link to comment Share on other sites More sharing options...
RazerM Posted May 2, 2006 Share Posted May 2, 2006 this is quite cool. 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 More sharing options...
slightly_abnormal Posted May 2, 2006 Share Posted May 2, 2006 this is quite cool. i like itnice! Link to comment Share on other sites More sharing options...
jvanegmond Posted May 2, 2006 Share Posted May 2, 2006 (edited) Wow, really nice You should make a maze for this Edited May 2, 2006 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
blindwig Posted May 3, 2006 Author Share Posted May 3, 2006 Wow, really nice You should make a maze for this It's more of a proof-of-concept than an actual finished game. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted May 3, 2006 Author Share Posted May 3, 2006 (edited) I added 2 more version of the snake! Like the first two, but these two new ones draw the snake with thick lines instead of "bead" segments. And the full screen version uses DLL calls to draw the snake instead of moving clipped forms around! Now if someone could show me how to have a DC repaint itself... Also, I'm trying to replace the lines with beziers (or some other type of smooth curves). If anyone knows anything about beziers or slines or anything like that, please help! Edited May 3, 2006 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
jvanegmond Posted May 4, 2006 Share Posted May 4, 2006 I added 2 more version of the snake! Like the first two, but these two new ones draw the snake with thick lines instead of "bead" segments. And the full screen version uses DLL calls to draw the snake instead of moving clipped forms around! Now if someone could show me how to have a DC repaint itself... Also, I'm trying to replace the lines with beziers (or some other type of smooth curves). If anyone knows anything about beziers or slines or anything like that, please help! Line 129 in MWR_Snake_4.au3 DllCall($hDLL_GDI32, "int", "LineTo", "hwnd", $hd[0], "int", $SnakeSeg[$i][0], "int", $SnakeSeg[$i][1]) $SnakeSeg[$i][0] Dimension range exceeded probably I turned colission detection off github.com/jvanegmond Link to comment Share on other sites More sharing options...
blindwig Posted May 4, 2006 Author Share Posted May 4, 2006 Line 129 in MWR_Snake_4.au3 DllCall($hDLL_GDI32, "int", "LineTo", "hwnd", $hd[0], "int", $SnakeSeg[$i][0], "int", $SnakeSeg[$i][1]) $SnakeSeg[$i][0] Dimension range exceeded probably I turned colission detection off In that version, the snake leaves a black trail (because I don't know how to clear the screen yet!) and does it by using unused snake segments for the trail. However, when the snake is at it's maximum length ($SnakeLen = $SnakeMaxLen) there are no unused segments. Change this: ;Line 29 Global $SnakeSeg[$SnakeMaxLen+1][2];x,y To give the snake an extra segment to draw the black trail. And here's a fun one I'm writing into my next version: Change the $SnakeWidth to 10 in line 27, and remove the Const keyword In the Item Collision section of the SnakeCheck() function, after "$SnakeLen+=1" in line 183, insert "$SnakeWidth+=1" as line 184 Now the snake will start out small and get fatter (as well as longer) as he eats. Cool effect! My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
blindwig Posted May 6, 2006 Author Share Posted May 6, 2006 I added a new zip file (at the top of this thread) containing a newer verion of my Snake_4 script. The snake now gains thickness as well as length (and also speed, since speed is a function relative to the snake's thickness.) I added eyes and nostrils to the head of the snake. I was going to add a tongue that flicked out every once in a while (just for effect) but it wasn't looking right so I'll have to come back to that. Added a status display (via ToolTop) to tell you the vital statistics. Added a pause function (use the pause key) Fixed the bug where the script crashes if the snake gets to it's maximum length. Tickness continues to increase even if the snake gets to maximum length. This means that the game can keep going until your snake is literally too fat to fit on the screen! Re-wrote the 90-degree turn check algorithm so that it works properly. I still don't know how to tell a DC to repaint itself. I still don't know how to wait for a screen refresh/retrace to eliminate flicker. I play the game several times and I think it's pretty challenging to get the snake to max length (currently set for 50). I am on a P4 2.8MHz with 1600x1200 display. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
jvanegmond Posted May 8, 2006 Share Posted May 8, 2006 (edited) I added a new zip file (at the top of this thread) containing a newer verion of my Snake_4 script. The snake now gains thickness as well as length (and also speed, since speed is a function relative to the snake's thickness.) I added eyes and nostrils to the head of the snake. I was going to add a tongue that flicked out every once in a while (just for effect) but it wasn't looking right so I'll have to come back to that. Added a status display (via ToolTop) to tell you the vital statistics. Added a pause function (use the pause key) Fixed the bug where the script crashes if the snake gets to it's maximum length. Tickness continues to increase even if the snake gets to maximum length. This means that the game can keep going until your snake is literally too fat to fit on the screen! Re-wrote the 90-degree turn check algorithm so that it works properly. I still don't know how to tell a DC to repaint itself. I still don't know how to wait for a screen refresh/retrace to eliminate flicker. I play the game several times and I think it's pretty challenging to get the snake to max length (currently set for 50). I am on a P4 2.8MHz with 1600x1200 display. I háve found that you can't use GDI to draw self-erasing lines. But i have no clue where do you get your info on dll's, i want to know what exactly you are doing here using GDI32.DLL but i can't find any information about it's functions. [edit] just seconds after my post i've found this http://custom.programming-in.net/articles/...p?lib=gdi32.dll [edit 2] On that website i just found: "After your program is finished using the pen, it must be deleted via the DeleteObject function" Edited May 8, 2006 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
blindwig Posted May 9, 2006 Author Share Posted May 9, 2006 I háve found that you can't use GDI to draw self-erasing lines. But i have no clue where do you get your info on dll's, i want to know what exactly you are doing here using GDI32.DLL but i can't find any information about it's functions. [edit] just seconds after my post i've found this http://custom.programming-in.net/articles/...p?lib=gdi32.dll [edit 2] On that website i just found: "After your program is finished using the pen, it must be deleted via the DeleteObject function"Thanks for that link! That's great! I've added the Delete Object to my code, so you'll see it in the next posting. I've never drawn to a DC before, I just found some code and have been playing with it (as you can see) As for self-erasing lines - there HAS to be a way to tell the DC to repaint itself. I used to do it in VB5 - a DC has 2 buffers - a temporary and a perminant. You draw on the temporary one, and when it repaints it pulls from the permanent one. I'm looking at the site you pointed me to, and I see functions called ResetDC and RestoreDC, maybe one of those will help. I also see Arc and SetArcDirection - I can use these to make a smoother looking snake! Now that I know I can draw an arc, I'm working on arc-calculation routines. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Zedna Posted May 9, 2006 Share Posted May 9, 2006 For erase DC use DLLCall("user32.dll","int","InvalidateRect","hwnd",$pic_hWnd,"int",0,"int",0); bErase=False Look at my signature for my RADAR project ... For smooth painting you may use GUIRegisterMsg() to catch WM_DRAW or WM_PAINT but this trick I haven't tried yet. For now only these tips and ideas, I will look at your code later. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
blindwig Posted May 12, 2006 Author Share Posted May 12, 2006 For erase DC use DLLCall("user32.dll","int","InvalidateRect","hwnd",$pic_hWnd,"int",0,"int",0); bErase=False Look at my signature for my RADAR project ... For smooth painting you may use GUIRegisterMsg() to catch WM_DRAW or WM_PAINT but this trick I haven't tried yet. For now only these tips and ideas, I will look at your code later.OK I put that in just before I draw the screen and it flickers like crazy and slows the script down. I think it's because it calls all visable windows to redraw themselves and waits for them to finish before returning. I added some more stuff to the snake - like a control panel to easily set options. I'm playing with Bezier functions to try to make the snake more natural and curved, but so far haven't found just the right formula. I added a new movement method, I call it string-mode because the snake acts like a piece of string and you are pulling on one end. This makes the game very challenging as the snake gets longer, because just as with a piece of string, it is hard to control the far end (the snake's tail) by just pulling on the other end (the snake's head) I also made it an option not to outline the snake, as this cuts down on the flicker. But any graphics glitch (like a window moving in the background) makes it hard to tell where your "real" snake is. Have a look! My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
zeroZshadow Posted May 12, 2006 Share Posted May 12, 2006 (edited) nice man, but it kinda sucks that the snake has a trail, make an option to switch it off will ya because the game gets flickering with a long trail EDIT: btw if u have a background color on ur desktop that is 0x160016 then ur'll have a funny effect with a black trail, try it Edited May 12, 2006 by zeroZshadow *If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip... Link to comment Share on other sites More sharing options...
blindwig Posted May 12, 2006 Author Share Posted May 12, 2006 nice man, but it kinda sucks that the snake has a trail, make an option to switch it off will ya because the game gets flickering with a long trailEDIT: btw if u have a background color on ur desktop that is 0x160016 then ur'll have a funny effect with a black trail, try it The only part of the trail that is redrawn is the bit that is immediately following the snake. The rest is not drawn or erased, so it shouldn't flicker at all.I tried using the method Zedna suggested for clearing the DC, but on my machine it made it flicker even worse. If you want to see that, call GameClear() right before GameDraw() in the main game loop.Also, if the snake itself is flickering too much, turn off the outline. I've made the default not to have an outline because I got tired of it flickering so much, but I can't remember if I did that before or after I posted.It also depends on your resolution. I'm developing this at 160x1200, so lower resolutions might not be displaying it the same as i see it as I develop it. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Zedna Posted May 12, 2006 Share Posted May 12, 2006 @blindwigI don't suggested InvalidateRect as antiflicker method.You just asked for way to erase place, so my answer was InvalidateRect.For antiflicker look at my old posts here:http://www.autoitscript.com/forum/index.ph...indpost&p=98250http://www.autoitscript.com/forum/index.ph...topic=14325&hl=http://www.autoitscript.com/forum/index.php?showtopic=14252http://www.autoitscript.com/forum/index.php?showtopic=14006http://www.autoitscript.com/forum/index.ph...5533;entry98708In time when I tried to solve flickering, there wasn't GUIRegisterMsg() yet.And now when GUIRegisterMsg() is here I didn't try to finish it with GUIRegisterMsg() and some of WM_DRAW, WM_PAINT,so if you want you can make your own testing... Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
quick_sliver007 Posted May 13, 2006 Share Posted May 13, 2006 Great work. When Smed and I made a snake game along time ago; we talked about making a second snake in the game that is controlled by the computer. The ideal was to make the player fight(a.k.a. race) for the food. I thought I would pass the ideal to you, just something to think about. . Link to comment Share on other sites More sharing options...
Simucal Posted May 14, 2006 Share Posted May 14, 2006 For anyone who wants to see the snake game in action, check this animated image out of Blindwigs snake script (I got bored today):http://img105.imageshack.us/img105/315/snake1wl.gif 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now