Backup
This commit is contained in:
commit
a0b9102b93
32
.gitignore
vendored
Normal file
32
.gitignore
vendored
Normal file
@ -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
|
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
2
.idea/Pong.iml
Normal file
2
.idea/Pong.iml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
6
.idea/editor.xml
Normal file
6
.idea/editor.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="BackendCodeEditorSettings">
|
||||||
|
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/misc.xml
Normal file
8
.idea/misc.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
|
||||||
|
<component name="DiscordProjectSettings">
|
||||||
|
<option name="show" value="ASK" />
|
||||||
|
<option name="description" value="" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Pong.iml" filepath="$PROJECT_DIR$/.idea/Pong.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
46
CMakeLists.txt
Normal file
46
CMakeLists.txt
Normal file
@ -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)
|
168
Levels/Game.cpp
Normal file
168
Levels/Game.cpp
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
#include "Game.h"
|
||||||
|
#include "LWE/IO/FontAtlas.h"
|
||||||
|
|
||||||
|
#include <LWE/GameLoop.h>
|
||||||
|
#include <LWE/IO/RenderWindow.h>
|
||||||
|
#include <LWE/Systems/RigidBodySystem.h>
|
||||||
|
#include <LWE/Systems/Portrait2DSystem.h>
|
||||||
|
#include <LWE/Systems/GuiSystem.h>
|
||||||
|
#include <LWE/Components/AABB2D.h>
|
||||||
|
#include <LWE/Components/Circle.h>
|
||||||
|
#include <LWE/Components/Portrait2D.h>
|
||||||
|
#include <LWE/Gui/LabelGui.h>
|
||||||
|
#include <LWE/IO/HID/Input.h>
|
||||||
|
#include <LWE/IO/HID/GenericInputHandler.h>
|
||||||
|
#include <LWE/IO/HID/Keyboard.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
26
Levels/Game.h
Normal file
26
Levels/Game.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LWE/LWE.h>
|
||||||
|
#include <LWE/Level.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
70
Main.cpp
Normal file
70
Main.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include <LWE/LWE.h>
|
||||||
|
#include <LWE/Log.h>
|
||||||
|
#include <LWE/GarbageCollector.h>
|
||||||
|
#include <LWE/GameLoop.h>
|
||||||
|
#include <LWE/IO/RenderWindow.h>
|
||||||
|
#include <LWE/IO/Console.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
11
README.md
Normal file
11
README.md
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user