-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.cpp
More file actions
63 lines (54 loc) · 2.03 KB
/
Copy pathCharacter.cpp
File metadata and controls
63 lines (54 loc) · 2.03 KB
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
#include "Character.h"
#include "raymath.h"
Character::Character(int winWidth, int winHeight) : windowWidth(winWidth), windowHeight(winHeight) {
width = texture.width / maxFrame;
height = texture.height;
}
Vector2 Character::getScreenPos() {
return Vector2 {
static_cast<float>(windowWidth) / 2.0f - scale * (0.5f * width),
static_cast<float>(windowHeight) / 2.0f - scale * (0.5f * height)
};
}
void Character::tick(float deltaTime) {
if(!getAlive()) return;
if (IsKeyDown(KEY_A)) velocity.x -= 1.0;
if (IsKeyDown(KEY_D)) velocity.x += 1.0;
if (IsKeyDown(KEY_W)) velocity.y -= 1.0;
if (IsKeyDown(KEY_S)) velocity.y += 1.0;
BaseCharacter::tick(deltaTime);
Vector2 origin{};
Vector2 offset{};
float rotation{};
if(rightLeft > 0.f) {
origin = {0.f, weapon.height * scale};
offset = {35.f, 55.f};
weaponCollisionRec = {
getScreenPos().x + offset.x,
getScreenPos().y + offset.y - weapon.height * scale,
weapon.width * scale,
weapon.height * scale
};
IsMouseButtonDown(MOUSE_LEFT_BUTTON) ? rotation = 35.f : rotation = 0.f;
} else {
origin = {weapon.width * scale, weapon.height * scale};
offset = {25.f, 55.f};
weaponCollisionRec = {
getScreenPos().x + offset.x - weapon.width * scale,
getScreenPos().y + offset.y - weapon.height * scale,
weapon.width * scale,
weapon.height * scale
};
IsMouseButtonDown(MOUSE_LEFT_BUTTON) ? rotation = -35.f : rotation = 0.f;
}
// Draw the Sword
Rectangle source{0.f, 0.f, static_cast<float>(weapon.width) * rightLeft, static_cast<float>(weapon.height)};
Rectangle dest{getScreenPos().x + offset.x, getScreenPos().y + offset.y, weapon.width * scale, weapon.height * scale};
DrawTexturePro(weapon, source, dest, origin, rotation, WHITE);
}
void Character::takeDamage(float damage) {
health -= damage;
if(health <= 0.f) {
setAlive(false);
}
}