Archived

This topic is now archived and is closed to further replies.

need help with Tetris type block dropping

This topic is 5583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need help understanding how I can make keys(VK_LEFT...)change focus on what block is moving. I have a function to draw block and I am using glTranslatef(x,y,z)to control movemnent, then I use the keys to move block if(keys->[VK_DOWN]==TRUE) { y-=0.05f; } I can get the block to move and I can draw another block if the first block moves far enough down...but once the other block is drawn they both move and I only want to move the new block.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can use block''s velocity to determine whether to move it:
if velocity is non-zero - respond on VK_UP...
if velocity is zero - don''t respond on VK_UP...
now, just when the block reachs an obstacle - you only have to make it''s velocity zero!

Good luck!

Share this post


Link to post
Share on other sites
So you have 1+ blocks that you can move at one time, but when there are 2 or more they all move the same??? I''m assuming this is what happens.

Have an array/list/whatever of all the possible moving blocks and the current block and then move only the current block:

float3 blocks[max_amount];
int current_block;

if (down)
blocks[current_block].y -= 0.05f;
else if (left/right)
change current_block;

That should do the trick...

Luigi Pino
The 23rd Dimension
Maybe it would be better if I show you all what I have got so far(using the newest NeHe.cpp and NeHe.h files) this is the main.cpp:

#include <windows.h>
#include <stdlib.h>
#include <gl/gl.h>

#include "NeHeGL.h"

#pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking
#pragma comment( lib, "glu32.lib" ) // Search For glu32.lib While Linking

#ifndef CDS_FULLSCREEN // CDS_FULLSCREEN Is Not Defined By Some
#define CDS_FULLSCREEN 4 // Compilers. By Defining It This Way,
#endif // We Can Avoid Errors

/*********************************************************************

-----------Globals-----------

*********************************************************************/
#define SCREENTOP 4
#define SCREENBOTTOM -2

GL_Window* g_window;
Keys* g_keys;
Application* app;

float x=0.0f;
float y=0.0f;
float z=0.0f;

bool active=true;

void Block(float px, float py,float pz)
{
glColor3f(0.0f,1.0f,0.0f);
glPushMatrix();
glTranslatef(px,py,pz-8);
glTranslatef(x,y,z);
glBegin(GL_QUADS);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glEnd();
glPopMatrix();
}

float GetPosition(void)
{
return y;
}

int CanDrawBlock(void)
{
if(y {
return true;
}
return false;
}
/*********************************************************************

------------Draw---------------

*********************************************************************/
void Draw(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity();

Block(0,0,0);
if(g_keys->keyDown[VK_LEFT]==TRUE)
{
x-=0.05f;
}

if(g_keys->keyDown[VK_RIGHT]==TRUE)
{
x+=0.05f;
}

if(g_keys->keyDown[VK_DOWN]==TRUE)
{
y-=0.05f;
}

if(g_keys->keyDown[VK_UP]==TRUE)
{
y+=0.05f;
}

if(CanDrawBlock())
{
Block(2,SCREENTOP,0);
}

if(y {
//active=false;
}

glFlush ();
}


/*********************************************************************

-----------Update---------------

*********************************************************************/
void Update(DWORD milliseconds)
{
if (g_keys->keyDown [VK_ESCAPE] == TRUE) // Is ESC Being Pressed?
{
TerminateApplication (g_window); // Terminate The Program
}

if (g_keys->keyDown [VK_F1] == TRUE) // Is F1 Being Pressed?
{
ToggleFullscreen (g_window); // Toggle Fullscreen Mode
}

}


/*********************************************************************

---------Initialize----------

*********************************************************************/
BOOL Initialize(GL_Window* window, Keys* keys)
{
g_window = window;
g_keys = keys;

glClearColor (0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glShadeModel(GL_SMOOTH); // use smooth shading
glEnable(GL_DEPTH_TEST); // hidden surface removal
//glEnable(GL_LIGHT0); // enable light0
//glEnable(GL_LIGHTING); // enable lighting
//glEnable(GL_TEXTURE_2D);

return true;
}


/*********************************************************************

---------Deinitailize---------------

*********************************************************************/
void Deinitialize(void)
{

}

Share this post


Link to post
Share on other sites