parent
bc8f6d253f
commit
fff5c18842
@ -0,0 +1,20 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - camera.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/01/25 (y/m/d)
|
||||||
|
* Mod Date - 2022/01/25 (y/m/d)
|
||||||
|
* Description - A 2D camera to be used with the World
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CAMERA_H_
|
||||||
|
#define CAMERA_H_
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
// TODO: class Camera
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CAMERA_H_
|
||||||
@ -0,0 +1,34 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - script.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/01/18 (y/m/d)
|
||||||
|
* Mod Date - 2022/01/18 (y/m/d)
|
||||||
|
* Description - Holds data for a LUA script
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef SCRIPT_H_
|
||||||
|
#define SCRIPT_H_
|
||||||
|
|
||||||
|
#include "asset.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class Script : public Asset
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void SetScript(const char* script);
|
||||||
|
const char* GetScript() const;
|
||||||
|
|
||||||
|
void AddError(std::string error);
|
||||||
|
const std::vector<std::string>* GetErrors() const;
|
||||||
|
private:
|
||||||
|
|
||||||
|
char* mpScript;
|
||||||
|
std::vector<std::string> mScriptErrors;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCRIPT_H_
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - grid.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/01/25 (y/m/d)
|
||||||
|
* Mod Date - 2022/01/25 (y/m/d)
|
||||||
|
* Description - A 2D fixed-size array of data. Size must be set when
|
||||||
|
* this container is created and can not be changed later.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef GRID_H_
|
||||||
|
#define GRID_H_
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
class Grid
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Grid(Sizei size);
|
||||||
|
|
||||||
|
T* operator[](Point2Di at);
|
||||||
|
T GetAt(Point2Di at);
|
||||||
|
void SetAt(Point2Di at, T value);
|
||||||
|
|
||||||
|
void SetAll(T value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
struct Node
|
||||||
|
{
|
||||||
|
T Data;
|
||||||
|
};
|
||||||
|
|
||||||
|
Sizei mSize;
|
||||||
|
Node** mGrid;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// IMPLEMENTATION
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Grid<T>::Grid(Sizei size)
|
||||||
|
: mSize(size)
|
||||||
|
{
|
||||||
|
mGrid = new Node*[size.Width];
|
||||||
|
for (int i = 0; i < size.Width; i++)
|
||||||
|
{
|
||||||
|
mGrid[i] = new Node[size.Height];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* Grid<T>::operator[](Point2Di at)
|
||||||
|
{
|
||||||
|
return &mGrid[at.X][at.Y].Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T Grid<T>::GetAt(Point2Di at)
|
||||||
|
{
|
||||||
|
return mGrid[at.X][at.Y].Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Grid<T>::SetAt(Point2Di at, T value)
|
||||||
|
{
|
||||||
|
mGrid[at.X][at.Y].Data = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void Grid<T>::SetAll(T value)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < mSize.Width; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < mSize.Height; j++)
|
||||||
|
{
|
||||||
|
mGrid[i][j].Data = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif GRID_H_
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
add_library(game world/world.cpp)
|
||||||
|
|
||||||
|
target_include_directories(game
|
||||||
|
PUBLIC "${PROJECT_BINARY_DIR}"
|
||||||
|
PUBLIC ./
|
||||||
|
PUBLIC ../../
|
||||||
|
PUBLIC ../../internal_libs
|
||||||
|
PUBLIC ../../../external/glm
|
||||||
|
PUBLIC ../../../external/glad/include
|
||||||
|
PUBLIC ../../../external/glfw/include
|
||||||
|
PUBLIC ../../../external/box2d/include
|
||||||
|
PUBLIC ../../../external/pugixml/src
|
||||||
|
)
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - object.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/01/25 (y/m/d)
|
||||||
|
* Mod Date - 2022/01/25 (y/m/d)
|
||||||
|
* Description - The base object for all in-game objects
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef OBJECT_H_
|
||||||
|
#define OBJECT_H_
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
class GameObject
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // OBJECT_H_
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - world.cpp
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/01/12 (y/m/d)
|
||||||
|
* Mod Date - 2022/01/20 (y/m/d)
|
||||||
|
* Description - Manages a game "world". A world is made up of regions which
|
||||||
|
* are subdivisions of the world. Each region contains: a set
|
||||||
|
* of images for the maps layers, a list of objects that spawn
|
||||||
|
* in this region and static collision data.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "world.h"
|
||||||
|
#include <object/object.h>
|
||||||
|
#include <assets/types/script.h>
|
||||||
|
#include <assets/types/image.h>
|
||||||
|
#include <graphics/igraphics.h>
|
||||||
|
#include <graphics/camera.h>
|
||||||
|
|
||||||
|
namespace lunarium
|
||||||
|
{
|
||||||
|
World::World(Camera* pCam, Sizei region_size)
|
||||||
|
: mpCamera(pCam), mRegionSize(region_size), mpWorldScript(nullptr), mRegions(region_size)
|
||||||
|
{
|
||||||
|
mActiveRegion = { 0, 0 };
|
||||||
|
mRegions.SetAll(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::OnLoad()
|
||||||
|
{
|
||||||
|
// TODO: Call OnLoad in the world script and on each region script
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::OnUnload()
|
||||||
|
{
|
||||||
|
// TODO: Call OnUnLoad in the world script and on each region script
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::Update(float dt)
|
||||||
|
{
|
||||||
|
// TODO: Call Update in the world script and on each region script
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::Render(Graphics* pGraphics) const
|
||||||
|
{
|
||||||
|
// TODO: Call Render in the world script and on each region
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::RenderToTexture(Graphics* pGraphics, Image* pTexture) const
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// void World::AddGameObject(GameObject* pObj)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// bool World::RemoveGameObject(GameObject* pObj)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
OpRes World::SetRegion(Region* region, Point2Di at)
|
||||||
|
{
|
||||||
|
if (*mRegions[at] != nullptr)
|
||||||
|
{
|
||||||
|
return OpRes::Fail("World::SetRegion failed because a region already exists at (%n, %n)", at.X, at.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
*mRegions[at] = region;
|
||||||
|
return OpRes::OK();
|
||||||
|
}
|
||||||
|
|
||||||
|
World::Region* World::GetRegion(Point2Di at)
|
||||||
|
{
|
||||||
|
return *mRegions[at];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool World::RemoveRegion(Point2Di at)
|
||||||
|
{
|
||||||
|
if (*mRegions[at] == nullptr)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*mRegions[at] = nullptr;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::SetWorldScript(Script* pScript)
|
||||||
|
{
|
||||||
|
mpWorldScript = pScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
Script* World::GetWorldScript()
|
||||||
|
{
|
||||||
|
return mpWorldScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue