Skip to content

Commit b5fbb87

Browse files
committed
GhostTree: implement assumed states
1 parent ca1c1b9 commit b5fbb87

File tree

3 files changed

+89
-55
lines changed

3 files changed

+89
-55
lines changed

data/images/engine/editor/objects.stoi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
(icon "images/creatures/yeti/hudlife.png"))
167167
(object
168168
(class "ghosttree")
169-
(icon "images/creatures/ghosttree/ghosttree.png"))
169+
(icon "images/creatures/ghosttree/idle-0.png"))
170170
)
171171

172172
(objectgroup

src/badguy/ghosttree.cpp

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,22 @@ static const float SUCK_TARGET_SPREAD = 8;
3939

4040
GhostTree::GhostTree(const ReaderMapping& mapping) :
4141
Boss(mapping, "images/creatures/ghosttree/ghosttree.sprite", LAYER_OBJECTS - 10),
42-
mystate(STATE_IDLE),
43-
willowisp_timer(),
42+
m_state(STATE_IDLE),
43+
m_attack(ATTACK_RED),
44+
/*willowisp_timer(),
4445
willo_spawn_y(0),
4546
willo_radius(200),
4647
willo_speed(1.8f),
47-
willo_color(0),
48-
glow_sprite(SpriteManager::current()->create("images/creatures/ghosttree/ghosttree-glow.sprite")),
49-
colorchange_timer(),
48+
willo_color(0),*/
49+
//glow_sprite(SpriteManager::current()->create("images/creatures/ghosttree/ghosttree-glow.sprite")),
50+
/*colorchange_timer(),
5051
suck_timer(),
5152
root_timer(),
5253
treecolor(0),
5354
suck_lantern_color(),
5455
m_taking_life(),
55-
suck_lantern(nullptr),
56-
willowisps()
56+
suck_lantern(nullptr),*/
57+
m_willowisps()
5758
{
5859
mapping.get("hud-icon", m_hud_icon, "images/creatures/ghosttree/hudlife.png");
5960
m_hud_head = Surface::from_file(m_hud_icon);
@@ -66,8 +67,8 @@ GhostTree::GhostTree(const ReaderMapping& mapping) :
6667
void
6768
GhostTree::die()
6869
{
69-
70-
for (const auto& willo : willowisps) {
70+
//TODO
71+
/*for (const auto& willo : willowisps) {
7172
willo->vanish();
7273
}
7374
@@ -76,22 +77,44 @@ GhostTree::die()
7677
set_action("dying", 1);
7778
glow_sprite->set_action("dying", 1);
7879
run_dead_script();
79-
}
80+
}*/
8081
}
8182

8283
void
8384
GhostTree::activate()
8485
{
85-
willowisp_timer.start(1.0f, true);
86+
/*willowisp_timer.start(1.0f, true);
8687
colorchange_timer.start(13, true);
87-
root_timer.start(5, true);
88+
root_timer.start(5, true);*/
8889
}
8990

9091
void
9192
GhostTree::active_update(float dt_sec)
9293
{
9394
Boss::boss_update(dt_sec);
94-
95+
switch (m_state) {
96+
case STATE_INIT:
97+
//TODO
98+
break;
99+
case STATE_SCREAM:
100+
//TODO
101+
break;
102+
case STATE_IDLE:
103+
//TODO
104+
break;
105+
case STATE_SUCKING:
106+
//TODO
107+
break;
108+
case STATE_ATTACKING:
109+
//TODO
110+
break;
111+
case STATE_DEAD:
112+
//TODO
113+
break;
114+
default:
115+
break;
116+
}
117+
/*
95118
if (mystate == STATE_IDLE) {
96119
m_taking_life = false;
97120
if (colorchange_timer.check()) {
@@ -164,15 +187,6 @@ GhostTree::active_update(float dt_sec)
164187
}
165188
}
166189
167-
// TODO: Add support for the new root implementation
168-
/*
169-
if (root_timer.check()) {
170-
//TODO: indicate root with an animation.
171-
auto player = get_nearest_player();
172-
if (player)
173-
Sector::get().add<Root>(Vector(player->get_bbox().get_left(), (m_flip == NO_FLIP ? (m_col.m_bbox.get_bottom() + ROOT_TOP_OFFSET) : (m_col.m_bbox.get_top() - ROOT_TOP_OFFSET - ROOT_HEIGHT))), m_flip);
174-
}
175-
*/
176190
} else if (mystate == STATE_SWALLOWING) {
177191
if (suck_lantern) {
178192
// Suck in the lantern.
@@ -205,31 +219,35 @@ GhostTree::active_update(float dt_sec)
205219
}
206220
}
207221
}
208-
}
222+
}*/
209223
}
210224

211-
bool
225+
void GhostTree::set_state(MyState new_state) {
226+
227+
}
228+
229+
/*bool
212230
GhostTree::is_color_deadly(Color color) const
213231
{
214232
if (color == Color(0,0,0)) return false;
215233
Color my_color = glow_sprite->get_color();
216234
return ((my_color.red != color.red) || (my_color.green != color.green) || (my_color.blue != color.blue));
217-
}
235+
}*/
218236

219237
void
220238
GhostTree::willowisp_died(TreeWillOWisp* willowisp)
221239
{
222-
if ((mystate == STATE_SUCKING) && (willowisp->was_sucked)) {
223-
mystate = STATE_IDLE;
240+
if ((m_state == STATE_SUCKING) && (willowisp->was_sucked)) {
241+
m_state = STATE_ATTACKING;
224242
}
225-
willowisps.erase(std::find_if(willowisps.begin(), willowisps.end(),
226-
[willowisp](const GameObject* lhs)
227-
{
228-
return lhs == willowisp;
229-
}));
243+
m_willowisps.erase(std::find_if(m_willowisps.begin(), m_willowisps.end(),
244+
[willowisp](const GameObject* lhs)
245+
{
246+
return lhs == willowisp;
247+
}));
230248
}
231249

232-
void
250+
/*void
233251
GhostTree::draw(DrawingContext& context)
234252
{
235253
Boss::draw(context);
@@ -242,23 +260,24 @@ GhostTree::draw(DrawingContext& context)
242260
}
243261
glow_sprite->draw(context.light(), get_pos(), m_layer);
244262
context.pop_transform();
245-
}
263+
}*/
246264

247265
bool
248266
GhostTree::collides(MovingObject& other, const CollisionHit& ) const
249267
{
250-
if (mystate != STATE_SUCKING) return false;
251-
if (dynamic_cast<Lantern*>(&other)) return true;
268+
if (m_state != STATE_RECHARGING) return false;
269+
//if (dynamic_cast<Lantern*>(&other)) return true;
252270
if (dynamic_cast<Player*>(&other)) return true;
253271
return false;
254272
}
255273

256274
HitResponse
257275
GhostTree::collision(MovingObject& other, const CollisionHit& )
258276
{
259-
if (mystate != STATE_SUCKING) return ABORT_MOVE;
277+
if (m_state != STATE_RECHARGING) return ABORT_MOVE;
260278

261-
auto player = dynamic_cast<Player*>(&other);
279+
//TODO collision from above? subtract one life
280+
/*auto player = dynamic_cast<Player*>(&other);
262281
if (player) {
263282
player->kill(false);
264283
}
@@ -269,16 +288,16 @@ GhostTree::collision(MovingObject& other, const CollisionHit& )
269288
suck_lantern->grab(*this, suck_lantern->get_pos(), Direction::RIGHT);
270289
suck_lantern_color = lantern->get_color();
271290
mystate = STATE_SWALLOWING;
272-
}
291+
}*/
273292

274293
return ABORT_MOVE;
275294
}
276295

277-
void
296+
/*void
278297
GhostTree::spawn_lantern()
279298
{
280299
Sector::get().add<Lantern>(m_col.m_bbox.get_middle() + SUCK_TARGET_OFFSET);
281-
}
300+
}*/
282301

283302
std::vector<Direction>
284303
GhostTree::get_allowed_directions() const

src/badguy/ghosttree.hpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class GhostTree final : public Boss
3030

3131
virtual void activate() override;
3232
virtual void active_update(float dt_sec) override;
33-
virtual void draw(DrawingContext& context) override;
33+
//virtual void draw(DrawingContext& context) override;
3434

3535
virtual bool collides(MovingObject& other, const CollisionHit& hit) const override;
3636
virtual HitResponse collision(MovingObject& other, const CollisionHit& hit) override;
@@ -51,33 +51,48 @@ class GhostTree final : public Boss
5151

5252
private:
5353
enum MyState {
54-
STATE_IDLE, STATE_SUCKING, STATE_SWALLOWING, STATE_DYING
54+
STATE_INIT,
55+
STATE_SCREAM,
56+
STATE_IDLE,
57+
STATE_SUCKING,
58+
STATE_ATTACKING,
59+
STATE_RECHARGING,
60+
STATE_DEAD
61+
};
62+
63+
enum AttackType {
64+
ATTACK_RED = 0,
65+
ATTACK_GREEN,
66+
ATTACK_BLUE,
67+
ATTACK_PINCH
5568
};
5669

5770
private:
58-
bool is_color_deadly(Color color) const;
59-
void spawn_lantern();
71+
void set_state(MyState new_state);
72+
/* bool is_color_deadly(Color color) const;
73+
void spawn_lantern();*/
6074

6175
private:
62-
MyState mystate;
63-
Timer willowisp_timer;
76+
MyState m_state;
77+
AttackType m_attack;
78+
/*Timer willowisp_timer;
6479
float willo_spawn_y;
6580
float willo_radius;
6681
float willo_speed;
67-
int willo_color;
82+
int willo_color;*/
6883

69-
SpritePtr glow_sprite;
70-
Timer colorchange_timer;
84+
//SpritePtr glow_sprite;
85+
/*Timer colorchange_timer;
7186
Timer suck_timer;
7287
Timer root_timer;
7388
int treecolor;
74-
Color suck_lantern_color;
89+
Color suck_lantern_color;*/
7590

76-
bool m_taking_life;
91+
//bool m_taking_life;
7792

78-
Lantern* suck_lantern; /**< Lantern that is currently being sucked in */
93+
//Lantern* suck_lantern; /**< Lantern that is currently being sucked in */
7994

80-
std::vector<TreeWillOWisp*> willowisps;
95+
std::vector<TreeWillOWisp*> m_willowisps;
8196

8297
private:
8398
GhostTree(const GhostTree&) = delete;

0 commit comments

Comments
 (0)