From c8ec418c041355abae3551538051e0405f3578aa Mon Sep 17 00:00:00 2001 From: karutoh Date: Thu, 16 Nov 2023 00:04:12 -0800 Subject: [PATCH] Added more difficulty. --- CMakeLists.txt | 2 +- Levels/Game.cpp | 49 +++++++++++++++++++++---------------------------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7644205..ab4d4ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,4 +44,4 @@ target_include_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/in find_package(Vulkan REQUIRED) -target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-xfixes xcb-xinput wooting_analog_wrapper LWE z asound) \ No newline at end of file +target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-xfixes xcb-xinput LWE z asound) \ No newline at end of file diff --git a/Levels/Game.cpp b/Levels/Game.cpp index b9d6a2e..0209bda 100644 --- a/Levels/Game.cpp +++ b/Levels/Game.cpp @@ -6,13 +6,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -22,19 +20,19 @@ #include const float Game::paddleSpeed = 400.0f; -const float Game::ballSpeed = 15000.0f; +const float Game::ballSpeed = 5000.0f; Game::~Game() { } Game::Game() - : Level("Game"), plyScore(0), aiScore(0) + : Level("Game"), plyScore(0), aiScore(0), started(false) { } Game::Game(const Game& lvl) - : Level(lvl), plyScore(lvl.plyScore), aiScore(lvl.aiScore) + : Level(lvl), plyScore(lvl.plyScore), aiScore(lvl.aiScore), started(lvl.started) { } @@ -47,6 +45,7 @@ Game& Game::operator=(const Game& lvl) plyScore = lvl.plyScore; aiScore = lvl.aiScore; + started = lvl.started; return *this; } @@ -81,7 +80,6 @@ void Game::Setup() AddSystem(new lwe::AudioSystem()); AddSystem(new lwe::Portrait2DSystem()); AddSystem(new lwe::RigidBodySystem()); - AddSystem(new lwe::DynamicsSystem()); lwe::GuiSystem* gui = new lwe::GuiSystem(); gui->AddResource(new lwe::FontAtlas("Resources/Fonts/Hack-Regular_48.ehf")); @@ -103,9 +101,9 @@ void Game::Setup() lwe::Entity* bounds = new lwe::Entity("Bounds"); bounds->SetScale({win->GetSwapChain()->GetScale(), 1.0f}); - lwe::AABB2D* collider = new lwe::AABB2D(); + lwe::AABB2D* collider = new lwe::AABB2D("BoundsCollider", 0.0f, 0.0f); collider->SetInverted(true); - collider->EnableStatic(true); + collider->SetStatic(true); bounds->AddComponent(collider); AddEntity(bounds); @@ -126,8 +124,8 @@ void Game::Setup() lwe::Entity* paddle = new lwe::Entity("Paddle"); paddle->SetScale({20.0f, 200.0f, 1.0f}); - lwe::AABB2D* paddleCollider = new lwe::AABB2D("Collider"); - paddleCollider->EnableStatic(true); + lwe::AABB2D* paddleCollider = new lwe::AABB2D("PaddleCollider", 0.0f, 0.0f); + paddleCollider->SetStatic(true); paddle->AddComponent(paddleCollider); lwe::Portrait2D* paddleImg = new lwe::Portrait2D("PaddleImg", "Circle"); @@ -149,7 +147,7 @@ void Game::Setup() ball->SetScale({20.0f, 20.0f, 1.0f}); ball->SetPos({center.x - 10.0f, center.y - 10.0f, 0.0f}); - lwe::AABB2D* ballCollider = new lwe::AABB2D("Collider"); + lwe::AABB2D* ballCollider = new lwe::AABB2D("BallCollider", 0.5f, 1.1f); ballCollider->SetCollidedCb([](lwe::RigidBody* a, lwe::RigidBody* b) { lwe::Entity* aOwner = (lwe::Entity*)a->GetParent(); @@ -176,9 +174,6 @@ void Game::Setup() }); ball->AddComponent(ballCollider); - lwe::Dynamics* ballDynamics = new lwe::Dynamics(1.0f, 1.01f); - ball->AddComponent(ballDynamics); - lwe::Portrait2D* ballImg = new lwe::Portrait2D("BallImg", "Circle"); ballImg->SetColor({1.0f, 0.0f, 0.0f}); ball->AddComponent(ballImg); @@ -209,7 +204,7 @@ void Game::OnUpdate(lwe::Input* input, const float delta) lwe::Vec3_f ballPos = ball->GetPos(); lwe::Vec3_f ballScale = ball->GetScale(); - if (ballPos.x <= bounds->GetPos().x) + if (ballPos.x <= bounds->GetPos().x + 10.0f) { aiScore++; @@ -219,7 +214,7 @@ void Game::OnUpdate(lwe::Input* input, const float delta) ResetGame(bounds, ball); } - else if (ballPos.x + ballScale.x >= bounds->GetScale().x) + else if (ballPos.x + ballScale.x >= bounds->GetScale().x - 10.0f) { plyScore++; @@ -237,18 +232,16 @@ void Game::OnUpdate(lwe::Input* input, const float delta) if (!lwe::CPU::HasRDRND()) return; - lwe::Dynamics* ballDynamics = (lwe::Dynamics*)ball->GetComponent("Dynamics", ""); - //ballDynamics->ApplyForce({0.0f, ballSpeed, 0.0f}); + lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D"); - lwe::UInt_8 result = lwe::HRNG::Generate_s8(0, 4); - if (result == 0) - ballDynamics->ApplyForce({ballSpeed, ballSpeed, 0.0f}); + if (const lwe::UInt_8 result = lwe::HRNG::Generate_s8(0, 4); result == 0) + ballCollider->ApplyForce({ballSpeed, ballSpeed, 0.0f}); else if (result == 1) - ballDynamics->ApplyForce({-ballSpeed, ballSpeed, 0.0f}); + ballCollider->ApplyForce({-ballSpeed, ballSpeed, 0.0f}); else if (result == 2) - ballDynamics->ApplyForce({ballSpeed, -ballSpeed, 0.0f}); + ballCollider->ApplyForce({ballSpeed, -ballSpeed, 0.0f}); else if (result == 3) - ballDynamics->ApplyForce({-ballSpeed, -ballSpeed, 0.0f}); + ballCollider->ApplyForce({-ballSpeed, -ballSpeed, 0.0f}); started = true; } @@ -277,7 +270,7 @@ void Game::OnUpdate(lwe::Input* input, const float delta) if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f) { - aiPaddlePos = aiPaddlePos + lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta; + aiPaddlePos = aiPaddlePos + lwe::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta; if (aiPaddlePos.y + aiPaddleScale.y / 2.0f > ballPos.y + ballScale.y / 2.0f) aiPaddlePos.y = ballPos.y + ballScale.y / 2.0f - aiPaddleScale.y / 2.0f; @@ -288,7 +281,7 @@ void Game::OnUpdate(lwe::Input* input, const float delta) } else { - aiPaddlePos = aiPaddlePos - lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta; + aiPaddlePos = aiPaddlePos - lwe::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta; if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f) aiPaddlePos.y = ballPos.y + ballScale.y / 2.0f - aiPaddleScale.y / 2.0f; @@ -316,8 +309,8 @@ void Game::ResetGame(const lwe::Entity* bounds, lwe::Entity* ball) ball->SetPos(bounds->GetScale() / 2.0f - ball->GetScale() / 2.0f); - lwe::Dynamics* ballDyn = (lwe::Dynamics*)ball->GetComponent("Dynamics"); - ballDyn->ResetVelocity(); + lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D"); + ballCollider->ResetVelocity(); started = false; }