diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 12541c6..cc97d79 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(aspire) +add_subdirectory(pong) diff --git a/app/pong/Ball.cpp b/app/pong/Ball.cpp new file mode 100644 index 0000000..e69de29 diff --git a/app/pong/Ball.h b/app/pong/Ball.h new file mode 100644 index 0000000..e69de29 diff --git a/app/aspire/CMakeLists.txt b/app/pong/CMakeLists.txt similarity index 61% rename from app/aspire/CMakeLists.txt rename to app/pong/CMakeLists.txt index 734bd88..2fd0a00 100644 --- a/app/aspire/CMakeLists.txt +++ b/app/pong/CMakeLists.txt @@ -1,9 +1,15 @@ -project(aspire) +project(aspire-pong) project_add_executable(${PROJECT_NAME}) target_sources(${PROJECT_NAME} PRIVATE + Ball.cpp + Ball.h main.cpp + Paddle.cpp + Paddle.h + Player.cpp + Player.h ) target_link_libraries(${PROJECT_NAME} PRIVATE diff --git a/app/pong/Paddle.cpp b/app/pong/Paddle.cpp new file mode 100644 index 0000000..f622059 --- /dev/null +++ b/app/pong/Paddle.cpp @@ -0,0 +1,35 @@ +#include "Paddle.h" + +Paddle::Paddle(aspire::scene::Node& root) : shape{root.createChild()} +{ +} + +auto Paddle::setPosition(sf::Vector2f x) -> void +{ + this->shape->setPosition(x); +} + +auto Paddle::getPosition() const -> sf::Vector2f +{ + return this->shape->getPosition(); +} + +auto Paddle::setSize(sf::Vector2f x) -> void +{ + this->shape->setSize(x); +} + +auto Paddle::getSize() const -> sf::Vector2f +{ + return this->shape->getSize(); +} + +auto Paddle::setColor(sf::Color x) -> void +{ + this->shape->setColor(x); +} + +auto Paddle::getColor() const -> sf::Color +{ + return this->shape->getColor(); +} diff --git a/app/pong/Paddle.h b/app/pong/Paddle.h new file mode 100644 index 0000000..4e38516 --- /dev/null +++ b/app/pong/Paddle.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +class Paddle +{ +public: + explicit Paddle(aspire::scene::Node& x); + + auto setPosition(sf::Vector2f x) -> void; + [[nodiscard]] auto getPosition() const -> sf::Vector2f; + + auto setSize(sf::Vector2f x) -> void; + [[nodiscard]] auto getSize() const -> sf::Vector2f; + + auto setColor(sf::Color x) -> void; + [[nodiscard]] auto getColor() const -> sf::Color; + +private: + aspire::scene::Rectangle* shape{}; +}; diff --git a/app/pong/Player.cpp b/app/pong/Player.cpp new file mode 100644 index 0000000..e69de29 diff --git a/app/pong/Player.h b/app/pong/Player.h new file mode 100644 index 0000000..e69de29 diff --git a/app/aspire/main.cpp b/app/pong/main.cpp similarity index 56% rename from app/aspire/main.cpp rename to app/pong/main.cpp index 49efa3f..3c0dcf5 100644 --- a/app/aspire/main.cpp +++ b/app/pong/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "Paddle.h" auto main() -> int { @@ -17,33 +18,18 @@ auto main() -> int window->setWidth(defaultWidth); window->setHeight(defaultHeight); window->setTitle("Aspire"); - window->setColor(sf::Color::Green); + window->setColor(sf::Color::Black); auto root = std::make_unique(); - auto rect = root->createChild(); - rect->setPosition({80, 80}); - rect->setSize({64, 64}); - rect->onFrameFixed( - [rect] - { - auto pos = rect->getPosition(); - pos.x += 0.01; - rect->setPosition(pos); - }); - - auto subrect = rect->createChild(); - subrect->setSize({16, 16}); - subrect->setColor(sf::Color::Red); - subrect->setRotation(30); - - subrect->onFrame( - [subrect] - { - auto rot = subrect->getRotation(); - rot += 0.01; - subrect->setRotation(rot); - }); + Paddle player{*root}; + player.setPosition({150, defaultHeight / 2.0}); + player.setSize({50, 150}); + + Paddle paddle{*root}; + + paddle.setPosition({defaultWidth - 150, defaultHeight / 2.0}); + paddle.setSize({50, 150}); window->setRootNode(std::move(root));