-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKirby.h
133 lines (90 loc) · 2.69 KB
/
Kirby.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include "GameObject.h"
#include "RenderableObject.h"
#include "TickableObject.h"
#include "Sprites.h"
#include "RigidBody.h"
#include <QGraphicsPixmapItem>
#include "Camera.h"
struct Impulse {
KA::Vec2Df value{0,0};
double remainingtime = 0;
};
class Kirby : public RigidBody {
protected:
int maxwalkspeed = 5;
uint jumpsLeft = 2;
const int jumpCooldownDefault = 300;
int jumpCooldown = 0;
QGraphicsTextItem* name = 0;
std::string sname = "";
bool isThisTheKirbyInstance();
int health = 6;
const int damageCooldownDefault = 300;
int damageCooldown = 0;
/* Tick Related */
void timeRelated(double deltatime);
void collisionRelated();
void movementRelated();
void animationRelated();
public:
bool invincible = false;
GameObject* storedObject = 0;
Kirby* setName(std::string nm) { sname = nm; return this; }
const double kirbyscale = 0.8;
TexID status = HUD_POWER;
int c=0;
double groundDistance();
Kirby(QPointF pos = QPointF(0.0, 0.0)) : RigidBody(pos, QPointF(0, 0), 1 * kirbyscale, 1 * kirbyscale) {
setObjectId(objects::KIRBY);
rigiddrawscale = kirbyscale;
animator->setAnimatable(TextureManager::getInstance().getAnimatable(KIRBY_STAND));
setZValue(4);
setSizeX(kirbyscale);
setSizeY(kirbyscale);
setAbility(HUD_POWER);
}
Cloneable* clone() const override { return new Kirby(QPointF(getX(), getY())); }
virtual void setX(const double x) override {
RigidBody::setX(x);
}
virtual void setY(const double y) override {
RigidBody::setY(y);
}
Kirby(const Kirby& go) : Kirby(QPointF(go.getX(), go.getY())) {
setObjectId(objects::KIRBY);
}
const static uint8_t buttonsize = 12;
enum KirbyKeys {
UP = 0, RIGHT = 1, LEFT = 2, DOWN = 3, SPACE = 4, INHALE_EXHALE = 5, INHALE_ENEMIES = 6, USE_SPECIALPWR = 7, DROP_SPECIALPWR = 8, ENTERDOOR = 9, THROW_ENEMY = 10, E = 11
};
bool buttons[buttonsize]{ false };
bool mirror = false;
Impulse jumpImpulse{ KA::Vec2Df{0,-150}, 0 };
void tick(double deltatime);
int l = 0;
void render(QGraphicsScene& scene, bool shouldClear = false) override;
QPixmap getTexture() override {
return animator->getCurrentPixmap((angle == 0 || !circa(velocity.x, 0.05) ? mirror : (angle < 0)));
}
void keyPressEvent(QKeyEvent* e, bool isPressed) override;
static int getScoreFromObject(GameObject* item);
void setAbility(TexID id);
void setHealth(unsigned int v);
int getHealth()const {return health;}
TexID statusToAnimatable(TexID id) {
switch (id) {
default:
return KIRBY_STAND;
case HUD_CUTTER:
return KIRBY_CUTTER;
case HUD_SPARK:
return KIRBY_SPARK;
case HUD_FIRE:
return KIRBY_FIRE;
case HUD_BEAM:
return KIRBY_BEAM;
}
}
void onCollision(RigidBody* rb) override;
};