Jump to content


Photo

Replicate "Keep the drunk walking"


  • Please log in to reply
2 replies to this topic

#1 overflo

overflo

    GMC Member

  • New Member
  • 61 posts
  • Version:GM8

Posted 28 April 2012 - 11:17 AM

Is there any way of replicating the "Keep the drunk walking" game found here http://gprime.net/game.php/drunkwalk

I don't mean the feet walking or anything, just trying to keeping it upright with the mouse and have the sprite change when it falls too far.

I have been fiddling around with
if ((abs(image_angle-90) >= 5) && (abs(image_angle+90) < 5))
{
    sprite_index = spr_upright;
    image_angle=point_direction(self.x-10, self.y, mouse_x, mouse_y)
}
else
{
    sprite_index = spr_half_over;
    image_angle=point_direction(self.x-10, self.y, mouse_x, mouse_y)
}

It will fall to the sides but once the sprite changes it doesn't change back when upright

Any suggestions greatly appreciated

Edited by overflo, 28 April 2012 - 11:19 AM.

  • 0

#2 annihilator127

annihilator127

    GMC Member

  • GMC Member
  • 143 posts
  • Version:GM8

Posted 28 April 2012 - 01:05 PM

Hi overflo!

Your if condition might be erroneous:
(abs(image_angle-90) >= 5) will return true if image_angle is not between 85 and 95 inclusive (if the mouse pointer is not above).
(abs(image_angle+90) < 5) will return true if image_angle is between -95 and -85 exclusive (if the mouse pointer is below).

The main problem, though, is that image_angle will never be between -95 and -85, because point_direction uses a scale from 0 to 360 that does not include -85. Correct is (abs(image_angle - 270) < 5).

Hope that helps.
  • 0

#3 overflo

overflo

    GMC Member

  • New Member
  • 61 posts
  • Version:GM8

Posted 29 April 2012 - 12:54 AM

Thanks annihilator127. I shouldn't write any code when I have been staring at the computer for way too long, this morning it is glaringly obviously wrong!

I am just testing the image_angle and displaying it to the screen and strangely when my image is upright the image_angle is 0, left is 90, straight down is 180 and right is 270 which would explain (sort of) how I tried all sorts of things before coming up with the bunky code.


Anyway it is now working like this

image_angle=point_direction(self.x, self.y, mouse_x, mouse_y);
if  ((abs(image_angle < 90)) || (abs(image_angle > 270)))
    sprite_index = spr_upright;
else
    sprite_index = spr_over;


Edited by overflo, 29 April 2012 - 12:56 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users