Skip to main content
gamedev.net
🔒 Locked

Scrolling Map?

Started by FlorianapoliS 1 reply 550+ views
Original Post
FlorianapoliS
FlorianapoliS
Hey, I''m trying to make a little overhead racer (GTA style) game in OpenGL, but I''ve got a little stuck on drawing the map:
    
int DrawMap(int xpos, int ypos)
{
	int tile, x, y, drawx, drawy;

	drawx = 15; // Position to draw on the screen

	drawy = -15;

	for (x = xpos; x > (xpos - 30); x--) // Tiles around the car to draw

	{
		drawx++;
		drawy = -15;
		for (y = ypos; y < (ypos + 30); y++)
		{
			drawy++;
			
			tile = MapArray[x][y].tile;

			if((tile > 7) || (tile < 0))
			{
				tile = 7;
			}

			glBindTexture(GL_TEXTURE_2D, texture[tile]);
			
			if (MapArray[x][y].driveable)
			{
				DrawCube((float)x, (float)-y, 2, 1, 1); // If not driveable draw solid textured cube

			}
			else
			{
				glBegin(GL_QUADS); // Draw flat tile


					glTexCoord2f(0.0f, 0.0f); glVertex3f(float(drawx), float(-drawy), 0.0f);
					glTexCoord2f(1.0f, 0.0f); glVertex3f(float(drawx + 1), float(-drawy), 0.0f);
					glTexCoord2f(1.0f, 1.0f); glVertex3f(float(drawx + 1), float(-drawy - 1), 0.0f);
					glTexCoord2f(0.0f, 1.0f); glVertex3f(float(drawx), float(-drawy - 1), 0.0f);
				
				glEnd();
			}

		}
	 }
	return(1);
}	
    
This is what I have now, I''m probably miles off but currently it just draws pieces of the map all over the shop? Need to know about any sections of my code just ask
FlorianapoliS
FlorianapoliS
Anybody got any ideas? I''ve changed my code to this, its still not working though, but it slightly closer.

  
void DrawMap(float map_drawx, float map_drawy)
{


int i, j, tile, mapx, mapy;

glTranslatef(map_drawx, map_drawy, -20.0f); // Set init pos to draw map from


mapx = (int)map_drawx / 1; // Work out current tile

mapy = (int)map_drawy / 1;

for(i = 0; i < 30; i++)
{
for(j = 0; j < 30; j++)
{
tile = MapArray[mapy + i][mapx + j].tile;
if ((tile > 7) || (tile < 0)) // Draw Solid if off map

{
tile = 7;
}
DrawTile(tile, -(float)i, -(float)j, 1);
}
}
}
bschwagg
bschwagg
Hello
I''ve a super easy way of scrolling the textures, that is if this is what you want to accomplish.
Do you remember when you use glMatrixMode() to select GL_MODELVIEW to be able to affect vertex points?
You can actually do the same thing selecting textures,
glMatrixMode(GL_TEXTURE);
then perform your translation, or rotation and your textures will scroll
make sure you reload GL_MODELVIEW after playing with your textures and it also might help to enable texture wrapping (although i''m not sure)

Hope this helps!

-brad

ps- send a link when you get the project done
cha cha cha

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.