Skip to content

Commit

Permalink
Begin implementing pong.
Browse files Browse the repository at this point in the history
  • Loading branch information
ASxa86 committed Jun 17, 2024
1 parent f070c27 commit 1cd4e89
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_subdirectory(aspire)
add_subdirectory(pong)
Empty file added app/pong/Ball.cpp
Empty file.
Empty file added app/pong/Ball.h
Empty file.
8 changes: 7 additions & 1 deletion app/aspire/CMakeLists.txt → app/pong/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions app/pong/Paddle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "Paddle.h"

Paddle::Paddle(aspire::scene::Node& root) : shape{root.createChild<aspire::scene::Rectangle>()}
{
}

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();
}
21 changes: 21 additions & 0 deletions app/pong/Paddle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include <aspire/scene/Rectangle.h>

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{};
};
Empty file added app/pong/Player.cpp
Empty file.
Empty file added app/pong/Player.h
Empty file.
34 changes: 10 additions & 24 deletions app/aspire/main.cpp → app/pong/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <aspire/core/Kernel.h>
#include <aspire/scene/Rectangle.h>
#include <aspire/scene/Window.h>
#include "Paddle.h"

auto main() -> int
{
Expand All @@ -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<aspire::scene::Node>();

auto rect = root->createChild<aspire::scene::Rectangle>();
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<aspire::scene::Rectangle>();
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));

Expand Down

0 comments on commit 1cd4e89

Please sign in to comment.