Sdl_Timer Problem


captainchris

Still Fresh
Joined
Feb 12, 2012
Messages
12
Hi everybody!

I need your help because I'm surrounded with a timer problem.

I'm making a remake of Game & Watch Zelda for Caanoo

This is the body of the Ganon function : http://pastebin.com/fNmSYhwq

So, I use the throw_arrow function to throw arrow.

To reduce speed, I use a timer which:

* show the first arrow,
* clear the first arrow and show the second arrow
* and finally clear and blit the third arrow.

This is the body of throw_arrow: http://pastebin.com/gm1KXZ79

Sorry for indentation,but i did it quickly to bring into pastebin.com

This works but the character Link undergoes the break. That's my problem.

Does anyone have an idea?

Thx Chris.
 
I'm not 100% sure what you mean... but I think it's that the character cannot move while the arrow is moving?

If so, then this might be your problem: Your arrow code basically seems to do this:
Code:
while not arrow at target {

  wait for one second to pass
  move arrow to next position
}
So your arrow code spins in a loop for several seconds, during which nothing else gets done (ie processing input and moving the character).

You may want to restructure your code so that stuff can happen in parallel:
Code:
// Main loop
Uint32 ticks0 = SDL_GetTicks();
while( !game_done ) {

  Uint32 ticks1 = SDL_GetTicks();
  Uint32 delta_ticks = ticks1 - ticks0;
  ticks0 = ticks1;

  update_gannon(delta_ticks, ...);
  update_arrow(delta_ticks, ...);
  update_link(delta_ticks, ...);  
}
Code:
Uint32 arrow_ticks = 0;
void update_arrow(Uint32 delta_ticks, ...)
{
   arrow_ticks += delta_ticks;
   while( arrow_ticks >= 1000 ) {

      arrow_ticks -= 1000;

      // move arrow to next position...
   }
}
 
that's ok. you're understand my problem but throw_arrow is a part of the switch of monster_func

Code:
  case 5:

		/* Clear Screen */
		draw_surface(S_back->wall, 222, 103, 220, 103, 40, 33);
		draw_surface(S_back->wall, 228, 75, 230, 75, 95, 60);	/* clear monster */

		/* Show Monster */
		draw_surface(S_sprite->img, 230, 78, 2, 153, 50, 53);
		S_sprite->monster_dst.x = 286;
		monster_attack = 0;



		throw_arrow(S_sprite, S_back, S_input);

		break;
 
Back
Top