From a0b9102b93fb41071adb262ea46d269be9055a6a Mon Sep 17 00:00:00 2001 From: karutoh Date: Sat, 11 Nov 2023 18:56:55 -0800 Subject: [PATCH] Backup --- .gitignore | 32 +++++++++ .idea/.gitignore | 5 ++ .idea/Pong.iml | 2 + .idea/editor.xml | 6 ++ .idea/misc.xml | 8 +++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ CMakeLists.txt | 46 +++++++++++++ Levels/Game.cpp | 168 ++++++++++++++++++++++++++++++++++++++++++++++ Levels/Game.h | 26 +++++++ Main.cpp | 70 +++++++++++++++++++ README.md | 11 +++ image.png | Bin 0 -> 8982 bytes 13 files changed, 388 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/Pong.iml create mode 100644 .idea/editor.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt create mode 100644 Levels/Game.cpp create mode 100644 Levels/Game.h create mode 100644 Main.cpp create mode 100644 README.md create mode 100644 image.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..259148f --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..b58b603 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Pong.iml b/.idea/Pong.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/Pong.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..46540da --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c2cdd87 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e3ff5e9 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ded3db7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.18.4) +project(Pong C CXX) + +if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Windows") + set(IS_OS_WINDOWS TRUE) + set(USER_HOME_DIRECTORY $ENV{USERPROFILE}) + message("Building for the Windows operating system.") +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux") + set(IS_OS_LINUX TRUE) + set(USER_HOME_DIRECTORY $ENV{HOME}) + add_compile_options(-Wno-stringop-overflow) + message("Building for the Linux operating system.") +elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin") + set(IS_OS_MAC TRUE) + set(USER_HOME_DIRECTORY $ENV{HOME}) + message("Building for the Mac operating system.") +endif () + +if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") + message("Building for AMD64 architecture.") + set(IS_ARCH_AMD64 TRUE) +elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ARM64" OR "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64") + message("Building for ARM64 architecture.") + set(IS_ARCH_ARM64 TRUE) +endif () + +set(CMAKE_CXX_STANDARD 20) + +add_executable(Pong + Levels/Game.h + Levels/Game.cpp + Main.cpp +) + +if (IS_OS_WINDOWS) + add_compile_definitions(VK_USE_PLATFORM_WIN32_KHR) +elseif (IS_OS_LINUX) + add_compile_definitions(VK_USE_PLATFORM_XCB_KHR) +endif() + +target_link_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/lib") +target_include_directories(Pong PRIVATE "${USER_HOME_DIRECTORY}/Libraries/LWE/include") + +find_package(Vulkan REQUIRED) + +target_link_libraries(Pong PRIVATE Vulkan::Headers Vulkan::Vulkan xcb xcb-xfixes xcb-xinput wooting_analog_wrapper LWE z asound) \ No newline at end of file diff --git a/Levels/Game.cpp b/Levels/Game.cpp new file mode 100644 index 0000000..196f4df --- /dev/null +++ b/Levels/Game.cpp @@ -0,0 +1,168 @@ +#include "Game.h" +#include "LWE/IO/FontAtlas.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +Game::~Game() +{ +} + +Game::Game() + : Level("Game") +{ +} + +Game::Game(const Game& lvl) + : Level(lvl) +{ +} + +Game& Game::operator=(const Game& lvl) +{ + if (this == &lvl) + return *this; + + Level::operator=(lvl); + + return *this; +} + +void Game::SetupResources() +{ + Level::SetupResources(); + + // Setup Resource Code Here + AddResource(new lwe::Mesh("PortraitGui", lwe::portraitGuiVerts, lwe::portraitGuiIndices)); + + 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); +} + +void Game::Setup() +{ + Level::Setup(); + + // Setup Code Here + + lwe::GameLoop* gl = (lwe::GameLoop*)GetParent("GameLoop"); + + lwe::RenderWindow* win = gl->GetWindow(); + + // Adding Systems Here + AddSystem(new lwe::Portrait2DSystem()); + AddSystem(new lwe::RigidBodySystem()); + + lwe::GuiSystem* gui = new lwe::GuiSystem(); + gui->AddResource(new lwe::FontAtlas("Resources/Fonts/Hack-Regular_48.ehf")); + AddSystem(gui); + + lwe::Vec2_f scale = win->GetSwapChain()->GetScale(); + lwe::Vec2_f center = win->GetSwapChain()->GetScale() / 2; + + // Score Gui + lwe::LabelGui* plyScore = new lwe::LabelGui("PlyScore", "Hack-Regular_48", "0"); + plyScore->SetPosition({20.0f, 20.0f}); + gui->AddGui(plyScore); + + lwe::LabelGui* aiScore = new lwe::LabelGui("AiScore", "Hack-Regular_48", "0"); + aiScore->SetPosition({scale.x - 68.0f, 20.0f}); + gui->AddGui(aiScore); + + // Bounds Entity + lwe::Entity* bounds = new lwe::Entity("Bounds"); + bounds->SetScale({win->GetSwapChain()->GetScale(), 1.0f}); + + lwe::AABB2D* collider = new lwe::AABB2D(); + bounds->AddComponent(collider); + + AddEntity(bounds); + + // Field Separator Entity + + lwe::Entity* fieldSep = new lwe::Entity("FieldSeparator"); + fieldSep->SetScale({10.0f, scale.y, 1.0f}); + fieldSep->SetPos({center.x - 5.0f, 0.0f, 0.0f}); + + lwe::Portrait2D* fieldSepImg = new lwe::Portrait2D("PaddleImg", "Circle"); + fieldSepImg->SetColor({0.75f}); + fieldSep->AddComponent(fieldSepImg); + + AddEntity(fieldSep); + + // Paddle Entity Template + lwe::Entity* paddle = new lwe::Entity("Paddle"); + paddle->SetScale({20.0f, 200.0f, 1.0f}); + + lwe::Portrait2D* paddleImg = new lwe::Portrait2D("PaddleImg", "Circle"); + paddleImg->SetColor({0.75f}); + paddle->AddComponent(paddleImg); + + AddTemplate(paddle); + + // Player's Paddle + lwe::Entity* plyPaddle = CreateEntity("Paddle", "PlyPaddle"); + plyPaddle->SetPos({50.0f, center.y - 100.0f, 0.0f}); + + // Player's Paddle + lwe::Entity* aiPaddle = CreateEntity("Paddle", "AiPaddle"); + aiPaddle->SetPos({scale.x - 50.0f, center.y - 100.0f, 0.0f}); + + // Ball Entity + lwe::Entity* ball = new lwe::Entity("Ball"); + ball->SetScale({20.0f, 20.0f, 1.0f}); + ball->SetPos({center.x - 10.0f, center.y - 10.0f, 0.0f}); + + lwe::Circle* ballCollider = new lwe::Circle("BallCollider", 50.0f); + ball->AddComponent(ballCollider); + + lwe::Portrait2D* ballImg = new lwe::Portrait2D("BallImg", "Circle"); + ballImg->SetColor({1.0f, 0.0f, 0.0f}); + ball->AddComponent(ballImg); + + AddEntity(ball); +} + +void Game::PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) +{ + Level::PostInitialize(cmdBuffer); + + // Post Initialization Code Here +} + +void Game::OnUpdate(lwe::Input* input, const float delta) +{ + Level::OnUpdate(input, delta); + + // Update Code Here + + const lwe::GenericInputHandler* handler = (lwe::GenericInputHandler*)input->GetHandler("GenericInputHandler"); + + const lwe::Keyboard* keyboard = handler->GetPrimaryKeyboard(); + + lwe::Entity* plyPaddle = GetEntity("PlyPaddle"); + + if (keyboard->IsDown(lwe::Keyboard::W)) + plyPaddle->SetPos(plyPaddle->GetPos() - lwe::Vec3_f(0.0f, 400.0f, 0.0f) * delta); + + if (keyboard->IsDown(lwe::Keyboard::S)) + plyPaddle->SetPos(plyPaddle->GetPos() + lwe::Vec3_f(0.0f, 400.0f, 0.0f) * delta); +} + +void Game::PreRender(lwe::GpuCmdBuffer* cmdBuffer) +{ + Level::PreRender(cmdBuffer); + + // Pre-Render Code Here +} \ No newline at end of file diff --git a/Levels/Game.h b/Levels/Game.h new file mode 100644 index 0000000..af52646 --- /dev/null +++ b/Levels/Game.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +class Game : public lwe::Level +{ +public: + ~Game() override; + + Game(); + + Game(const Game& lvl); + + Game& operator=(const Game& lvl); + + void SetupResources() override; + + void Setup() override; + + void PostInitialize(lwe::GpuCmdBuffer* cmdBuffer) override; + + void OnUpdate(lwe::Input* input, const float delta) override; + + void PreRender(lwe::GpuCmdBuffer* cmdBuffer) override; +}; \ No newline at end of file diff --git a/Main.cpp b/Main.cpp new file mode 100644 index 0000000..4470fe0 --- /dev/null +++ b/Main.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include + +#include "Levels/Game.h" +#include "LWE/IO/HID/GenericInputHandler.h" + +void LogCallback(const lwe::Log& log) +{ + lwe::Console::Write_8(log.ToStr()); +} + +lwe::SInt_32 Main(lwe::Str_8* appName, lwe::Str_8* appVerId, lwe::Version* appVer) +{ + *appName = "Pong"; + *appVerId = "Alpha"; + *appVer = {0, 0, 1}; + + lwe::Console::Attach(); + + lwe::Log::SetCallback(LogCallback); + + #if defined(LWE_OS_WINDOWS) + lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); + #elif defined(LWE_OS_LINUX) + lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME); + #endif + + lwe::GpuInstance::AddExtension(VK_KHR_SURFACE_EXTENSION_NAME); + + lwe::GpuInstance::Initialize(true); + + lwe::GpuDevice primary = lwe::GpuDevice::GetBest(); + + lwe::GpuQueueFamily* family = primary.GetQueueFamily(lwe::QueueType::GRAPHICS); + + lwe::GpuInterface inf(&primary); + inf.AddExtensions(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + + lwe::GpuQueue queue(family, &inf, 1.0f); + + inf.Initialize(); + + lwe::RenderWindow win(&inf, &queue); + win.Create_8(*appName, {0, 0}, {1024, 768}); + + lwe::GameLoop gl(&win, 6, 0); + gl.GetInput()->AddHandler(new lwe::GenericInputHandler()); + + lwe::Frame* mainFrame = new lwe::Frame("Main"); + + gl.AddFrame(mainFrame); + + mainFrame->AddLevel(new Game()); + + gl.Initialize(); + gl.Start(); + gl.UnInitialize(); + + win.Close(); + + inf.Release(); + + lwe::GpuInstance::Release(); + + return 0; +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..636c7d7 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Pong + +Designed over the top of the Lone Wolf Engine. Meant to display the 2D functionality, and ease-of-use of the API. +The Lone Wolf Engine was designed from the ground, up from scratch. Very few libraries are linked to this engine. + +![](image.png) + +## Planned Features + +- Online Multiplayer +- Graphical User Interface \ No newline at end of file diff --git a/image.png b/image.png new file mode 100644 index 0000000000000000000000000000000000000000..1d8fa50f5ec71ceaa06691e8c1135a92d5114c0a GIT binary patch literal 8982 zcmeHNc~p~En|~1twQP2*Qg%DGI$tf)iYN*JSC(2q)DR&;P!yC95itvd5L&C$vZ=H# z2*kPpAtVYU5kd%v1T8|)kOT+`C`u$D>|ser^4&OR=FFVa@0|H-+V4C5k^A0r^SsY} zmfy47n_So%5@_?0<3|t#*#rme+y_C6!PMOOLksZepi9)?vE)=xL<$7iJ~n;KeqC$p z1VJmI;GNqJ5Q@|?@-H$hNii{7eEqv89*@S?E(`iOGw8TikmKVokGD48x`|#3S0!w- zyT$3!*A`Ej2L*l2 zi@RK_v$W9+g&YYQid)HO9dw&ZADh(`3%Co-id6quIX{)by)i?ewaM$W8bJ zNITxgLg)IE(omY2nQ%#G=UzRMP;;JJ; z6TA1WMbK%*KKQ(+I{|T~xn}}&4MxQ2hnJ64$mMc<-7t`Vq~+gG{+8vsa0d4<%Lm< z&vLzHcM%P4i=mrS9Yy{O@JV_$x+(ccQk3xmI*_ZlKBW+8C=XeyL;BeHO*5b}z4B9uHL9%)7Sl3$AB+@HIdC~2Y#hGVEswp}KR@`H* zu}rEhyRtwyAxm#wgMM+RnNN&_#%bd!IjsN9_4@3FP4OKR1cfut*Y>q<%8OWhP+Oo& zXbPlLRel-pHkbg2N7v24nFFg3q8F4tcIa#`8ai%mC#q>-i>6yp4Ev&~!nB^vimvgz zVhxkyMzbV8pjwO>l8Xt-Y~_=lQc;lPap9JQ7_Y)+%b5`1h%hNq_qH;r9PK|tX?-(q)@bOKaugh2A^!O+j$+b@ zJ3F~n$-Rnt&WiD0>VK&I&KHXol&_3g*;hxVNHdO58bXE&OecrIlEqFHaV7g0e#V8u z=lv)o>tuzLM+&sDv6BqP7lq}HmN+U?l}O{7L=-7TU=0xh9CHI)uw9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