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

TODO fix collision core

parent 9992c549
Branches
No related tags found
No related merge requests found
......@@ -65,14 +65,14 @@
<ClCompile Include="TestGenerator.cpp">
<Filter>Source Files\gameObj</Filter>
</ClCompile>
<ClCompile Include="CharacterTexture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LivingEntity.cpp">
<Filter>Source Files\gameObj\entities</Filter>
</ClCompile>
<ClCompile Include="CharacterTexture.cpp">
<Filter>Source Files\gameObj</Filter>
</ClCompile>
<ClCompile Include="PlayerEntity.cpp">
<Filter>Source Files</Filter>
<Filter>Source Files\gameObj\entities</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
......@@ -127,14 +127,14 @@
<ClInclude Include="TestGenerator.h">
<Filter>Header Files\gameObj\management</Filter>
</ClInclude>
<ClInclude Include="CharacterTexture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LivingEntity.h">
<Filter>Header Files\gameObj\entities</Filter>
</ClInclude>
<ClInclude Include="CharacterTexture.h">
<Filter>Header Files\gameObj\render</Filter>
</ClInclude>
<ClInclude Include="PlayerEntity.h">
<Filter>Header Files</Filter>
<Filter>Header Files\gameObj\entities</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
......
#include "CharacterTexture.h"
#include "Entity.h"
#include "GameException.h"
#include "LivingEntity.h"
using namespace olc;
namespace render {
CharacterTexture::CharacterTexture(const std::string& name, vf2d size)
: sprite(name), size(size) {}
void CharacterTexture::render(TransformedView& scene, entities::Entity& entity)
{
if (entity.getAsLivingEntity() == nullptr) {
throw GameException("Can't render character texture for a not-living entity...", entity);
}
entities::LivingEntity& livingEntity = *entity.getAsLivingEntity();
vf2d pos = this->uv + vf2d(livingEntity.getAnimPhase() * this->size.x, livingEntity.getDirection() * size.y);
this->sprite.renderCentered(scene, entity.getPos(), pos, size, entity.getSize());
}
CharacterTexture CharacterTexture::EngineerTexture("Commissions/Engineer.png");
CharacterTexture CharacterTexture::MageTexture("Commissions/Mage.png");
}
\ No newline at end of file
......@@ -5,6 +5,17 @@ namespace render {
class CharacterTexture :
public ITexture
{
public:
static CharacterTexture EngineerTexture;
static CharacterTexture MageTexture;
//TODO add the others
private:
LazySprite sprite;
const olc::vf2d uv, size;
public:
CharacterTexture(const std::string& name, olc::vf2d size = {16, 16});
void render(olc::TransformedView& scene, entities::Entity& entity) override;
};
}
......@@ -25,10 +25,10 @@ namespace entities {
offset *= dir;
hitSize -= vf2d(ignoreDistance, ignoreDistance);
if (delta.x > hitSize.x) {
offset.x = 0;
offset.y = 0;
}
if (delta.y > hitSize.y) {
offset.y = 0;
offset.x = 0;
}
return offset;
}
......
......@@ -30,8 +30,12 @@ namespace entities {
}
}
}
return offset;
}
LivingEntity::LivingEntity(olc::vf2d pos)
: Entity(pos), timeUntilNextPhase(0), direction(0), anim_phase(0) {}
bool LivingEntity::damage(int damage, Entity& attacker)
{
if (isAlive()) {
......@@ -66,6 +70,11 @@ namespace entities {
return direction;
}
char LivingEntity::getAnimPhase() const
{
return this->anim_phase;
}
void LivingEntity::tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this)
{
timeUntilNextPhase += deltaT;
......@@ -80,5 +89,10 @@ namespace entities {
pos += offset;
}
LivingEntity* LivingEntity::getAsLivingEntity()
{
return this;
}
const float LivingEntity::phaseLength = 0.5;
}
\ No newline at end of file
......@@ -23,5 +23,7 @@ namespace entities {
void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override; //TODO
LivingEntity* getAsLivingEntity() override;
};
}
#include "PlayerEntity.h"
entities::PlayerEntity::PlayerEntity(olc::vf2d pos, const std::string& name)
: LivingEntity(pos), name(name)
#include "mainGame.h"
using namespace olc;
namespace entities {
render::ITexture& PlayerEntity::getTexture()
{
return this->texture;
}
void PlayerEntity::tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this)
{
vf2d newSpeed = { 0, 0 };
if (client.GetKey(olc::Key::A).bHeld) newSpeed -= {-1, 0};
if (client.GetKey(olc::Key::S).bHeld) newSpeed -= {0, 1};
if (client.GetKey(olc::Key::D).bHeld) newSpeed -= {1, 0};
if (client.GetKey(olc::Key::W).bHeld) newSpeed -= {0, -1};
this->speed = newSpeed;
LivingEntity::tick(client, deltaT, shared_this);
}
PlayerEntity::PlayerEntity(olc::vf2d pos, render::ITexture& skin, const std::string& name)
: LivingEntity(pos), name(name), texture(skin)
{
}
}
\ No newline at end of file
......@@ -8,10 +8,10 @@ namespace entities {
{
private:
std::string name;
render::ITexture& texture;
render::ITexture& getTexture() override;
public:
void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override;
PlayerEntity(olc::vf2d pos, const std::string& name = "Player");
PlayerEntity(olc::vf2d pos, render::ITexture& skin, const std::string& name = "Player");
};
}
entities::PlayerEntity* = new entities::PlayerEntity();
\ No newline at end of file
......@@ -2,6 +2,8 @@
#include "WallEntity.h"
#include "mainGame.h"
#include "PlayerEntity.h"
#include "CharacterTexture.h"
using namespace entities;
using namespace std;
......@@ -17,4 +19,5 @@ void TestGenerator::generate(GameClient& client)
client += make_shared<WallEntity>(*new WallEntity(olc::vf2d(-1, -1)));
client += make_shared<WallEntity>(*asd);
client += make_shared<PlayerEntity>(*new PlayerEntity({ 0, -4 }, render::CharacterTexture::EngineerTexture));
}
......@@ -54,7 +54,7 @@ bool GameClient::OnUserUpdate(float fElapsedTime)
//return false if it want to exit.
for(std::shared_ptr<Entity>& entity : this->getEntities()){
entity->tick(*this, fElapsedTime);
entity->tick(*this, fElapsedTime, entity);
}
entities.finalizeAdd();
......
 TestGenerator.cpp
WallEntity.cpp
WallTexture.cpp
 Entity.cpp
C:\Users\kosmx\Documents\GitHub\2d-game\Entity.cpp(20,42): warning C4244: 'argument': conversion from 'int' to 'T', possible loss of data
with
[
T=float
]
C:\Users\kosmx\Documents\GitHub\2d-game\Entity.cpp(20,20): warning C4244: 'argument': conversion from 'int' to 'T', possible loss of data
with
[
T=float
]
Generating code
313 of 2009 functions (15.6%) were compiled, the rest were copied from previous compilation.
4 functions were new in current compilation
1 of 2184 functions (<0.1%) were compiled, the rest were copied from previous compilation.
0 functions were new in current compilation
1 functions had inline decision re-evaluated but remain unchanged
Finished generating code
2d-game.vcxproj -> C:\Users\kosmx\Documents\GitHub\2d-game\x64\Release\2d-game.exe
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment