-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsunflower_player.h
134 lines (103 loc) · 4.1 KB
/
sunflower_player.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
134
#pragma once
# include "player.h"
# include "resource.h"
# include "sun_bullet.h"
# include "sun_bullet_ex.h"
# include <iostream>
extern Player* player_1;
extern Player* player_2;
class SunflowerPlayer :public Player {
public:
SunflowerPlayer() {
animation_idle_left.set_atlas(&rs::atlas_sunflower_idle_left);
animation_idle_right.set_atlas(&rs::atlas_sunflower_idle_right);
animation_run_left.set_atlas(&rs::atlas_sunflower_run_left);
animation_run_right.set_atlas(&rs::atlas_sunflower_run_right);
animation_attack_ex_left.set_atlas(&rs::atlas_sunflower_attack_ex_left);
animation_attack_ex_right.set_atlas(&rs::atlas_sunflower_attack_ex_right);
animation_sun_text.set_atlas(&rs::atlas_sun_text);
animation_die_left.set_atlas(&rs::atlas_sunflower_die_left);
animation_die_right.set_atlas(&rs::atlas_sunflower_die_right);
animation_idle_left.set_interval(75);
animation_idle_right.set_interval(75);
animation_run_left.set_interval(75);
animation_run_right.set_interval(75);
animation_attack_ex_left.set_interval(100);
animation_attack_ex_right.set_interval(100);
animation_sun_text.set_interval(100);
animation_die_left.set_interval(150);
animation_die_right.set_interval(150);
animation_attack_ex_left.set_loop(false);
animation_attack_ex_right.set_loop(false);
animation_die_left.set_loop(false);
animation_die_right.set_loop(false);
animation_sun_text.set_loop(false);
animation_attack_ex_left.set_callback([&]() {
is_attacking_ex = false;
is_sun_text_visible = false;
});
animation_attack_ex_right.set_callback([&]() {
is_attacking_ex = false;
is_sun_text_visible = false;
});
size.x = 96;
size.y = 96;
attack_cd = 250;
img_avatar = &rs::img_avatar_sunflower;
}
~SunflowerPlayer() = default;
void on_update(int delta) {
Player::on_update(delta);
if (is_sun_text_visible)
animation_sun_text.on_update(delta);
}
void on_draw(const Camera& camera) {
Player::on_draw(camera);
if (is_sun_text_visible) {
Vector2 text_position;
IMAGE* frame = animation_sun_text.get_frame();
text_position.x = position.x + (size.x - frame->getwidth()) / 2;
text_position.y = position.y - frame->getheight();
animation_sun_text.on_draw(camera, text_position.x, text_position.y);
}
}
void on_attack() {
Bullet* bullet = new SunBullet();
Vector2 bullet_position;
const Vector2& bullet_size = bullet->get_size();
bullet_position.x = position.x + (size.x - bullet_size.x) / 2;
bullet_position.y = position.y;
bullet->set_position(bullet_position.x, bullet_position.y);
bullet->set_velocity(is_facing_right? velocity_sun.x: -velocity_sun.x, velocity_sun.y);
bullet->set_collide_target(id == PlayerID::P1 ? PlayerID::P2 : PlayerID::P1);
bullet->set_callback([&]() {mp += 35; });
bullet_list.push_back(bullet);
}
void on_attack_ex() {
is_attacking_ex = true;
is_sun_text_visible = true;
animation_sun_text.reset();
is_facing_right ? animation_attack_ex_right.reset() : animation_attack_ex_left.reset();
Bullet* bullet = new SunBulletEx();
Player* target_player = (id == PlayerID::P1 ? player_2 : player_1);
Vector2 bullet_position, bullet_velocity;
const Vector2& bullet_size = bullet->get_size();
const Vector2& target_size = target_player->get_size();
const Vector2& target_position = target_player->get_position();
bullet_position.x = target_position.x + (target_size.x - bullet_size.x) / 2;
bullet_position.y = -bullet_size.y;
bullet_velocity.x = 0;
bullet_velocity.y = speed_sun_ex;
bullet->set_position(bullet_position.x, bullet_position.y);
bullet->set_velocity(bullet_velocity.x, bullet_velocity.y);
bullet->set_collide_target(id == PlayerID::P1 ? PlayerID::P2 : PlayerID::P1);
bullet->set_callback([&]() {mp += 50; });
bullet_list.push_back(bullet);
mciSendString(_T("play sun_text fomr 0"), NULL, 0, NULL);
}
private:
const float speed_sun_ex = 0.15f;
const Vector2 velocity_sun = { 0.25f,-0.5f };
Animation animation_sun_text;
bool is_sun_text_visible = false;
};