Cleanup
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
#include "J3ML/J3ML.hpp"
|
||||
#include "Engine/Entity/Entity.h"
|
||||
#include "Engine/Globals.h"
|
||||
#include <J3ML/J3ML.hpp>
|
||||
#include <Engine/Entity/Entity.h>
|
||||
#include <Engine/Globals.h>
|
||||
|
||||
using namespace J3ML;
|
||||
void Entity::MoveX(float speed) {
|
||||
void Engine::Entity::MoveX(float speed) {
|
||||
position.x = position.x + (speed * Globals::Window->GetDeltaTime());
|
||||
}
|
||||
|
||||
void Entity::MoveY(float speed) {
|
||||
void Engine::Entity::MoveY(float speed) {
|
||||
position.y = position.y + (speed * Globals::DeltaTime());
|
||||
}
|
||||
|
||||
void Entity::MoveForward(float speed) {
|
||||
void Engine::Entity::MoveForward(float speed) {
|
||||
position.x = position.x + (speed * Globals::DeltaTime()) * Math::Cos(face_angle);
|
||||
position.y = position.y + (speed * Globals::DeltaTime()) * Math::Sin(face_angle);
|
||||
}
|
||||
|
||||
void Entity::MoveBackward(float speed) {
|
||||
void Engine::Entity::MoveBackward(float speed) {
|
||||
speed = -speed;
|
||||
position.x = position.x + (speed * Globals::DeltaTime()) * Math::Cos(face_angle);
|
||||
position.y = position.y + (speed * Globals::DeltaTime()) * Math::Sin(face_angle);
|
||||
}
|
||||
|
||||
void Entity::MoveLeft(float speed) {
|
||||
void Engine::Entity::MoveLeft(float speed) {
|
||||
position.x = position.x + (speed * Globals::DeltaTime()) * -Math::Sin(face_angle);
|
||||
position.y = position.y + (speed * Globals::DeltaTime()) * Math::Cos(face_angle);
|
||||
}
|
||||
|
||||
void Entity::MoveRight(float speed) {
|
||||
void Engine::Entity::MoveRight(float speed) {
|
||||
position.x = position.x + (speed * Globals::DeltaTime()) * Math::Sin(face_angle);
|
||||
position.y = position.y + (speed * Globals::DeltaTime()) * -Math::Cos(face_angle);
|
||||
}
|
||||
|
||||
void Entity::SetRotation(float new_face_angle) {
|
||||
void Engine::Entity::SetRotation(float new_face_angle) {
|
||||
face_angle = new_face_angle;
|
||||
|
||||
if (face_angle < 0)
|
||||
@@ -41,33 +41,33 @@ void Entity::SetRotation(float new_face_angle) {
|
||||
face_angle = fmod(face_angle, Math::Pi * 2);
|
||||
}
|
||||
|
||||
void Entity::Rotate(float speed) {
|
||||
void Engine::Entity::Rotate(float speed) {
|
||||
SetRotation(face_angle + speed * Globals::DeltaTime());
|
||||
}
|
||||
|
||||
float Entity::GetRotation() const {
|
||||
float Engine::Entity::GetRotation() const {
|
||||
return face_angle;
|
||||
}
|
||||
|
||||
Vector2 Entity::GetPosition() const {
|
||||
Vector2 Engine::Entity::GetPosition() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
bool Entity::AppendChild(Entity* entity) {
|
||||
bool Engine::Entity::AppendChild(Entity* entity) {
|
||||
bool success = false;
|
||||
if (!Globals::CurrentScene->EntityListContains(entity))
|
||||
children.push_back(entity), success = true;
|
||||
return success;
|
||||
}
|
||||
|
||||
Entity::~Entity() {
|
||||
Engine::Entity::~Entity() {
|
||||
for (auto* e : children)
|
||||
delete e;
|
||||
|
||||
children = {};
|
||||
}
|
||||
|
||||
void Entity::UpdateChildren() {
|
||||
void Engine::Entity::UpdateChildren() {
|
||||
for (auto& e : children) {
|
||||
e->Update();
|
||||
if (!e->children.empty())
|
||||
@@ -75,13 +75,13 @@ void Entity::UpdateChildren() {
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::DestroyChild(Entity* entity) {
|
||||
void Engine::Entity::DestroyChild(Entity* entity) {
|
||||
auto it = std::find(children.begin(), children.end(), entity);
|
||||
if (it != children.end())
|
||||
delete *it, children.erase(it);
|
||||
}
|
||||
|
||||
void Entity::RemoveChild(Entity* entity) {
|
||||
void Engine::Entity::RemoveChild(Entity* entity) {
|
||||
auto it = std::find(children.begin(), children.end(), entity);
|
||||
if (it != children.end())
|
||||
children.erase(it);
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "Engine/GameWindow.h"
|
||||
#include "Engine/Globals.h"
|
||||
#include "Engine/Entity/Camera.h"
|
||||
#include "JGL/JGL.h"
|
||||
#include <Engine/GameWindow.h>
|
||||
#include <Engine/Globals.h>
|
||||
#include <Engine/Entity/Camera.h>
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
|
||||
void DemoGameWindow::InitGL() {
|
||||
void Engine::DemoGameWindow::InitGL() {
|
||||
if (!JGL::Init(GetSize(), 0, 0))
|
||||
exit(-1);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void DemoGameWindow::Display() {
|
||||
void Engine::DemoGameWindow::Display() {
|
||||
JGL::Update(GetSize());
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -24,9 +24,9 @@ void DemoGameWindow::Display() {
|
||||
if (Globals::CurrentScene)
|
||||
Globals::CurrentScene->Render();
|
||||
|
||||
DemoGameWindow::GLSwapBuffers();
|
||||
Engine::DemoGameWindow::GLSwapBuffers();
|
||||
}
|
||||
|
||||
void DemoGameWindow::OnRefresh(float elapsed) {
|
||||
void Engine::DemoGameWindow::OnRefresh(float elapsed) {
|
||||
Display();
|
||||
}
|
||||
|
@@ -1,35 +1,35 @@
|
||||
#include "Engine/Level/Fixed.h"
|
||||
#include <Engine/Level/Fixed.h>
|
||||
|
||||
bool Fixed::Collidable() const {
|
||||
bool Engine::Fixed::Collidable() const {
|
||||
return collidable;
|
||||
}
|
||||
|
||||
Vector2i Fixed::GetPosition() const {
|
||||
Vector2i Engine::Fixed::GetPosition() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
AABB2D Fixed::GetBounds() const {
|
||||
AABB2D Engine::Fixed::GetBounds() const {
|
||||
auto maximum = Vector2(position.x + texture->GetDimensions().x, position.y + texture->GetDimensions().y);
|
||||
return { Vector2(position), maximum };
|
||||
}
|
||||
|
||||
bool Fixed::Enabled() const {
|
||||
bool Engine::Fixed::Enabled() const {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void Fixed::Enable() {
|
||||
void Engine::Fixed::Enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void Fixed::Disable() {
|
||||
void Engine::Fixed::Disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
Fixed::~Fixed() {
|
||||
Engine::Fixed::~Fixed() {
|
||||
delete texture;
|
||||
}
|
||||
|
||||
void Fixed::GenerateCollision() {
|
||||
void Engine::Fixed::GenerateCollision() {
|
||||
if (!Collidable() || !Enabled() || !texture)
|
||||
return;
|
||||
|
||||
@@ -43,10 +43,10 @@ void Fixed::GenerateCollision() {
|
||||
collision = result;
|
||||
}
|
||||
|
||||
std::vector<Vector2i> Fixed::GetCollision() {
|
||||
std::vector<Vector2i> Engine::Fixed::GetCollision() {
|
||||
return collision;
|
||||
}
|
||||
|
||||
const Texture* Fixed::GetTexture() {
|
||||
const Texture* Engine::Fixed::GetTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
@@ -1,33 +1,33 @@
|
||||
#include <Engine/Level/Scene.h>
|
||||
|
||||
bool Scene::EntityListContains(const Entity* entity) const {
|
||||
bool Engine::Scene::EntityListContains(const Entity* entity) const {
|
||||
for (auto* e : EntityList)
|
||||
if (e == entity)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Scene::FixedListContains(const Fixed* fixed) const {
|
||||
bool Engine::Scene::FixedListContains(const Fixed* fixed) const {
|
||||
for (auto* f : FixedList)
|
||||
if (f == fixed)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t Scene::FixedCount() const {
|
||||
size_t Engine::Scene::FixedCount() const {
|
||||
return FixedList.size();
|
||||
}
|
||||
|
||||
size_t Scene::EntityCount() const {
|
||||
size_t Engine::Scene::EntityCount() const {
|
||||
return EntityList.size();
|
||||
}
|
||||
|
||||
void Scene::Update() {
|
||||
void Engine::Scene::Update() {
|
||||
for (auto& e : EntityList)
|
||||
e->Update();
|
||||
}
|
||||
|
||||
void Scene::Render() {
|
||||
void Engine::Scene::Render() {
|
||||
for (auto& f : FixedList)
|
||||
if (f->Enabled())
|
||||
f->Render();
|
||||
@@ -41,7 +41,7 @@ void Scene::Render() {
|
||||
HeadsUpDisplay->Render();
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
Engine::Scene::~Scene() {
|
||||
for (auto* f : FixedList)
|
||||
delete f;
|
||||
|
||||
@@ -51,7 +51,7 @@ Scene::~Scene() {
|
||||
delete HeadsUpDisplay;
|
||||
}
|
||||
|
||||
void Scene::Unload() {
|
||||
void Engine::Scene::Unload() {
|
||||
for (auto* f : FixedList)
|
||||
delete f;
|
||||
|
||||
@@ -61,42 +61,42 @@ void Scene::Unload() {
|
||||
delete HeadsUpDisplay;
|
||||
}
|
||||
|
||||
void Scene::AppendEntity(Entity* entity) {
|
||||
void Engine::Scene::AppendEntity(Entity* entity) {
|
||||
if (!EntityListContains(entity))
|
||||
EntityList.push_back(entity);
|
||||
}
|
||||
|
||||
void Scene::AppendFixed(Fixed* fixed) {
|
||||
void Engine::Scene::AppendFixed(Fixed* fixed) {
|
||||
if (!FixedListContains(fixed))
|
||||
FixedList.push_back(fixed);
|
||||
}
|
||||
|
||||
void Scene::DestroyEntity(Entity *entity) {
|
||||
void Engine::Scene::DestroyEntity(Entity *entity) {
|
||||
auto it = std::find(EntityList.begin(), EntityList.end(), entity);
|
||||
if (it != EntityList.end())
|
||||
delete *it, EntityList.erase(it);
|
||||
}
|
||||
|
||||
void Scene::DestroyFixed(Fixed* fixed) {
|
||||
void Engine::Scene::DestroyFixed(Fixed* fixed) {
|
||||
auto it = std::find(FixedList.begin(), FixedList.end(), fixed);
|
||||
if (it != FixedList.end())
|
||||
delete *it, FixedList.erase(it);
|
||||
}
|
||||
|
||||
void Scene::RemoveEntity(Entity* entity) {
|
||||
void Engine::Scene::RemoveEntity(Entity* entity) {
|
||||
auto it = std::find(EntityList.begin(), EntityList.end(), entity);
|
||||
if (it != EntityList.end())
|
||||
EntityList.erase(it);
|
||||
}
|
||||
|
||||
|
||||
void Scene::RemoveFixed(Fixed* fixed) {
|
||||
void Engine::Scene::RemoveFixed(Fixed* fixed) {
|
||||
auto it = std::find(FixedList.begin(), FixedList.end(), fixed);
|
||||
if (it != FixedList.end())
|
||||
FixedList.erase(it);
|
||||
}
|
||||
|
||||
std::string Scene::GetName() const {
|
||||
std::string Engine::Scene::GetName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#include <Game/Entity/Box.h>
|
||||
|
||||
void Box::Render() {
|
||||
void Game::Box::Render() {
|
||||
J2D::Begin(nullptr, true);
|
||||
J2D::FillRect(Colors::Red, Vector2(position), {20, 20});
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
void Box::Update() {
|
||||
void Game::Box::Update() {
|
||||
if (Globals::Window->IsKeyDown(Keys::W))
|
||||
MoveY(-500);
|
||||
if (Globals::Window->IsKeyDown(Keys::S))
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <Game/Entity/DemoGameHud.h>
|
||||
#include <Engine/Globals.h>
|
||||
|
||||
void DemoGameHud::Render() {
|
||||
void Game::DemoGameHud::Render() {
|
||||
float framerate = Globals::Window->GetRefreshRate();
|
||||
J2D::Begin(nullptr, true);
|
||||
J2D::DrawString(Colors::Whites::Ivory, "Framerate: " + std::to_string((int) framerate), 0, 0, 1, 16);
|
||||
|
@@ -3,8 +3,8 @@
|
||||
#include <Game/Entity/Box.h>
|
||||
|
||||
void ControllableBox::Init() {
|
||||
auto* hud = new DemoGameHud();
|
||||
auto* b = new Box({0, 0});
|
||||
auto* hud = new Game::DemoGameHud();
|
||||
auto* b = new Game::Box({0, 0});
|
||||
HeadsUpDisplay = hud;
|
||||
AppendEntity(b);
|
||||
}
|
||||
|
Reference in New Issue
Block a user