Skip to main content
gamedev.net
🔒 Locked

Timer Question

Started by CannoN346 2 replies 150+ views
Original Post
CannoN346
CannoN346
Ok, in my pacman game everytime a big square is hit a timer goes off and for the duration of that timer pacman chases the ghosts. But each time another big square is hit, the timer is shorter. Whats the problem? Heres my code...
  
for (int index=0; index < MAX_BIG_SQUARES; index++)
{
	if (big_squares[index].state == SQUARE_OFF)
	{
		if (++chase_timer < MAX_CHASE_TIMER)
		{ 
			if (pacman.x > ghost_1.x)
			dir = DIR_LEFT;
			else
			if (pacman.x < ghost_1.x)
			dir = DIR_RIGHT;
			else
			if (pacman.y > ghost_1.y)
			dir = DIR_UP;
			else
			if (pacman.y < ghost_1.y)
			dir = DIR_DOWN;

			if (pacman.x > ghost_2.x)
			opcode = DIR_LEFT;
			else
			if (pacman.x < ghost_2.x)
			opcode = DIR_RIGHT;
			else
			if (pacman.y > ghost_2.y)
			opcode = DIR_UP;
			else
			if (pacman.y < ghost_2.y)
			opcode = DIR_DOWN;

			if (pacman.x > ghost_3.x)
			blue = DIR_LEFT;
			else
			if (pacman.x < ghost_3.x)
			blue = DIR_RIGHT;
			else
			if (pacman.y > ghost_3.y)
			blue = DIR_UP;
			else
			if (pacman.y < ghost_3.y)
			blue = DIR_DOWN;

			if (pacman.x > ghost_4.x)
			orange = DIR_LEFT;
			else
			if (pacman.x < ghost_4.x)
			orange = DIR_RIGHT;
			else
			if (pacman.y > ghost_4.y)
			orange = DIR_UP;
			else
			if (pacman.y < ghost_4.y)
			orange = DIR_DOWN;
		}

	}
}
  
And i make sure to reset the timer...
  
for (index=0; index<MAX_BIG_SQUARES; index++)
{

	if(Collision_BOBS(&pacman,&big_squares[index]))
	{
		if(big_squares[index].state == SQUARE_ON)
		{
			Destroy_BOB2(&big_squares[index]); 
			player_score+=50;
			big_squares[index].state = SQUARE_OFF;
			total_squares-=1;
			chase_timer=0;

		}
		if (big_squares[index].state == SQUARE_OFF)
			player_score+=0;
		
	}
	
}
  
Fruny
Fruny
Answer: You increment chase_timer inside your big_squares conditional.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
CannoN346
CannoN346
Anything else? That last reply was only a bit helpful.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.