Advertisement

Rotate only one time

Started by April 23, 2002 08:39 PM
10 comments, last by edwinnie 22 years, 7 months ago
okie, still in tetris clonie. i got a problem with rotation> how do u limit the rotation to only one time? here, everytime control is pressed, the block animates from 1st frame to 3rd frame. my code>
  
void Rotate_Crystal(void)
{	
if( (KEY_DOWN(VK_CONTROL)) && (crystal_L.curr_frame == 0) )
	{
	Set_Animation_BOB(&crystal_L, 0);
        crystal_L.curr_frame = 1;
	} 

if( (KEY_DOWN(VK_CONTROL)) && (crystal_L.curr_frame == 1) )
	{
	Set_Animation_BOB(&crystal_L, 1);
        crystal_L.curr_frame = 2;
	}
}  
Use an else statement ...

if( (KEY_DOWN(VK_CONTROL)) && (crystal_L.curr_frame == 0)
...

else if( (KEY_DOWN(VK_CONTROL)) && (crystal_L.curr_frame == 1) )
...
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
If you notice in your code, the two procedures will execute together if the first if statement evaluates to true.

This is because if your first if statement evaluates to true, then curr_frame is set to equal 1, which is what is required for the second if procedure to evaluate to true.

Therefore anytime the control key is down and the curr_frame is equal to 0, both of the following will execute:


  void Rotate_Crystal(void){    if( (KEY_DOWN(VK_CONTROL)) && (crystal_L.curr_frame == 0) )    {	Set_Animation_BOB(&crystal_L, 0);        // sets curr_frame equal to 1, which is what is required        // for next if statement to evaluate to true        crystal_L.curr_frame = 1;    }    if( (KEY_DOWN(VK_CONTROL)) && (crystal_L.curr_frame == 1) )    {	Set_Animation_BOB(&crystal_L, 1);        crystal_L.curr_frame = 2;    }}    


Hope this helps.


------

Shop for the Lowest Price!
Then, Check a Reseller''s Rating Before You Purchase!
------Shop for the Lowest Price!Then, Check a Reseller's Rating Before You Purchase!
but for this case oso doesnt seem to work,
it stills starts from 1st frame to 3rd frame.


              void Rotate_Crystal(void){	if (KEY_DOWN(VK_CONTROL)){	if (crystal[0].counter_1 == CRYSTAL_L)  	{		if(crystal[0].counter_2 == ROTATE_1)    		   {			crystal[2].x = crystal[0].x +30;            //translation			crystal[2].y = crystal[0].y;			Set_Pos_BOB(&crystal[2], crystal[2].x, crystal[2].y ); 						crystal[3].x = crystal[0].x +60;                        crystal[3].y = crystal[0].y;			Set_Pos_BOB(&crystal[3], crystal[3].x, crystal[3].y);    	        				   			crystal[0].counter_2 = ROTATE_2;		   }            else		if(crystal[0].counter_2 == ROTATE_2)		   {			crystal[0].x = crystal[3].x; 		        crystal[0].y = crystal[3].y + 30;			Set_Pos_BOB(&crystal[0], crystal[0].x, crystal[0].y);							crystal[1].x = crystal[3].x;                        crystal[1].y = crystal[3].y + 60;			Set_Pos_BOB(&crystal[1], crystal[1].x, crystal[1].y);		   		    crystal[0].counter_2 = ROTATE_3;		   }          }//end if	}//end if}// end rotate_crystal    




[edited by - edwinnie on April 24, 2002 6:08:23 AM]

[edited by - edwinnie on April 24, 2002 6:09:07 AM]
HELP!!
above^^
Two things:

1. Are you sure that you know what your frames look like? Have you written some debugging code that rotates the objects through their entire animation sequence?

2. How often is RotateCrystal called? Are you getting into this function twice with each key press, or could you be calling this function twice each update?
Advertisement
oh btw, i changed the code if u observe.

there r no animation sequences.
now there is just a shift of coordinates, and repositioning.

the next frame of rotation is correct, i checked 1st b4.

i tried putting a modified one in game_init, and only the
KEY_DOWN(VK_CONTROL) in game_main.
still din work.

the problem is the counter_2, but i am not sure where to put it.
this counter_2 helps to check which rotation to perform.

btw, i couldnt think of any code that can put a more "general"
type of rotation. here the rotation is specific(coordinates shifting). which could be the problem oso.



[edited by - edwinnie on April 24, 2002 9:13:30 AM]
or is there a way that i can break out after the 1st rotation?
now i noe why>

the rotations move too fast!
To rotate a grid clockwise 90 degrees:

for y=0 to 3
for x= 0 to 3
NewGrid(3-y,x) = OldGrid(x,y);


assuming a grid 4*4.

I read you were doing tetris.

,Jay

This topic is closed to new replies.

Advertisement