00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "badguy/captainsnowball.hpp"
00018
00019 #include "sprite/sprite.hpp"
00020 #include "supertux/object_factory.hpp"
00021 #include "supertux/sector.hpp"
00022
00023 namespace{
00024 static const float CAPTAIN_WALK_SPEED = 100;
00025 static const float BOARDING_SPEED = 200;
00026 }
00027
00028 CaptainSnowball::CaptainSnowball(const Reader& reader)
00029 : WalkingBadguy(reader, "images/creatures/snowball/cpt-snowball.sprite", "left", "right")
00030 {
00031 walk_speed = BOARDING_SPEED;
00032 max_drop_height = -1;
00033 physic.set_velocity_y(-400);
00034 }
00035
00036 CaptainSnowball::CaptainSnowball(const Vector& pos, Direction d)
00037 : WalkingBadguy(pos, d, "images/creatures/snowball/cpt-snowball.sprite", "left", "right")
00038 {
00039
00040 walk_speed = BOARDING_SPEED;
00041 max_drop_height = -1;
00042 physic.set_velocity_y(-400);
00043 }
00044
00045 bool
00046 CaptainSnowball::might_climb(int width, int height)
00047 {
00048
00049 assert(height > 0);
00050
00051 float x1;
00052 float x2;
00053 float y1a = bbox.p1.y + 1;
00054 float y2a = bbox.p2.y - 1;
00055 float y1b = bbox.p1.y + 1 - height;
00056 float y2b = bbox.p2.y - 1 - height;
00057 if (dir == LEFT) {
00058 x1 = bbox.p1.x - width;
00059 x2 = bbox.p1.x - 1;
00060 } else {
00061 x1 = bbox.p2.x + 1;
00062 x2 = bbox.p2.x + width;
00063 }
00064 return ((!Sector::current()->is_free_of_statics(Rectf(x1, y1a, x2, y2a))) &&
00065 (Sector::current()->is_free_of_statics(Rectf(x1, y1b, x2, y2b))));
00066 }
00067
00068 void
00069 CaptainSnowball::active_update(float elapsed_time)
00070 {
00071 if (on_ground() && might_climb(8, 64)) {
00072 physic.set_velocity_y(-400);
00073 } else if (on_ground() && might_fall(16)) {
00074 physic.set_velocity_y(-400);
00075 walk_speed = BOARDING_SPEED;
00076 physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
00077 }
00078 WalkingBadguy::active_update(elapsed_time);
00079 }
00080
00081 void
00082 CaptainSnowball::collision_solid(const CollisionHit& hit)
00083 {
00084 if (is_active() && (walk_speed == BOARDING_SPEED)) {
00085 walk_speed = CAPTAIN_WALK_SPEED;
00086 physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
00087 }
00088 WalkingBadguy::collision_solid(hit);
00089 }
00090
00091 bool
00092 CaptainSnowball::collision_squished(GameObject& object)
00093 {
00094 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
00095 kill_squished(object);
00096 return true;
00097 }
00098
00099