src/badguy/mrtree.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/mrtree.hpp"
00018 
00019 #include "audio/sound_manager.hpp"
00020 #include "badguy/poisonivy.hpp"
00021 #include "badguy/stumpy.hpp"
00022 #include "math/random_generator.hpp"
00023 #include "object/player.hpp"
00024 #include "object/sprite_particle.hpp"
00025 #include "supertux/object_factory.hpp"
00026 #include "supertux/sector.hpp"
00027 
00028 #include <math.h>
00029 
00030 static const float TREE_SPEED = 100;
00031 
00032 static const float POISONIVY_WIDTH = 32;
00033 static const float POISONIVY_HEIGHT = 32;
00034 static const float POISONIVY_Y_OFFSET = 24;
00035 
00036 MrTree::MrTree(const Reader& reader)
00037   : WalkingBadguy(reader, "images/creatures/mr_tree/mr_tree.sprite","left","right")
00038 {
00039   walk_speed = TREE_SPEED;
00040   max_drop_height = 16;
00041   sound_manager->preload("sounds/mr_tree.ogg");
00042 }
00043 
00044 bool
00045 MrTree::collision_squished(GameObject& object)
00046 {
00047   // replace with Stumpy
00048   Vector stumpy_pos = get_pos();
00049   stumpy_pos.x += 20;
00050   stumpy_pos.y += 25;
00051   Stumpy* stumpy = new Stumpy(stumpy_pos, dir);
00052   remove_me();
00053   Sector::current()->add_object(stumpy);
00054 
00055   // give Feedback
00056   sound_manager->play("sounds/mr_tree.ogg", get_pos());
00057   Player* player = dynamic_cast<Player*>(&object);
00058   if (player) player->bounce(*this);
00059 
00060   // spawn some particles
00061   // TODO: provide convenience function in MovingSprite or MovingObject?
00062   for (int px = (int)stumpy->get_bbox().p1.x; px < (int)stumpy->get_bbox().p2.x; px+=10) {
00063     Vector ppos = Vector(px, stumpy->get_bbox().p1.y-5);
00064     float angle = graphicsRandom.randf(-M_PI_2, M_PI_2);
00065     float velocity = graphicsRandom.randf(45, 90);
00066     float vx = sin(angle)*velocity;
00067     float vy = -cos(angle)*velocity;
00068     Vector pspeed = Vector(vx, vy);
00069     Vector paccel = Vector(0, 100);
00070     Sector::current()->add_object(new SpriteParticle("images/objects/particles/leaf.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
00071   }
00072 
00073   // spawn PoisonIvy
00074   Vector leaf1_pos(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
00075   Rectf leaf1_bbox(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT);
00076   if (Sector::current()->is_free_of_movingstatics(leaf1_bbox, this)) {
00077     PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT);
00078     leaf1 = leaf1;
00079     leaf1->countMe = false;
00080     Sector::current()->add_object(leaf1);
00081   }
00082 
00083   // spawn PoisonIvy
00084   Vector leaf2_pos(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
00085   Rectf leaf2_bbox(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT);
00086   if (Sector::current()->is_free_of_movingstatics(leaf2_bbox, this)) {
00087     PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT);
00088     leaf2 = leaf2;
00089     leaf2->countMe = false;
00090     Sector::current()->add_object(leaf2);
00091   }
00092 
00093   return true;
00094 }
00095 
00096 /* EOF */

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