projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Set 'licence' attribute on sound files
[supertux.git]
/
src
/
badguy
/
willowisp.cpp
diff --git
a/src/badguy/willowisp.cpp
b/src/badguy/willowisp.cpp
index
22ec617
..
db467e7
100644
(file)
--- a/
src/badguy/willowisp.cpp
+++ b/
src/badguy/willowisp.cpp
@@
-20,11
+20,20
@@
#include <config.h>
#include "willowisp.hpp"
#include <config.h>
#include "willowisp.hpp"
+
#include "log.hpp"
#include "game_session.hpp"
#include "object/lantern.hpp"
#include "object/player.hpp"
#include "scripting/squirrel_util.hpp"
#include "log.hpp"
#include "game_session.hpp"
#include "object/lantern.hpp"
#include "object/player.hpp"
#include "scripting/squirrel_util.hpp"
+#include "object/path.hpp"
+#include "object/path_walker.hpp"
+#include "audio/sound_source.hpp"
+#include "lisp/writer.hpp"
+#include "object_factory.hpp"
+#include "audio/sound_manager.hpp"
+#include "sector.hpp"
+#include "sprite/sprite.hpp"
static const float FLYSPEED = 64; /**< speed in px per second */
static const float TRACK_RANGE = 384; /**< at what distance to start tracking the player */
static const float FLYSPEED = 64; /**< speed in px per second */
static const float TRACK_RANGE = 384; /**< at what distance to start tracking the player */
@@
-34,6
+43,7
@@
static const std::string SOUNDFILE = "sounds/willowisp.wav";
WillOWisp::WillOWisp(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/willowisp/willowisp.sprite", LAYER_FLOATINGOBJECTS), mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main")
{
WillOWisp::WillOWisp(const lisp::Lisp& reader)
: BadGuy(reader, "images/creatures/willowisp/willowisp.sprite", LAYER_FLOATINGOBJECTS), mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main")
{
+ bool running = false;
flyspeed = FLYSPEED;
track_range = TRACK_RANGE;
vanish_range = VANISH_RANGE;
flyspeed = FLYSPEED;
track_range = TRACK_RANGE;
vanish_range = VANISH_RANGE;
@@
-45,16
+55,22
@@
WillOWisp::WillOWisp(const lisp::Lisp& reader)
reader.get("track-range", track_range);
reader.get("vanish-range", vanish_range);
reader.get("hit-script", hit_script);
reader.get("track-range", track_range);
reader.get("vanish-range", vanish_range);
reader.get("hit-script", hit_script);
+ reader.get("running", running);
const lisp::Lisp* pathLisp = reader.get_lisp("path");
if(pathLisp != NULL) {
path.reset(new Path());
const lisp::Lisp* pathLisp = reader.get_lisp("path");
if(pathLisp != NULL) {
path.reset(new Path());
- path->read(*pathLisp);
- walker.reset(new PathWalker(path.get(), false));
+ path->read(*pathLisp);
+ walker.reset(new PathWalker(path.get(), running));
+ if(running)
+ mystate = STATE_PATHMOVING_TRACK;
}
countMe = false;
sound_manager->preload(SOUNDFILE);
}
countMe = false;
sound_manager->preload(SOUNDFILE);
+ sound_manager->preload("sounds/warp.wav");
+
+ sprite->set_action("idle");
}
void
}
void
@@
-90,11
+106,14
@@
WillOWisp::active_update(float elapsed_time)
break;
case STATE_TRACKING:
break;
case STATE_TRACKING:
- if (dist.norm() <= vanish_range) {
+ if (dist.norm() > vanish_range) {
+ vanish();
+ } else if (dist.norm() >= 1) {
Vector dir = dist.unit();
movement = dir * elapsed_time * flyspeed;
} else {
Vector dir = dist.unit();
movement = dir * elapsed_time * flyspeed;
} else {
- vanish();
+ /* We somehow landed right on top of the player without colliding.
+ * Sit tight and avoid a division by zero. */
}
sound_source->set_position(get_pos());
break;
}
sound_source->set_position(get_pos());
break;
@@
-131,8
+150,6
@@
WillOWisp::active_update(float elapsed_time)
void
WillOWisp::activate()
{
void
WillOWisp::activate()
{
- sprite->set_action("idle");
-
sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
sound_source->set_position(get_pos());
sound_source->set_looping(true);
sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
sound_source->set_position(get_pos());
sound_source->set_looping(true);
@@
-167,7
+184,7
@@
WillOWisp::vanish()
{
mystate = STATE_VANISHING;
sprite->set_action("vanishing", 1);
{
mystate = STATE_VANISHING;
sprite->set_action("vanishing", 1);
- set_
group
(COLGROUP_DISABLED);
+ set_
colgroup_active
(COLGROUP_DISABLED);
}
bool
}
bool
@@
-211,11
+228,22
@@
WillOWisp::goto_node(int node_no)
walker->goto_node(node_no);
if(mystate != STATE_PATHMOVING && mystate != STATE_PATHMOVING_TRACK) {
mystate = STATE_PATHMOVING;
walker->goto_node(node_no);
if(mystate != STATE_PATHMOVING && mystate != STATE_PATHMOVING_TRACK) {
mystate = STATE_PATHMOVING;
- walker->start_moving();
}
}
void
}
}
void
+WillOWisp::start_moving()
+{
+ walker->start_moving();
+}
+
+void
+WillOWisp::stop_moving()
+{
+ walker->stop_moving();
+}
+
+void
WillOWisp::set_state(const std::string& new_state)
{
if(new_state == "stopped") {
WillOWisp::set_state(const std::string& new_state)
{
if(new_state == "stopped") {
@@
-230,10
+258,12
@@
WillOWisp::set_state(const std::string& new_state)
walker->start_moving();
} else if(new_state == "normal") {
mystate = STATE_IDLE;
walker->start_moving();
} else if(new_state == "normal") {
mystate = STATE_IDLE;
+ } else if(new_state == "vanish") {
+ vanish();
} else {
std::ostringstream msg;
msg << "Can't set unknown willowisp state '" << new_state << "', should "
} else {
std::ostringstream msg;
msg << "Can't set unknown willowisp state '" << new_state << "', should "
- "be stopped, move_path, move_path_track or normal";
+
"be stopped, move_path, move_path_track or normal";
throw new std::runtime_error(msg.str());
}
}
throw new std::runtime_error(msg.str());
}
}