Skip to content
Snippets Groups Projects
Commit 3bee5d6e authored by KosmX's avatar KosmX
Browse files

Success build

some changes
parent 434caeae
Branches
No related tags found
No related merge requests found
......@@ -149,6 +149,7 @@
<ClCompile Include="mainGame.cpp" />
<ClCompile Include="ResourceManager.cpp" />
<ClCompile Include="SimpleSprite.cpp" />
<ClCompile Include="WallEntity.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DynamicArray.hpp" />
......@@ -163,6 +164,7 @@
<ClInclude Include="resource.h" />
<ClInclude Include="ResourceManager.h" />
<ClInclude Include="SimpleSprite.h" />
<ClInclude Include="WallEntity.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -24,14 +24,17 @@
<Filter Include="Header Files\gameObj\management">
<UniqueIdentifier>{886a9672-46a0-46f4-a068-e12dce07d024}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\gameObj\entities">
<UniqueIdentifier>{2a6abf62-06d5-4f89-a9e3-f572fb2f7d2f}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\gameObj\entities">
<UniqueIdentifier>{df2376d0-03f2-4c26-aabc-0cfcf53c4a2c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="game.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Entity.cpp">
<Filter>Source Files\gameObj</Filter>
</ClCompile>
<ClCompile Include="ResourceManager.cpp">
<Filter>Source Files\gameObj</Filter>
</ClCompile>
......@@ -44,14 +47,17 @@
<ClCompile Include="mainGame.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Entity.cpp">
<Filter>Source Files\gameObj\entities</Filter>
</ClCompile>
<ClCompile Include="WallEntity.cpp">
<Filter>Source Files\gameObj\entities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="interfaces.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Entity.h">
<Filter>Header Files\gameObj</Filter>
</ClInclude>
<ClInclude Include="LazySprite.h">
<Filter>Header Files\gameObj\render</Filter>
</ClInclude>
......@@ -82,5 +88,11 @@
<ClInclude Include="DynamicArray.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Entity.h">
<Filter>Header Files\gameObj\entities</Filter>
</ClInclude>
<ClInclude Include="WallEntity.h">
<Filter>Header Files\gameObj\entities</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -2,10 +2,13 @@
#include "olc.h"
#include "ITexture.h"
#include "mainGame.h"
class GameClient;
namespace entities {
class WallEntity;
class Entity
{
protected:
......@@ -29,6 +32,12 @@ namespace entities {
virtual ~Entity() = default;
//TODO getAs*** stuff, all virtual
//same purpose to dynamic_cast, but without using language server
virtual WallEntity* getAsWallEntity()
{
return nullptr;
}
};
......
#pragma once
#include "Entity.h"
#include "olcPGEX_TransformedView.h"
namespace entities {
class Entity;
}
namespace render
{
......@@ -10,7 +14,7 @@ namespace render
public:
//Giving the entity will reduce the variables needed, and will make it's use more dynamic
virtual void render(olc::TransformedView& scene, Entity& entity) = 0;
virtual void render(olc::TransformedView& scene, entities::Entity& entity) = 0;
virtual ~ITexture() = default;
};
......
......@@ -6,28 +6,24 @@ namespace render {
olc::Decal* LazySprite::getDecay()
{
if (sprite == nullptr) {
this->sprite = render::ResourceManager::getSprite(this->resourceName);
this->sprite = ResourceManager::getSprite(this->resourceName);
}
return this->sprite;
}
LazySprite::LazySprite(const std::string& resName, int u, int v, int sizeU, int sizeV)
: LazySprite(resName, olc::vi2d(u, v), olc::vi2d(sizeU, sizeV))
{}
LazySprite::LazySprite(const std::string& resName, olc::vi2d pos, olc::vi2d size)
: resourceName(resName), uv(pos), size(size)
{
sprite = nullptr;
}
LazySprite::LazySprite(const std::string& resName)
: sprite(nullptr), resourceName(resName)
{}
void LazySprite::render(olc::TransformedView& scene, olc::vf2d pos, olc::vf2d scale)
void LazySprite::render(olc::TransformedView& scene, const olc::vi2d& pos, const olc::vf2d& uv, const olc::vf2d& size, olc::vf2d scale)
{
scene.DrawPartialDecal(pos, this->getDecay(), uv, size, scale);
}
void LazySprite::renderCentered(olc::TransformedView& scene, olc::vf2d pos, olc::vf2d scale)
void LazySprite::renderCentered(olc::TransformedView& scene, const olc::vi2d& pos, const olc::vf2d& uv, const olc::vf2d& size, olc::vf2d scale)
{
//probably modify the ints to doubles???
render(scene, pos + size*2.0, scale);
this->render(scene, pos + size / 2.0f, uv, size, scale);
}
}
......@@ -13,28 +13,26 @@ namespace render {
class LazySprite
{
private:
olc::Decal* sprite = nullptr;
olc::Decal* sprite;
protected:
const std::string resourceName;
//int const u, v, sizeU, sizeV;
olc::vi2d const uv, size;
//olc::vi2d const uv, size;
olc::Decal* getDecay();
public:
/**
* u, v the texture coordinates on the image,
* sizeU, V are the size of that sprite
*/
LazySprite(const std::string& resName, int u, int v, int sizeU = 16, int sizeV = 16);
LazySprite(const std::string& resName, olc::vi2d pos, olc::vi2d size = olc::vi2d(16, 16));
explicit LazySprite(const std::string& resName);
/**
* Render the sprite in world-space
*/
void render(olc::TransformedView& scene, olc::vf2d, olc::vf2d scale = olc::vf2d(1, 1));
void render(olc::TransformedView& scene, const olc::vi2d& pos, const olc::vf2d& uv, const olc::vf2d& size, olc::vf2d scale = olc::vf2d(1, 1));
void renderCentered(olc::TransformedView& scene, olc::vf2d, olc::vf2d scale);
void renderCentered(olc::TransformedView& scene, const olc::vi2d& pos, const olc::vf2d& uv, const olc::vf2d& size, olc::vf2d scale = olc::vf2d(1, 1));
//decal reference is not my stuff, I don't have to delete it.
};
......
......@@ -37,7 +37,10 @@ namespace render
*/
void ResourceManager::createInstance(std::string* parent)
{
instance = std::make_unique<ResourceManager>(*new ResourceManager(parent));
if(instance != nullptr){
throw std::runtime_error("Can't create a second instance of a singleton resource manager");
}
instance = new ResourceManager(parent);
}
olc::Decal* ResourceManager::getSprite(const std::string& key)
......@@ -59,5 +62,5 @@ namespace render
return &this->decalData;
}
//std::unique_ptr<ResourceManager> ResourceManager::instance;
ResourceManager* ResourceManager::instance = nullptr;
}
\ No newline at end of file
#pragma once
#include <string>
#include <map>
#include <memory>
#include "olcPixelGameEngine.h"
namespace render
......@@ -15,7 +13,7 @@ namespace render
class ResourceManager
{
private: //static
static std::unique_ptr<ResourceManager> instance;
static ResourceManager* instance;
static ResourceManager& getInstance(); //who needs that???
public: //static
......
#include "SimpleSprite.h"
#include "Entity.h"
render::SimpleSprite::SimpleSprite(const std::string name, olc::vi2d pos)
: sprite(name, pos)
{
using namespace olc;
}
render::SimpleSprite::SimpleSprite(const std::string& name, const vi2d& pos, const vf2d& size)
: sprite(name), uv(pos), size(size) {}
void render::SimpleSprite::render(olc::TransformedView& scene, entities::Entity& entity)
{
this->sprite.render(scene, entity.getPos());
this->sprite.render(scene, entity.getPos(), uv, size);
}
......@@ -3,7 +3,6 @@
#include <string>
#include "LazySprite.h"
namespace render {
class SimpleSprite :
......@@ -11,9 +10,10 @@ namespace render {
{
private:
LazySprite sprite;
const olc::vf2d uv, size;
public:
SimpleSprite(const std::string name, olc::vi2d pos);
SimpleSprite(const std::string& name, const olc::vi2d& pos, const olc::vf2d& size);
void render(olc::TransformedView& scene, entities::Entity& entity) override;
};
......
#include "WallEntity.h"
#pragma once
#include "Entity.h"
namespace entities {
class WallEntity : public Entity
{
public:
//This is a wall entity after all.
WallEntity* getAsWallEntity() override
{
return this;
}
};
}
#define OLC_PGE_APPLICATION
#define OLC_PGEX_TRANSFORMEDVIEW
#include "olcPixelGameEngine.h"
#include "mainGame.h"
......
......@@ -49,3 +49,5 @@ bool GameClient::OnUserUpdate(float fElapsedTime)
return true;
}
GameClient* GameClient::instance = nullptr;
\ No newline at end of file
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.ipdb
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.iobj
c:\users\kosmx\documents\github\2d-game\x64\release\vc142.pdb
c:\users\kosmx\documents\github\2d-game\x64\release\wallentity.obj
c:\users\kosmx\documents\github\2d-game\x64\release\simplesprite.obj
c:\users\kosmx\documents\github\2d-game\x64\release\resourcemanager.obj
c:\users\kosmx\documents\github\2d-game\x64\release\maingame.obj
c:\users\kosmx\documents\github\2d-game\x64\release\lazysprite.obj
c:\users\kosmx\documents\github\2d-game\x64\release\game.obj
c:\users\kosmx\documents\github\2d-game\x64\release\entity.obj
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.exe
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.pdb
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\2d-game.write.1u.tlog
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\cl.command.1.tlog
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\cl.read.1.tlog
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\cl.write.1.tlog
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\link.command.1.tlog
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\link.read.1.tlog
c:\users\kosmx\documents\github\2d-game\x64\release\2d-game.tlog\link.write.1.tlog
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\kosmx\Documents\GitHub\2d-game\x64\Release\2d-game.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>
\ No newline at end of file

\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment