PDA

View Full Version : Having trouble with smooth movement in tile engine



AlacomoJr
02-23-2012, 01:21 AM
I have this tiling engine with a player, and i want to make it so that the player moves smoothly, lets say it translates by .2 every time, instead of the full 1.
I can't get this to work however. I've gotten as far as moving the whole scene to the right when the character goes left, but i don't know how i would make the character stay in the center of the screen while the rest of the scene moves right.


#include < stdio.h >
#include < stdlib.h >
#include < GL/glut.h >
#include < GL/gl.h >
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <time.h>
using namespace std;

//PROGRAM VARIABLES
void dec(void)
{
}

bool keyStates[256] = { 0 }; // Create an array of boolean values of length 256 (0-255)
bool keySpecialStates[256] = { 0 };// Create an arroy of boolean values of length 246 (0-245)

bool isMoving = false;
bool doneAnimation = false;

float scenePlacementX = 0.0f ;
float scenePlacementY = 0.0f ;
float scenePlacementZ = -25.0f;

float tilePlacementX = 0;
float tilePlacementY = -1.0f;

GLuint tex0 = 0;
GLuint tex1 = 0;
GLuint tex2 = 0;

int tilePosX = 0, tilePosY = 0;

int playerPosX = 0, playerPosY = 0;
int lastPlayerPosX = 0, lastPlayerPosY = 0;

int Map1[50][50] =
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1 },
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1 },
{1,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
};

//PROGRAM VARIABLES

void readMap(void)
{

}

GLuint LoadTexture( const char* filename, int width, int height)
{
unsigned char * data;
FILE * file;

file = fopen( filename, "rb" ); // We need to open our file
if ( file == NULL ) return 0; // If our file is empty, set our texture to empty

data = (unsigned char *)malloc( width * height * 3 ); // Assign the nessecary memory for the texture

fread( data, width * height * 3, 1, file ); // read in our file
fclose( file ); //close our file, no point leaving it open

glGenTextures( 1, &amp;tex0 ); // then we need to tell OpenGL that we are generating a texture
glBindTexture( GL_TEXTURE_2D, tex0 ); // now we bind the texture that we are working with
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // set texture environment parameters The parameter GL_MODULATE will blend the texture with whatever is underneath, setting it to GL_DECAL will tell the texture to replace whatever is on the object.

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //Here we are setting the parameter to repeat the texture instead of clamping the texture to the edge of our shape.
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
free( data ); // free the texture
return tex0; // return the texture data
}

GLuint LoadTexture1( const char* filename, int width, int height)
{
unsigned char * data;
FILE * file;

file = fopen( filename, "rb" ); // We need to open our file
if ( file == NULL ) return 0; // If our file is empty, set our texture to empty

data = (unsigned char *)malloc( width * height * 3 ); // Assign the nessecary memory for the texture

fread( data, width * height * 3, 1, file ); // read in our file
fclose( file ); //close our file, no point leaving it open

glGenTextures( 1, &amp;tex1 ); // then we need to tell OpenGL that we are generating a texture
glBindTexture( GL_TEXTURE_2D, tex1 ); // now we bind the texture that we are working with
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // set texture environment parameters The parameter GL_MODULATE will blend the texture with whatever is underneath, setting it to GL_DECAL will tell the texture to replace whatever is on the object.

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //Here we are setting the parameter to repeat the texture instead of clamping the texture to the edge of our shape.
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
free( data ); // free the texture
return tex1; // return the texture data
}

GLuint LoadTexture2( const char* filename, int width, int height)
{
unsigned char * data;
FILE * file;

file = fopen( filename, "rb" ); // We need to open our file
if ( file == NULL ) return 0; // If our file is empty, set our texture to empty

data = (unsigned char *)malloc( width * height * 3 ); // Assign the nessecary memory for the texture

fread( data, width * height * 3, 1, file ); // read in our file
fclose( file ); //close our file, no point leaving it open

glGenTextures( 1, &amp;tex2 ); // then we need to tell OpenGL that we are generating a texture
glBindTexture( GL_TEXTURE_2D, tex2 ); // now we bind the texture that we are working with
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // set texture environment parameters The parameter GL_MODULATE will blend the texture with whatever is underneath, setting it to GL_DECAL will tell the texture to replace whatever is on the object.

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); //Here we are setting the parameter to repeat the texture instead of clamping the texture to the edge of our shape.
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data );
free( data ); // free the texture
return tex2; // return the texture data
}

void FreeTexture0( GLuint tex0 )
{
glDeleteTextures( 1, &amp;tex0 ); // Delete our texture, simple enough.
}
void FreeTexture1( GLuint tex1 )
{
glDeleteTextures( 1, &amp;tex1 ); // Delete our texture, simple enough.
}
void FreeTexture2( GLuint tex2 )
{
glDeleteTextures( 1, &amp;tex2 ); // Delete our texture, simple enough.
}

void wait(int x)
{
int seconds = 1;
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}

void renderTile(void)
{
for (int h = 0; h < 50; h++)
{
for (int w = 0; w < 50; w++)
{
if (Map1[h][w] == 1)
{
glBindTexture( GL_TEXTURE_2D, tex1);
}
else if (Map1[h][w] == 0)
{
glBindTexture( GL_TEXTURE_2D, tex0);
}
glPushMatrix();
glTranslatef(w, -h, 0);

glBegin (GL_QUADS);
glTexCoord2d(0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);

glTexCoord2d(1.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);

glTexCoord2d(1.0, 1.0);
glVertex3f(1.0, 1.0, 0.0);

glTexCoord2d(0.0, 1.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
glPopMatrix();
}
}
}

void renderPlayer(void)
{
for (int h = 0; h < 50; h++)
{
for (int w = 0; w < 50; w++)
{
if (Player[h][w] == 1)
{
glBindTexture( GL_TEXTURE_2D, tex2);
glPushMatrix();
glTranslatef(w, -h, 0);

glBegin (GL_QUADS);
glTexCoord2d(0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);

glTexCoord2d(1.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);

glTexCoord2d(1.0, 1.0);
glVertex3f(1.0, 1.0, 0.0);

glTexCoord2d(0.0, 1.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();
glPopMatrix();

playerPosX = w;
playerPosY = h;
}
}
}
}

void notMoving(int x)
{
isMoving = false;
}

bool a = false, b = false, c = false, d = false, e = false;


void animateLeft(int x)
{
doneAnimation = false;
if (a == false)
{
glTranslatef(.2,0,0);
a = true;
glutTimerFunc(100, animateLeft, 0);
}
else if (b == false)
{
glTranslatef(.2,0,0);
b = true;
glutTimerFunc(100, animateLeft, 0);
}
else if (c == false)
{
glTranslatef(.2,0,0);
c = true;
glutTimerFunc(100, animateLeft, 0);
}
else if (d == false)
{
glTranslatef(.2,0,0);
d = true;
glutTimerFunc(100, animateLeft, 0);
}
else if (e == false)
{
glTranslatef(.2,0,0);
a = false;
b = false;
c = false;
d = false;
doneAnimation = true;
}
}

void playerLeft(void)
{
isMoving = true;
lastPlayerPosX = playerPosX - 1;
for (int h = 0; h < 50; h++)
{
for (int w = 0; w < 50; w++)
{
if (Player[h][w] == 1 &amp;&amp; Map1[h][lastPlayerPosX] != 1)
{
Player[h][w] = 0;
animateLeft(0);
Player[h][w -= 1] = 1;
}
}
}
glutTimerFunc(100, notMoving, 0);
}

void playerRight(void)
{
isMoving = true;
lastPlayerPosX = playerPosX + 1;
for (int h = 0; h < 50; h++)
{
for (int w = 0; w < 50; w++)
{
if (Player[h][w] == 1 &amp;&amp; Map1[h][lastPlayerPosX] != 1)
{
Player[h][w] = 0;
Player[h][w += 1] = 1;
glTranslatef(-1,0,0);
}
}
}
glutTimerFunc(100, notMoving, 0);
}

void playerUp(void)
{
isMoving = true;
lastPlayerPosY = playerPosY - 1;
for (int h = 0; h < 50; h++)
{
for (int w = 0; w < 50; w++)
{
if (Player[h][w] == 1 &amp;&amp; Map1[lastPlayerPosY][w] != 1)
{
Player[h][w] = 0;
Player[h -= 1][w] = 1;
glTranslatef(0,-1,0);
}
}
}
glutTimerFunc(100, notMoving, 0);
}

void playerDown(void)
{
isMoving = true;
lastPlayerPosY = playerPosY + 1;
for (int h = 0; h < 50; h++)
{
for (int w = 0; w < 50; w++)
{
if (Player[h][w] == 1 &amp;&amp; Map1[lastPlayerPosY][w] != 1)
{
Player[h][w] = 0;
Player[h += 1][w] = 1;
glTranslatef(0,1,0);
}
}
}
glutTimerFunc(100, notMoving, 0);
}

void Update(int value)
{
glutPostRedisplay();
glutTimerFunc(25, Update, 0);
}

void display (void)
{
glClearColor(0.f, 0.f, 0.f, 1.f); // Clear the background of our window to red
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
glEnable( GL_TEXTURE_2D );
glPushMatrix();
glTranslatef(-48, 2, -20);

renderTile();
renderPlayer();

glPopMatrix();
glutSwapBuffers(); // Flushes everything above to the window
}

void reshape (int width, int height)
{
glViewport(0, 0, (GLsizei)width, (GLsizei)height); // Sets viewport to size of the window
glMatrixMode(GL_PROJECTION); // Switch to the projection matrix so that we can manipulate how our scene is viewed
glLoadIdentity(); // Reset the projection matrix to the identity matrix so that we don't get any artifacts (cleaning up)

gluPerspective(60, (GLfloat)width / (GLfloat)height, 0.1, 100.0); // FOV, Aspect ratio, Near and Far rendering values.

glMatrixMode(GL_MODELVIEW); // Switch back to Model matrix to draw objects.
}

void keyOperations(void)
{
if (keyStates['a'])
{
if(isMoving == false)
playerLeft();
}
if (keyStates['b'])
{

}
if (keyStates['c'])
{
cout << playerPosX << "\n";
cout << playerPosY << "\n";
}
if (keyStates['d'])
{
if(isMoving == false)
playerRight();
}
if (keyStates['e'])
{

}
if (keyStates['f'])
{

}
if (keyStates['g'])
{

}
if (keyStates['h'])
{

}
if (keyStates['i'])
{

}
if (keyStates['j'])
{

}
if (keyStates['k'])
{

}
if (keyStates['l'])
{

}
if (keyStates['m'])
{

}
if (keyStates['n'])
{

}
if (keyStates['o'])
{

}
if (keyStates['p'])
{

}
if (keyStates['q'])
{

}
if (keyStates['r'])
{

}
if (keyStates['s'])
{
if(isMoving == false)
playerDown();
}
if (keyStates['t'])
{

}
if (keyStates['u'])
{

}
if (keyStates['v'])
{

}
if (keyStates['w'])
{
if(isMoving == false)
playerUp();
}
if (keyStates['x'])
{

}
if (keyStates['y'])
{

}
if (keyStates['z'])
{

}
if (keyStates[27]) // ESCAPE
{
exit(0);
}
}

void keySpecialOperations(void)
{
if (keySpecialStates[GLUT_KEY_LEFT])
{
// Blah
}
}

void keyPressed (unsigned char key, int x, int y)
{
keyStates[key] = true; // Set the state of the key to pressed
keyOperations();
}

void keyUp (unsigned char key, int x, int y)
{
keyStates[key] = false; // Set the state of the key to unpressed
keyOperations();
}

void keySpecial (int key, int x, int y)
{
keySpecialStates[key] = true; // Set the state of the key to pressed
keySpecialOperations();
}

void keySpecialUp (int key, int x, int y)
{
keySpecialStates[key] = false; // Set the state of the key to unpressed
keySpecialOperations();
}



int main(int argc, char **argv)
{
glutSetKeyRepeat(GLUT_KEY_REPEAT_OFF);

glutInit(&amp;argc, argv); // Initialize GLUT
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); // Sets up a single buffered display / Alpha
glutInitWindowSize (500, 500); // Window size
glutInitWindowPosition (100, 100); // Window position
glutCreateWindow ("OpenGL Window"); // Create window

glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0, GLUT_WINDOW_WIDTH, GLUT_WINDOW_HEIGHT, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);

glutReshapeFunc(reshape); // Uses our reshape function for reshaping the window
glutDisplayFunc(display); // Uses our display function for display
glutKeyboardFunc(keyPressed); // Uses our keyPressed function for keyboard interaction
glutKeyboardUpFunc(keyUp);// Uses our keyUp function for keyboard interaction when keys are released
glutSpecialFunc(keySpecial);
glutSpecialUpFunc(keySpecialUp);

glutTimerFunc(25, Update, 0);

tex0 = LoadTexture("C:/Program Files (x86)/ACGames/Textures/Dirt.raw", 16, 16);
tex1 = LoadTexture1("C:/Program Files (x86)/ACGames/Textures/Bedrock.raw", 16, 16);
tex2 = LoadTexture2("C:/Program Files (x86)/ACGames/Textures/Player.raw", 8, 8);

glutMainLoop(); // Enter main display loop

FreeTexture0(tex0);
FreeTexture1(tex1);
FreeTexture2(tex2);
}