src/badguy/captainsnowball.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2008 Wolfgang Becker <uafr@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
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   // Created during game eg. by dispencer. Board the enemy!
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   // make sure we check for at least a 1-pixel climb
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 /* EOF */

Generated on Mon Jun 9 03:38:16 2014 for SuperTux by  doxygen 1.5.1