4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "poisonivy.hpp"
26 #include "random_generator.hpp"
27 #include "object/sprite_particle.hpp"
29 #include "lisp/writer.hpp"
30 #include "object_factory.hpp"
31 #include "audio/sound_manager.hpp"
35 static const float WALKSPEED = 100;
37 static const float POISONIVY_WIDTH = 32;
38 static const float POISONIVY_HEIGHT = 32;
39 static const float POISONIVY_Y_OFFSET = 24;
42 MrTree::MrTree(const lisp::Lisp& reader)
43 : WalkingBadguy(reader, "images/creatures/mr_tree/mr_tree.sprite","left","right")
45 walk_speed = WALKSPEED;
47 sound_manager->preload("sounds/mr_tree.ogg");
51 MrTree::write(lisp::Writer& writer)
53 writer.start_list("mrtree");
54 WalkingBadguy::write(writer);
55 writer.end_list("mrtree");
59 MrTree::collision_squished(GameObject& object)
61 // replace with Stumpy
62 Vector stumpy_pos = get_pos();
65 Stumpy* stumpy = new Stumpy(stumpy_pos, dir);
67 Sector::current()->add_object(stumpy);
70 sound_manager->play("sounds/mr_tree.ogg", get_pos());
71 Player* player = dynamic_cast<Player*>(&object);
72 if (player) player->bounce(*this);
74 // spawn some particles
75 // TODO: provide convenience function in MovingSprite or MovingObject?
76 for (int px = (int)stumpy->get_bbox().p1.x; px < (int)stumpy->get_bbox().p2.x; px+=10) {
77 Vector ppos = Vector(px, stumpy->get_bbox().p1.y-5);
78 float angle = systemRandom.randf(-M_PI_2, M_PI_2);
79 float velocity = systemRandom.randf(45, 90);
80 float vx = sin(angle)*velocity;
81 float vy = -cos(angle)*velocity;
82 Vector pspeed = Vector(vx, vy);
83 Vector paccel = Vector(0, 100);
84 Sector::current()->add_object(new SpriteParticle("images/objects/particles/leaf.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
88 Vector leaf1_pos = Vector(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
89 Rect leaf1_bbox = Rect(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT);
90 if (Sector::current()->is_free_of_movingstatics(leaf1_bbox, this)) {
91 PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT);
93 Sector::current()->add_object(leaf1);
97 Vector leaf2_pos = Vector(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
98 Rect leaf2_bbox = Rect(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT);
99 if (Sector::current()->is_free_of_movingstatics(leaf2_bbox, this)) {
100 PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT);
102 Sector::current()->add_object(leaf2);
108 IMPLEMENT_FACTORY(MrTree, "mrtree")