-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.h
executable file
·95 lines (83 loc) · 1.37 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once
#include <SFML\Graphics.hpp>
#include "Physics.h"
class Entity
{
float x, y, xVel, yVel;
sf::Sprite sprite;
//**not fields**
float GRAVITY = .2f;
bool jumpStarted = false;
float fallVel = .5f;
//**************
public:
Entity(sf::Sprite sprite, float x, float y, float xVel, float yVel)
{
this->sprite = sprite;
this->x = x;
this->xVel = xVel;
this->y = y;
this->yVel = yVel;
}
//changes curretn sprite of entity
void setSprite(sf::Sprite sprite)
{
this->sprite = sprite;
}
//return either the x or y coordienate of the entity's curent location
float getX()
{
return x;
}
float getY()
{
return y;
}
//used with game state class to move entity
void moveRight()
{
if (testRight(x, y))
x += xVel;
else
x -= xVel;
}
void moveLeft()
{
if (testLeft(x, y))
x -= xVel;
else
x += xVel;
}
void jump()
{
if (testUp(x, y))
y -= yVel;
else
y += yVel;
}
//used for when player walks off an edge
void fall()
{
y += fallVel;
fallVel += GRAVITY;
}
//draws entity
void drawEntity(sf::RenderWindow &window)
{
sprite.setPosition(x, y);
window.draw(sprite);
}
//resets jumpStarted
void resetJumpStart()
{
fallVel = .5f;
}
void setX(float x)
{
this->x = x;
}
void setY(float y)
{
this->y = y;
}
};