From a203038a495267c8b6a740c076599f6b12913a35 Mon Sep 17 00:00:00 2001 From: KosmX <kosmx.mc@gmail.com> Date: Thu, 13 May 2021 22:05:41 +0200 Subject: [PATCH] C++ docs Description --- 2d-game.vcxproj | 1 - 2d-game.vcxproj.filters | 3 --- CharacterEntity.h | 3 +++ CharacterTexture.h | 10 +++++++- DummyEntity.h | 3 +++ DungeonGenerator.h | 2 +- DynamicArray.hpp | 3 +++ EMGun.h | 14 ++++++++++- Entity.h | 42 ++++++++++++++++++++++++++++++- EntityWithAI.h | 25 ++++++++++++++++-- ExplosiveProjectile.h | 9 +++++++ GlitchGun.h | 22 ++++++++++++++-- ITexture.h | 15 ++++++++--- LazySprite.cpp | 4 +-- LazySprite.h | 24 +++++++++++++++--- LivingEntity.h | 29 +++++++++++++++++++++ MeleeWeapon.h | 34 ++++++++++++++++++++++--- Pistol.h | 3 +++ PlayerEntity.h | 48 ++++++++++++++++++++++++++++++++--- ProjectileEntity.h | 19 +++++++++++++- RangedWeapon.h | 14 +++++++++-- ResourceManager.h | 19 +++++++++++++- SimpleSprite.h | 9 +++++++ SquareRoomGenerator.h | 3 +++ TestGenerator.h | 4 +++ TypicalMeleeWeapon.h | 3 +++ WallEntity.h | 26 ++++++++++++++++--- WallTexture.h | 6 +++++ Weapon.h | 35 ++++++++++++++++++++------ WeaponTextures.h | 3 +++ interfaces.h | 18 ------------- mainGame.h | 56 +++++++++++++++++++++++++++++++++++------ 32 files changed, 442 insertions(+), 67 deletions(-) delete mode 100644 interfaces.h diff --git a/2d-game.vcxproj b/2d-game.vcxproj index 6a45226..09137af 100644 --- a/2d-game.vcxproj +++ b/2d-game.vcxproj @@ -188,7 +188,6 @@ <ClInclude Include="olc.h" /> <ClInclude Include="ITexture.h" /> <ClInclude Include="Entity.h" /> - <ClInclude Include="interfaces.h" /> <ClInclude Include="LazySprite.h" /> <ClInclude Include="olcPGEX_TransformedView.h" /> <ClInclude Include="olcPixelGameEngine.h" /> diff --git a/2d-game.vcxproj.filters b/2d-game.vcxproj.filters index 9a9e930..cbd904d 100644 --- a/2d-game.vcxproj.filters +++ b/2d-game.vcxproj.filters @@ -121,9 +121,6 @@ </ClCompile> </ItemGroup> <ItemGroup> - <ClInclude Include="interfaces.h"> - <Filter>Header Files</Filter> - </ClInclude> <ClInclude Include="LazySprite.h"> <Filter>Header Files\gameObj\render</Filter> </ClInclude> diff --git a/CharacterEntity.h b/CharacterEntity.h index 857ee13..474ebc2 100644 --- a/CharacterEntity.h +++ b/CharacterEntity.h @@ -7,6 +7,9 @@ namespace weapons } namespace entities { + /** + * @brief A player or an enemy + */ class CharacterEntity : public LivingEntity { diff --git a/CharacterTexture.h b/CharacterTexture.h index 0c56fc0..502b838 100644 --- a/CharacterTexture.h +++ b/CharacterTexture.h @@ -2,6 +2,9 @@ #include "ITexture.h" namespace render { + /** + * @brief Texture for CharacterEntities. + */ class CharacterTexture : public ITexture { @@ -18,7 +21,12 @@ namespace render { public: CharacterTexture(const std::string& name, olc::vf2d size = {16, 16}); - + + /** + * @brief Throws a GameException, if we try to render a non-character entity with it + * @param scene scene + * @param entity a CharacterEntity + */ void render(olc::TransformedView& scene, entities::Entity& entity) override; }; } diff --git a/DummyEntity.h b/DummyEntity.h index 144b821..cf16f8f 100644 --- a/DummyEntity.h +++ b/DummyEntity.h @@ -2,6 +2,9 @@ #include "CharacterEntity.h" namespace entities { + /** + * @brief A test/dummy entity. it can't do anything... no, it can die + */ class DummyEntity : public CharacterEntity { diff --git a/DungeonGenerator.h b/DungeonGenerator.h index d100a2c..531099f 100644 --- a/DungeonGenerator.h +++ b/DungeonGenerator.h @@ -8,7 +8,7 @@ namespace entities { class GameClient; /** - * Generate random dungeons... + * @brief Generate random dungeons... */ class DungeonGenerator { diff --git a/DynamicArray.hpp b/DynamicArray.hpp index 3193f6d..35f83aa 100644 --- a/DynamicArray.hpp +++ b/DynamicArray.hpp @@ -7,6 +7,9 @@ //Dynamic data type, set (not ordered), I'll use arrays for entry pointers, I will leave nullptr in the list. //I don't want to waste time with resizing this, I'll allocate more memory and if I delete from this, I'll do it in +/** + * @brief Dynamic array, to store entities, have a buffer, to don't tick newly added entities too early + */ template<typename T> class DynamicArray { diff --git a/EMGun.h b/EMGun.h index 7321848..b57bbf1 100644 --- a/EMGun.h +++ b/EMGun.h @@ -4,17 +4,29 @@ namespace weapons { - + /** + * @brief Weapon with energy level + */ class EMGun : public Pistol { private: + /** + * @brief How much energy it does have + */ float energy = 128; + /** + * @brief one shot always uses 10 energy, but recharge rate can be changed + */ float energyRegenRate; public: EMGun(render::ITexture& texture, float cooldownTime, int damage, float projectileSpeed = 10, const std::string& name = "RangedWeapon", const olc::vf2d& pos = { 0, 0 }, float energyRegen = 12); bool use(std::shared_ptr<Entity> user, const olc::vf2d& direction) override; + /** + * @brief Shows the energy level in the secondary status-bar + * @return 0-1 float + */ float getSecondaryBar() override; bool update(float dTick) override; diff --git a/Entity.h b/Entity.h index bf0c20f..920d76a 100644 --- a/Entity.h +++ b/Entity.h @@ -10,15 +10,39 @@ namespace entities { class WallEntity; class LivingEntity; + /** + * @brief Every object, what can be on the map. + */ class Entity { protected: + /** + * @brief it's position + */ olc::vf2d pos; //I can store these safely directly + /** + * @brief the object's texture + * @return the texture + */ virtual render::ITexture& getTexture() = 0; - + /** + * @brief half hitbox size + * @return hitbox size as a vector + */ virtual olc::vf2d getHitBoxSize() const = 0; + /** + * @brief Calculate collision with another Entity, how much should this entity move, to avoid the collision + * @param other the other entity + * @return collision vector, 0 if there is no collision + */ virtual olc::vf2d getCollision(const Entity& other); + /** + * @brief well, is initialized + */ bool is_initialized; + /** + * @brief true, if it is alive + */ bool is_alive; //walls shouldn't have variables like this. But it will be an intended bug. public: @@ -29,19 +53,35 @@ namespace entities { //nodiscard??? [[nodiscard]] virtual olc::vf2d getPos() const; + /** + * @brief get it's size to render + */ [[nodiscard]] virtual olc::vf2d getSize() const; [[nodiscard]] virtual bool isAlive() const; + /** + * @return can be deleted from the entity list. mostly is dead + */ [[nodiscard]] virtual bool canBeRemoved() const; + /** + * @brief Entity tick multiple times per sec + * @param client the game client object + * @param deltaT how long take a tick + * @param shared_this this as a shared_ptr + */ virtual void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this){} /** + * @brief something damage this * @param damage how much damage should it take * @param attacker who deal the damage. not the projectile, the entity * @return did the entity take the damage or no (like a wall) */ virtual bool damage(int damage, Entity& attacker) = 0; //this shouldn't change it's state + /** + * @brief render + */ virtual void render(olc::TransformedView& scene); virtual std::string getName() const; diff --git a/EntityWithAI.h b/EntityWithAI.h index 42367ba..a572f40 100644 --- a/EntityWithAI.h +++ b/EntityWithAI.h @@ -5,16 +5,37 @@ namespace entities { - + /** + * @brief The enemies. go after the player, and try to kill it + */ class EntityWithAI : public CharacterEntity { private: + /** + * @brief Its weapon, can be nullptr + */ std::shared_ptr<weapons::Weapon> weapon; + /** + * @brief the attack cooldown variable + */ float attackCooldown = 0; + /** + * @brief How strong is our foe. + */ const int damageAmount; public: - void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override; + /** + * @brief Tick, from Entity + * @param client client + * @param deltaT fElapsedTime + * @param shared_this it as a shared_ptr + */ + void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override; + /** + * @brief override it's weapon + * @param weapon the new weapon, can be nullptr + */ void addWeapon(std::shared_ptr<weapons::Weapon>& weapon); EntityWithAI(const olc::vf2d& pos, render::ITexture& skin, int damage = 20, const std::string& name = "Enemy"); diff --git a/ExplosiveProjectile.h b/ExplosiveProjectile.h index 2cc73eb..c6b83e0 100644 --- a/ExplosiveProjectile.h +++ b/ExplosiveProjectile.h @@ -2,11 +2,20 @@ #include "ProjectileEntity.h" namespace entities { + /** + * @brief A projectile, that explodes + */ class ExplosiveProjectile : public ProjectileEntity { private: + /** + * @brief After exploding, it will expire + */ float stateTime = 0; + /** + * @brief Is still a projectile, or a fireball + */ bool state = false; static render::SimpleSprite explosion; protected: diff --git a/GlitchGun.h b/GlitchGun.h index 59d9449..c463dbf 100644 --- a/GlitchGun.h +++ b/GlitchGun.h @@ -3,28 +3,46 @@ namespace weapons { - + /** + * @brief Texture for the bug weapon + */ class GlitchTexture : public render::ITexture { private: render::LazySprite sprite; public: + /** + * @brief Texture from my friend, Macskusz111 + * @param name the file path and name + */ GlitchTexture(const std::string& name = "FromMacskusz111/bug.png"); void render(olc::TransformedView& scene, Entity& entity) override; }; - + /** + * @brief TODO make the bug weapon more buggy + */ class GlitchGun : public EMGun { friend GlitchTexture; private: + /** + * @brief internal variable for the animated texture + */ float timeState = 0; static GlitchTexture GlitchTexture; public: GlitchGun(float cooldownTime, int damage, float projectileSpeed = 10, const std::string& name = "RangedWeapon", const olc::vf2d& pos = { 0, 0 }, float energyRegen = 10); + /** + * @brief It does randomly shoot normal and explosive projectiles + * @param user the user + * @param pos where is the user + * @param v0 the base speed of the projectile + * @param damage how much damage does it have + */ void spawnProjectile(std::shared_ptr<Entity>& user, const olc::vf2d& pos, const olc::vf2d& v0, int damage) override; bool update(float dTick) override; }; diff --git a/ITexture.h b/ITexture.h index 575963f..167580b 100644 --- a/ITexture.h +++ b/ITexture.h @@ -9,14 +9,23 @@ namespace entities { namespace render { - + /** + * @brief Every texture, what can render an entity + */ class ITexture { public: - //Giving the entity will reduce the variables needed, and will make it's use more dynamic + /** + * @brief Render the sprite, abstract function + * @param scene view description + * @param entity entity to render with this texture + */ virtual void render(olc::TransformedView& scene, entities::Entity& entity) = 0; - + + /** + * @brief mostly not needed, but I can never know it + */ virtual ~ITexture() = default; }; } diff --git a/LazySprite.cpp b/LazySprite.cpp index c2fc212..04df8d7 100644 --- a/LazySprite.cpp +++ b/LazySprite.cpp @@ -3,7 +3,7 @@ #include "ResourceManager.h" namespace render { - olc::Decal* LazySprite::getDecay() + olc::Decal* LazySprite::getDecal() { if (sprite == nullptr) { this->sprite = ResourceManager::getSprite(this->resourceName); @@ -18,7 +18,7 @@ namespace render { void LazySprite::render(olc::TransformedView& scene, const olc::vf2d& pos, const olc::vf2d& uv, const olc::vf2d& size, olc::vf2d scale) { - scene.DrawPartialDecal(pos, this->getDecay(), uv, size, scale); + scene.DrawPartialDecal(pos, this->getDecal(), uv, size, scale); } diff --git a/LazySprite.h b/LazySprite.h index b72ea26..00e8db8 100644 --- a/LazySprite.h +++ b/LazySprite.h @@ -7,7 +7,7 @@ namespace render { /** - * Refer to one texture, not animated, not modifiable, just a simple image. + * @brief Refer to one texture, not animated, not modifiable, just a simple image. * Lazy loading means, it will load it only, when you're trying to use it. */ class LazySprite @@ -19,7 +19,10 @@ namespace render { const std::string resourceName; //int const u, v, sizeU, sizeV; //olc::vi2d const uv, size; - olc::Decal* getDecay(); + /** + * @brief get an old::Decal + */ + olc::Decal* getDecal(); public: /** * u, v the texture coordinates on the image, @@ -28,10 +31,23 @@ namespace render { explicit LazySprite(const std::string& resName); /** - * Render the sprite in world-space - */ + * @brief Renders the sprite into the world + * @param scene olc::TransformedView scene + * @param pos the in-world pos + * @param uv texture uv pos + * @param size texture size + * @param scale scale, 1 by default + */ void render(olc::TransformedView& scene, const olc::vf2d& pos, const olc::vf2d& uv, const olc::vf2d& size, olc::vf2d scale = olc::vf2d(1, 1)); + /** + * @brief Render, but pos in the center + * @param scene olc::TransformedView scene + * @param pos the in-world pos + * @param uv texture uv pos + * @param size texture size + * @param scale scale, 1 by default + */ void renderCentered(olc::TransformedView& scene, const olc::vf2d& 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. diff --git a/LivingEntity.h b/LivingEntity.h index 1780996..9185c88 100644 --- a/LivingEntity.h +++ b/LivingEntity.h @@ -1,23 +1,52 @@ #pragma once #include "Entity.h" namespace entities { + /** + * @brief Any moving animal or player + */ class LivingEntity : public Entity { private: + /** + * @brief It is moving to that direction + */ char direction; + /** + * @brief it is animated + */ char anim_phase; + /** + * @brief animation internal variable + */ float timeUntilNextPhase; + /** + * @brief animation internal constant + */ const static float phaseLength; protected: olc::vf2d getHitBoxSize() const override; + /** + * @brief Its speed and moving direction + */ olc::vf2d speed; virtual olc::vf2d collisionOffset(GameClient& client); + /** + * @brief It has a health + */ int health; public: LivingEntity(olc::vf2d pos, int health = 100); bool damage(int damage, Entity& attacker) override; + /** + * @brief Animation related getter + * @return its direction + */ char getDirection(); + /** + * @brief Animation phase + * @return phase + */ char getAnimPhase() const; diff --git a/MeleeWeapon.h b/MeleeWeapon.h index 217e7f0..8805cf2 100644 --- a/MeleeWeapon.h +++ b/MeleeWeapon.h @@ -3,26 +3,54 @@ #include <functional> namespace weapons { + /** + * @brief A melee weapon, like a spoon + */ class MeleeWeapon : public Weapon { protected: virtual int getDamage() const; + /** + * @brief Damage the victim + * @param user user + * @param victim victim + * @return true, if it could damage. false for a wall... + */ virtual bool damageEntity(std::shared_ptr<Entity> user, std::shared_ptr<Entity>& victim); + /** + * @brief Tries to damage every entity in a range. + * @param user user + * @param predicate range selector predicate + * @return true, if it could damage at least one entity + */ virtual bool damageIf(std::shared_ptr<Entity>& user, std::function<bool(std::shared_ptr<Entity> self, std::shared_ptr<Entity> other)> predicate); - //virtual bool(*getPredicator())(std::shared_ptr<Entity>, std::shared_ptr<Entity>) = 0; + /** + * @brief The predicate function getter for the damageIf + * @param direction users direction + * @return the predicate + */ virtual std::function<bool(std::shared_ptr<Entity>, std::shared_ptr<Entity>)> getPredicator(const olc::vf2d& direction) = 0; + /** + * @brief the hit's center distance from the user + * @return float + */ virtual float getHitOffset() const; /** - * Functor to predicate entity distance. - * You can also use lambda, if you want + * @brief Functor to predicate entity distance. You can also use lambda, if you want */ class predicateDistance { public: float minDistance = 0; float maxDistance = 5; + /** + * @brief A functor + * @param usePos :D + * @param other :) + * @return is the potential victim in the range + */ bool operator()(const olc::vf2d& usePos, std::shared_ptr<Entity> other) const; }; diff --git a/Pistol.h b/Pistol.h index 31ad987..3d9e129 100644 --- a/Pistol.h +++ b/Pistol.h @@ -4,6 +4,9 @@ namespace weapons { + /** + * @brief Just a pistol, nothing too dangerous + */ class Pistol : public RangedWeapon { diff --git a/PlayerEntity.h b/PlayerEntity.h index 9185803..290443e 100644 --- a/PlayerEntity.h +++ b/PlayerEntity.h @@ -4,27 +4,69 @@ namespace entities { + /** + * @brief You, or the player + */ class PlayerEntity : public CharacterEntity { private: + /** + * @brief It can hold maximum n weapons + */ static const int maxWeapons = 3; std::string name; + /** + * @brief internal variable + */ std::shared_ptr<weapons::Weapon> weaponToPickUp; + /** + * @brief array, storing the weapons + */ std::shared_ptr<weapons::Weapon> weapons[maxWeapons]; + /** + * @brief Selected weapon slot. circular, 0->1->2->0... + */ int selectedSlot = 0; + /** + * @brief max health, for HP regen upper limit and status bar + */ float maxHealth = 200; + /** + * @brief HP regen cooldown + */ float lastDamage = 0; public: + /** + * @brief Get selected weapon + * @return nullptr if has no selected weapon + */ std::shared_ptr<weapons::Weapon> getWeapon() override; - + /** + * @brief Tick the entity, read the control keys, HP regen logic, etc... + * @param client client + * @param deltaT fElapsedTime + * @param shared_this this + */ 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"); + /** + * @brief Constant weapon getter + * @return idk + */ const std::shared_ptr<weapons::Weapon>& getWeapon() const; - + /** + * @brief Ouch + * @param damage that hurt + * @param attacker the bad guy + * @return :D + */ bool damage(int damage, Entity& attacker) override; - + /** + * @brief Sorry for these very meaningless descriptions + * @return 0-1 float, hp in percents. + */ float getHealthStatus(); }; } diff --git a/ProjectileEntity.h b/ProjectileEntity.h index 3a31950..46b8d40 100644 --- a/ProjectileEntity.h +++ b/ProjectileEntity.h @@ -3,6 +3,9 @@ #include "SimpleSprite.h" namespace entities { + /** + * @brief A projectile, a bullet + */ class ProjectileEntity : public Entity { @@ -10,17 +13,27 @@ namespace entities { static render::SimpleSprite projectile; private: render::ITexture& texture; + /** + * @brief It will be deleted if it doesn't hit anything in a time + */ float age = 0; protected: olc::vf2d velocity; + /** + * @brief Who is the owner of this bullet. needed to not damage the user + */ std::shared_ptr<Entity> user; render::ITexture& getTexture() override; int damageValue; virtual int getDamage(); + /** + * @brief not used, do a bounce function + * @param collision collision vector + */ virtual void bounce(const olc::vf2d& collision); /** - * Determines, what will the projectile do, if it hit something. + * @brief Determines, what will the projectile do, if it hit something. * @param collisionVector the collision vector * @param who who is the affected entity * @return is the projectile destroyed. @@ -34,6 +47,10 @@ namespace entities { void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override; + /** + * @brief Set its velocity + * @param v velocity vector + */ virtual void setVelocity(const olc::vf2d& v); bool damage(int damage, Entity& attacker) override; }; diff --git a/RangedWeapon.h b/RangedWeapon.h index d9b66f8..2eca63b 100644 --- a/RangedWeapon.h +++ b/RangedWeapon.h @@ -5,7 +5,10 @@ namespace weapons { class Pistol; class EMGun; - + + /** + * @brief Any weapon, what does shoot. not melee + */ class RangedWeapon : public Weapon { @@ -15,7 +18,14 @@ namespace weapons { protected: float projectileSpeed; - + + /** + * @brief Spawn a projectile entity + * @param user the user of the weapon + * @param pos where to + * @param v0 what speed + * @param damage what damage + */ virtual void spawnProjectile(std::shared_ptr<Entity>& user, const olc::vf2d& pos, const olc::vf2d& v0, int damage) = 0; public: diff --git a/ResourceManager.h b/ResourceManager.h index f2eb314..a5a0507 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -5,10 +5,11 @@ namespace render { + class SpriteManager; /** - * Load every sprite only once, + * @brief Load every sprite only once, act as a set for loaded textures */ class ResourceManager { @@ -23,6 +24,11 @@ namespace render */ static void createInstance(std::string* parent = nullptr); + /** + * @brief get a sprite, it it's already loaded, doesn't load it again + * @param key string sprite key + * @return the sprite + */ static olc::Decal* getSprite(const std::string& key); private: @@ -30,11 +36,22 @@ namespace render const std::string parentFolder; ResourceManager(std::string* parent, olc::ResourcePack *pack = nullptr); ResourceManager(const ResourceManager& other) = default; //make it private... I won't copy it. + /** + * @brief The map of the sprites + */ std::map<std::string, SpriteManager*> resourceMap; olc::ResourcePack* pack; public: + /** + * @brief used by GetSprite + * @param string asd + * @return the sprite + */ olc::Decal* getDecal(const std::string& string); //olc::Decal* operator[](std::string* key); + /** + * @brief indexing operator :D + */ olc::Decal* operator[](const std::string& key); ~ResourceManager(); diff --git a/SimpleSprite.h b/SimpleSprite.h index 9cc301a..77a46da 100644 --- a/SimpleSprite.h +++ b/SimpleSprite.h @@ -5,11 +5,20 @@ namespace render { + /** + * @brief Simplest useable texture + */ class SimpleSprite : public ITexture { private: + /** + * @brief The sprite it is referring + */ LazySprite sprite; + /** + * @brief image in the sprite + */ const olc::vf2d uv, size; public: diff --git a/SquareRoomGenerator.h b/SquareRoomGenerator.h index 0a69ec6..b01f1d5 100644 --- a/SquareRoomGenerator.h +++ b/SquareRoomGenerator.h @@ -1,5 +1,8 @@ #pragma once #include "DungeonGenerator.h" +/** + * @brief Generates a weird square dungeon, filled with stupid enemies and weapons +*/ class SquareRoomGenerator : public DungeonGenerator { diff --git a/TestGenerator.h b/TestGenerator.h index a16fa5f..4d07188 100644 --- a/TestGenerator.h +++ b/TestGenerator.h @@ -1,5 +1,9 @@ #pragma once #include "DungeonGenerator.h" + +/** + * @brief Used for testing, doesn't random +*/ class TestGenerator : public DungeonGenerator { diff --git a/TypicalMeleeWeapon.h b/TypicalMeleeWeapon.h index 78eaae1..aa9ad8c 100644 --- a/TypicalMeleeWeapon.h +++ b/TypicalMeleeWeapon.h @@ -1,6 +1,9 @@ #pragma once #include "MeleeWeapon.h" namespace weapons { + /** + * @brief A typical melee weapon. I want to do not typical melee weapons too + */ class TypicalMeleeWeapon : public MeleeWeapon { diff --git a/WallEntity.h b/WallEntity.h index b941f11..ced8ec3 100644 --- a/WallEntity.h +++ b/WallEntity.h @@ -5,6 +5,9 @@ #include "WallTexture.h" namespace entities { + /** + * @brief Just a stupid wall, it doesn't do much, can't be killed... + */ class WallEntity : public Entity { public: @@ -12,22 +15,37 @@ namespace entities { static render::WallTexture simpleGreenWallTexture; private: - byte neighbourID; + /** + * @brief How much neighbours does it have + * 16 possible states + */ + char neighbourID; render::WallTexture& usedTexture; protected: + /** + * @brief Calculate the neighbour id + * @param client the cliet + */ virtual void updateNeighbours(GameClient& client); render::ITexture& getTexture() override; olc::vf2d getHitBoxSize() const override; public: explicit WallEntity(const olc::vf2d& pos, render::WallTexture& texture = simpleWallTexture); - + /** + * @brief Init, before tick, used to calculate neighbours + * @param client + */ void init(GameClient& client) override; bool damage(int damage, Entity& attacker) override; - - virtual byte getNeighbourID() const; + + /** + * @brief Accessor for neighbourID + * @return 42 + */ + virtual char getNeighbourID() const; //This is a wall entity after all. }; diff --git a/WallTexture.h b/WallTexture.h index 1c8b3f3..6a16056 100644 --- a/WallTexture.h +++ b/WallTexture.h @@ -5,6 +5,9 @@ namespace render { + /** + * @brief Texture to render walls, with 16 possible states + */ class WallTexture : public ITexture { @@ -12,6 +15,9 @@ namespace render LazySprite sprite; const olc::vf2d baseOffset, size; protected: + /** + * @brief map, witch state means what coordinates in the sprite + */ static const std::map<byte, olc::vi2d> offsetMap; public: WallTexture(const std::string& resName, const olc::vf2d& baseOffset, const olc::vf2d& size = olc::vf2d(16, 16)); diff --git a/Weapon.h b/Weapon.h index 8b4fee9..2d02b5d 100644 --- a/Weapon.h +++ b/Weapon.h @@ -5,8 +5,7 @@ using namespace entities; //yes, I know, I'm using `using namespace` in a header namespace weapons { /** - * You can throw it to the ground, this is why it's an entity. But it will be possible to use it. and shoot enemies. - * or projectiles. + * @brief You can throw it to the ground, this is why it's an entity. But it will be possible to use it. and shoot enemies, or projectiles. */ class Weapon : public Entity @@ -19,6 +18,9 @@ namespace weapons { float cooldownTime; int baseDamage; std::string name; + /** + * @brief Is on the ground, or in an entity's inventory + */ bool isPickedUp = false; olc::vf2d getHitBoxSize() const override; public: @@ -26,29 +28,48 @@ namespace weapons { Weapon(render::ITexture& texture, float cooldownTime, int damage = 10, const std::string& name = "Weapon", const olc::vf2d& pos = { 0, 0 }); /** - * @return true, if can use + * @return true, if you did something with it. false otherwise */ virtual bool use(std::shared_ptr<Entity> user, const olc::vf2d& direction) = 0; + /** + * @brief tick, if on the ground. It does charge energy, or whatever. + * @param client see + * @param deltaT the + * @param shared_this Entity class + */ void tick(GameClient& client, float deltaT, std::shared_ptr<Entity>& shared_this) override { update(deltaT); //weapons on the ground can charge... } - + + /** + * @brief Update the weapon in a Character's inventory + * @param dTick a.k.a. deltaT, or fElapsedTime + * @return is the user can use it + */ virtual bool update(float dTick); /** - * 0 - 1 cooldown, 1 is ready to use, more than one makes sense, - * like 2 charges + * @brief 0 - 1 cooldown, 1 is ready to use, more than one makes sense, like 2 charges + * @return cooldown time */ virtual float getCooldownBar(); + /** + * @brief Can be removed form the ground. + * @return true if someone picked it up + */ bool canBeRemoved() const override; + /** + * @brief Mutator to isPickedUp + * @param bl bool + */ virtual void setPickUp(bool bl); /** - * Secondary charge bar. for some purpose + * @brief Secondary charge bar. for some purpose */ virtual float getSecondaryBar() { return 0; } virtual void setPos(const olc::vf2d& newPos); diff --git a/WeaponTextures.h b/WeaponTextures.h index 4a03740..61b0bc4 100644 --- a/WeaponTextures.h +++ b/WeaponTextures.h @@ -4,6 +4,9 @@ namespace weapons { + /** + * @brief Textures for common weapons... + */ namespace textures { inline render::SimpleSprite sword1("Items/LongWep.png", { 0, 16 }); diff --git a/interfaces.h b/interfaces.h deleted file mode 100644 index ba03706..0000000 --- a/interfaces.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - - -namespace render -{ - - - /** - * Everything what can be rendered. PLS use as virtual - * - */ - class IRenderable - { - public: - virtual void render() const = 0; - }; - -} diff --git a/mainGame.h b/mainGame.h index 63bb0cc..abd5278 100644 --- a/mainGame.h +++ b/mainGame.h @@ -5,21 +5,38 @@ #include "Entity.h" #include "PlayerEntity.h" - +/** + * @brief The game main class itself. manages the entities, adjust the screen... +*/ class GameClient : public olc::PixelGameEngine { private: static GameClient* instance; + /** + * @brief create a new singleton instance + * @param debug debug enabled + * @return the created GameClient + */ static GameClient& createInstance(bool debug); //I want it to me a singleton, but I don't want to let anything init this friend int main(int, char* []); olc::vf2d viewArea = {-2, -2}; //olc::vf2d viewScale = {2, 2}; bool debug; + /** + * @brief The scene + */ olc::TransformedView scene; + /** + * @brief The main player. or a reference to the main player + */ std::shared_ptr<entities::PlayerEntity> player; void updateWorldOffset(float dTick); + /** + * @brief Renders the status-bar + * @bug it renders the status behind other things. I should fix that + */ void renderStatus(); void renderStatusLine(int i, float f, const olc::Pixel& pixel); public: @@ -34,19 +51,44 @@ public: GameClient(bool debug = false); DynamicArray<std::shared_ptr<entities::Entity>>& getEntities(); - - bool OnUserCreate() override; + /** + * @brief Create a new game instance + * @return + */ + bool OnUserCreate() override; + /** + * @brief Update the game + * @param fElapsedTime the length of the last tick + * @return false, if the game can quit + */ bool OnUserUpdate(float fElapsedTime) override; - + /** + * @brief turn on debug, caused by an exception + * @param bl true + */ void setDebugMode(bool bl = true); - + /** + * @brief Add a new entity to the world. you can also use += + * @param entity entity + */ void addEntity(std::shared_ptr<entities::Entity>& entity); - + /** + * @brief Get the screen details. needed in fire direction calculation + * @return the scene + */ const olc::TransformedView& getScene(); //for some reason - + /** + * @brief Add an entity to the world. + * @param entity the entity + * @return GameClient + */ GameClient& operator+=(std::shared_ptr<entities::Entity> entity); + /** + * @brief Get the main player + * @return the PlayerEntity + */ std::shared_ptr<entities::PlayerEntity> getPlayerEntity(); //for some reason, probably I won't need it //bool OnUserDestroy() override; -- GitLab