Implementing Main Menu Design and Entity Collision Test

This commit is contained in:
2024-10-08 16:57:13 -04:00
parent a7f429ddca
commit 3912802bba
15 changed files with 125 additions and 21 deletions

View File

@@ -1,11 +1,27 @@
#pragma once
#include <Client/Scene.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <Core/Entity.hpp>
namespace CaveGame::Client
{
class GameSession : public Scene
{
using CaveGame::Core::Entity;
class GameSession : public Scene {
public:
GameSession();
void Update(float elapsed) override;
void Draw() override;
void Load() override;
void Unload() override;
protected:
std::vector<Entity*> entity_list;
private:
};
}

View File

@@ -15,13 +15,13 @@ namespace CaveGame::Client
void Unload() override;
void PassFont(JGL::Font font);
void PassWindowSize(const Vector2& size);
void PassWindowSize(const J3ML::LinearAlgebra::Vector2 &size) override;
protected:
JUI::Scene* scene;
JUI::TextRect* title;
JGL::Font font;
Vector2 window_size;
private:
};

View File

@@ -1,5 +1,7 @@
#pragma once
#include <J3ML/LinearAlgebra/Vector2.hpp>
namespace CaveGame::Client
{
class Scene
@@ -12,9 +14,11 @@ namespace CaveGame::Client
virtual void Unload();
virtual void Update(float elapsed) = 0;
virtual void Draw() = 0;
virtual void PassWindowSize(const Vector2& size);
[[nodiscard]] bool Active() const;
protected:
bool active;
Vector2 window_size;
private:
};
}

View File

@@ -3,5 +3,5 @@
namespace CaveGame::Client
{
c
}

View File

@@ -19,7 +19,6 @@ namespace CaveGame::Client
void Load() override;
void Unload() override;
void PassWindowSize(const Vector2& size);
void PassFont(JGL::Font passed);
bool SplashComplete() const;
@@ -28,7 +27,6 @@ namespace CaveGame::Client
float load_percent = 0.f;
JGL::Texture splash;
JGL::Font font;
Vector2 window_size;
float increment = 0;
std::array<JGL::RenderTarget*, 16> column_textures{};

View File

@@ -0,0 +1,12 @@
#pragma once
#include <JUI/JUI.hpp>
#include <JUI/Widgets/Scene.hpp>
namespace CaveGame::Client
{
class WindowWidgetManager : public JUI::Scene
{
};
} using namespace JUI;

View File

@@ -1 +1,27 @@
#include <Client/GameSession.hpp>
#include <Client/GameSession.hpp>
void CaveGame::Client::GameSession::Unload() {
Scene::Unload();
}
void CaveGame::Client::GameSession::Load() {
Scene::Load();
}
void CaveGame::Client::GameSession::Draw() {
for (auto& entity: entity_list)
{
entity->Draw();
}
}
void CaveGame::Client::GameSession::Update(float elapsed) {
for (auto& entity: entity_list)
{
entity->Update(elapsed);
}
}
CaveGame::Client::GameSession::GameSession() : Scene() {
entity_list = std::vector<Entity*>();
}

View File

@@ -46,6 +46,7 @@ void CaveGame::Client::MainMenu::PassFont(JGL::Font passed) {
}
void CaveGame::Client::MainMenu::PassWindowSize(const Vector2 &size) {
window_size = size;
Scene::PassWindowSize(size);
scene->SetViewportSize(window_size.x, window_size.y);
}
}

View File

@@ -1,5 +1,6 @@
#include <Client/Scene.hpp>
bool CaveGame::Client::Scene::Active() const { return active;}
void CaveGame::Client::Scene::Load() {
@@ -13,3 +14,7 @@ void CaveGame::Client::Scene::Unload() {
CaveGame::Client::Scene::Scene() {
active = false;
}
void CaveGame::Client::Scene::PassWindowSize(const Vector2 &size) {
window_size = size;
}

View File

@@ -147,9 +147,7 @@ void CaveGame::Client::Splash::PassFont(JGL::Font passed) {
font = passed;
}
void CaveGame::Client::Splash::PassWindowSize(const Vector2 &size) {
window_size = size;
}
bool CaveGame::Client::Splash::SplashComplete() const {
return splash_timer < 0;

View File

@@ -0,0 +1,2 @@
#include <Client/WindowWidgetManager.hpp>

View File

@@ -17,6 +17,7 @@
#include <Client/Scene.hpp>
#include <Client/Splash.hpp>
#include <Client/MainMenu.hpp>
#include <Client/GameSession.hpp>
using CaveGame::Client::Scene;
@@ -29,11 +30,9 @@ constexpr float test_grid_scale = 2;
int test_tiles[test_grid_size][test_grid_size];
JGL::Font Jupiteroid;
float z = 0;
namespace CaveGame::ClientApp
{
class CaveGameWindow : public ReWindow::RWindow
@@ -41,6 +40,7 @@ namespace CaveGame::ClientApp
public:
CaveGame::Client::Splash* splash_ctx;
CaveGame::Client::MainMenu* menu_ctx;
CaveGame::Client::GameSession* game_ctx;
Scene* current_scene = nullptr;
bool render_grid = true;
@@ -159,11 +159,10 @@ namespace CaveGame::ClientApp
if (current_scene != nullptr)
{
current_scene->PassWindowSize(getSize());
current_scene->Update(elapsed);
// TODO: Ugly temporary hack.
splash_ctx->PassWindowSize(getSize());
menu_ctx->PassWindowSize(getSize());
}
}

View File

@@ -0,0 +1,44 @@
#pragma once
#include <J3ML/LinearAlgebra.hpp>
#include <vector>
#include "Color4.hpp"
namespace CaveGame::Core {
class StatusEffect { };
class Entity
{
public:
int Health() const { return health; }
int MaxHealth() const { return max_health; }
virtual void Draw() = 0;
virtual void Update(float elapsed) = 0;
protected:
int health;
int max_health;
int entity_instance_id;
float age;
Vector2 position;
Vector2 bounding_box;
std::vector<StatusEffect> active_effects;
Color4 color;
private:
};
class PhysicsEntity : public Entity
{
public:
[[nodiscard]] Vector2 Velocity() const { return velocity;}
[[nodiscard]] Vector2 EstimatedNextPosition() const { return next_position; }
protected:
Vector2 velocity;
Vector2 next_position;
float mass;
private:
};
}

View File

@@ -14,8 +14,6 @@ namespace CaveGame::Core
Wall& GetWall(int x, int y);
void SetWall(int x, int y, Wall w);
protected:
private:

1
Core/src/Core/Entity.cpp Normal file
View File

@@ -0,0 +1 @@
#include <Core/Entity.hpp>