static const float Y_OFFSCREEN_DISTANCE = 1200;
BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name, int layer)
- : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), start_dir(AUTO), frozen(false), ignited(false), draw_dead_script_hint(false), state(STATE_INIT), on_ground_flag(false)
+ : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true),
+ dir(LEFT), start_dir(AUTO), frozen(false), ignited(false),
+ state(STATE_INIT), on_ground_flag(false)
{
start_position = bbox.p1;
}
BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer)
- : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(direction), start_dir(direction), frozen(false), ignited(false), draw_dead_script_hint(false), state(STATE_INIT), on_ground_flag(false)
+ : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true),
+ dir(direction), start_dir(direction), frozen(false), ignited(false),
+ state(STATE_INIT), on_ground_flag(false)
{
start_position = bbox.p1;
reader.get("direction", dir_str);
start_dir = str2dir( dir_str );
dir = start_dir;
-
+
reader.get("dead-script", dead_script);
- draw_dead_script_hint = (dead_script != "");
sound_manager->preload("sounds/squish.wav");
sound_manager->preload("sounds/fall.wav");
context.set_drawing_effect(old_effect);
} else {
sprite->draw(context, get_pos(), layer);
- if (draw_dead_script_hint) {
- Vector ppos = Vector(systemRandom.randf(bbox.p1.x+8, bbox.p2.x-8), bbox.p2.y);
- Vector pspeed = Vector(0, -100);
- Sector::current()->add_object(new Particles(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.6f, .2f, .2f), 3, .1f, LAYER_OBJECTS+1));
- }
}
}
BadGuy::update(float elapsed_time)
{
if(!Sector::current()->inside(bbox)) {
+ is_active_flag = false;
remove_me();
return;
}
switch(state) {
case STATE_ACTIVE:
+ is_active_flag = true;
active_update(elapsed_time);
break;
case STATE_INIT:
case STATE_INACTIVE:
+ is_active_flag = false;
inactive_update(elapsed_time);
try_activate();
break;
case STATE_SQUISHED:
+ is_active_flag = false;
if(state_timer.check()) {
remove_me();
break;
movement = physic.get_movement(elapsed_time);
break;
case STATE_FALLING:
+ is_active_flag = false;
movement = physic.get_movement(elapsed_time);
break;
}
}
void
-BadGuy::save(lisp::Writer& )
+BadGuy::write(lisp::Writer& )
{
log_warning << "tried to write out a generic badguy" << std::endl;
}
if(tile_attributes & Tile::HURTS) {
if (tile_attributes & Tile::FIRE) {
if (is_flammable()) ignite();
- }
+ }
else if (tile_attributes & Tile::ICE) {
if (is_freezable()) freeze();
}
HitResponse
BadGuy::collision(GameObject& other, const CollisionHit& hit)
{
- switch(state) {
- case STATE_INIT:
- case STATE_INACTIVE:
- return ABORT_MOVE;
- case STATE_ACTIVE: {
- BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
- if(badguy && badguy->state == STATE_ACTIVE && badguy->get_group() == COLGROUP_MOVING) {
-
- // hit from above?
- if (badguy->get_bbox().p2.y < (bbox.p1.y + 16)) {
- if(collision_squished(*badguy)) {
- return ABORT_MOVE;
- }
- }
-
- return collision_badguy(*badguy, hit);
- }
+ if (!is_active()) return ABORT_MOVE;
- Player* player = dynamic_cast<Player*> (&other);
- if(player) {
+ BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
+ if(badguy && badguy->is_active() && badguy->get_group() == COLGROUP_MOVING) {
- // hit from above?
- if (player->get_bbox().p2.y < (bbox.p1.y + 16)) {
- if(collision_squished(*player)) {
- return ABORT_MOVE;
- }
- }
-
- return collision_player(*player, hit);
+ // hit from above?
+ if (badguy->get_bbox().p2.y < (bbox.p1.y + 16)) {
+ if(collision_squished(*badguy)) {
+ return ABORT_MOVE;
}
+ }
- Bullet* bullet = dynamic_cast<Bullet*> (&other);
- if(bullet)
- return collision_bullet(*bullet, hit);
+ return collision_badguy(*badguy, hit);
+ }
- return FORCE_MOVE;
+ Player* player = dynamic_cast<Player*> (&other);
+ if(player) {
+
+ // hit from above?
+ if (player->get_bbox().p2.y < (bbox.p1.y + 16)) {
+ if(collision_squished(*player)) {
+ return ABORT_MOVE;
+ }
}
- case STATE_SQUISHED:
- return FORCE_MOVE;
- case STATE_FALLING:
- return FORCE_MOVE;
+
+ return collision_player(*player, hit);
}
- return ABORT_MOVE;
+ Bullet* bullet = dynamic_cast<Bullet*> (&other);
+ if(bullet)
+ return collision_bullet(*bullet, hit);
+
+ return FORCE_MOVE;
}
void
bullet.ricochet(*this, hit);
return FORCE_MOVE;
}
- }
+ }
else if (is_ignited()) {
if(bullet.get_type() == ICE_BONUS) {
// ice bullets extinguish ignited badguys
}
void
+BadGuy::run_dead_script()
+{
+ if (countMe)
+ Sector::current()->get_level()->stats.badguys++;
+
+ // start dead-script
+ if(dead_script != "") {
+ std::istringstream stream(dead_script);
+ Sector::current()->run_script(stream, "dead-script");
+ }
+}
+
+void
BadGuy::set_state(State state)
{
if(this->state == state)
return on_ground_flag;
}
+bool
+BadGuy::is_active()
+{
+ return is_active_flag;
+}
+
Vector
BadGuy::get_floor_normal()
{
return frozen;
}
-void
-BadGuy::ignite()
+void
+BadGuy::ignite()
{
kill_fall();
}
-void
-BadGuy::extinguish()
+void
+BadGuy::extinguish()
{
}
-bool
-BadGuy::is_flammable() const
+bool
+BadGuy::is_flammable() const
{
return true;
}
-bool
-BadGuy::is_ignited() const
+bool
+BadGuy::is_ignited() const
{
return ignited;
}
-