#include <mrtree.hpp>
Inherits WalkingBadguy.
Public Member Functions | |
MrTree (const Reader &reader) | |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. |
Definition at line 22 of file mrtree.hpp.
MrTree::MrTree | ( | const Reader & | reader | ) |
Definition at line 36 of file mrtree.cpp.
References WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, TREE_SPEED, and WalkingBadguy::walk_speed.
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 }
bool MrTree::collision_squished | ( | GameObject & | object | ) | [protected, virtual] |
Called when the player hit the badguy from above.
You should return true if the badguy was squished, false if squishing wasn't possible
Reimplemented from BadGuy.
Definition at line 45 of file mrtree.cpp.
References Sector::add_object(), ANCHOR_MIDDLE, Player::bounce(), BadGuy::countMe, Sector::current(), BadGuy::dir, MovingObject::get_bbox(), MovingObject::get_pos(), graphicsRandom, LAYER_OBJECTS, LEFT, Rectf::p1, Rectf::p2, SoundManager::play(), POISONIVY_HEIGHT, POISONIVY_WIDTH, POISONIVY_Y_OFFSET, RandomGenerator::randf(), GameObject::remove_me(), RIGHT, sound_manager, MovingSprite::sprite, Vector::x, and Vector::y.
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 }