Example #1
0
void Engine::RenderFrame()
{

	int cameraXOffset = camera->GetPosition().x, cameraYOffset = camera->GetPosition().y;
	Tile* tile;
	window->Clear();	
	
	bound = camera->GetTileBounds(tileSize);

	int tmp = bound.GetHeight();
	

	tmp++;
	tmp--;

	for(int y = 0, tileY = bound.Top; y < bound.GetHeight(); y++, tileY++)
	{
		for(int x = 0, tileX = bound.Left; x < bound.GetWidth(); x++, tileX++)
		{
			tile = graph->getTile(tileX,tileY);
			tile->Draw( (x * tileSize) - cameraXOffset, (y * tileSize) - cameraYOffset, window);
		}
	}

	window->Display();
}
Example #2
0
void Engine::RenderFrame()
{	    
	Collision checker; //DELETE
	//Camera offsets
	int camOffsetX, camOffsetY;

	Tile* tile;
	window->clear();
	
	//Get the tile bounds we need to draw
	sf::IntRect bounds = camera->GetTileBounds(tileSize);

	//Figure out how much to offset each tile
	camOffsetX = camera->GetTileOffset(tileSize).x;
	camOffsetY = camera->GetTileOffset(tileSize).y;
	//Loop through and draw each tile
	//We're keeping track of two variables in each loop. How many tiles
	//we've drawn (x and y), and which tile on the map we're drawing (tileX
	//and tileY)
	player->ground = false;	
	for(int y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
	{
		for(int x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
		{
			tile = new Tile(TextureManager.GetTexture(0)); // background!
			tile->Draw((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, window);
			//Get the tile	
			tile = currentLevel->GetTile(tileX, tileY);
			if(tile){
 				tile->Draw((x * tileSize) - camOffsetX, (y * tileSize) - camOffsetY, window);
				if(checker.RectCollide(sf::FloatRect((x * tileSize), (y * tileSize), tileSize, tileSize), sf::FloatRect((player->getPosition().left), (player->getPosition().top), tileSize, tileSize)) && tile->baseSprite.getTexture() == Tile(TextureManager.GetTexture(2)).baseSprite.getTexture()){
				player->ground = true;
				}				
			}
					
		}
	}
	
	player->Draw(camOffsetX, camOffsetY, window);
	window->display();
}
Example #3
0
void Level::Draw(bool actionMode, Vector2i camOffset, IntRect bounds, Vector2f camPos, RenderWindow* window)
{
	int camOffsetX = camOffset.x;
	int camOffsetY = camOffset.y;

	//Variables: X & Y - how many tiles drawn, TILEX & TILEY - which tile being drawn
	int x, y, tileX, tileY;

	Tile* tile;
	
	//Loop and draw each tile
	for (y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
	{
		for (x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
		{
			//make sure tile location is within map
			if (tileX < 0 || tileY < 0 || tileX >= map.size() || tileY >= map[0].size())
				continue;

			//get the tile being drawn
			tile = map[tileX][tileY];
			if(tile)
			{
				tile->Draw((x * TILESIZE) - camOffsetX, (y * TILESIZE) - camOffsetY, window);

				if(selectedTile == tile)
				{
					DrawSelectBorder((x * TILESIZE) - camOffsetX, (y * TILESIZE) - camOffsetY, window);
				}
				else if (targetedTile == tile)
				{
					DrawTargetBorder((x * TILESIZE) - camOffsetX, (y * TILESIZE) - camOffsetY, window);
				}
				if(hoverTile == tile)
				{
					DrawHoverBorder((x * TILESIZE) - camOffsetX, (y * TILESIZE) - camOffsetY, window);
				}
				if(actionMode && selectedTile && selectedTile->GetDomOccupant())
				{
					DrawMoveSprites((x * TILESIZE) - camOffsetX, (y * TILESIZE) - camOffsetY, selectedTile->GetDomOccupant()->GetSpeed(), tile, window);
				}
				else if(actionMode)
				{
					DrawGridSprite((x * TILESIZE) - camOffsetX, (y * TILESIZE) - camOffsetY, window);
				}
			}
		}
	}

	//Loop and draw each tile's occupants; this requires its own loop so that tiles don't get
	//drawn over entities
	for (y = 0, tileY = bounds.top; y < bounds.height; y++, tileY++)
	{
		for (x = 0, tileX = bounds.left; x < bounds.width; x++, tileX++)
		{
			//make sure tile location is within map
			if (tileX < 0 || tileY < 0 || tileX >= map.size() || tileY >= map[0].size())
				continue;

			//get the tile whose occupants are to be drawn
			tile = map[tileX][tileY];
			if(tile)
			{
				tile->DrawOccupants(camPos.x, camPos.y, window);
			}
		}
	}
}