1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
void mainGame::Initialize(sf::RenderWindow* window){
std::cout << "Init\n";
int level[] = {
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 2, 2, 3, 6, 6, 1, 1, 1, 3, 3, 3, 7, 7, 7, 7, 1,
8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 1, 3,
};
if (!map.load("tileset.png", sf::Vector2u(32, 32), level, 32, 16))
std::cout << "Error Updating level\n";
}
void mainGame::updateLevel(){
if (!map.load("tileset.png", sf::Vector2u(32, 32), level, 32, 16))
std::cout << "Error Updating level\n";
for (int i = 0; i < 512; i++){
std::cout << level[i] << std::endl;
}
}
void mainGame::Update(sf::RenderWindow* window){
//Process input
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
quitGame = true;
if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && mouseDown){
int mousePosX = sf::Mouse::getPosition(*window).x;
int mousePosY = sf::Mouse::getPosition(*window).y;
int tileX = mousePosX / 32;
int tileY = mousePosY / 32;
int tilePressed = tileY*tileMapWidth + tileX;
//std::cout << "Tile pressed: " << tilePressed << "\n";
if (money > 0){
int tileTexture = level[tilePressed];
if (tileTexture > 64)
tileTexture = -1;
level[tilePressed] = tileTexture + 1;
mouseDown = false;
money -= 10;
ErrorString = "";
updateLevel();
}
else{
ErrorString = "To little money";
}
}
if (sf::Event::MouseButtonReleased){
mouseDown = true;
}
}
|