Fixed.
This commit is contained in:
parent
42226d3cde
commit
d361e171fd
@ -36,12 +36,12 @@ add_executable(Pong
|
|||||||
if (IS_OS_WINDOWS)
|
if (IS_OS_WINDOWS)
|
||||||
add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR)
|
add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR)
|
||||||
elseif (IS_OS_LINUX)
|
elseif (IS_OS_LINUX)
|
||||||
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR)
|
add_compile_definitions(VK_USE_PLATFORM_XCB_KHR EHS_WS_XCB)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/lib")
|
target_link_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/.local/lib")
|
||||||
target_include_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/include")
|
target_include_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/.local/include")
|
||||||
|
|
||||||
find_package(Vulkan REQUIRED)
|
find_package(Vulkan REQUIRED)
|
||||||
|
|
||||||
target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-xfixes xcb-xinput LWE z asound)
|
target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-cursor xcb-xfixes xcb-xinput LWE EHC EHE EHS z asound)
|
151
Levels/Game.cpp
151
Levels/Game.cpp
@ -1,23 +1,22 @@
|
|||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
#include "LWE/IO/FontAtlas.h"
|
|
||||||
|
|
||||||
#include <LWE/GameLoop.h>
|
#include <lwe/GameLoop.h>
|
||||||
#include <LWE/IO/RenderWindow.h>
|
#include <lwe/RenderWindow.h>
|
||||||
#include <LWE/Systems/AudioSystem.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/GuiSystem.h>
|
#include <lwe/systems/GuiSystem.h>
|
||||||
#include <LWE/Components/AudioSource.h>
|
#include <lwe/coms/AudioSource.h>
|
||||||
#include <LWE/Components/AABB2D.h>
|
#include <lwe/coms/AABB2D.h>
|
||||||
#include <LWE/Components/Circle.h>
|
#include <lwe/coms/Circle.h>
|
||||||
#include <LWE/Components/Portrait2D.h>
|
#include <lwe/coms/Portrait2D.h>
|
||||||
#include <LWE/Gui/LabelGui.h>
|
#include <lwe/gpu/GpuFontAtlas.h>
|
||||||
#include <LWE/IO/Audio/Audio.h>
|
#include <lwe/gui/LabelGui.h>
|
||||||
#include <LWE/IO/HID/Input.h>
|
#include <ehs/io/audio/Audio.h>
|
||||||
#include <LWE/IO/HID/GenericInputHandler.h>
|
#include <ehs/io/hid/Input.h>
|
||||||
#include <LWE/IO/HID/Keyboard.h>
|
#include <ehs/io/hid/Keyboard.h>
|
||||||
#include <LWE/HRNG.h>
|
#include <ehs/HRNG.h>
|
||||||
#include <LWE/System/CPU.h>
|
#include <ehs/system/CPU.h>
|
||||||
|
|
||||||
const float Game::paddleSpeed = 400.0f;
|
const float Game::paddleSpeed = 400.0f;
|
||||||
const float Game::ballSpeed = 5000.0f;
|
const float Game::ballSpeed = 5000.0f;
|
||||||
@ -50,87 +49,87 @@ Game& Game::operator=(const Game& lvl)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::SetupResources()
|
void Game::SetupResources(lwe::GpuInterface *inf)
|
||||||
{
|
{
|
||||||
Level::SetupResources();
|
Level::SetupResources(inf);
|
||||||
|
|
||||||
// Setup Resource Code Here
|
// Setup Resource Code Here
|
||||||
AddResource(new lwe::Mesh("PortraitGui", lwe::portraitGuiVerts, lwe::portraitGuiIndices));
|
AddResource(new lwe::GpuMesh(inf, ehs::portraitGui));
|
||||||
|
|
||||||
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Wall.wav", lwe::DataType::FLOAT));
|
AddResource(new ehs::Audio("resources/audio/Wall.wav", ehs::DataType::FLOAT));
|
||||||
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Paddle.wav", lwe::DataType::FLOAT));
|
AddResource(new ehs::Audio("resources/audio/Paddle.wav", ehs::DataType::FLOAT));
|
||||||
AddResource(lwe::Audio::FromFile_Heap("Resources/Audio/Score.wav", lwe::DataType::FLOAT));
|
AddResource(new ehs::Audio("resources/audio/Score.wav", ehs::DataType::FLOAT));
|
||||||
|
|
||||||
constexpr lwe::UInt_8 circleData[] = {255, 255, 255, 255};
|
constexpr ehs::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::GpuImg* circle = new lwe::GpuImg("Circle", inf, 1, 4, {1, 1}, (ehs::Byte*)circleData, lwe::GpuImgAspect::IMG_ASPECT_COLOR);
|
||||||
AddResource(circle);
|
AddResource(circle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::Setup()
|
void Game::Setup(lwe::GpuInterface *inf)
|
||||||
{
|
{
|
||||||
Level::Setup();
|
Level::Setup(inf);
|
||||||
|
|
||||||
// Setup Code Here
|
// Setup Code Here
|
||||||
|
|
||||||
lwe::GameLoop* gl = (lwe::GameLoop*)GetParent("GameLoop");
|
lwe::GameLoop* gl = GetParent();
|
||||||
|
|
||||||
lwe::RenderWindow* win = gl->GetWindow();
|
lwe::RenderWindow* win = gl->GetWindow();
|
||||||
|
|
||||||
// Adding Systems Here
|
// Adding Systems Here
|
||||||
AddSystem(new lwe::AudioSystem());
|
//AddSystem(new lwe::AudioSystem());
|
||||||
AddSystem(new lwe::Portrait2DSystem());
|
AddSystem(new lwe::Portrait2DSystem());
|
||||||
AddSystem(new lwe::RigidBodySystem());
|
AddSystem(new lwe::RigidBodySystem());
|
||||||
|
|
||||||
lwe::GuiSystem* gui = new lwe::GuiSystem();
|
lwe::GuiSystem* gui = new lwe::GuiSystem();
|
||||||
gui->AddResource(new lwe::FontAtlas("Resources/Fonts/Hack-Regular_48.ehf"));
|
gui->AddResource(new lwe::GpuFontAtlas("resources/fonts/Arial_48.ehf", win->GetInterface()));
|
||||||
AddSystem(gui);
|
AddSystem(gui);
|
||||||
|
|
||||||
lwe::Vec2_f scale = win->GetSwapChain()->GetScale();
|
ehs::Vec2_f scale = win->GetSwapChain()->GetScale();
|
||||||
lwe::Vec2_f center = win->GetSwapChain()->GetScale() / 2;
|
ehs::Vec2_f center = win->GetSwapChain()->GetScale() / 2;
|
||||||
|
|
||||||
// Score Gui
|
// Score Gui
|
||||||
lwe::LabelGui* plyScore = new lwe::LabelGui("PlyScore", "Hack-Regular_48", "0");
|
lwe::LabelGui* plyScore = new lwe::LabelGui("PlyScore", "Arial_48", "0");
|
||||||
plyScore->SetPosition({20.0f, 20.0f});
|
plyScore->SetPosition({20.0f, 20.0f, 0.0f});
|
||||||
gui->AddGui(plyScore);
|
gui->AddGui(plyScore);
|
||||||
|
|
||||||
lwe::LabelGui* aiScore = new lwe::LabelGui("AiScore", "Hack-Regular_48", "0");
|
lwe::LabelGui* aiScore = new lwe::LabelGui("AiScore", "Arial_48", "0");
|
||||||
aiScore->SetPosition({scale.x - 68.0f, 20.0f});
|
aiScore->SetPosition({scale.x - 68.0f, 20.0f, 0.0f});
|
||||||
gui->AddGui(aiScore);
|
gui->AddGui(aiScore);
|
||||||
|
|
||||||
// Bounds Entity
|
// Bounds Entity
|
||||||
lwe::Entity* bounds = new lwe::Entity("Bounds");
|
lwe::Entity bounds("Bounds");
|
||||||
bounds->SetScale({win->GetSwapChain()->GetScale(), 1.0f});
|
bounds.SetScale({win->GetSwapChain()->GetScale(), 1.0f});
|
||||||
|
|
||||||
lwe::AABB2D* collider = new lwe::AABB2D("BoundsCollider", 0.0f, 0.0f);
|
lwe::AABB2D* collider = new lwe::AABB2D("BoundsCollider", 0.0f, 0.0f);
|
||||||
collider->SetInverted(true);
|
collider->SetInverted(true);
|
||||||
collider->SetStatic(true);
|
collider->SetStatic(true);
|
||||||
bounds->AddComponent(collider);
|
bounds.AddComponent(collider);
|
||||||
|
|
||||||
AddEntity(bounds);
|
AddEntity(bounds);
|
||||||
|
|
||||||
// Field Separator Entity
|
// Field Separator Entity
|
||||||
|
|
||||||
lwe::Entity* fieldSep = new lwe::Entity("FieldSeparator");
|
lwe::Entity fieldSep("FieldSeparator");
|
||||||
fieldSep->SetScale({10.0f, scale.y, 1.0f});
|
fieldSep.SetScale({10.0f, scale.y, 1.0f});
|
||||||
fieldSep->SetPos({center.x - 5.0f, 0.0f, 0.0f});
|
fieldSep.SetPos({center.x - 5.0f, 0.0f, 0.0f});
|
||||||
|
|
||||||
lwe::Portrait2D* fieldSepImg = new lwe::Portrait2D("PaddleImg", "Circle");
|
lwe::Portrait2D* fieldSepImg = new lwe::Portrait2D("PaddleImg", "Circle");
|
||||||
fieldSepImg->SetColor({0.75f});
|
fieldSepImg->SetColor({0.75f});
|
||||||
fieldSep->AddComponent(fieldSepImg);
|
fieldSep.AddComponent(fieldSepImg);
|
||||||
|
|
||||||
AddEntity(fieldSep);
|
AddEntity(fieldSep);
|
||||||
|
|
||||||
// Paddle Entity Template
|
// Paddle Entity Template
|
||||||
lwe::Entity* paddle = new lwe::Entity("Paddle");
|
lwe::Entity paddle("Paddle");
|
||||||
paddle->SetScale({20.0f, 200.0f, 1.0f});
|
paddle.SetScale({20.0f, 200.0f, 1.0f});
|
||||||
|
|
||||||
lwe::AABB2D* paddleCollider = new lwe::AABB2D("PaddleCollider", 0.0f, 0.0f);
|
lwe::AABB2D* paddleCollider = new lwe::AABB2D("PaddleCollider", 0.0f, 0.0f);
|
||||||
paddleCollider->SetStatic(true);
|
paddleCollider->SetStatic(true);
|
||||||
paddle->AddComponent(paddleCollider);
|
paddle.AddComponent(paddleCollider);
|
||||||
|
|
||||||
lwe::Portrait2D* paddleImg = new lwe::Portrait2D("PaddleImg", "Circle");
|
lwe::Portrait2D* paddleImg = new lwe::Portrait2D("PaddleImg", "Circle");
|
||||||
paddleImg->SetColor({0.75f});
|
paddleImg->SetColor({0.75f});
|
||||||
paddle->AddComponent(paddleImg);
|
paddle.AddComponent(paddleImg);
|
||||||
|
|
||||||
AddTemplate(paddle);
|
AddTemplate(paddle);
|
||||||
|
|
||||||
@ -143,21 +142,21 @@ void Game::Setup()
|
|||||||
aiPaddle->SetPos({scale.x - 50.0f, center.y - 100.0f, 0.0f});
|
aiPaddle->SetPos({scale.x - 50.0f, center.y - 100.0f, 0.0f});
|
||||||
|
|
||||||
// Ball Entity
|
// Ball Entity
|
||||||
lwe::Entity* ball = new lwe::Entity("Ball");
|
lwe::Entity ball("Ball");
|
||||||
ball->SetScale({20.0f, 20.0f, 1.0f});
|
ball.SetScale({20.0f, 20.0f, 1.0f});
|
||||||
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("BallCollider", 0.5f, 1.1f);
|
lwe::AABB2D* ballCollider = new lwe::AABB2D("BallCollider", 0.5f, 1.1f);
|
||||||
ballCollider->SetCollidedCb([](lwe::RigidBody* a, lwe::RigidBody* b)
|
ballCollider->SetCollidedCb([](lwe::RigidBody* a, lwe::RigidBody* b)
|
||||||
{
|
{
|
||||||
lwe::Entity* aOwner = (lwe::Entity*)a->GetParent();
|
lwe::Entity* aOwner = (lwe::Entity*)a->GetEntity();
|
||||||
lwe::Entity* bOwner = (lwe::Entity*)b->GetParent();
|
lwe::Entity* bOwner = (lwe::Entity*)b->GetEntity();
|
||||||
|
|
||||||
static lwe::UInt_64 id = 0;
|
static ehs::UInt_64 id = 0;
|
||||||
|
|
||||||
if (bOwner->GetId() == "Bounds")
|
if (bOwner->GetId() == "Bounds")
|
||||||
{
|
{
|
||||||
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + lwe::Str_8::FromNum(id++),"Wall");
|
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + ehs::Str_8::FromNum(id++),"Wall");
|
||||||
audio->EnableAutoDelete(true);
|
audio->EnableAutoDelete(true);
|
||||||
audio->EnableLoop(false);
|
audio->EnableLoop(false);
|
||||||
audio->Play();
|
audio->Play();
|
||||||
@ -165,18 +164,18 @@ void Game::Setup()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + lwe::Str_8::FromNum(id++),"Paddle");
|
lwe::AudioSource* audio = new lwe::AudioSource("Audio_" + ehs::Str_8::FromNum(id++),"Paddle");
|
||||||
audio->EnableAutoDelete(true);
|
audio->EnableAutoDelete(true);
|
||||||
audio->EnableLoop(false);
|
audio->EnableLoop(false);
|
||||||
audio->Play();
|
audio->Play();
|
||||||
aOwner->AddComponent(audio);
|
aOwner->AddComponent(audio);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ball->AddComponent(ballCollider);
|
ball.AddComponent(ballCollider);
|
||||||
|
|
||||||
lwe::Portrait2D* ballImg = new lwe::Portrait2D("BallImg", "Circle");
|
lwe::Portrait2D* ballImg = new lwe::Portrait2D("BallImg", "Circle");
|
||||||
ballImg->SetColor({1.0f, 0.0f, 0.0f});
|
ballImg->SetColor({1.0f, 0.0f, 0.0f});
|
||||||
ball->AddComponent(ballImg);
|
ball.AddComponent(ballImg);
|
||||||
|
|
||||||
AddEntity(ball);
|
AddEntity(ball);
|
||||||
}
|
}
|
||||||
@ -188,23 +187,23 @@ void Game::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer)
|
|||||||
// Post Initialization Code Here
|
// Post Initialization Code Here
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta)
|
void Game::OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta)
|
||||||
{
|
{
|
||||||
Level::OnUpdate(win, input, delta);
|
Level::OnUpdate(win, input, delta);
|
||||||
|
|
||||||
// Update Code Here
|
// Update Code Here
|
||||||
|
|
||||||
const lwe::InputHandler* ih = win->GetInputHandler();
|
const ehs::InputHandler* ih = win->GetInputHandler();
|
||||||
|
|
||||||
const lwe::Keyboard* keyboard = (lwe::Keyboard*)ih->GetDeviceByType(LWE_HID_KEYBOARD);
|
const ehs::Keyboard* keyboard = (ehs::Keyboard*)ih->GetDeviceByType(EHS_HID_KEYBOARD);
|
||||||
if (!keyboard)
|
if (!keyboard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lwe::Entity* bounds = GetEntity("Bounds");
|
lwe::Entity* bounds = GetEntity("Bounds");
|
||||||
|
|
||||||
lwe::Entity* ball = GetEntity("Ball");
|
lwe::Entity* ball = GetEntity("Ball");
|
||||||
lwe::Vec3_f ballPos = ball->GetPos();
|
ehs::Vec3_f ballPos = ball->GetPos();
|
||||||
lwe::Vec3_f ballScale = ball->GetScale();
|
ehs::Vec3_f ballScale = ball->GetScale();
|
||||||
|
|
||||||
if (ballPos.x <= bounds->GetPos().x + 10.0f)
|
if (ballPos.x <= bounds->GetPos().x + 10.0f)
|
||||||
{
|
{
|
||||||
@ -212,7 +211,7 @@ void Game::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta
|
|||||||
|
|
||||||
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
||||||
lwe::LabelGui* aiScoreLabel = (lwe::LabelGui*)gui->GetGui("AiScore");
|
lwe::LabelGui* aiScoreLabel = (lwe::LabelGui*)gui->GetGui("AiScore");
|
||||||
aiScoreLabel->SetText(lwe::Str_8::FromNum(aiScore));
|
aiScoreLabel->SetText(ehs::Str_8::FromNum(aiScore));
|
||||||
|
|
||||||
ResetGame(bounds, ball);
|
ResetGame(bounds, ball);
|
||||||
}
|
}
|
||||||
@ -222,21 +221,21 @@ void Game::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta
|
|||||||
|
|
||||||
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
|
||||||
lwe::LabelGui* plyScoreLabel = (lwe::LabelGui*)gui->GetGui("PlyScore");
|
lwe::LabelGui* plyScoreLabel = (lwe::LabelGui*)gui->GetGui("PlyScore");
|
||||||
plyScoreLabel->SetText(lwe::Str_8::FromNum(plyScore));
|
plyScoreLabel->SetText(ehs::Str_8::FromNum(plyScore));
|
||||||
|
|
||||||
ResetGame(bounds, ball);
|
ResetGame(bounds, ball);
|
||||||
}
|
}
|
||||||
|
|
||||||
lwe::Entity* plyPaddle = GetEntity("PlyPaddle");
|
lwe::Entity* plyPaddle = GetEntity("PlyPaddle");
|
||||||
|
|
||||||
if (!started && keyboard->IsTouched(lwe::Keyboard::Space))
|
if (!started && keyboard->IsTouched(ehs::Keyboard::Space))
|
||||||
{
|
{
|
||||||
if (!lwe::CPU::HasRDRND())
|
if (!ehs::CPU::HasRDRND())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D");
|
lwe::AABB2D* ballCollider = (lwe::AABB2D*)ball->GetComponent("AABB2D");
|
||||||
|
|
||||||
if (const lwe::UInt_8 result = lwe::HRNG::Generate_s8(0, 4); result == 0)
|
if (const ehs::UInt_8 result = ehs::HRNG::Generate_s8(0, 4); result == 0)
|
||||||
ballCollider->ApplyForce({ballSpeed, ballSpeed, 0.0f});
|
ballCollider->ApplyForce({ballSpeed, ballSpeed, 0.0f});
|
||||||
else if (result == 1)
|
else if (result == 1)
|
||||||
ballCollider->ApplyForce({-ballSpeed, ballSpeed, 0.0f});
|
ballCollider->ApplyForce({-ballSpeed, ballSpeed, 0.0f});
|
||||||
@ -248,18 +247,18 @@ void Game::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta
|
|||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyboard->IsDown(lwe::Keyboard::W))
|
if (keyboard->IsDown(ehs::Keyboard::W))
|
||||||
{
|
{
|
||||||
lwe::Vec3_f newPos = plyPaddle->GetPos() - lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
ehs::Vec3_f newPos = plyPaddle->GetPos() - ehs::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||||
if (newPos.y <= bounds->GetPos().y)
|
if (newPos.y <= bounds->GetPos().y)
|
||||||
newPos.y = bounds->GetPos().y;
|
newPos.y = bounds->GetPos().y;
|
||||||
|
|
||||||
plyPaddle->SetPos(newPos);
|
plyPaddle->SetPos(newPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyboard->IsDown(lwe::Keyboard::S))
|
if (keyboard->IsDown(ehs::Keyboard::S))
|
||||||
{
|
{
|
||||||
lwe::Vec3_f newPos = plyPaddle->GetPos() + lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
ehs::Vec3_f newPos = plyPaddle->GetPos() + ehs::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
|
||||||
if (newPos.y + plyPaddle->GetScale().y >= bounds->GetScale().y)
|
if (newPos.y + plyPaddle->GetScale().y >= bounds->GetScale().y)
|
||||||
newPos.y = bounds->GetScale().y - plyPaddle->GetScale().y;
|
newPos.y = bounds->GetScale().y - plyPaddle->GetScale().y;
|
||||||
|
|
||||||
@ -267,12 +266,12 @@ void Game::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta
|
|||||||
}
|
}
|
||||||
|
|
||||||
lwe::Entity* aiPaddle = GetEntity("AiPaddle");
|
lwe::Entity* aiPaddle = GetEntity("AiPaddle");
|
||||||
lwe::Vec3_f aiPaddlePos = aiPaddle->GetPos();
|
ehs::Vec3_f aiPaddlePos = aiPaddle->GetPos();
|
||||||
lwe::Vec3_f aiPaddleScale = aiPaddle->GetScale();
|
ehs::Vec3_f aiPaddleScale = aiPaddle->GetScale();
|
||||||
|
|
||||||
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f)
|
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f)
|
||||||
{
|
{
|
||||||
aiPaddlePos = aiPaddlePos + lwe::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta;
|
aiPaddlePos = aiPaddlePos + ehs::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta;
|
||||||
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f > ballPos.y + ballScale.y / 2.0f)
|
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;
|
aiPaddlePos.y = ballPos.y + ballScale.y / 2.0f - aiPaddleScale.y / 2.0f;
|
||||||
|
|
||||||
@ -283,7 +282,7 @@ void Game::OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aiPaddlePos = aiPaddlePos - lwe::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta;
|
aiPaddlePos = aiPaddlePos - ehs::Vec3_f(0.0f, paddleSpeed * 2.0f, 0.0f) * delta;
|
||||||
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f)
|
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;
|
aiPaddlePos.y = ballPos.y + ballScale.y / 2.0f - aiPaddleScale.y / 2.0f;
|
||||||
|
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LWE/LWE.h>
|
#include <lwe/Level.h>
|
||||||
#include <LWE/Level.h>
|
#include <lwe/RenderWindow.h>
|
||||||
#include <LWE/IO/RenderWindow.h>
|
|
||||||
|
|
||||||
class Game : public lwe::Level
|
class Game : public lwe::Level
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static const float paddleSpeed;
|
static const float paddleSpeed;
|
||||||
static const float ballSpeed;
|
static const float ballSpeed;
|
||||||
lwe::UInt_64 plyScore;
|
ehs::UInt_64 plyScore;
|
||||||
lwe::UInt_64 aiScore;
|
ehs::UInt_64 aiScore;
|
||||||
bool started;
|
bool started;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -22,13 +21,13 @@ public:
|
|||||||
|
|
||||||
Game& operator=(const Game& lvl);
|
Game& operator=(const Game& lvl);
|
||||||
|
|
||||||
void SetupResources() override;
|
void SetupResources(lwe::GpuInterface *inf) override;
|
||||||
|
|
||||||
void Setup() override;
|
void Setup(lwe::GpuInterface *inf) override;
|
||||||
|
|
||||||
void PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) override;
|
void PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) override;
|
||||||
|
|
||||||
void OnUpdate(lwe::RenderWindow* win, lwe::Input* input, const float delta) override;
|
void OnUpdate(lwe::RenderWindow* win, ehs::Input* input, const float delta) override;
|
||||||
|
|
||||||
void PreRender(lwe::GpuCmdBuffer* cmdBuffer) override;
|
void PreRender(lwe::GpuCmdBuffer* cmdBuffer) override;
|
||||||
|
|
||||||
|
35
Main.cpp
35
Main.cpp
@ -1,31 +1,23 @@
|
|||||||
#include <LWE/LWE.h>
|
#include <ehs/Log.h>
|
||||||
#include <LWE/Log.h>
|
#include <ehs/GC.h>
|
||||||
#include <LWE/GarbageCollector.h>
|
#include <lwe/GameLoop.h>
|
||||||
#include <LWE/GameLoop.h>
|
#include <lwe/RenderWindow.h>
|
||||||
#include <LWE/IO/RenderWindow.h>
|
|
||||||
#include <LWE/IO/Console.h>
|
#include <ehs/io/Console.h>
|
||||||
|
|
||||||
#include "Levels/Game.h"
|
#include "Levels/Game.h"
|
||||||
#include "LWE/IO/HID/GenericInputHandler.h"
|
|
||||||
|
|
||||||
void LogCallback(const lwe::Log& log)
|
ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
|
||||||
{
|
|
||||||
lwe::Console::Write_8(log.ToStr());
|
|
||||||
}
|
|
||||||
|
|
||||||
lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVer)
|
|
||||||
{
|
{
|
||||||
*appName = "Pong";
|
*appName = "Pong";
|
||||||
*appVerId = "Release";
|
*appVerId = "Release";
|
||||||
*appVer = {1, 0, 0};
|
*appVer = {1, 0, 0};
|
||||||
|
|
||||||
lwe::Console::Attach();
|
ehs::Console::Attach();
|
||||||
|
|
||||||
lwe::Log::SetCallback(LogCallback);
|
#if defined(EHS_OS_WINDOWS)
|
||||||
|
|
||||||
#if defined(LWE_OS_WINDOWS)
|
|
||||||
lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
|
||||||
#elif defined(LWE_OS_LINUX)
|
#elif defined(EHS_OS_LINUX)
|
||||||
lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
|
lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -48,12 +40,7 @@ lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVe
|
|||||||
win.Create_8(*appName, {0, 0}, {1024, 768});
|
win.Create_8(*appName, {0, 0}, {1024, 768});
|
||||||
|
|
||||||
lwe::GameLoop gl(&win, 6, 0);
|
lwe::GameLoop gl(&win, 6, 0);
|
||||||
|
gl.AddLevel(new Game());
|
||||||
lwe::Frame* mainFrame = new lwe::Frame("Main");
|
|
||||||
|
|
||||||
gl.AddFrame(mainFrame);
|
|
||||||
|
|
||||||
mainFrame->AddLevel(new Game());
|
|
||||||
|
|
||||||
gl.Initialize();
|
gl.Initialize();
|
||||||
gl.Start();
|
gl.Start();
|
||||||
|
Loading…
Reference in New Issue
Block a user