Adapted to current EHS and LWE projects.

This commit is contained in:
2025-05-18 23:41:00 -07:00
parent c374893b34
commit ea74b5db21
8 changed files with 312 additions and 141 deletions

View File

@@ -6,7 +6,7 @@
#include <lwe/systems/RigidBodySystem.h>
#include <lwe/systems/Portrait2DSystem.h>
#include <lwe/systems/GuiSystem.h>
#include <lwe/coms/AudioSource.h>
#include <lwe/AudioSource.h>
#include <lwe/coms/AABB2D.h>
#include <lwe/coms/Circle.h>
#include <lwe/coms/Portrait2D.h>
@@ -15,7 +15,7 @@
#include <ehs/io/audio/Audio.h>
#include <ehs/io/hid/Input.h>
#include <ehs/io/hid/Keyboard.h>
#include <ehs/HRNG.h>
#include <ehs/PRNG.h>
#include <ehs/system/CPU.h>
const float Game::paddleSpeed = 400.0f;
@@ -56,6 +56,8 @@ void Game::SetupResources(lwe::GpuInterface *inf)
// Setup Resource Code Here
AddResource(new lwe::GpuMesh(inf, ehs::portraitGui));
AddResource(new lwe::GpuFontAtlas("resources/fonts/Arial_48.ehf", inf));
AddResource(new ehs::Audio("resources/audio/Wall.wav", ehs::DataType::FLOAT));
AddResource(new ehs::Audio("resources/audio/Paddle.wav", ehs::DataType::FLOAT));
AddResource(new ehs::Audio("resources/audio/Score.wav", ehs::DataType::FLOAT));
@@ -81,7 +83,6 @@ void Game::Setup(lwe::GpuInterface *inf)
AddSystem(new lwe::RigidBodySystem());
lwe::GuiSystem* gui = new lwe::GuiSystem();
gui->AddResource(new lwe::GpuFontAtlas("resources/fonts/Arial_48.ehf", win->GetInterface()));
AddSystem(gui);
ehs::Vec2_f scale = win->GetSwapChain()->GetScale();
@@ -151,24 +152,26 @@ void Game::Setup(lwe::GpuInterface *inf)
{
lwe::Entity* aOwner = (lwe::Entity*)a->GetEntity();
lwe::Entity* bOwner = (lwe::Entity*)b->GetEntity();
lwe::Level *lvl = aOwner->GetParent();
lwe::AudioSystem *audioSys = (lwe::AudioSystem *)lvl->GetSystem("AudioSystem");
static ehs::UInt_64 id = 0;
if (bOwner->GetId() == "Bounds")
{
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + ehs::Str_8::FromNum(id++),"Wall");
audio->EnableAutoDelete(true);
audio->EnableLoop(false);
audio->Play();
aOwner->AddComponent(audio);
lwe::AudioSource audio("Audio_" + ehs::Str_8::FromNum(id++),"Wall");
audio.EnableAutoDelete(true);
audio.EnableLoop(false);
audio.Play();
audioSys->AddSource(audio);
}
else
{
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + ehs::Str_8::FromNum(id++),"Paddle");
audio->EnableAutoDelete(true);
audio->EnableLoop(false);
audio->Play();
aOwner->AddComponent(audio);
lwe::AudioSource audio("Audio_" + ehs::Str_8::FromNum(id++),"Paddle");
audio.EnableAutoDelete(true);
audio.EnableLoop(false);
audio.Play();
audioSys->AddSource(audio);
}
});
ball.AddComponent(ballCollider);
@@ -230,12 +233,11 @@ void Game::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta
if (!started && keyboard->IsTouched(ehs::Keyboard::Space))
{
if (!ehs::CPU::HasRDRND())
return;
ehs::PRNG<ehs::UInt_8> rng((ehs::UInt_8)ehs::CPU::GetTSC());
lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D");
if (const ehs::UInt_8 result = ehs::HRNG::Generate_s8(0, 4); result == 0)
if (const ehs::UInt_8 result = rng.Generate(0, 4); result == 0)
ballCollider->ApplyForce({ballSpeed, ballSpeed, 0.0f});
else if (result == 1)
ballCollider->ApplyForce({-ballSpeed, ballSpeed, 0.0f});
@@ -302,11 +304,13 @@ 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);
lwe::AudioSystem *audioSys = (lwe::AudioSystem *)GetSystem("AudioSystem");
lwe::AudioSource audio("Score", "Score");
audio.EnableAutoDelete(true);
audio.EnableLoop(false);
audio.Play();
audioSys->AddSource(audio);
ball->SetPos(bounds->GetScale() / 2.0f - ball->GetScale() / 2.0f);