Ok, I'm here once again.
This project is due Tuesday-Thursday (depends on the instructor). I REALLY want to finish implementing a very simple battle system. So, let me explain how I want this to go.
When user hits SPACEBAR, Link should be displayed with his sword out and attacking. So if you're facing Southwards, I want Link to use the proper sprites/frames, face downwards and attack.
So, to avoid complication (and the horrible errors I was getting last night), I made another update attack function as follows:
|1||/* displays proper sword attack sprite depending on direction */|
|2||void updateattacksprite(SPRITE *spr)|
|5|| //update frame based on dir|
|6|| if (++spr->framecount > spr->framedelay)|
|8|| spr->framecount = 0;|
|11|| if(prev_dir == 4)|
|13|| textout(buffer, font, "USER PRESSED SPACEBAR,|
|14|| SHOULD USE SWORD ANIMATION", 20, 20, WHITE);|
|16|| //for(a=0; a<3; a++)|
|18|| if(spr->curframe != 14) |
|22|| if(spr->curframe == 14)|
|23|| spr->curframe = 12;|
|25|| else if(spr->curframe < 12)|
|26|| spr->curframe = 14; |
|28|| draw_link(); |
|30|| } |
Now, within main(), within the while loop, I have this:
key = getinput();
/* key will only be 1 if SPACEBAR was pressed */
if(key == 0)
else if((key == 1) && (a != 0))
NOTE: Keep in mind, a is set to 3 (a=3;) is done when the spacebar is pressed.
Okay, so when user is facing south and hits spacebar, frames 12-14 should consecutively be displayed. I don't want to do this using a for loop (as I've commented out) because it looks really choppy and b) even using rest(100) within the for loop, the frames happen really quickly; it seemed rest had no effect on slowing down the animation.
Now what's happening is that the results are weird. Sometimes the animation frames 12 and 13 appear. Sometimes only 12 appears or only 13. Also, sometimes Little Link disappears from screen for just the slightest fraction of a second. Is this because of the keypressed()?
Can someone point out the mistakes I'm making? Appreciate the help, TIA.