src/badguy/snowman.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2010 Ingo Ruhnke <grumbel@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/snowman.hpp"
00018 
00019 #include "badguy/snowball.hpp"
00020 #include "object/player.hpp"
00021 #include "supertux/sector.hpp"
00022 
00023 Snowman::Snowman(const Reader& reader) :
00024   WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
00025 {
00026   walk_speed = 40;
00027 }
00028 
00029 Snowman::Snowman(const Vector& pos, Direction d) :
00030   WalkingBadguy(pos, d, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
00031 {
00032   walk_speed = 40;
00033 }
00034 
00035 bool
00036 Snowman::collision_squished(GameObject& object)
00037 {
00038   // replace with Snowball
00039   Vector snowball_pos = get_pos();
00040   // Hard-coded values from sprites
00041   snowball_pos.x += 5;
00042   snowball_pos.y += 1;
00043 
00044   // bounce
00045   Player* player = dynamic_cast<Player*>(&object);
00046   if (player)
00047     player->bounce(*this);
00048 
00049   /* Create death animation for the (now headless) snowman. */
00050   set_action (dir == LEFT ? "headless-left" : "headless-right", /* loops = */ -1);
00051   set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */
00052   physic.set_velocity_y(0);
00053   physic.set_acceleration_y(0);
00054   physic.enable_gravity(true);
00055   set_state (STATE_FALLING);
00056 
00057   /* Create a new snowball where the snowman's head was */
00058   /* TODO: Pass on our "dead_script" to the snowball. */
00059   SnowBall* snowball = new SnowBall(snowball_pos, dir);
00060   Sector::current()->add_object(snowball);
00061 
00062   return true;
00063 }
00064 
00065 /* EOF */

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