In the game loop:
//Fixes some stupid bug
gl.glColor3f(1.0f, 1.0f, 1.0f);
// Clear the drawing area
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);// | GL.GL_COLOR_BUFFER_BIT);
// Reset the current matrix to the "identity"
gl.glLoadIdentity();
//Set the view
gl.glOrtho(-8f, 7f, -4f, 3f, 0.1f, 100f);
update(gl);
mapMan.draw_map(gl);
(Part of) the update method:
else if((key_set[3] && !player.get_moving() && mapMan.collision(player.get_player_position('x'), player.get_player_position('y') + 1)) || (player.get_coord('y') > 0 && player.get_coord('y') <= 1f))
{
if(!player.set_moving(true))
{
player.set_stride(player.get_foot() ? 2 : 1);
player.set_direction(3);
mapMan.set_passable(player.get_player_position('x'), player.get_player_position('y')+1, false);
}
if(player.set_coord('y', 0.05f))
{
player.set_foot();
if(!key_set[3])
{
player.set_stride(0);
}
mapMan.set_passable(player.get_player_position('x'), player.get_player_position('y')-1, true);
update_map(gl);
mapMan.update_player_tex(gl, player.get_direction()*3+player.get_stride());
}
else
{
mapMan.update_player(0.0f, -player.get_coord('y'), gl, player.get_direction()*3+player.get_stride());
}
}
else
{
player.set_stride(0);
mapMan.update_player_tex(gl, player.get_direction()*3+player.get_stride());
}
Ugh yes I know that’s complex. And that’s just for the down direction. I have not yet optimized it in any way. Lastly:
public void draw_map(GL gl)
{
engine.pass_tex().bind();
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
for(int index = 0; index < VBOtex.length-1; index++)
{
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOtex[index]);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
gl.glDrawArrays(GL.GL_QUADS, 0, vertexCount);
}
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOtex[4]);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, VBOVertices[1]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
gl.glDrawArrays(GL.GL_QUADS, 0, 12);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
}
The for loop is for drawing all four layers of the map. Ummmm… probably not the best way to do it but I’m still figuring things out.
Thanks for the help.