Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Game Problem (Multiple Movements)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Spence607




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Laplace's Demon




PostPosted: 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.
andrew.




PostPosted: 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.
code:
var picture : int


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




PostPosted: Mon Jan 05, 2009 11:34 pm   Post subject: Re: Game Problem (Multiple Movements)

Got it, thanks for the help.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: