Added sound effects.
This commit is contained in:
parent
893c701345
commit
9c6da6b5cd
@ -1,4 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.18.4)
|
cmake_minimum_required(VERSION 3.18.4)
|
||||||
|
|
||||||
project(Pong C CXX)
|
project(Pong C CXX)
|
||||||
|
|
||||||
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
|
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows")
|
||||||
|
@ -3,15 +3,18 @@
|
|||||||
|
|
||||||
#include <LWE/GameLoop.h>
|
#include <LWE/GameLoop.h>
|
||||||
#include <LWE/IO/RenderWindow.h>
|
#include <LWE/IO/RenderWindow.h>
|
||||||
|
#include <LWE/Systems/AudioSystem.h>
|
||||||
#include <LWE/Systems/RigidBodySystem.h>
|
#include <LWE/Systems/RigidBodySystem.h>
|
||||||
#include <LWE/Systems/Portrait2DSystem.h>
|
#include <LWE/Systems/Portrait2DSystem.h>
|
||||||
#include <LWE/Systems/DynamicsSystem.h>
|
#include <LWE/Systems/DynamicsSystem.h>
|
||||||
#include <LWE/Systems/GuiSystem.h>
|
#include <LWE/Systems/GuiSystem.h>
|
||||||
|
#include <LWE/Components/AudioSource.h>
|
||||||
#include <LWE/Components/AABB2D.h>
|
#include <LWE/Components/AABB2D.h>
|
||||||
#include <LWE/Components/Circle.h>
|
#include <LWE/Components/Circle.h>
|
||||||
#include <LWE/Components/Portrait2D.h>
|
#include <LWE/Components/Portrait2D.h>
|
||||||
#include <LWE/Components/Dynamics.h>
|
#include <LWE/Components/Dynamics.h>
|
||||||
#include <LWE/Gui/LabelGui.h>
|
#include <LWE/Gui/LabelGui.h>
|
||||||
|
#include <LWE/IO/Audio/Audio.h>
|
||||||
#include <LWE/IO/HID/Input.h>
|
#include <LWE/IO/HID/Input.h>
|
||||||
#include <LWE/IO/HID/GenericInputHandler.h>
|
#include <LWE/IO/HID/GenericInputHandler.h>
|
||||||
#include <LWE/IO/HID/Keyboard.h>
|
#include <LWE/IO/HID/Keyboard.h>
|
||||||
@ -19,7 +22,7 @@
|
|||||||
#include <LWE/System/CPU.h>
|
#include <LWE/System/CPU.h>
|
||||||
|
|
||||||
const float Game::paddleSpeed = 400.0f;
|
const float Game::paddleSpeed = 400.0f;
|
||||||
const float Game::ballSpeed = 400.0f;
|
const float Game::ballSpeed = 15000.0f;
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
@ -55,6 +58,10 @@ void Game::SetupResources()
|
|||||||
// Setup Resource Code Here
|
// Setup Resource Code Here
|
||||||
AddResource(new lwe::Mesh("PortraitGui", lwe::portraitGuiVerts, lwe::portraitGuiIndices));
|
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};
|
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);
|
lwe::Img* circle = new lwe::Img("Circle", 8, 4, 1, 1, (lwe::Byte*)circleData, lwe::ImgAspect::IMG_ASPECT_COLOR);
|
||||||
AddResource(circle);
|
AddResource(circle);
|
||||||
@ -71,6 +78,7 @@ void Game::Setup()
|
|||||||
lwe::RenderWindow* win = gl->GetWindow();
|
lwe::RenderWindow* win = gl->GetWindow();
|
||||||
|
|
||||||
// Adding Systems Here
|
// Adding Systems Here
|
||||||
|
AddSystem(new lwe::AudioSystem());
|
||||||
AddSystem(new lwe::Portrait2DSystem());
|
AddSystem(new lwe::Portrait2DSystem());
|
||||||
AddSystem(new lwe::RigidBodySystem());
|
AddSystem(new lwe::RigidBodySystem());
|
||||||
AddSystem(new lwe::DynamicsSystem());
|
AddSystem(new lwe::DynamicsSystem());
|
||||||
@ -142,6 +150,30 @@ void Game::Setup()
|
|||||||
ball->SetPos({center.x - 10.0f, center.y - 10.0f, 0.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("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);
|
ball->AddComponent(ballCollider);
|
||||||
|
|
||||||
lwe::Dynamics* ballDynamics = new lwe::Dynamics(1.0f, 1.01f);
|
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)
|
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);
|
ball->SetPos(bounds->GetScale() / 2.0f - ball->GetScale() / 2.0f);
|
||||||
|
|
||||||
lwe::Dynamics* ballDyn = (lwe::Dynamics*)ball->GetComponent("Dynamics");
|
lwe::Dynamics* ballDyn = (lwe::Dynamics*)ball->GetComponent("Dynamics");
|
||||||
ballDyn->SetVelocity(0.0f);
|
ballDyn->ResetVelocity();
|
||||||
|
|
||||||
started = false;
|
started = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user