X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fmrtree.cpp;h=775c82102e973f1a5f859bea16351bdb7583cbcf;hb=4a486d92343d1824b311c234e9321e08f280fe68;hp=8955e1c9ca611761a0724cb95da2fd0a7a3490fd;hpb=cbbcc7dfbaca831dc4cbf714ff54b246135f7625;p=supertux.git diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 8955e1c9c..775c82102 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,111 +12,90 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "mrtree.hpp" +#include "stumpy.hpp" +#include "poisonivy.hpp" +#include "random_generator.hpp" +#include "object/sprite_particle.hpp" +#include "sector.hpp" static const float WALKSPEED = 100; -static const float WALKSPEED_SMALL =120; + +static const float POISONIVY_WIDTH = 32; +static const float POISONIVY_HEIGHT = 32; +static const float POISONIVY_Y_OFFSET = 24; + MrTree::MrTree(const lisp::Lisp& reader) - : mystate(STATE_BIG) + : WalkingBadguy(reader, "images/creatures/mr_tree/mr_tree.sprite","left","right") { - reader.get("x", start_position.x); - reader.get("y", start_position.y); - stay_on_platform = false; - reader.get("stay-on-platform", stay_on_platform); - bbox.set_size(99.8, 99.8); - sprite = sprite_manager->create("images/creatures/mr_tree/mr_tree.sprite"); + walk_speed = WALKSPEED; + max_drop_height = 0; + sound_manager->preload("sounds/mr_tree.ogg"); } void MrTree::write(lisp::Writer& writer) { writer.start_list("mrtree"); - - writer.write_float("x", start_position.x); - writer.write_float("y", start_position.y); - + WalkingBadguy::write(writer); writer.end_list("mrtree"); } -void -MrTree::activate() -{ - if(mystate == STATE_BIG) { - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); - sprite->set_action(dir == LEFT ? "left" : "right"); - } else { - physic.set_velocity_x(dir == LEFT ? -WALKSPEED_SMALL : WALKSPEED_SMALL); - bbox.set_size(31.8, 68.8); - sprite->set_action(dir == LEFT ? "small-left" : "small-right"); - } -} - -void -MrTree::active_update(float elapsed_time) -{ - if (stay_on_platform && may_fall_off_platform()) - { - dir = (dir == LEFT ? RIGHT : LEFT); - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); - } - - BadGuy::active_update(elapsed_time); -} - bool MrTree::collision_squished(Player& player) { - if(mystate == STATE_BIG) { - mystate = STATE_NORMAL; - activate(); - - - sound_manager->play("sounds/mr_tree.ogg", get_pos()); - player.bounce(*this); - } else { -bbox.set_size(67.8, 99.8); -sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); -sound_manager->play("sounds/mr_treehit.ogg", get_pos()); -player.bounce(*this); - + // replace with Stumpy + Vector stumpy_pos = get_pos(); + stumpy_pos.x += 20; + stumpy_pos.y += 25; + Stumpy* stumpy = new Stumpy(stumpy_pos, dir); + remove_me(); + Sector::current()->add_object(stumpy); + + // give Feedback + sound_manager->play("sounds/mr_tree.ogg", get_pos()); + player.bounce(*this); + + // spawn some particles + // TODO: provide convenience function in MovingSprite or MovingObject? + for (int px = (int)stumpy->get_bbox().p1.x; px < (int)stumpy->get_bbox().p2.x; px+=10) { + Vector ppos = Vector(px, stumpy->get_bbox().p1.y-5); + float angle = systemRandom.randf(-M_PI_2, M_PI_2); + float velocity = systemRandom.randf(45, 90); + float vx = sin(angle)*velocity; + float vy = -cos(angle)*velocity; + Vector pspeed = Vector(vx, vy); + Vector paccel = Vector(0, 100); + Sector::current()->add_object(new SpriteParticle("images/objects/particles/leaf.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); } - - return true; -} -HitResponse -MrTree::collision_solid(GameObject& , const CollisionHit& hit) -{ - if(fabsf(hit.normal.y) > .5) { - physic.set_velocity_y(0); - } else { - dir = dir == LEFT ? RIGHT : LEFT; - activate(); + // spawn PoisonIvy + Vector leaf1_pos = Vector(stumpy_pos.x - POISONIVY_WIDTH - 1, stumpy_pos.y - POISONIVY_Y_OFFSET); + Rect leaf1_bbox = Rect(leaf1_pos.x, leaf1_pos.y, leaf1_pos.x + POISONIVY_WIDTH, leaf1_pos.y + POISONIVY_HEIGHT); + if (Sector::current()->is_free_space(leaf1_bbox)) { + PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1, LEFT); + leaf1 = leaf1; + Sector::current()->add_object(leaf1); } - return CONTINUE; -} - -HitResponse -MrTree::collision_badguy(BadGuy& , const CollisionHit& hit) -{ - if(fabsf(hit.normal.x) > .8) { // left or right hit - dir = dir == LEFT ? RIGHT : LEFT; - activate(); + // spawn PoisonIvy + Vector leaf2_pos = Vector(stumpy_pos.x + sprite->get_current_hitbox_width() + 1, stumpy_pos.y - POISONIVY_Y_OFFSET); + Rect leaf2_bbox = Rect(leaf2_pos.x, leaf2_pos.y, leaf2_pos.x + POISONIVY_WIDTH, leaf2_pos.y + POISONIVY_HEIGHT); + if (Sector::current()->is_free_space(leaf2_bbox)) { + PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1, RIGHT); + leaf2 = leaf2; + Sector::current()->add_object(leaf2); } - return CONTINUE; + return true; } IMPLEMENT_FACTORY(MrTree, "mrtree") -