activate();
}
}
+
+bool
+BadGuy::may_fall_off_platform()
+{
+ int tile_x, tile_y;
+ // First, let's say the badguy moves once its width in the
+ // direction it's heading.
+ Vector pos = get_pos();
+ pos.x += (dir == LEFT ? -bbox.get_width() : bbox.get_width());
+
+ // Now, snap the badguy's X coordinate to the 32x32/cell grid.
+ if (dir == LEFT) // use the ceiling
+ tile_x = (int)ceilf(pos.x/32.0f);
+ else // use the floor
+ tile_x = (int)floorf(pos.x/32.0f);
+
+ // We might be falling down, so use the ceiling to round upward and
+ // get the lower position. (Positive Y goes downward.)
+ tile_y = (int)ceilf(pos.y/32.0f);
+
+ // Now, if the badguy intersects with a tile, he won't fall off.
+ // If he doesn't intersect, he probably will.
+ if (Sector::current()->solids->get_tile(tile_x, tile_y)->getAttributes() & FLAG_SOLID)
+ {
+ // It's a solid tile. Good.
+ return false;
+ }
+
+ // Watch out there buddy, you might take a sticky end!
+ return true;
+}
{
reader.get("x", start_position.x);
reader.get("y", start_position.y);
+ reader.get("stay-on-platform", stay_on_platform);
bbox.set_size(31.8, 31.8);
sprite = sprite_manager->create("mriceblock");
set_direction = false;
if(ice_state == ICESTATE_FLAT && flat_timer.check()) {
set_state(ICESTATE_NORMAL);
}
-
+
+ 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);
}