AutoHotkey Community

It is currently May 26th, 2012, 8:46 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: "Snake" for AHK
PostPosted: August 27th, 2009, 3:16 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Well, I was really bored yesterday, and felt like doing in something in AHK, so I whipped up an AHK port of Snake. Dunno if it's been done before, but anyway,
Snake for AHK
Relies on three standard libraries:
SimpleArrayby infogulch
Gdip by tic
Common Dialogs by majkinetor

Screenshots
Image
Image

Edit:
[8/27/09 1:27PM] - Post Change
-Added the libraries it relies on.

[8/27/09 2:37PM] - Feature Update
-Added pause button, and added space to the pause hotkeys.
-Added a screenshot.

[8/27/09 8:26PM]
-Made settings able to change during a game without ending it; they get applied next new game
-Settings are now saved in an ini file
-Added support for hotkey customization
-Added a new hotkey for "New Game"
-Fixed a glitch where if the head moved to the same position the last body part was leaving from, the head would first get drawn—then deleted again.

[8/28/09 4:31PM]
-Improved the MsgBox you get upon exiting settings
-Fixed a bug when using Space or Launch_App2 as a hotkey
-Made it possible to have the New Game / Start Game hotkeys the same, or the Pause / Start Game hotkeys the same
-Fixed a problem where the pause graphic would be drawn the wrong color after changing the background color
-Fixed a bug where opening Settings would not pause the game unless it had been paused once before
-(Hopefully) fixed a bug where the window would move a bit on startup

[8/29/09 10:00PM]
-Added a custom built Color Picker window. Still needs a couple of improvements, but it's good enough for now.

[12/1/09 9:05PM]
-Changed my custom Color Picker window to the Common Dialog for windows, utilized through majkinetor's Common Dialog functions. Works much smoother, and with much less code, although I dislike that the picker has a Luminance slider instead of a Hue slider ): Maybe I'm just too used to Photoshop.
-Embedded the two bitmaps in the script, so that external files are no longer necessary.


Last edited by Krogdor on December 2nd, 2009, 6:06 am, edited 16 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: "Snake" for AHK
PostPosted: August 27th, 2009, 8:32 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Krogdor wrote:
Well, I was really bored yesterday, and felt like doing in something in AHK, so I whipped up an AHK port of Snake. Dunno if it's been done before, but anyway,
http://www.autohotkey.net/~Krogdor/Snake.ahk

Relies on two images, both around 2kb, that will be automatically downloaded.

Was kinda psyched to see this, but have to report the following;
    Error: Call to nonexistent function.
    Specifically: SA_Set(BodyParts, HeadX "x" HeadY, "1")

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 8:35 pm 
Online

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
same.
and omg! Infogulch! see?!!? I'm not the only one to have issues with your SA library!
now i don't feel so retarded. thanks SoggyDog

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 8:51 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Oh... Standard library;
Guess I should get that in to my lib folder;
That clears it right up and I'm happy again. :D

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 8:55 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Got to 26 on my first run;
I could have gotten further, but I'm at work and couldn't find a pause button so I could answer the phone!

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 9:23 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Whoops, sorry, I forgot that I had used infogulch's SimpleArray library :x
Sorry about that.

@SoggyDog:
P or the Pause button to pause. I'll make it into a graphic button later.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 9:33 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Krogdor wrote:
@SoggyDog:
P or the Pause button to pause. I'll make it into a graphic button later.

Thanks;
I had tried Space and P;
I tried the P again (now that you've mentioned it) and it worked this time;
Don't know what I hit last time, but apparently not P;
I've added Space as a 'Pause' hotkey to mine.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 9:56 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
tidbit wrote:
same.
and omg! Infogulch! see?!!? I'm not the only one to have issues with your SA library!
now i don't feel so retarded.
I use it too :!: I think the main problem is lacking documentation :(

and yes, nice game too!

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 10:35 pm 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
SoggyDog wrote:
Krogdor wrote:
@SoggyDog:
P or the Pause button to pause. I'll make it into a graphic button later.

Thanks;
I had tried Space and P;
I tried the P again (now that you've mentioned it) and it worked this time;
Don't know what I hit last time, but apparently not P;
I've added Space as a 'Pause' hotkey to mine.


Okay, added Space to the list of Pause hotkeys. Seemed like a good idea.
Also added a button to change the pause state via the mouse. New code has been uploaded.

HugoV wrote:
tidbit wrote:
same.
and omg! Infogulch! see?!!? I'm not the only one to have issues with your SA library!
now i don't feel so retarded.
I use it too :!: I think the main problem is lacking documentation :(

The documentation is rather sparse, but I was only using it very simply, so it was enough for my needs. I did get confused, however, because I assumed the Arrays were being passed ByRef, and I didn't know why they weren't being updated. Then I realized I had to do, for example,
Array := SA_SetArray(Array, Value)
Instead of just
SA_SetArray(Array, Value)
Whoops .

HugoV wrote:
and yes, nice game too!

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 27th, 2009, 11:18 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
If you change Settings in the middle of a game, the game ends (which is reasonable) but it says your score was '0' regardless of actual score.

Instead of a 'Game Over' message, might consider simply pausing the game with a message that the new settings will take effect on the next new game, then give the player the option to continue or start new game.

For simplicity of gameplay, I've actually changed the hotkeys such that Space starts new games as well as pausing/unpausing.

Perhaps allow the player to establish their own key bindings under Settings.

Funny how such a mindless little game can be so addicting;
I love it. Thanks.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 12:37 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
SoggyDog wrote:
If you change Settings in the middle of a game, the game ends (which is reasonable) but it says your score was '0' regardless of actual score.

Instead of a 'Game Over' message, might consider simply pausing the game with a message that the new settings will take effect on the next new game, then give the player the option to continue or start new game.

Yeah, that was kinda hacked together. At first it was changing settings mid-game, but only the snake colors and any block it had already touched were changing colors, the speed didn't change, etc. I was just happy to make it stop doing that and then forgot about it :/ Not sure why it displays the score as 0 though... it should display correctly still o_O Anyway, not important.
I'll try to fix it up.
Quote:
For simplicity of gameplay, I've actually changed the hotkeys such that Space starts new games as well as pausing/unpausing.

Perhaps allow the player to establish their own key bindings under Settings.

I'll add that. Thanks for the input

Quote:
Funny how such a mindless little game can be so addicting;
I love it. Thanks.

I know.. I used to play this game 24/7 back on my old Nokia phone.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 4:29 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Updated it; changelog in first post.

The hotkey customization isn't done very well though... The AHK Hotkey control doesn't accept keys like Space or Enter, so I made it an edit control with a button next to it to display a (very poorly formatted) key list.

I've seen two different threads about improved hotkey controls, but both of them are much more difficult to implement than would make it worth the effort. One of the posters, here, said he was working on a way to make it into functions that could be used for any GUI easily, but that was back in February and no word yet. Anyhow, I'm open to suggestions. I might make each hotkey input a ComboBox or something like that instead. Not sure yet.

Edit: Changed it to use ComboBoxes. I like it this way better, although a better hotkey control would still be preferable...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 28th, 2009, 8:33 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
It just keeps getting better, so here are some more things to consider;

1) Your post sounds like Sapce wasn't working, but then after making changes did work; Did I misread this? My Space still isn't working under the current configuration.

2) As it stands now, if the same hotkey is defined for multiple tasks, it doesn't know which task to perform; i.e. I have mine set to do all three. In the midst of a game, the hotkey ends the game (acting as NewGameHotKey). Should probably check for game-state so it knows what function to perform.

3) After changing colors (background color, specifically), the right-most vertical bar in the pause graphic ( i.e. || ) becomes the same as the background color (but reverts back to white after executing an actual pause).

4) Maybe add one of the many color pickers here on the AHK forum for selecting colors.

5) When I first start the game, it draws the screen, then a split second later it drops down and to the right a couple pixels.

6) Tell me to quit making suggestions at any time :wink:

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2009, 12:15 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
SoggyDog wrote:
1) Your post sounds like Sapce wasn't working, but then after making changes did work; Did I misread this? My Space still isn't working under the current configuration.

Oops, a little bit of flawed checking for if the key was valid >.< Launch_App2 also would not have worked, although I doubt anyone would have noticed. Fixed.
Quote:
2) As it stands now, if the same hotkey is defined for multiple tasks, it doesn't know which task to perform; i.e. I have mine set to do all three. In the midst of a game, the hotkey ends the game (acting as NewGameHotKey). Should probably check for game-state so it knows what function to perform.

Er... Having one for all three won't work too well. Having one for both NewGameHotkey and StartGameHotkey, or PauseHotkey and StartGameHotkey would be fine, but PauseHotkey and NewGameHotkey both fire during game play, so it would be impossible to know which one you wanted ._. However, I have fixed it so that you can have two of the same, as long as PauseHotkey and NewGameHotkey are not the same.
Quote:
3) After changing colors (background color, specifically), the right-most vertical bar in the pause graphic ( i.e. || ) becomes the same as the background color (but reverts back to white after executing an actual pause).

Whoops. When the background was hardcoded as white, I was using the same brush for drawing the pause graphic as the background, and that one reference to it didn't get changed over. Fixed
Quote:
4) Maybe add one of the many color pickers here on the AHK forum for selecting colors.

Good idea. I'll add that.

Quote:
5) When I first start the game, it draws the screen, then a split second later it drops down and to the right a couple pixels.

I haven't really noticed this, but I changed some stuff that might fix it. Please tell me if it helped or not. Maybe-fixed.

Quote:
6) Tell me to quit making suggestions at any time :wink:

Please don't :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 30th, 2009, 5:58 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
There is now a color picker included! I didn't really like any of the ones I found on the forum, so I made my own. It's based on the Photoshop one, except much crappier <3 It takes up about as much code as the entire rest of the game... But it was pretty fun to write, although it took me a LONG time, trying about three different functions, and finally writing my own, to get the RGB to HSV and vice-versa conversions right... Yikes. That was a bit painful.

There was also a bit of trouble making the Edit controls update each other without getting stuck in an infinite loop... Help-thread found here. I based my solution off of what SKAN posted.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Blackholyman, RoAltmann and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group