-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.h
76 lines (68 loc) · 2.16 KB
/
Entity.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <cmath>
#include <iostream>
#include "Animation.h"
#include "HealthBar.h"
#include "Block.h"
enum AnimationName
{
Basic,
Idle,
Walk,
Attack,
Damage,
Death
};
class Entity : public sf::Sprite
{
private:
float jumpVelocity = 0;
bool jumping = false;
sf::Vector2f lastPosition;
sf::Vector2f velocity;
sf::FloatRect nextPosition;
View entityView;
sf::Texture texture;
void setEntityView();
protected:
bool isAlive = true, isPlayer = false;
float isDeadTime = 0, healingTime = 0, stepSoundTime = 0;
int health = 100, maxHealth = 100;
float speed = 200;
float jumpSpeed = 400;
float attackTime, holdAttackTime = 2;
AnimationName state = AnimationName::Basic;
Vector2f origin;
HealthBar healthBar;
std::map<AnimationName, Animation*> animations;
SoundBuffer bufferStep, bufferJump, bufferLand, bufferAttack, bufferDamage, bufferEat;
Sound soundStep, soundJump, soundLand, soundAttack, soundDamage;
public:
Entity();
Entity(sf::Texture _texture, std::vector<std::vector<int>> options);
void setEntity(sf::Texture _texture, std::vector<std::vector<int>> options);
void Up(float elapsed);
void Down(float elapsed);
void Left(float elapsed);
void Right(float elapsed);
void TakeDamage(int damage);
virtual void Attack(float elapsed, Entity& entity);
virtual void Update(float elapsed);
virtual void UpdateAI(float elapsed, Entity& player, map<int, map<int, B>>& world) {};
View getEntityView();
Sound soundEat;
float playerDistance;
void GravityUpdate(float elapsed, float gravity);
void CheckCollisions(const sf::FloatRect *arg);
void setState(AnimationName _state) { state = _state; };
AnimationName getState() { return state; };
void Respawn();
void Heal(int arg) { if (health + arg < maxHealth) health += arg; else health = maxHealth; };
bool getIsAlive() { return isAlive; };
bool getIsPlayer() { return isPlayer; };
float getIsDeadTime() { return isDeadTime; };
virtual void Draw(RenderWindow&) = 0;
};