Added more difficulty.

This commit is contained in:
Arron David Nelson 2023-11-16 00:04:12 -08:00
parent 9c6da6b5cd
commit c8ec418c04
2 changed files with 22 additions and 29 deletions

View File

@ -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)
target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-xfixes xcb-xinput LWE z asound)

View File

@ -6,13 +6,11 @@
#include <LWE/Systems/AudioSystem.h>
#include <LWE/Systems/RigidBodySystem.h>
#include <LWE/Systems/Portrait2DSystem.h>
#include <LWE/Systems/DynamicsSystem.h>
#include <LWE/Systems/GuiSystem.h>
#include <LWE/Components/AudioSource.h>
#include <LWE/Components/AABB2D.h>
#include <LWE/Components/Circle.h>
#include <LWE/Components/Portrait2D.h>
#include <LWE/Components/Dynamics.h>
#include <LWE/Gui/LabelGui.h>
#include <LWE/IO/Audio/Audio.h>
#include <LWE/IO/HID/Input.h>
@ -22,19 +20,19 @@
#include <LWE/System/CPU.h>
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;
}