View Single Post
Old 02-02-2005, 01:59 AM   #1
feminista
Abandonia nerd

 
Join Date: Dec 2004
Location: ,
Posts: 50
Default

Okay, I have a few SDL sprites who move when I hit the arrow keys, according to this code:

Code:
int spd = 5;

if ( keys[SDLK_UP] *&& (vikings1.yget() >= 200) ) { vikings1.yadd(-spd); }
if ( keys[SDLK_DOWN] ) { vikings1.yadd(spd); }
if ( keys[SDLK_LEFT] ) { vikings1.xadd(-spd); }
if ( keys[SDLK_RIGHT] ) { vikings1.xadd(spd); }
spd is how many pixels they move at a time, and the 200 is a limit on vertical height.

The problem that I have is that when I press and hold right, and then press left (or any other combination of opposite directions, the new one doesn't override the old one. Now, I did try something along these lines:

Code:
if ( keys[SDLK_UP] *&& (vikings1.yget() >= 200) ) { 
 *if (keys[SDLK_DOWN]) { vikings1.yadd(-2*spd); } 
 *else { vikings1.yadd(-spd); }
}
However, that's not at all what I want, and it only works in one direction anyway.

So, how precisely would I get these keys to behave the nice, normal way (i.e. each keypress in an opposing direction overriding the last, regardless of hardware capabilities)?
feminista is offline                         Send a private message to feminista
Reply With Quote