Game Problem (Multiple Movements)
Author |
Message |
Spence607
![](http://compsci.ca/v3/uploads/user_avatars/1842328521497e82b827a66.jpg)
|
Posted: Mon Jan 05, 2009 8:38 pm Post subject: Game Problem (Multiple Movements) |
|
|
Alright, this is kind of hard to explain, so I'll post some pics. I'm using Input.KeyDown for my character movements, my character can only move in four directions, up, down, left, and right. Now if I press up and left, my character will be drawn facing both ways and will move diagonally, same if any other two keys are pressed, unless it's up and down or left and right or up, down, left, and right then the character faces those ways but does not move. Is there a way I can prevent all of this, so my character can only move up, down, left and right, and will only face and move according to the last key pressed, no matter if another key is being pressed at the same time.
![Posted Image, might have been reduced in size. Click Image to view fullscreen. Posted Image, might have been reduced in size. Click Image to view fullscreen.](http://i410.photobucket.com/albums/pp184/Spence607/Screen%20Shots/Movements.jpg) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Laplace's Demon
|
Posted: Mon Jan 05, 2009 8:56 pm Post subject: Re: Game Problem (Multiple Movements) |
|
|
Well, the simplest solution would be to use a single if statement for all 4 movement keys, rather than seperate if statements.
in pseudo-code:
if upkey then
moveup
elsif downkey then
movedown
elsif rightkey then
moveright
elsif leftkey then
moveleft
end if
This would make it so you could only be moving in one direction at once, however the obvious drawback is that your movement keys have a priority. For example if you're pressing both the up and left keys you will always move up, even if you pressed the left-key after you pressed up-key. |
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Mon Jan 05, 2009 10:28 pm Post subject: RE:Game Problem (Multiple Movements) |
|
|
Laplace's Demon got it. To make the picture stay the same if you're not pressing anything, just make another variable for a picture
e.g.
And whenever you move, copy the image for moving right into that variable and always display that image.
e.g.
code: | var leftpicture : int := Pic.FileNew ("picture.jpg")
var stationarypic : int := Pic.FileNew ("somepicture.jpg")
% In your loop put:
if leftkey then
moveleft
stationarypic := leftpicture
end if
|
That is just a really basic example. Also, left key is where you would put KEY_ARROW_LEFT or whatever and moveleft is whatever you do to move left. I hope I am making this clear. |
|
|
|
|
![](images/spacer.gif) |
Spence607
![](http://compsci.ca/v3/uploads/user_avatars/1842328521497e82b827a66.jpg)
|
Posted: Mon Jan 05, 2009 11:34 pm Post subject: Re: Game Problem (Multiple Movements) |
|
|
Got it, thanks for the help. |
|
|
|
|
![](images/spacer.gif) |
|
|