Advertisement

yet another tetris related question.

Started by February 12, 2003 09:58 PM
2 comments, last by skittleZ 22 years ago
ok...assuming im using the code from my last post (it worked perfect) I am now trying to draw another square AFTER the 1st square hits its y axis limit(-20) here is the code I tried... if(yposy<=-20) { move=false;//When the square hits its mark... glLoadIdentity(); //Draw a new square glTranslatef(xposy,yposy,-20.0f); //Start the same place glBegin(GL_QUADS); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); //Same size glVertex3f( 1.0f,-1.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glEnd(); } This didnt work...Any suggestions? [edited by - skittlez on February 12, 2003 11:13:59 PM]
well, now that you're getting in to multiple blocks, you're going to need to create an array of blocks. My suggestion would be to create a structure like so:


      #define NUMOFBLOCKS 100struct TetrisBlocks{	float xpos,ypos;};TetrisBlocks blocks[NUMOFBLOCKS];int currblock=0;  //we need to know which tile we want to move// This would all go in the top part of your file again    


ok, now that we have our basic structure (you can add more as you please), we can start testing it.

in your drawglscene code, replace the code you put in earlier with the bool move variable and all that stuff and then replace it with this:


  if(count>50){	count=0;	blocks[currblock].ypos--;}count++;   //increase the counting variableif(blocks[currblock].ypos<=-20 && currblock<NUMOFBLOCKS)	currblock++;  //move to the next tile and draw that one    

oh yah, and we also want to set up our variables, too, the following code would go in the InitGL function:


  for(int a=0;a<NUMOFBLOCKS;a++){	blocks<A href='http://.ypos=10.0f;   //or whatever y value you want them to start at	blocks[a].xpos=0.0f;}  


and that will run through them all and set their stuff up.
also, you might want to change your glTranslate too, so that it draws all of the blocks that have been set so far:


  // this should go in DrawGLScene, and you'll want to replace the glLoadIdentity and the glTranslatef with this codefor(int a=0;a<currblock+1;a++){	glLoadIdentity();	glTranslatef(blocks[a].xpos, blocks[a].ypos, -10.0f);	// and then your quad stuff goes here}      


and that will draw all of the blocks that have been placed so far AND the one that is falling

hopefully you understand most of this, lol

bloodright.150m.com //For the latest on all of the IVGDA projects!

[edited by - jverkoey on February 12, 2003 11:13:34 PM]

[edited by - jverkoey on February 12, 2003 11:14:17 PM]

[edited by - jverkoey on February 12, 2003 11:15:05 PM]
Advertisement
Interested in the source code of a tetris java applet?
yes, paparagnarock@uomail.com

This topic is closed to new replies.

Advertisement