src/badguy/poisonivy.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.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/poisonivy.hpp"
00018 #include "math/random_generator.hpp"
00019 #include "object/sprite_particle.hpp"
00020 #include "supertux/object_factory.hpp"
00021 #include "supertux/sector.hpp"
00022 
00023 #include <math.h>
00024 
00025 PoisonIvy::PoisonIvy(const Reader& reader)
00026   : WalkingBadguy(reader, "images/creatures/poison_ivy/poison_ivy.sprite", "left", "right")
00027 {
00028   walk_speed = 80;
00029 }
00030 
00031 PoisonIvy::PoisonIvy(const Vector& pos, Direction d)
00032   : WalkingBadguy(pos, d, "images/creatures/poison_ivy/poison_ivy.sprite", "left", "right")
00033 {
00034   walk_speed = 80;
00035 }
00036 
00037 bool
00038 PoisonIvy::collision_squished(GameObject& object)
00039 {
00040   sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
00041   // spawn some particles
00042   // TODO: provide convenience function in MovingSprite or MovingObject?
00043   for (int i = 0; i < 3; i++) {
00044     Vector ppos = bbox.get_middle();
00045     float angle = graphicsRandom.randf(-M_PI_2, M_PI_2);
00046     float velocity = graphicsRandom.randf(350, 400);
00047     float vx = sin(angle)*velocity;
00048     float vy = -cos(angle)*velocity;
00049     Vector pspeed = Vector(vx, vy);
00050     Vector paccel = Vector(0, 100);
00051     Sector::current()->add_object(new SpriteParticle("images/objects/particles/poisonivy.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
00052   }
00053   kill_squished(object);
00054   return true;
00055 }
00056 
00057 /* EOF */

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