AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

"Snake" for AHK
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Thu Aug 27, 2009 2:16 pm    Post subject: "Snake" for AHK Reply with quote

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:
SimpleArray by infogulch
Gdip by tic
Common Dialogs by majkinetor

Screenshots



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 Wed Dec 02, 2009 5:06 am; edited 16 times in total
Back to top
View user's profile Send private message AIM Address
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Thu Aug 27, 2009 7:32 pm    Post subject: Re: "Snake" for AHK Reply with quote

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

_________________

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
tidbit



Joined: 09 Mar 2008
Posts: 1807
Location: Minnesota, USA

PostPosted: Thu Aug 27, 2009 7:35 pm    Post subject: Reply with quote

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.
Even monkeys fall from trees. - Japanese proverb
Back to top
View user's profile Send private message
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Thu Aug 27, 2009 7:51 pm    Post subject: Reply with quote

Oh... Standard library;
Guess I should get that in to my lib folder;
That clears it right up and I'm happy again. Very Happy
_________________

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Thu Aug 27, 2009 7:55 pm    Post subject: Reply with quote

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!
_________________

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Thu Aug 27, 2009 8:23 pm    Post subject: Reply with quote

Whoops, sorry, I forgot that I had used infogulch's SimpleArray library Mad
Sorry about that.

@SoggyDog:
P or the Pause button to pause. I'll make it into a graphic button later.
Back to top
View user's profile Send private message AIM Address
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Thu Aug 27, 2009 8:33 pm    Post subject: Reply with quote

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

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Thu Aug 27, 2009 8:56 pm    Post subject: Reply with quote

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 Exclamation I think the main problem is lacking documentation Sad

and yes, nice game too!
_________________
AHK Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Thu Aug 27, 2009 9:35 pm    Post subject: Reply with quote

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 Exclamation I think the main problem is lacking documentation Sad

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!
Back to top
View user's profile Send private message AIM Address
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Thu Aug 27, 2009 10:18 pm    Post subject: Reply with quote

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

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Thu Aug 27, 2009 11:37 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Fri Aug 28, 2009 3:29 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message AIM Address
SoggyDog



Joined: 02 May 2006
Posts: 783
Location: Greeley, CO

PostPosted: Fri Aug 28, 2009 7:33 pm    Post subject: Reply with quote

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
_________________

SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Fri Aug 28, 2009 11:15 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message AIM Address
Krogdor



Joined: 18 Apr 2008
Posts: 1390
Location: The Interwebs

PostPosted: Sun Aug 30, 2009 4:58 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group