Skip to content

Commit 8f8e968

Browse files
committed
Add root attacks
1 parent f69e1b3 commit 8f8e968

File tree

5 files changed

+634
-7
lines changed

5 files changed

+634
-7
lines changed

data/images/creatures/ghosttree/blue_root.sprite

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
(action
1818
(name "down")
1919
(hitbox 12 11 8 70)
20-
(flip-action "down")
20+
(flip-action "up")
2121
)
2222
)

src/badguy/ghosttree.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <math.h>
2121

2222
#include "audio/sound_manager.hpp"
23+
#include "badguy/ghosttree_attack.hpp"
2324
#include "badguy/root.hpp"
2425
#include "badguy/treewillowisp.hpp"
2526
#include "math/random.hpp"
@@ -57,7 +58,8 @@ GhostTree::GhostTree(const ReaderMapping& mapping) :
5758
suck_lantern_color(),
5859
m_taking_life(),
5960
suck_lantern(nullptr),*/
60-
m_willowisps()
61+
m_willowisps(),
62+
m_root_attack()
6163
{
6264
mapping.get("hud-icon", m_hud_icon, "images/creatures/ghosttree/hudlife.png");
6365
m_hud_head = Surface::from_file(m_hud_icon);
@@ -69,6 +71,11 @@ GhostTree::GhostTree(const ReaderMapping& mapping) :
6971
set_state(STATE_INIT);
7072
}
7173

74+
GhostTree::~GhostTree()
75+
{
76+
77+
}
78+
7279
void
7380
GhostTree::die()
7481
{
@@ -93,6 +100,17 @@ GhostTree::activate()
93100
root_timer.start(5, true);*/
94101
}
95102

103+
Vector
104+
GhostTree::get_player_pos()
105+
{
106+
auto player = get_nearest_player();
107+
if (player) {
108+
return player->get_pos();
109+
} else {
110+
return m_col.m_bbox.get_middle();
111+
}
112+
}
113+
96114
void
97115
GhostTree::active_update(float dt_sec)
98116
{
@@ -122,7 +140,8 @@ GhostTree::active_update(float dt_sec)
122140
case STATE_SUCKING:
123141
break;
124142
case STATE_ATTACKING:
125-
if (m_state_timer.check()) {
143+
m_root_attack->active_update(dt_sec);
144+
if (m_root_attack->is_done()) {
126145
set_state(STATE_RECHARGING);
127146
}
128147
break;
@@ -255,7 +274,8 @@ GhostTree::active_update(float dt_sec)
255274
}*/
256275
}
257276

258-
bool GhostTree::suck_now(const Color& color) const {
277+
bool
278+
GhostTree::suck_now(const Color& color) const {
259279
switch (m_attack) {
260280
case ATTACK_RED:
261281
return color.red == 1.0;
@@ -349,8 +369,7 @@ GhostTree::set_state(MyState new_state) {
349369
std::cout<<"attacking"<<std::endl;
350370
set_action(m_attack == ATTACK_PINCH ? "scream-pinch" : "scream");
351371
SoundManager::current()->play("sounds/tree_howling.ogg", get_pos());
352-
m_state_timer.start(5);
353-
//TODO
372+
start_attack();
354373
break;
355374
case STATE_RECHARGING:
356375
std::cout<<"recharging"<<std::endl;
@@ -369,6 +388,32 @@ GhostTree::set_state(MyState new_state) {
369388
m_state = new_state;
370389
}
371390

391+
void
392+
GhostTree::start_attack()
393+
{
394+
Vector player_pos = get_player_pos();
395+
const float middle = m_col.m_bbox.get_middle().x;
396+
const float base = m_col.m_bbox.get_bottom() + 64;
397+
switch (m_attack) {
398+
case ATTACK_RED:
399+
if (player_pos.x > middle) {
400+
m_root_attack.reset(new GhostTreeAttackRed(base, middle - 512, middle + 512));
401+
} else {
402+
m_root_attack.reset(new GhostTreeAttackRed(base, middle + 512, middle - 512));
403+
}
404+
break;
405+
case ATTACK_GREEN:
406+
m_root_attack.reset(new GhostTreeAttackGreen(Vector(player_pos.x, base)));
407+
break;
408+
case ATTACK_BLUE:
409+
m_root_attack.reset(new GhostTreeAttackBlue(Vector(player_pos.x, base)));
410+
break;
411+
case ATTACK_PINCH:
412+
default:
413+
m_root_attack.reset(new GhostTreeAttackPinch(Vector(player_pos.x, base), middle - 512, middle + 512));
414+
break;
415+
}
416+
}
372417
/*bool
373418
GhostTree::is_color_deadly(Color color) const
374419
{

src/badguy/ghosttree.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818

1919
#include "badguy/boss.hpp"
2020

21+
class GhostTreeAttack;
2122
class TreeWillOWisp;
22-
class Lantern;
23+
//class Lantern;
2324

2425
class GhostTree final : public Boss
2526
{
2627
public:
2728
GhostTree(const ReaderMapping& mapping);
29+
~GhostTree();
2830

2931
virtual void kill_fall() override { }
3032

@@ -98,8 +100,11 @@ class GhostTree final : public Boss
98100
//Lantern* suck_lantern; /**< Lantern that is currently being sucked in */
99101

100102
std::vector<TreeWillOWisp*> m_willowisps;
103+
std::unique_ptr<GhostTreeAttack> m_root_attack;
101104
void spawn_willowisp(AttackType color);
102105
void rotate_willo_color();
106+
void start_attack();
107+
Vector get_player_pos();
103108

104109
private:
105110
GhostTree(const GhostTree&) = delete;

0 commit comments

Comments
 (0)