X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Ftreewillowisp.cpp;h=3dd74f1aeb645a78df34e999a6d8ae493409aac5;hb=db14b806439363d7f4809d0d5e4187e356295841;hp=e1eb027216156a8d1a71836ba66fd41130c36dfa;hpb=fea3446f05e1e7673607b835c269d3e8d1929ab3;p=supertux.git diff --git a/src/badguy/treewillowisp.cpp b/src/badguy/treewillowisp.cpp index e1eb02721..3dd74f1ae 100644 --- a/src/badguy/treewillowisp.cpp +++ b/src/badguy/treewillowisp.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux - "Will-O-Wisp" Badguy // Copyright (C) 2007 Matthias Braun // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,30 +12,42 @@ // 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. -#include - -#include "treewillowisp.hpp" -#include "ghosttree.hpp" -#include "object/lantern.hpp" +// along with this program. If not, see . -static const std::string SOUNDFILE = "sounds/willowisp.wav"; -static const float SUCKSPEED = 25; +#include "badguy/treewillowisp.hpp" -TreeWillOWisp::TreeWillOWisp(GhostTree* tree, const Vector& pos, - float radius, float speed) - : BadGuy(Vector(0, 0), "images/creatures/willowisp/willowisp.sprite", - LAYER_OBJECTS - 20), was_sucked(false), mystate(STATE_DEFAULT), tree(tree) +#include "audio/sound_manager.hpp" +#include "audio/sound_source.hpp" +#include "badguy/ghosttree.hpp" +#include "object/lantern.hpp" +#include "object/player.hpp" +#include "sprite/sprite.hpp" + +#include + +static const std::string TREEWILLOSOUND = "sounds/willowisp.wav"; + +TreeWillOWisp::TreeWillOWisp(GhostTree* tree_, const Vector& pos, + float radius_, float speed_) : + BadGuy(tree_->get_pos() + pos, "images/creatures/willowisp/willowisp.sprite", + LAYER_OBJECTS - 20), + was_sucked(false), + mystate(STATE_DEFAULT), + color(), + angle(), + radius(), + speed(), + sound_source(), + tree(tree_), + suck_target() { - treepos_delta = pos; - sound_manager->preload(SOUNDFILE); + SoundManager::current()->preload(TREEWILLOSOUND); - this->radius = radius; + this->radius = radius_; this->angle = 0; - this->speed = speed; - start_position = tree->get_pos() + treepos_delta; + this->speed = speed_; + + set_colgroup_active(COLGROUP_MOVING); } TreeWillOWisp::~TreeWillOWisp() @@ -47,14 +57,12 @@ TreeWillOWisp::~TreeWillOWisp() void TreeWillOWisp::activate() { - sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); + sound_source = SoundManager::current()->create_sound_source(TREEWILLOSOUND); sound_source->set_position(get_pos()); sound_source->set_looping(true); sound_source->set_gain(2.0); sound_source->set_reference_distance(32); sound_source->play(); - - set_group(COLGROUP_MOVING); } void @@ -62,14 +70,14 @@ TreeWillOWisp::vanish() { mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); } void -TreeWillOWisp::start_sucking(Vector suck_target) +TreeWillOWisp::start_sucking(Vector suck_target_) { mystate = STATE_SUCKED; - this->suck_target = suck_target; + this->suck_target = suck_target_; was_sucked = true; } @@ -87,7 +95,7 @@ TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) { return true; if (dynamic_cast(&other)) return true; - + return false; } @@ -117,18 +125,18 @@ TreeWillOWisp::active_update(float elapsed_time) } if (mystate == STATE_SUCKED) { - Vector dir = suck_target - get_pos(); - if(dir.norm() < 5) { + Vector dir_ = suck_target - get_pos(); + if(dir_.norm() < 5) { vanish(); return; } - Vector newpos = get_pos() + dir * elapsed_time; + Vector newpos = get_pos() + dir_ * elapsed_time; movement = newpos - get_pos(); return; } angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI)); - Vector newpos(tree->get_pos() + treepos_delta + Vector(sin(angle) * radius, 0)); + Vector newpos(start_position + Vector(sin(angle) * radius, 0)); movement = newpos - get_pos(); float sizemod = cos(angle) * 0.8f; /* TODO: modify sprite size */ @@ -143,10 +151,10 @@ TreeWillOWisp::active_update(float elapsed_time) } void -TreeWillOWisp::set_color(const Color& color) +TreeWillOWisp::set_color(const Color& color_) { - this->color = color; - sprite->set_color(color); + this->color = color_; + sprite->set_color(color_); } Color @@ -155,3 +163,4 @@ TreeWillOWisp::get_color() const return color; } +/* EOF */