Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef RIGIDBODY_HPP_
- #define RIGIDBODY_HPP_
- #include "Physics/Physics.hpp"
- #include <SFML/Graphics.hpp>
- #include <SFML/System.hpp>
- #include <cmath>
- namespace LGE{
- enum RigidBodyType{
- RIGIDBODY_ELASTIC = 1, // The elastic resolution will displace and also bounce the colliding entity off by reducing the velocity by it's restituion coefficient
- RIGIDBODY_DISPLACE = 2, // The displace resolution will only move an entity outside of the space of the other and zero the velocity in that direction
- RIGIDBODY_NONE = 3 // Collision will be ignored
- };
- class RigidBody{
- public:
- RigidBody(sf::FloatRect rect, RigidBodyType type, bool dynamic = true); // If body isn't dynamic, it will be parsed as kinematic
- RigidBody(RigidBodyType type = RIGIDBODY_ELASTIC, bool dynamic = true);
- void setDynamic(bool dynamic){ this->dynamic = dynamic; };
- void setMass(int mass);
- void setMaxVelocity(sf::Vector2f maxVelocity){ this->maxVelocity = maxVelocity; };
- void updatePhysics(sf::Time dt, RigidBody **bodys, int numBodys = 1);
- bool isDynamic(){ return this->dynamic; };
- bool checkCollisionAndResolve(RigidBody *object);
- int getLeft(){ return this->rect.left; };
- int getRight(){ return this->rect.left + this->rect.width; };
- int getTop(){ return this->rect.top; };
- int getBottom(){ return this->rect.top + this->rect.height; };
- int getWidth(){ return this->rect.width; };
- int getHeight(){ return this->rect.height; };
- int getMass(){ return this->mass; };
- int getDistance(RigidBody *object){ return sqrt((int)(this->rect.left - object->rect.left) ^ 2
- + (int)(this->rect.top - object->rect.top) ^ 2); };
- float getRestitution(){ return this->restitution; };
- sf::Vector2f getCenter(){ return sf::Vector2f(this->rect.left + this->rect.width / 2,
- this->rect.top + this->rect.height / 2); };
- sf::FloatRect rect;
- protected:
- sf::Vector2f velocity;
- sf::Vector2f acceleration;
- sf::Vector2f maxVelocity;
- RigidBodyType bodyType;
- bool dynamic;
- int mass = 1;
- float restitution = 0.2;
- };
- };
- #endif // RIGIDBODY_HPP
- #ifndef ITEM_HPP_
- #define ITEM_HPP_
- #include "Physics/RigidBody.hpp"
- #include "Item/ItemInfo.hpp"
- #include <SFML/Graphics.hpp>
- #include <SFML/System.hpp>
- #include <string>
- namespace LGE{
- class Item : public RigidBody{
- public:
- Item(ItemInfo *info, sf::Texture texture);
- Item();
- Item *drop();
- virtual void update(sf::Time dt);
- virtual void draw(sf::RenderWindow *window);
- virtual void updateSpriteRect(bool neighbors[8]);
- void setTexture(sf::Texture &texture){ this->sprite.setTexture(texture); };
- void setPosition(int x, int y){ this->rect.left = x; this->rect.top = y; };
- int getId(){ return this->info->getId(); };
- int getCost(){ return this->info->getCost(); };
- int getStackMax(){ return this->info->getStackMax(); };
- int getDamage(){ return this->info->getDamage(); };
- int getWidth(){ return this->info->getWidth(); };
- int getHeight(){ return this->info->getHeight(); };
- bool isPlaceable(){ return this->info->isPlaceable(); };
- bool isSolid(){ return this->info->isSolid(); };
- bool isDropped(){ return this->dropped; };
- std::string getName(){ return this->info->getName(); };
- std::string getDescription(){ return this->info->getDescription(); };
- std::string getTexturePath(){ return this->info->getTexturePath(); };
- ItemType getType(){ return this->info->getType(); };
- protected:
- ItemInfo *info;
- sf::Sprite sprite;
- bool dropped;
- };
- class Air : public Item{
- public:
- Air(ItemInfo *info, sf::Texture texture);
- void update(sf::Time dt);
- void draw(sf::RenderWindow *window);
- void updateSpriteRect(bool neighbors[8]);
- private:
- };
- };
- #endif // ITEM_HPP_
- #ifndef BLOCK_HPP_
- #define BLOCK_HPP_
- #include "Item/Item.hpp"
- #include "Item/ItemInfo.hpp"
- namespace LGE{
- class Block : public Item{
- public:
- Block(ItemInfo *info, sf::Texture texture);
- void update(sf::Time dt);
- void draw(sf::RenderWindow *window);
- void updateSpriteRect(bool neighbors[8]);
- private:
- };
- };
- #endif // BLOCK_HPP_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement