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

Weapons and logic fixes

parent 9331f7e2
Branches
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ namespace entities { ...@@ -14,7 +14,7 @@ namespace entities {
/** /**
* Return null if not available * Return null if not available
*/ */
std::shared_ptr<weapons::Weapon> getWeapon(); virtual std::shared_ptr<weapons::Weapon> getWeapon();
render::ITexture& texture; render::ITexture& texture;
render::ITexture& getTexture() override; render::ITexture& getTexture() override;
......
...@@ -74,7 +74,7 @@ namespace entities { ...@@ -74,7 +74,7 @@ namespace entities {
bool Entity::canBeRemoved() const bool Entity::canBeRemoved() const
{ {
return this->isAlive(); //most times return !this->isAlive(); //most times
} }
} }
......
...@@ -15,6 +15,9 @@ namespace entities { ...@@ -15,6 +15,9 @@ namespace entities {
{ {
vf2d offset = { 0, 0 }; vf2d offset = { 0, 0 };
for (auto& entity : client.getEntities()) { for (auto& entity : client.getEntities()) {
if(std::dynamic_pointer_cast<LivingEntity>(entity) != nullptr){
continue;
}
vf2d current = this->getCollision(*entity); vf2d current = this->getCollision(*entity);
if (offset == vf2d(0, 0)) { if (offset == vf2d(0, 0)) {
offset = current; offset = current;
......
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
using namespace olc; using namespace olc;
namespace entities { namespace entities {
std::shared_ptr<weapons::Weapon> PlayerEntity::getWeapon()
{
return this->weapons[selectedSlot];
}
void PlayerEntity::tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) void PlayerEntity::tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this)
{ {
vf2d newSpeed = { 0, 0 }; vf2d newSpeed = { 0, 0 };
...@@ -24,9 +27,37 @@ namespace entities { ...@@ -24,9 +27,37 @@ namespace entities {
this->getWeapon()->use(shared_this, mouse); this->getWeapon()->use(shared_this, mouse);
} }
this->weaponToPickUp = nullptr;
for(auto& entity : client.getEntities()){ for(auto& entity : client.getEntities()){
if(std::dynamic_pointer_cast<weapons::Weapon>(entity)){ if(std::dynamic_pointer_cast<weapons::Weapon>(entity)){
weaponToPickUp = std::dynamic_pointer_cast<weapons::Weapon>(entity);
break;
}
}
if(client.GetKey(TAB).bPressed){
if(weaponToPickUp != nullptr){
weaponToPickUp->setPickUp(true);
if(this->getWeapon() != nullptr){
this->getWeapon()->setPickUp(false);
std::shared_ptr<Entity> tmp = this->getWeapon();
client.addEntity(tmp);
this->weapons[selectedSlot] = weaponToPickUp;
weaponToPickUp = nullptr;
}
}
}
int mouseWheel = client.GetMouseWheel();
if(mouseWheel != 0){
if(mouseWheel > 0){
this->selectedSlot = (selectedSlot + 1)%maxWeapons;
}
else{
if(--this->selectedSlot < 0){
selectedSlot = maxWeapons - 1;
}
} }
} }
...@@ -38,4 +69,8 @@ namespace entities { ...@@ -38,4 +69,8 @@ namespace entities {
{ {
} }
const std::shared_ptr<weapons::Weapon>& PlayerEntity::getWeapon() const
{
return this->weapons[selectedSlot];
}
} }
\ No newline at end of file
#pragma once #pragma once
#include "CharacterEntity.h" #include "CharacterEntity.h"
#include <vector>
namespace entities { namespace entities {
...@@ -7,10 +8,18 @@ namespace entities { ...@@ -7,10 +8,18 @@ namespace entities {
public CharacterEntity public CharacterEntity
{ {
private: private:
static const int maxWeapons = 3;
std::string name; std::string name;
std::shared_ptr<weapons::Weapon> weaponToPickUp; std::shared_ptr<weapons::Weapon> weaponToPickUp;
std::shared_ptr<weapons::Weapon> weapons[maxWeapons];
int selectedSlot = 0;
protected:
std::shared_ptr<weapons::Weapon> getWeapon() override;
public: public:
void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override; void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override;
PlayerEntity(olc::vf2d pos, render::ITexture& skin, const std::string& name = "Player"); PlayerEntity(olc::vf2d pos, render::ITexture& skin, const std::string& name = "Player");
const std::shared_ptr<weapons::Weapon>& getWeapon() const;
}; };
} }
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "mainGame.h" #include "mainGame.h"
#include "PlayerEntity.h" #include "PlayerEntity.h"
#include "CharacterTexture.h" #include "CharacterTexture.h"
#include "DummyEntity.h"
#include "TypicalMeleeWeapon.h"
using namespace entities; using namespace entities;
using namespace std; using namespace std;
...@@ -19,7 +21,15 @@ shared_ptr<PlayerEntity> TestGenerator::generate(GameClient& client) ...@@ -19,7 +21,15 @@ shared_ptr<PlayerEntity> TestGenerator::generate(GameClient& client)
client += make_shared<WallEntity>(*new WallEntity(olc::vf2d(-1, -1))); client += make_shared<WallEntity>(*new WallEntity(olc::vf2d(-1, -1)));
client += make_shared<WallEntity>(*asd); client += make_shared<WallEntity>(*asd);
shared_ptr<PlayerEntity> player(new PlayerEntity({ 0, -4 }, render::CharacterTexture::MageTexture)); client += make_shared<CharacterEntity>(*new DummyEntity(olc::vf2d(5, 6), render::CharacterTexture::MageTexture));
auto weapon = make_shared<weapons::TypicalMeleeWeapon>(*new weapons::TypicalMeleeWeapon(weapons::TypicalMeleeWeapon::sword));
weapon->setPos({ -3, -4 });
client += weapon;
shared_ptr<PlayerEntity> player(new PlayerEntity({ 0, -4 }, render::CharacterTexture::EngineerTexture));
client += player; client += player;
return player; return player;
......
...@@ -22,4 +22,15 @@ namespace weapons ...@@ -22,4 +22,15 @@ namespace weapons
return this->cooldown / this->cooldownTime; return this->cooldown / this->cooldownTime;
} }
bool Weapon::canBeRemoved() const
{
return isPickedUp;
}
void Weapon::setPickUp(bool bl)
{
isPickedUp = bl;
}
} }
\ No newline at end of file
...@@ -19,6 +19,7 @@ namespace weapons { ...@@ -19,6 +19,7 @@ namespace weapons {
float cooldownTime; float cooldownTime;
int baseDamage; int baseDamage;
std::string name; std::string name;
bool isPickedUp = false;
public: public:
Weapon(render::ITexture& texture, float cooldownTime, int damage = 10, const std::string& name = "Weapon", const olc::vf2d& pos = { 0, 0 }); Weapon(render::ITexture& texture, float cooldownTime, int damage = 10, const std::string& name = "Weapon", const olc::vf2d& pos = { 0, 0 });
...@@ -36,6 +37,10 @@ namespace weapons { ...@@ -36,6 +37,10 @@ namespace weapons {
*/ */
virtual float getCooldownBar(); virtual float getCooldownBar();
bool canBeRemoved() const override;
virtual void setPickUp(bool bl);
/** /**
* Secondary charge bar. for some purpose * Secondary charge bar. for some purpose
*/ */
......
...@@ -74,7 +74,7 @@ bool GameClient::OnUserUpdate(float fElapsedTime) ...@@ -74,7 +74,7 @@ bool GameClient::OnUserUpdate(float fElapsedTime)
//lambda remove condition. because why not? //lambda remove condition. because why not?
entities.removeIf([](const shared_ptr<Entity>& entity)->bool entities.removeIf([](const shared_ptr<Entity>& entity)->bool
{ {
return !entity->canBeRemoved(); return entity->canBeRemoved();
}); });
this->updateWorldOffset(fElapsedTime); this->updateWorldOffset(fElapsedTime);
...@@ -103,7 +103,7 @@ void GameClient::setDebugMode(bool bl) ...@@ -103,7 +103,7 @@ void GameClient::setDebugMode(bool bl)
this->debug = bl; this->debug = bl;
} }
void GameClient::addEntity(std::shared_ptr<entities::Entity>& entity) void GameClient::addEntity(std::shared_ptr<Entity>& entity)
{ {
this->entities.operator+=(entity); this->entities.operator+=(entity);
} }
...@@ -113,7 +113,7 @@ const olc::TransformedView& GameClient::getScene() ...@@ -113,7 +113,7 @@ const olc::TransformedView& GameClient::getScene()
return scene; return scene;
} }
GameClient& GameClient::operator+=(std::shared_ptr<entities::Entity> entity) GameClient& GameClient::operator+=(std::shared_ptr<Entity> entity)
{ {
this->addEntity(entity); this->addEntity(entity);
return *this; return *this;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment