Original Post
Hello everyone
I have been working on a tile map editor and i have a small problem.
I have 6 buttons on my screen where you can choose what tile you want to draw. You click on the button and press on the screen to start drawing.
now the problem is when you click on grass tile and draw then click on ice tile, all the grass tiles turns into grass. what should happen is when you click on ice you draw ice and when you click on grass you draw grass not change the existing tile.
here is a video to explain my problem more.
BTW sorry i was listing to that song when i recorded and forgot to disable the sound .
Map.cpp
UI.CPP
Main.cpp
I have been working on a tile map editor and i have a small problem.
I have 6 buttons on my screen where you can choose what tile you want to draw. You click on the button and press on the screen to start drawing.
now the problem is when you click on grass tile and draw then click on ice tile, all the grass tiles turns into grass. what should happen is when you click on ice you draw ice and when you click on grass you draw grass not change the existing tile.
here is a video to explain my problem more.
BTW sorry i was listing to that song when i recorded and forgot to disable the sound .
Map.cpp
#include "Map.h"
#include "UI.h"
UI UI1;
Map::Map(float x, float y)
{
Delete=false;
Position = sf::Vector2f(x,y);
TileImage[0].LoadFromFile("Data/Tiles/Grass.png");
TileImage[1].LoadFromFile("Data/Tiles/Grass2.png");
TileImage[2].LoadFromFile("Data/Tiles/Dirt.png");
TileImage[3].LoadFromFile("Data/Tiles/Desert.png");
TileImage[4].LoadFromFile("Data/Tiles/Stone.png");
TileImage[5].LoadFromFile("Data/Tiles/Ice.png");
TileImage[6].LoadFromFile("Data/Tiles/Water.png");
TileSprite[0].SetImage(TileImage[0]);
TileSprite[1].SetImage(TileImage[1]);
TileSprite[2].SetImage(TileImage[2]);
TileSprite[3].SetImage(TileImage[3]);
TileSprite[4].SetImage(TileImage[4]);
TileSprite[5].SetImage(TileImage[5]);
TileSprite[6].SetImage(TileImage[6]);
TileImage[0].SetSmooth(false);
TileImage[1].SetSmooth(false);
TileImage[2].SetSmooth(false);
TileImage[3].SetSmooth(false);
TileImage[4].SetSmooth(false);
TileImage[5].SetSmooth(false);
TileImage[6].SetSmooth(false);
}
Map::~Map(void)
{
}
void Map::Init(sf::RenderWindow &Window)
{
MouseX = Window.GetInput().GetMouseX();
MouseY = Window.GetInput().GetMouseY();
}
void Map::AddTile()
{
TowerVector.push_back(new Map(MouseX, MouseY));
}
void Map::Event(sf::Event Event)
{
if(Event.Type == sf::Event::MouseButtonPressed && Event.MouseButton.Button == sf::Mouse::Left)
AddTile();
if(Event.Type == sf::Event::KeyPressed && Event.Key.Code== sf::Key:<img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/biggrin.gif' class='bbc_emoticon' alt=':D' />)
Delete=true;
}
void Map::Draw(sf::RenderWindow &Window)
{
for(int x=4; x<28; x++)
for(int y=4; y<20; y++)
map[y][x] = 0;
for(int i = 0; i <TowerVector.size(); i++)
{
int X = TowerVector->Position.x / 32;
int Y = TowerVector->Position.y / 32;
map[Y][X] = 1;
for(int x=4; x<28; x++)
{
for(int y=4; y<20; y++)
{
if(X == x && Y == y)
{
if(UI1.GetTileID() == 0)
TileSprite[0].SetPosition(X*32, Y*32);
if(UI1.GetTileID() == 1)
TileSprite[1].SetPosition(X*32, Y*32);
if(UI1.GetTileID() == 2)
TileSprite[2].SetPosition(X*32, Y*32);
if(UI1.GetTileID() == 3)
TileSprite[3].SetPosition(X*32, Y*32);
if(UI1.GetTileID() == 4)
TileSprite[4].SetPosition(X*32, Y*32);
if(UI1.GetTileID() == 5)
TileSprite[5].SetPosition(X*32, Y*32);
if(UI1.GetTileID() == 6)
TileSprite[6].SetPosition(X*32, Y*32);
}
}
}
if(Delete==true)
{
TowerVector.erase(TowerVector.end() - 1);
}
Delete=false;
for(int i=0; i<6; i++)
Window.Draw(TileSprite);
}
}
UI.CPP
int UI::GetTileID()
{
if(Tiles[0].Clicked == true)
TileID = 0;
if(Tiles[1].Clicked == true)
TileID = 1;
if(Tiles[2].Clicked == true)
TileID = 2;
if(Tiles[3].Clicked == true)
TileID = 3;
if(Tiles[4].Clicked == true)
TileID = 4;
if(Tiles[5].Clicked == true)
TileID = 5;
if(Tiles[6].Clicked == true)
TileID = 6;
return TileID;
}
Main.cpp
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Map.h"
#include "UI.h"
int main()
{
sf::RenderWindow Window (sf::VideoMode(1024, 768, 32),"vovo");
Map Map(0,0);
UI UI;
UI.LoadFiles();
while(Window.IsOpened())
{
Window.SetFramerateLimit(60);
sf::Event Event;
Map.Init(Window);
while(Window.GetEvent(Event))
{
Map.Event(Event);
UI.Event(Event);
}
Window.Clear();
Map.Draw(Window);
Map.DrawLines(Window);
UI.Draw(Window);
Window.Display();
}
return 0;
}