diff --git a/CMakeLists.txt b/CMakeLists.txt index ded3db7..7644205 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 3.18.4) + project(Pong C CXX) if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") diff --git a/Levels/Game.cpp b/Levels/Game.cpp index 7a51257..b9d6a2e 100644 --- a/Levels/Game.cpp +++ b/Levels/Game.cpp @@ -3,15 +3,18 @@ #include #include +#include #include #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -19,7 +22,7 @@ #include const float Game::paddleSpeed = 400.0f; -const float Game::ballSpeed = 400.0f; +const float Game::ballSpeed = 15000.0f; Game::~Game() { @@ -55,6 +58,10 @@ void Game::SetupResources() // Setup Resource Code Here AddResource(new lwe::Mesh("PortraitGui", lwe::portraitGuiVerts, lwe::portraitGuiIndices)); + AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Wall.wav", lwe::DataType::FLOAT)); + AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Paddle.wav", lwe::DataType::FLOAT)); + AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Score.wav", lwe::DataType::FLOAT)); + constexpr lwe::UInt_8 circleData[] = {255, 255, 255, 255}; lwe::Img* circle = new lwe::Img("Circle", 8, 4, 1, 1, (lwe::Byte*)circleData, lwe::ImgAspect::IMG_ASPECT_COLOR); AddResource(circle); @@ -71,6 +78,7 @@ void Game::Setup() lwe::RenderWindow* win = gl->GetWindow(); // Adding Systems Here + AddSystem(new lwe::AudioSystem()); AddSystem(new lwe::Portrait2DSystem()); AddSystem(new lwe::RigidBodySystem()); AddSystem(new lwe::DynamicsSystem()); @@ -142,6 +150,30 @@ void Game::Setup() ball->SetPos({center.x - 10.0f, center.y - 10.0f, 0.0f}); lwe::AABB2D* ballCollider = new lwe::AABB2D("Collider"); + ballCollider->SetCollidedCb([](lwe::RigidBody* a, lwe::RigidBody* b) + { + lwe::Entity* aOwner = (lwe::Entity*)a->GetParent(); + lwe::Entity* bOwner = (lwe::Entity*)b->GetParent(); + + static lwe::UInt_64 id = 0; + + if (bOwner->GetId() == "Bounds") + { + lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + lwe::Str_8::FromNum(id++),"Wall"); + audio->EnableAutoDelete(true); + audio->EnableLoop(false); + audio->Play(); + aOwner->AddComponent(audio); + } + else + { + lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + lwe::Str_8::FromNum(id++),"Paddle"); + audio->EnableAutoDelete(true); + audio->EnableLoop(false); + audio->Play(); + aOwner->AddComponent(audio); + } + }); ball->AddComponent(ballCollider); lwe::Dynamics* ballDynamics = new lwe::Dynamics(1.0f, 1.01f); @@ -276,10 +308,16 @@ void Game::PreRender(lwe::GpuCmdBuffer* cmdBuffer) void Game::ResetGame(const lwe::Entity* bounds, lwe::Entity* ball) { + lwe::AudioSource* audio = new lwe::AudioSource("Score", "Score"); + audio->EnableAutoDelete(true); + audio->EnableLoop(false); + audio->Play(); + ball->AddComponent(audio); + ball->SetPos(bounds->GetScale() / 2.0f - ball->GetScale() / 2.0f); lwe::Dynamics* ballDyn = (lwe::Dynamics*)ball->GetComponent("Dynamics"); - ballDyn->SetVelocity(0.0f); + ballDyn->ResetVelocity(); started = false; }