return true;
}
+bool
+BadGuy::might_fall(int height)
+{
+ // make sure we check for at least a 1-pixel fall
+ assert(height > 0);
+
+ float x1;
+ float x2;
+ float y1 = bbox.p2.y + 1;
+ float y2 = bbox.p2.y + 1 + height;
+ if (dir == LEFT) {
+ x1 = bbox.p1.x - 1;
+ x2 = bbox.p1.x - 1;
+ } else {
+ x1 = bbox.p2.x + 1;
+ x2 = bbox.p2.x + 1;
+ }
+ return Sector::current()->is_free_space(Rect(x1, y1, x2, y2));
+}
+
Player*
BadGuy::get_nearest_player()
{
* Checks if the badguy may fall off a platform if continuing a given movement.
*/
bool may_fall_off_platform();
+ bool might_fall(int height); /**< returns true if we might soon fall at least @c height pixels. Minimum value for height is 1 pixel */
Vector start_position;
//FIXME: Does is_offscreen() work right here?
if (!is_offscreen()) {
if (badguy == "snowball")
- Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir, false));
+ Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir));
else if (badguy == "bouncingsnowball")
Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir));
else if (badguy == "mrbomb")
- Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir, false));
+ Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir));
else if (badguy == "mriceblock")
- Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false));
+ Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir));
else if (badguy == "snowsnail")
- Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir, false));
+ Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir));
else if (badguy == "mrrocket") {
Sector::current()->add_object(new MrRocket(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y, dir));}
else if (badguy == "poisonivy")
- Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir, false));
+ Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir));
else if (badguy == "skullyhop")
Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir));
else if (badguy == "random")
{
switch (rand()%7)
{
- case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir, false)); break;
+ case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); break;
case 1: Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); break;
- case 2: Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir, false)); break;
- case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false)); break;
- case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir, false)); break;
- case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir, false)); break;
+ case 2: Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir)); break;
+ case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir)); break;
+ case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); break;
+ case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir)); break;
case 6: Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir)); break;
}
}
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/mr_bomb/mr_bomb.sprite");
set_direction = false;
}
-MrBomb::MrBomb(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
+MrBomb::MrBomb(float pos_x, float pos_y, Direction d)
{
start_position.x = pos_x;
start_position.y = pos_y;
- stay_on_platform = stay_on_plat;
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/mr_bomb/mr_bomb.sprite");
set_direction = true;
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- writer.write_bool("stay-on-platform", stay_on_platform);
writer.end_list("mrbomb");
}
void
MrBomb::active_update(float elapsed_time)
{
- if (stay_on_platform && may_fall_off_platform())
+ if (may_fall_off_platform())
{
dir = (dir == LEFT ? RIGHT : LEFT);
sprite->set_action(dir == LEFT ? "left" : "right");
{
public:
MrBomb(const lisp::Lisp& reader);
- MrBomb(float pos_x, float pos_y, Direction d, bool stay_on_plat);
+ MrBomb(float pos_x, float pos_y, Direction d);
void activate();
void active_update(float elapsed_time);
protected:
bool collision_squished(Player& player);
bool set_direction;
- bool stay_on_platform;
Direction initial_direction;
};
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/mr_iceblock/mr_iceblock.sprite");
set_direction = false;
}
-MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d, bool stay_on_plat = false )
+MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d)
: ice_state(ICESTATE_NORMAL), squishcount(0)
{
start_position.x = pos_x;
start_position.y = pos_y;
- stay_on_platform = stay_on_plat;
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/mr_iceblock/mr_iceblock.sprite");
set_direction = true;
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- writer.write_bool("stay-on-platform", stay_on_platform);
writer.end_list("mriceblock");
}
set_state(ICESTATE_NORMAL);
}
- if (ice_state == ICESTATE_NORMAL &&
- stay_on_platform &&
- may_fall_off_platform())
+ if (ice_state == ICESTATE_NORMAL && might_fall(601))
{
dir = (dir == LEFT ? RIGHT : LEFT);
sprite->set_action(dir == LEFT ? "left" : "right");
{
public:
MrIceBlock(const lisp::Lisp& reader);
- MrIceBlock(float pos_x, float pos_y, Direction d, bool stay_on_plat);
+ MrIceBlock(float pos_x, float pos_y, Direction d);
void activate();
void write(lisp::Writer& writer);
Timer flat_timer;
int squishcount;
bool set_direction;
- bool stay_on_platform;
Direction initial_direction;
};
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(84.8, 84.8);
sprite = sprite_manager->create("images/creatures/mr_tree/mr_tree.sprite");
}
activate();
}
- if (stay_on_platform && may_fall_off_platform())
+ if (may_fall_off_platform())
{
dir = (dir == LEFT ? RIGHT : LEFT);
activate();
Rect leaf1_bbox = Rect(pos.x-32-1, pos.y-23+1, pos.x-32-1+32, pos.y-23+1+32);
if (Sector::current()->is_free_space(leaf1_bbox)) {
- PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1.x, leaf1_bbox.p1.y, LEFT, true);
+ PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1.x, leaf1_bbox.p1.y, LEFT);
Sector::current()->add_object(leaf1);
}
Rect leaf2_bbox = Rect(pos.x+42+1, pos.y-23+1, pos.x+32+1+32, pos.y-23+1+32);
if (Sector::current()->is_free_space(leaf2_bbox)) {
- PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1.x, leaf2_bbox.p1.y, RIGHT, true);
+ PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1.x, leaf2_bbox.p1.y, RIGHT);
Sector::current()->add_object(leaf2);
}
STATE_BIG, STATE_INVINCIBLE, STATE_NORMAL
};
MyState mystate;
- bool stay_on_platform;
Timer invincible_timer;
}
case SHOOTING:
{
- Sector::current()->add_object(new SnowSnail(get_pos().x - 64, get_pos().y, LEFT, true));
- Sector::current()->add_object(new SnowSnail(get_pos().x + 64, get_pos().y, RIGHT, true));
+ Sector::current()->add_object(new SnowSnail(get_pos().x - 64, get_pos().y, LEFT));
+ Sector::current()->add_object(new SnowSnail(get_pos().x + 64, get_pos().y, RIGHT));
physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
sprite->set_action(dir == LEFT ? "left" : "right");
action = WALKING;
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/poison_ivy/poison_ivy.sprite");
set_direction = false;
}
-PoisonIvy::PoisonIvy(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
+PoisonIvy::PoisonIvy(float pos_x, float pos_y, Direction d)
{
start_position.x = pos_x;
start_position.y = pos_y;
- stay_on_platform = stay_on_plat;
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/poison_ivy/poison_ivy.sprite");
set_direction = true;
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- if (stay_on_platform) writer.write_bool("stay-on-platform", true);
writer.end_list("poisonivy");
}
sprite->set_action(dir == LEFT ? "left" : "right");
}
-void
-PoisonIvy::active_update(float elapsed_time)
-{
- BadGuy::active_update(elapsed_time);
-
- if (stay_on_platform && may_fall_off_platform())
- {
- dir = (dir == LEFT ? RIGHT : LEFT);
- sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(-physic.get_velocity_x());
- }
-}
-
bool
PoisonIvy::collision_squished(Player& player)
{
{
public:
PoisonIvy(const lisp::Lisp& reader);
- PoisonIvy(float pos_x, float pos_y, Direction d, bool stay_on_plat);
+ PoisonIvy(float pos_x, float pos_y, Direction d);
void activate();
void write(lisp::Writer& writer);
- void active_update(float elapsed_time);
HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
protected:
bool collision_squished(Player& player);
bool set_direction;
- bool stay_on_platform;
Direction initial_direction;
};
//This is for a hidden badguy :)
fluffy = false;
reader.get("fluffy",fluffy);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
if (fluffy) sprite = sprite_manager->create("images/creatures/fluffy/fluffy.sprite");
else sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite");
set_direction = false;
}
-SnowBall::SnowBall(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
+SnowBall::SnowBall(float pos_x, float pos_y, Direction d)
{
start_position.x = pos_x;
start_position.y = pos_y;
- stay_on_platform = stay_on_plat;
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite");
set_direction = true;
writer.write_bool("fluffy", true);
}
- if (stay_on_platform)
- writer.write_bool("stay-on-platform", true);
-
writer.end_list("snowball");
}
sprite->set_action(dir == LEFT ? "left" : "right");
}
-void
-SnowBall::active_update(float elapsed_time)
-{
- BadGuy::active_update(elapsed_time);
-
- if (stay_on_platform && may_fall_off_platform())
- {
- dir = (dir == LEFT ? RIGHT : LEFT);
- sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(-physic.get_velocity_x());
- }
-}
-
bool
SnowBall::collision_squished(Player& player)
{
{
public:
SnowBall(const lisp::Lisp& reader);
- SnowBall(float pos_x, float pos_y, Direction d, bool stay_on_plat);
+ SnowBall(float pos_x, float pos_y, Direction d);
void activate();
void write(lisp::Writer& writer);
- void active_update(float elapsed_time);
HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
protected:
bool collision_squished(Player& player);
bool set_direction;
- bool stay_on_platform;
Direction initial_direction;
bool fluffy;
};
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite");
set_direction = false;
}
-SnowSnail::SnowSnail(float pos_x, float pos_y, Direction d, bool stay_on_plat = false)
+SnowSnail::SnowSnail(float pos_x, float pos_y, Direction d)
: ice_state(ICESTATE_NORMAL), squishcount(0)
{
start_position.x = pos_x;
start_position.y = pos_y;
- stay_on_platform = stay_on_plat;
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite");
set_direction = true;
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- if (stay_on_platform) writer.write_bool("stay-on-platform", true);
writer.end_list("snowsnail");
}
physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
sprite->set_action(dir == LEFT ? "left" : "right");
}
- if(ice_state == ICESTATE_NORMAL && stay_on_platform
- && may_fall_off_platform())
- {
- dir = (dir == LEFT ? RIGHT : LEFT);
- sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(-physic.get_velocity_x());
- }
BadGuy::active_update(elapsed_time);
}
{
public:
SnowSnail(const lisp::Lisp& reader);
- SnowSnail(float pos_x, float pos_y, Direction d, bool stay_on_plat);
+ SnowSnail(float pos_x, float pos_y, Direction d);
void activate();
void write(lisp::Writer& writer);
Timer flat_timer;
int squishcount;
bool set_direction;
- bool stay_on_platform;
Direction initial_direction;
};
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/spiky/spiky.sprite");
}
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- if (stay_on_platform) writer.write_bool("stay-on-platform", true);
writer.end_list("spiky");
}
{
BadGuy::active_update(elapsed_time);
- if (stay_on_platform && may_fall_off_platform())
+ if (might_fall(601))
{
dir = (dir == LEFT ? RIGHT : LEFT);
sprite->set_action(dir == LEFT ? "left" : "right");
void active_update(float elapsed_time);
HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
-private:
- bool stay_on_platform;
};
#endif
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- stay_on_platform = false;
- reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("images/creatures/spiky/sleepingspiky.sprite");
state = SSPIKY_SLEEPING;
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- if (stay_on_platform) writer.write_bool("stay-on-platform", true);
writer.end_list("sspiky");
}
state = SSPIKY_WALKING;
}
}
-
- if (state == SSPIKY_WALKING && stay_on_platform && may_fall_off_platform())
- {
- dir = (dir == LEFT ? RIGHT : LEFT);
- sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(-physic.get_velocity_x());
- }
}
IMPLEMENT_FACTORY(SSpiky, "sspiky")
SSPIKY_WALKING
};
SSpikyState state;
-private:
- bool stay_on_platform;
};
#endif
Totem::Totem(const lisp::Lisp& reader)
{
- stay_on_platform = false;
carrying = 0;
carried_by = 0;
bbox.set_size(48, 49);
reader.get("x", start_position.x);
reader.get("y", start_position.y);
- reader.get("stay-on-platform", stay_on_platform);
sprite = sprite_manager->create("images/creatures/totem/totem.sprite");
}
writer.write_float("x", start_position.x);
writer.write_float("y", start_position.y);
- writer.write_bool("stay-on-platform", stay_on_platform);
writer.end_list("totem");
}
BadGuy::active_update(elapsed_time);
if (!carried_by) {
- if (stay_on_platform && may_fall_off_platform())
+ if (may_fall_off_platform())
{
dir = (dir == LEFT ? RIGHT : LEFT);
activate();
HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
protected:
- bool stay_on_platform; /**< change direction before falling off a ledge */
-
Totem* carrying; /**< Totem we are currently carrying (or 0) */
Totem* carried_by; /**< Totem by which we are currently carried (or 0) */
int max_x = int(rect.p2.x);
int max_y = int(rect.p2.y);
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
+ for(int x = starttilex; x*32 <= max_x; ++x) {
+ for(int y = starttiley; y*32 <= max_y; ++y) {
const Tile* tile = solids->get_tile(x, y);
if(!tile)
continue;