diff --git a/include/Util.h b/include/Util.h index 369c3af..7aa1f92 100644 --- a/include/Util.h +++ b/include/Util.h @@ -38,7 +38,7 @@ struct Color namespace global { - inline sf::Vector2f playerSize{500, 25}; + inline sf::Vector2f playerSize{500, 10}; inline sf::Vector2f playerHalfSize{playerSize / 2.f}; inline sf::Vector2f brickSize{50, 10}; inline sf::Vector2f brickHalfSize{brickSize / 2.f}; diff --git a/src/Game.cpp b/src/Game.cpp index 8462bf4..7285f78 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -110,6 +110,19 @@ void Game::input() break; } } + + if (const auto* MouseButtonPressed = event->getIf()) + { + switch (MouseButtonPressed->button) + { + case sf::Mouse::Button::Left: + bricks.emplace_back((sf::Vector2f)MouseButtonPressed->position); + break; + default: + break; + } + + } } } @@ -135,7 +148,7 @@ void Game::collision() { brick.alive = false; ball.velocity.x *= -1; - if (ball.pos.x < player.pos.x) + if (ball.pos.x < brick.pos.x) { ball.pos.x -= intersect.x; } @@ -150,7 +163,7 @@ void Game::collision() { brick.alive = false; ball.velocity.y *= -1; - if (ball.pos.y < player.pos.y) + if (ball.pos.y < brick.pos.y) { ball.pos.y -= intersect.y; } @@ -174,7 +187,7 @@ void Game::collision() brick.alive = false; spawnExtraBall = true; ball.velocity.x *= -1; - if (ball.pos.x < player.pos.x) + if (ball.pos.x < brick.pos.x) { ball.pos.x -= intersect.x; } @@ -190,7 +203,7 @@ void Game::collision() brick.alive = false; spawnExtraBall = true; ball.velocity.y *= -1; - if (ball.pos.y < player.pos.y) + if (ball.pos.y < brick.pos.y) { ball.pos.y -= intersect.y; } @@ -333,6 +346,7 @@ void Game::imgui() ImGui::Text("A/D or arrow keys: move left and right"); ImGui::Text("R: reset game"); ImGui::Text("F1: expand/collaspe this window"); + ImGui::Text("left click: spawn brick"); ImGui::Unindent(); ImGui::End(); @@ -343,8 +357,8 @@ void Game::render() window.clear(); - tempRect.setSize(global::brickSize); tempRect.setOrigin(global::brickHalfSize); + tempRect.setSize(global::brickSize); for (auto& brick : bricks) { tempRect.setPosition(brick.pos);