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.
24 #include "poisonivy.hpp"
25 #include "random_generator.hpp"
26 #include "object/sprite_particle.hpp"
29 static const float WALKSPEED = 100;
31 static const float POISONIVY_WIDTH = 32;
32 static const float POISONIVY_HEIGHT = 32;
33 static const float POISONIVY_Y_OFFSET = 24;
36 MrTree::MrTree(const lisp::Lisp& reader)
37 : WalkingBadguy(reader, "images/creatures/mr_tree/mr_tree.sprite","left","right")
39 walk_speed = WALKSPEED;
41 sound_manager->preload("sounds/mr_tree.ogg");
45 MrTree::write(lisp::Writer& writer)
47 writer.start_list("mrtree");
48 WalkingBadguy::write(writer);
49 writer.end_list("mrtree");
53 MrTree::collision_squished(GameObject& object)
55 // replace with Stumpy
56 Vector stumpy_pos = get_pos();
59 Stumpy* stumpy = new Stumpy(stumpy_pos, dir);
61 Sector::current()->add_object(stumpy);
64 sound_manager->play("sounds/mr_tree.ogg", get_pos());
65 Player* player = dynamic_cast<Player*>(&object);
66 if (player) player->bounce(*this);
68 // spawn some particles
69 // TODO: provide convenience function in MovingSprite or MovingObject?
70 for (int px = (int)stumpy->get_bbox().p1.x; px < (int)stumpy->get_bbox().p2.x; px+=10) {
71 Vector ppos = Vector(px, stumpy->get_bbox().p1.y-5);
72 float angle = systemRandom.randf(-M_PI_2, M_PI_2);
73 float velocity = systemRandom.randf(45, 90);
74 float vx = sin(angle)*velocity;
75 float vy = -cos(angle)*velocity;
76 Vector pspeed = Vector(vx, vy);
77 Vector paccel = Vector(0, 100);
78 Sector::current()->add_object(new SpriteParticle("images/objects/particles/leaf.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
82 Vector leaf1_pos = Vector(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
83 Rect leaf1_bbox = Rect(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT);
84 if (Sector::current()->is_free_of_movingstatics(leaf1_bbox, this)) {
85 PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT);
87 Sector::current()->add_object(leaf1);
91 Vector leaf2_pos = Vector(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET);
92 Rect leaf2_bbox = Rect(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT);
93 if (Sector::current()->is_free_of_movingstatics(leaf2_bbox, this)) {
94 PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT);
96 Sector::current()->add_object(leaf2);
102 IMPLEMENT_FACTORY(MrTree, "mrtree")