-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimatedCharacter.cpp
109 lines (103 loc) · 2.66 KB
/
AnimatedCharacter.cpp
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
#include <iostream>
#include <algorithm>
#include "constants.h"
#include "AnimatedCharacter.h"
namespace game {
/*
*The AnimCharacter class needs an ImageLibrary pointer to
*display images, but other than that, takes care of itself.
*/
AnimCharacter::AnimCharacter(ImageLibrary& init, EnemyHorde& horde) :
Character(init, spriteSheet),
sprites(init),
enemies(horde),
projectiles(),
spriteSheet(sprites) {};
//lets the character jump
void AnimCharacter::Jump() {
if (!GetJump()) {
SetYVelocity(GetYVelocity() + Y_ACCELERATION);
SetJump(true);
if (GetXVelocity() > 0) {
SetState(JUMP_RIGHT);
}
else {
SetState(JUMP_LEFT);
}
ResetFrame();
}
}
//ducks the character, which makes them fall faster
void AnimCharacter::Duck() {
if (GetState() == WALK_RIGHT
||GetState() == STAND_RIGHT
||GetState() == DUCK_RIGHT
||GetState() == JUMP_RIGHT
) {
SetState(DUCK_RIGHT);
}
else {
SetState(DUCK_LEFT);
}
SetXVelocity(0);
SetYVelocity(GetYVelocity() - GRAVITY);
}
//Displays the current sprite
void AnimCharacter::Display() {
if (Dead()) {
sprites.DisplayText("GAME OVER", WINDOW_WIDTH/2, WINDOW_HEIGHT/2);
return;
}
for (AuraSphere& projectile : projectiles) {
projectile.Display(GetFrame());
enemies.AttackAt(projectile.GetX(), projectile.GetY());
}
if (!projectiles.empty() && !projectiles.back().Active()) {
projectiles.pop_back();
}
if(GetState() == DUCK_ATTACK_LEFT
|| GetState() == DUCK_ATTACK_RIGHT) {
enemies.AttackAt(GetX(), GetY());
}
sprites.DisplayText("Player 1", GetX(), GetY() - SPRITE_HEIGHT);
Character::Display();
}
/* Shoots an aura sphere
*/
void AnimCharacter::Attack() {
const int PROJECTILE_OFFSET = 10;
bool direction = false;
if (GetState() == WALK_RIGHT
|| GetState() == STAND_RIGHT) {
SetState(RANGED_ATTACK_RIGHT, GetState());
direction = true;
projectiles.push_front(AuraSphere(&spriteSheet));
projectiles.front().Start(GetX() - PROJECTILE_OFFSET, GetY(), direction, pGetState());
ResetFrame();
}
else if (GetState() == DUCK_LEFT) {
ResetFrame();
SetState(DUCK_ATTACK_LEFT, GetState());
}
else if (GetState() == DUCK_RIGHT) {
ResetFrame();
SetState(DUCK_ATTACK_RIGHT, GetState());
}
else if (GetState() == JUMP_LEFT) {
ResetFrame();
SetState(AIR_ATTACK_LEFT, GetState());
}
else if (GetState() == JUMP_RIGHT) {
ResetFrame();
SetState(AIR_ATTACK_RIGHT, GetState());
}
else if (GetState() != RANGED_ATTACK_RIGHT
&& GetState() != RANGED_ATTACK_LEFT) {
SetState(RANGED_ATTACK_LEFT, GetState());
direction = false;
projectiles.push_front(AuraSphere(&spriteSheet));
projectiles.front().Start(GetX() - PROJECTILE_OFFSET, GetY(), direction, pGetState());
ResetFrame();
}
}
}