Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

"Snake" for AHK


  • Please log in to reply
19 replies to this topic
Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
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
Posted Image
Posted 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.

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006

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,
<!-- m -->https://ahknet.autoh...ogdor/Snake.ahk<!-- m -->

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


tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
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*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
Oh... Standard library;
Guess I should get that in to my lib folder;
That clears it right up and I'm happy again. :D

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
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!

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
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.

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006

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

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

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!

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008

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

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 .

and yes, nice game too!

Thanks!

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
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.

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008

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.

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

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.

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
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...

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
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:

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008

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.

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.

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

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

Good idea. I'll add that.

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.

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

Please don't :D

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
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.