Question: Hello! Using the c language and I need help with a particular problem. I have sprite that has to move from stationary to walking speed

Hello! Using the c language and I need help with a particular problem.

I have sprite that has to move from stationary to walking speed (0.5) when a key is pressed. Either 'a' or 'd' for left and right respectivly. All this is encpsulated in a single function called onestep that plays one step of the game. Now, the problem arises when I have to make the character run i.e change the speed to 1 from the current walking speed of 0.5 when the same key is pressed again. So far i've got something like this for walking right: if ( key == d ){ walk }, however I dont' know how to deal with a second key press once the sprite is walking. Heres what I have so far, I know its wrong, but am I at least on the right track?

I.e

set global variable speed = 0;

for walking: if ( key == d) { walk and set speed = 1}

for running: if ( key == d && speed = 1){ run and set speed = 2}

doesn't work because the program goes right into the 'run' if statement regardless once d is pressed.... Any help would be appreaciated! Thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!