Pong development has been completed.

This commit is contained in:
Arron David Nelson 2023-11-14 00:07:42 -08:00
parent 7d62ac35c8
commit c458513f42
4 changed files with 222 additions and 6 deletions

View File

@ -2,5 +2,86 @@
<project version="4"> <project version="4">
<component name="BackendCodeEditorSettings"> <component name="BackendCodeEditorSettings">
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" /> <option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppClangFormat/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/EditorConfig/EnableClangFormatSupport/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_BINARY_EXPRESSIONS_CHAIN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_CALLS_CHAIN/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXPRESSION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_FOR_STMT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_BLANK_LINES_IN_CODE/@EntryValue" value="2" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/KEEP_USER_LINEBREAKS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SIMPLE_BLOCK_STYLE/@EntryValue" value="DO_NOT_CHANGE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_ARGS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_SEMICOLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_SEMICOLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_UNARY_OPERATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_ARRAY_ACCESS_BRACKETS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_CAST_EXPRESSION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_METHOD_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_INITIALIZER_BRACES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_TERNARY_OPSIGNS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DECLARATION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_FUNCTION_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue" value="All" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_ARGUMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_EXTENDS_LIST/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_PARAMETER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_ARGUMENT/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_ACCESS_SPECIFIERS_FROM_CLASS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/LINE_BREAK_AFTER_COLON_IN_MEMBER_INITIALIZER_LISTS/@EntryValue" value="ON_SINGLE_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/MEMBER_INITIALIZER_LIST_STYLE/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/PLACE_NAMESPACE_DEFINITIONS_ON_SAME_LINE/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_COLON_IN_BITFIELD_DECLARATOR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_EXTENDS_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_FOR_COLON/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_FOR_COLON/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_AFTER_REF_IN_DATA_MEMBER/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_DATA_MEMBERS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_PTR_IN_ABSTRACT_DECL/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_REF_IN_ABSTRACT_DECL/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_BEFORE_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_DECLARATION_PARENTHESES/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_BLOCKS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_EMPTY_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_INVOCATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_BEFORE_DECLARATION_RPAR/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_ARGUMENTS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_PARAMETERS_STYLE/@EntryValue" value="WRAP_IF_LONG" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BREAK_TEMPLATE_DECLARATION/@EntryValue" value="LINE_BREAK" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_DECLARATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/FREE_BLOCK_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="NEXT_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Tab" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CONTINUOUS_LINE_INDENT/@EntryValue" value="Double" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
</component> </component>
</project> </project>

View File

@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
<option name="clangTidyChecks" value="-*,bugprone-argument-comment,bugprone-assert-side-effect,bugprone-bad-signal-to-kill-thread,bugprone-branch-clone,bugprone-copy-constructor-init,bugprone-dangling-handle,bugprone-dynamic-static-initializers,bugprone-fold-init-type,bugprone-forward-declaration-namespace,bugprone-forwarding-reference-overload,bugprone-inaccurate-erase,bugprone-incorrect-roundings,bugprone-integer-division,bugprone-lambda-function-name,bugprone-macro-parentheses,bugprone-macro-repeated-side-effects,bugprone-misplaced-operator-in-strlen-in-alloc,bugprone-misplaced-pointer-arithmetic-in-alloc,bugprone-misplaced-widening-cast,bugprone-move-forwarding-reference,bugprone-multiple-statement-macro,bugprone-no-escape,bugprone-parent-virtual-call,bugprone-posix-return,bugprone-reserved-identifier,bugprone-sizeof-container,bugprone-sizeof-expression,bugprone-spuriously-wake-up-functions,bugprone-string-constructor,bugprone-string-integer-assignment,bugprone-string-literal-with-embedded-nul,bugprone-suspicious-enum-usage,bugprone-suspicious-include,bugprone-suspicious-memset-usage,bugprone-suspicious-missing-comma,bugprone-suspicious-semicolon,bugprone-suspicious-string-compare,bugprone-suspicious-memory-comparison,bugprone-suspicious-realloc-usage,bugprone-swapped-arguments,bugprone-terminating-continue,bugprone-throw-keyword-missing,bugprone-too-small-loop-variable,bugprone-undefined-memory-manipulation,bugprone-undelegated-constructor,bugprone-unhandled-self-assignment,bugprone-unused-raii,bugprone-unused-return-value,bugprone-use-after-move,bugprone-virtual-near-miss,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,cppcoreguidelines-interfaces-global-init,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-pro-type-member-init,cppcoreguidelines-pro-type-static-cast-downcast,cppcoreguidelines-slicing,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,performance-faster-string-find,performance-for-range-copy,performance-implicit-conversion-in-loop,performance-inefficient-algorithm,performance-inefficient-string-concatenation,performance-inefficient-vector-operation,performance-move-const-arg,performance-move-constructor-init,performance-no-automatic-move,performance-noexcept-move-constructor,performance-trivially-destructible,performance-type-promotion-in-math-fn,performance-unnecessary-copy-initialization,performance-unnecessary-value-param,portability-simd-intrinsics,readability-avoid-const-params-in-decls,readability-const-return-type,readability-container-size-empty,readability-convert-member-functions-to-static,readability-delete-null-pointer,readability-deleted-default,readability-inconsistent-declaration-parameter-name,readability-make-member-function-const,readability-misleading-indentation,readability-misplaced-array-index,readability-non-const-parameter,readability-redundant-control-flow,readability-redundant-declaration,readability-redundant-function-ptr-dereference,readability-redundant-smartptr-get,readability-redundant-string-cstr,readability-redundant-string-init,readability-simplify-subscript-expr,readability-static-accessed-through-instance,readability-static-definition-in-anonymous-namespace,readability-string-compare,readability-uniqueptr-delete-release,readability-use-anyofallof" />
</inspection_tool>
</profile>
</component>

View File

@ -5,26 +5,33 @@
#include <LWE/IO/RenderWindow.h> #include <LWE/IO/RenderWindow.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/GuiSystem.h> #include <LWE/Systems/GuiSystem.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/Gui/LabelGui.h> #include <LWE/Gui/LabelGui.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>
#include <LWE/HRNG.h>
#include <LWE/System/CPU.h>
const float Game::paddleSpeed = 400.0f;
const float Game::ballSpeed = 400.0f;
Game::~Game() Game::~Game()
{ {
} }
Game::Game() Game::Game()
: Level("Game") : Level("Game"), plyScore(0), aiScore(0)
{ {
} }
Game::Game(const Game& lvl) Game::Game(const Game& lvl)
: Level(lvl) : Level(lvl), plyScore(lvl.plyScore), aiScore(lvl.aiScore)
{ {
} }
@ -35,6 +42,9 @@ Game& Game::operator=(const Game& lvl)
Level::operator=(lvl); Level::operator=(lvl);
plyScore = lvl.plyScore;
aiScore = lvl.aiScore;
return *this; return *this;
} }
@ -63,6 +73,7 @@ void Game::Setup()
// Adding Systems Here // Adding Systems Here
AddSystem(new lwe::Portrait2DSystem()); AddSystem(new lwe::Portrait2DSystem());
AddSystem(new lwe::RigidBodySystem()); AddSystem(new lwe::RigidBodySystem());
AddSystem(new lwe::DynamicsSystem());
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::FontAtlas("Resources/Fonts/Hack-Regular_48.ehf"));
@ -85,6 +96,8 @@ void Game::Setup()
bounds->SetScale({win->GetSwapChain()->GetScale(), 1.0f}); bounds->SetScale({win->GetSwapChain()->GetScale(), 1.0f});
lwe::AABB2D* collider = new lwe::AABB2D(); lwe::AABB2D* collider = new lwe::AABB2D();
collider->SetInverted(true);
collider->EnableStatic(true);
bounds->AddComponent(collider); bounds->AddComponent(collider);
AddEntity(bounds); AddEntity(bounds);
@ -105,6 +118,10 @@ void Game::Setup()
lwe::Entity* paddle = new lwe::Entity("Paddle"); lwe::Entity* paddle = new lwe::Entity("Paddle");
paddle->SetScale({20.0f, 200.0f, 1.0f}); paddle->SetScale({20.0f, 200.0f, 1.0f});
lwe::AABB2D* paddleCollider = new lwe::AABB2D("Collider");
paddleCollider->EnableStatic(true);
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);
@ -124,9 +141,12 @@ void Game::Setup()
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::Circle* ballCollider = new lwe::Circle("BallCollider", 50.0f); lwe::AABB2D* ballCollider = new lwe::AABB2D("Collider");
ball->AddComponent(ballCollider); ball->AddComponent(ballCollider);
lwe::Dynamics* ballDynamics = new lwe::Dynamics(1.0f, 1.01f);
ball->AddComponent(ballDynamics);
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);
@ -151,13 +171,100 @@ void Game::OnUpdate(lwe::Input* input, const float delta)
const lwe::Keyboard* keyboard = handler->GetPrimaryKeyboard(); const lwe::Keyboard* keyboard = handler->GetPrimaryKeyboard();
lwe::Entity* bounds = GetEntity("Bounds");
lwe::Entity* ball = GetEntity("Ball");
lwe::Vec3_f ballPos = ball->GetPos();
lwe::Vec3_f ballScale = ball->GetScale();
if (ballPos.x <= bounds->GetPos().x)
{
aiScore++;
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
lwe::LabelGui* aiScoreLabel = (lwe::LabelGui*)gui->GetGui("AiScore");
aiScoreLabel->SetText(lwe::Str_8::FromNum(aiScore));
ResetGame(bounds, ball);
}
else if (ballPos.x + ballScale.x >= bounds->GetScale().x)
{
plyScore++;
lwe::GuiSystem* gui = (lwe::GuiSystem*)GetSystem("GuiSystem");
lwe::LabelGui* plyScoreLabel = (lwe::LabelGui*)gui->GetGui("PlyScore");
plyScoreLabel->SetText(lwe::Str_8::FromNum(plyScore));
ResetGame(bounds, ball);
}
lwe::Entity* plyPaddle = GetEntity("PlyPaddle"); lwe::Entity* plyPaddle = GetEntity("PlyPaddle");
if (!started && keyboard->IsTouched(lwe::Keyboard::Space))
{
if (!lwe::CPU::HasRDRND())
return;
lwe::Dynamics* ballDynamics = (lwe::Dynamics*)ball->GetComponent("Dynamics", "");
//ballDynamics->ApplyForce({0.0f, ballSpeed, 0.0f});
lwe::UInt_8 result = lwe::HRNG::Generate_s8(0, 4);
if (result == 0)
ballDynamics->ApplyForce({ballSpeed, ballSpeed, 0.0f});
else if (result == 1)
ballDynamics->ApplyForce({-ballSpeed, ballSpeed, 0.0f});
else if (result == 2)
ballDynamics->ApplyForce({ballSpeed, -ballSpeed, 0.0f});
else if (result == 3)
ballDynamics->ApplyForce({-ballSpeed, -ballSpeed, 0.0f});
started = true;
}
if (keyboard->IsDown(lwe::Keyboard::W)) if (keyboard->IsDown(lwe::Keyboard::W))
plyPaddle->SetPos(plyPaddle->GetPos() - lwe::Vec3_f(0.0f, 400.0f, 0.0f) * delta); {
lwe::Vec3_f newPos = plyPaddle->GetPos() - lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
if (newPos.y <= bounds->GetPos().y)
newPos.y = bounds->GetPos().y;
plyPaddle->SetPos(newPos);
}
if (keyboard->IsDown(lwe::Keyboard::S)) if (keyboard->IsDown(lwe::Keyboard::S))
plyPaddle->SetPos(plyPaddle->GetPos() + lwe::Vec3_f(0.0f, 400.0f, 0.0f) * delta); {
lwe::Vec3_f newPos = plyPaddle->GetPos() + lwe::Vec3_f(0.0f, paddleSpeed, 0.0f) * delta;
if (newPos.y + plyPaddle->GetScale().y >= bounds->GetScale().y)
newPos.y = bounds->GetScale().y - plyPaddle->GetScale().y;
plyPaddle->SetPos(newPos);
}
lwe::Entity* aiPaddle = GetEntity("AiPaddle");
lwe::Vec3_f aiPaddlePos = aiPaddle->GetPos();
lwe::Vec3_f aiPaddleScale = aiPaddle->GetScale();
if (aiPaddlePos.y + aiPaddleScale.y / 2.0f < ballPos.y + ballScale.y / 2.0f)
{
aiPaddlePos = aiPaddlePos + lwe::Vec3_f(0.0f, paddleSpeed, 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;
if (aiPaddlePos.y + aiPaddleScale.y >= bounds->GetScale().y)
aiPaddlePos.y = bounds->GetScale().y - aiPaddleScale.y;
aiPaddle->SetPos(aiPaddlePos);
}
else
{
aiPaddlePos = aiPaddlePos - lwe::Vec3_f(0.0f, paddleSpeed, 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;
if (aiPaddlePos.y <= bounds->GetPos().y)
aiPaddlePos.y = bounds->GetPos().y;
aiPaddle->SetPos(aiPaddlePos);
}
} }
void Game::PreRender(lwe::GpuCmdBuffer* cmdBuffer) void Game::PreRender(lwe::GpuCmdBuffer* cmdBuffer)
@ -166,3 +273,13 @@ void Game::PreRender(lwe::GpuCmdBuffer* cmdBuffer)
// Pre-Render Code Here // Pre-Render Code Here
} }
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->SetVelocity(0.0f);
started = false;
}

View File

@ -5,6 +5,13 @@
class Game : public lwe::Level class Game : public lwe::Level
{ {
private:
static const float paddleSpeed;
static const float ballSpeed;
lwe::UInt_64 plyScore;
lwe::UInt_64 aiScore;
bool started;
public: public:
~Game() override; ~Game() override;
@ -23,4 +30,7 @@ public:
void OnUpdate(lwe::Input* input, const float delta) override; void OnUpdate(lwe::Input* input, const float delta) override;
void PreRender(lwe::GpuCmdBuffer* cmdBuffer) override; void PreRender(lwe::GpuCmdBuffer* cmdBuffer) override;
private:
void ResetGame(const lwe::Entity* bounds, lwe::Entity* ball);
}; };