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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started