Initial Commit

This commit is contained in:
2025-01-02 00:15:37 -05:00
commit b9afc57e6e
29 changed files with 1826 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#pragma once
#include "JGL/types/Texture.h"
using JGL::Texture;
class Animation {
protected:
std::string name{};
float ms_between_frames = 1.0f;
std::vector<Texture> textures{};
public:
[[nodiscard]] std::string GetName() const;
[[nodiscard]] float GetMsBetweenFrames() const;
/// @param animation_time a float from 0 to 1. 0 being the beginning of the animation and 1 being the end.
[[nodiscard]] const JGL::Texture* GetTexture(float animation_time) const;
public:
void SetMsBetweenFrames(float new_ms_between_frames);
public:
Animation(const std::string& name, float ms_between_frames, std::vector<Texture>& textures) : name(name), ms_between_frames(ms_between_frames), textures(textures) {};
~Animation() = default;
};

View File

@@ -0,0 +1,7 @@
#include "J3ML/LinearAlgebra/Vector2.hpp"
#include "Entity.h"
#pragma once
class Camera : public Entity {
};

View File

@@ -0,0 +1,37 @@
#pragma once
#include "J3ML/LinearAlgebra/Vector2.hpp"
#include <vector>
class Entity {
protected:
std::vector<Entity*> children{};
Vector2 position = {0, 0};
// Assuming 0 radians is up.
float face_angle = 0.0f;
void UpdateChildren();
public:
// Movements independent of the rotation.
void MoveX(float speed);
void MoveY(float speed);
// Movements dependent on face angle.
void MoveForward(float speed);
void MoveBackward(float speed);
void MoveLeft(float speed);
void MoveRight(float speed);
void Rotate(float speed);
void SetRotation(float new_rotation);
[[nodiscard]] bool AppendChild(Entity* entity);
void DestroyChild(Entity* entity);
void RemoveChild(Entity* entity);
public:
[[nodiscard]] float GetRotation() const;
[[nodiscard]] Vector2 GetPosition() const;
public:
virtual void Update() {}
public:
explicit Entity(const Vector2& position, float rotation = 0.0f) : position(position), face_angle(rotation) {}
virtual ~Entity();
};

View File

@@ -0,0 +1,7 @@
#pragma once
#include "Renderable.h"
class Hud : public Renderable {
public:
Hud() : Renderable({0, 0}, 0) {};
};

View File

@@ -0,0 +1,11 @@
#pragma once
#include "Entity.h"
#include "JGL/JGL.h"
class Renderable : public Entity {
public:
virtual void Render() {}
public:
explicit Renderable(const Vector2& position, float rotation = 0.0f) : Entity(position, rotation) {}
};

View File

@@ -0,0 +1,15 @@
#include <rewindow/types/window.h>
#pragma once
class Camera;
class DemoGameWindow : public ReWindow::RWindow {
public:
void InitGL();
void Display();
public:
void OnRefresh(float elapsed) override;
public:
DemoGameWindow() : ReWindow::RWindow() {}
DemoGameWindow(const std::string& title, int width, int height) : ReWindow::RWindow(title, width, height) {}
};

13
include/Engine/Globals.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
#include <Engine/Level/Scene.h>
#include <Engine/GameWindow.h>
namespace Globals {
inline Scene* CurrentScene = nullptr;
inline DemoGameWindow* Window = nullptr;
inline float DeltaTime() { return Window->GetDeltaTime(); }
inline void RemoveScene() { delete CurrentScene; CurrentScene = nullptr; }
inline void ChangeScene(Scene* scene) { delete CurrentScene; CurrentScene = scene; CurrentScene->Init(); }
}

View File

@@ -0,0 +1,36 @@
#pragma once
#include "J3ML/LinearAlgebra/Vector2i.hpp"
#include "J3ML/Geometry/AABB2D.hpp"
#include "JGL/types/Texture.h"
using J3ML::LinearAlgebra::Vector2i;
using JGL::Texture;
// Things that are considered non-movable parts of the level.
// TODO instanced textures.
class Fixed {
private:
void GenerateCollision();
protected:
std::vector<Vector2i> collision{};
bool enabled = false;
bool collidable = false;
Vector2i position = {0, 0};
const Texture* texture = nullptr;
public:
[[nodiscard]] bool Collidable() const;
[[nodiscard]] Vector2i GetPosition() const;
[[nodiscard]] AABB2D GetBounds() const;
[[nodiscard]] bool Enabled() const;
[[nodiscard]] std::vector<Vector2i> GetCollision();
[[nodiscard]] const Texture* GetTexture();
public:
void Enable();
void Disable();
virtual void Render() {};
public:
Fixed(const Vector2i& position, bool enabled, bool collidable, const Texture* texture) : position(position), enabled(enabled), collidable(collidable), texture(texture)
{ if (collidable) GenerateCollision(); }
virtual ~Fixed();
};

View File

@@ -0,0 +1,37 @@
#pragma once
#include <vector>
#include <Engine/Entity/Renderable.h>
#include <Engine/Entity/Hud.h>
#include <Engine/Level/Fixed.h>
class Scene {
protected:
bool Paused = false;
Hud* HeadsUpDisplay = nullptr;
std::vector<Fixed*> FixedList{};
std::vector<Entity*> EntityList{};
public:
[[nodiscard]] bool EntityListContains(const Entity* entity) const;
[[nodiscard]] bool FixedListContains(const Fixed* fixed) const;
[[nodiscard]] size_t FixedCount() const;
[[nodiscard]] size_t EntityCount() const;
public:
void AppendEntity(Entity* entity);
void AppendFixed(Fixed* fixed);
// Removes and deallocates.
void DestroyEntity(Entity* entity);
void DestroyFixed(Fixed* fixed);
// Only removes from the list.
void RemoveEntity(Entity* entity);
void RemoveFixed(Fixed* fixed);
virtual void Init() {}
virtual void Update();
virtual void Render();
public:
Scene() = default;
virtual ~Scene();
};