-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
99 lines (84 loc) · 3.03 KB
/
Player.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
#include "Player.h"
Player *Player::player_getter;
void Player::Attack()
{
if (spr.SetState(E_LiveObjState::Attack)) {
blocked_to_time = GameTime::Now().GetTime() + spr.GetCurAnimTime();
now_attack = true;
auto dir = GetCurDir();
auto cp = position.CenterPos();
switch (dir) {
case E_Dir::UP:
{
bool b = GameMap::GetCur()->TryAttack({cp.x, cp.y + 25}, damage);
if (!b)b = GameMap::GetCur()->TryAttack({cp.x - 10, cp.y + 25}, damage);
if (!b)b = GameMap::GetCur()->TryAttack({cp.x + 10, cp.y + 25}, damage);
break;
}
case E_Dir::DOWN:
{
bool b = GameMap::GetCur()->TryAttack({cp.x, cp.y - 25}, damage);
if(!b)b = GameMap::GetCur()->TryAttack({cp.x - 10, cp.y - 25}, damage);
if(!b)b = GameMap::GetCur()->TryAttack({cp.x + 10, cp.y - 25}, damage);
break;
}
case E_Dir::LEFT:
GameMap::GetCur()->TryAttack({cp.x - 25, cp.y}, damage);
break;
case E_Dir::RIGHT:
GameMap::GetCur()->TryAttack({cp.x + 25, cp.y}, damage);
break;
}
}
}
bool Player::Moved() { return !now_attack && position.Moved(); }
void Player::RefreshMoveState(E_X_Dir x, E_Y_Dir y, bool ctrl)
{
if (now_attack) { position.UpdateLastTime(); return; }
old_coords = coords;
position.Move((x == E_X_Dir::Not) ? 0 : ((x == E_X_Dir::Right) ? 1 : -1),
(y == E_Y_Dir::Not) ? 0 : ((y == E_Y_Dir::Up) ? 1 : -1), (ctrl) ? move_speed_ctrl : move_speed);
bool x_move = x != E_X_Dir::Not;
bool y_move = y != E_Y_Dir::Not;
if (x_move && y_move) {
E_Dir e_dir_x = (x == E_X_Dir::Left) ? E_Dir::LEFT : E_Dir::RIGHT;
E_Dir e_dir_y = (y == E_Y_Dir::Up) ? E_Dir::UP : E_Dir::DOWN;
if(e_dir_x != back_dir && e_dir_y != back_dir)
spr.SetDir(Is_X_Dir(back_dir) ? e_dir_y : e_dir_x);
}
else if (x_move) {
E_Dir e_dir_x = (x == E_X_Dir::Left) ? E_Dir::LEFT : E_Dir::RIGHT;
spr.SetDir(e_dir_x);
back_dir = e_dir_x;
}
else if (y_move) {
E_Dir e_dir_y = (y == E_Y_Dir::Up) ? E_Dir::UP : E_Dir::DOWN;
spr.SetDir(e_dir_y);
back_dir = e_dir_y;
}
coords = position.Pos();
//TODO : if (NOT ATTACKED)
spr.SetState(Moved() ? E_LiveObjState::Walk : E_LiveObjState::Idle);
CheckStayOnEmpty(coords);
//printf(Moved() ? "move\n" : "not move\n");
}
void Player::DieDraw(Image &canvas, double proc)
{
if (!died)return;
if (die_type == E_DieType::EmptyStay) {
SetPosY(-30 + -50 + (50 + die_pos.y) * (1 - proc));
spr.GetImage(E_LiveObjState::Idle, 0).Draw(canvas, coords, false);
} else {
grave.Draw(canvas, coords, true);
}
//for kill draw grave
}
void Player::Draw(Image &screen)
{
if (died)return;
if (now_attack && GameTime::Now().TimeCome(blocked_to_time)) {
now_attack = false;
spr.SetState(E_LiveObjState::Idle);
}
spr.Draw(screen, coords, true);
}