Skip to main content
gamedev.net
🔒 Locked

Time Based Movement....

Started by werdy666 0 replies 300+ views
Original Post
werdy666
werdy666
hi, I am having afew troubles implementing timebased movement to my little tile based program. I understand the concept but i don''t know how to incorporate it in my program. here is my frame based movement code...
  
	if (keys[VK_RIGHT])
	{
		if (maxxsize < mapxsize)
		{
			xaxis-=0.1f;
			countx++;			// and we need to change the tile number to be drawn

			if (countx > 10)
			{
				xaxis += 0.1f;
				countx = 0;
				minxsize += 1;
				maxxsize += 1;
			// do something with the map array for which texture to assign the new tile

			// that is to be displayed now.

		
			}
		}
	}

  
for my program to render correctly the xaxis value and the countx value are dependant on eachother. for example if i wanted to move the xaxis at 0.2 then the count would be halved to 5. and if i wanted the xaxis value to be 0.05, then the count would have to go to 20. and here is a section of my time based code which makes my rendering go haywire...
  
	timerdiff = (timeGetTime() - timer);

// timer is given the current time before rendering occurs.


	secsperframe=(float)(timerdiff/1000.0f);

	//now compute the movement value

	movementvalue = (float)(1*secsperframe);


	if (keys[VK_LEFT])
	{
		if (minxsize > 0)
		{
			xaxis+=(movementvalue/10);
			
			countx+=movementvalue;		
			if (countx < 0)
			{
				xaxis -=(movementvalue/10);
				minxsize -= 1;
				maxxsize -= 1;
				countx = 10;
			}
		}
	}

  
another problem i don''t know how to overcome is the fact that when i assign countx to 10, that is based on the xaxis increasing/decreasing by 0.1 each keypress. So if anyone could help me with this i would greatly appreciatte it! And if u need more code just tell me! Werdy666 My Homepage : http://werdy666.20megsfree.com/

Topic Locked

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

Sign in to reply to this topic.