--- /dev/null
+(supertux-sprite
+ (action
+ (images
+ "smoke-1.png"
+ "smoke-2.png"
+ "smoke-3.png"
+ "smoke-4.png"
+ "smoke-5.png"
+ "smoke-6.png"
+ )
+ )
+)
#include <stdio.h>
#include "flyingsnowball.hpp"
+#include "random_generator.hpp"
+#include "object/sprite_particle.hpp"
static const float FLYTIME = 1.0;
static const float FLYSPEED = 100.0;
+namespace {
+ const float PUFF_PROBABILITY = 0.1; /**< chanche of puffs being spawned in the current cycle */
+ const float PUFF_INTERVAL_MIN = 0.1; /**< spawn new puff of smoke at most that often */
+ const float PUFF_INTERVAL_MAX = 1.1; /**< spawn new puff of smoke at least that often */
+}
+
FlyingSnowBall::FlyingSnowBall(const lisp::Lisp& reader)
{
reader.get("x", start_position.x);
mode = FLY_UP;
physic.set_velocity_y(FLYSPEED);
timer.start(FLYTIME/2);
+ puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));
}
bool
if(mode == FLY_UP) {
mode = FLY_DOWN;
physic.set_velocity_y(-FLYSPEED);
+
+ // stop puffing
+ puff_timer.stop();
+
} else if(mode == FLY_DOWN) {
mode = FLY_UP;
physic.set_velocity_y(FLYSPEED);
+
+ // roll a dice whether to start puffing
+ if (systemRandom.randf(0, 1) < PUFF_PROBABILITY) {
+ puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));
+ }
+
}
timer.start(FLYTIME);
}
dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
sprite->set_action(dir == LEFT ? "left" : "right");
}
+
+ // spawn smoke puffs
+ if (puff_timer.check()) {
+ Vector ppos = bbox.get_middle();
+ Vector pspeed = Vector(systemRandom.randf(-10, 10), 150);
+ Vector paccel = Vector(0,0);
+ Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", ppos, pspeed, paccel, LAYER_OBJECTS-1));
+ puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));
+ }
}
IMPLEMENT_FACTORY(FlyingSnowBall, "flyingsnowball")
bool collision_squished(Player& player);
private:
Timer timer;
+ Timer puff_timer; /**< time until the next smoke puff is spawned */
};
#endif
--- /dev/null
+// $Id: rainsplash.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+// 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 distributed in the hope that it will be useful,
+// 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.
+
+#include "sprite_particle.hpp"
+#include "sector.hpp"
+#include "camera.hpp"
+#include "main.hpp"
+
+SpriteParticle::SpriteParticle(std::string sprite_name, Vector position, Vector velocity, Vector acceleration, int drawing_layer)
+ : position(position), velocity(velocity), acceleration(acceleration), drawing_layer(drawing_layer)
+{
+ sprite = sprite_manager->create(sprite_name);
+ if (!sprite) throw std::runtime_error("Could not load sprite "+sprite_name);
+ sprite->set_animation_loops(1);
+}
+
+SpriteParticle::~SpriteParticle()
+{
+ remove_me();
+}
+
+void
+SpriteParticle::hit(Player& )
+{
+}
+
+void
+SpriteParticle::update(float elapsed_time)
+{
+ // die when animation is complete
+ if (sprite->animation_done()) {
+ remove_me();
+ return;
+ }
+
+ // calculate new position and velocity
+ position.x += velocity.x * elapsed_time;
+ position.y += velocity.y * elapsed_time;
+ velocity.x += acceleration.x * elapsed_time;
+ velocity.y += acceleration.y * elapsed_time;
+
+ // die when too far offscreen
+ Vector camera = Sector::current()->camera->get_translation();
+ if ((position.x < camera.x - 128) || (position.x > SCREEN_WIDTH + camera.x + 128) ||
+ (position.y < camera.y - 128) || (position.y > SCREEN_HEIGHT + camera.y + 128)) {
+ remove_me();
+ return;
+ }
+}
+
+void
+SpriteParticle::draw(DrawingContext& context)
+{
+ sprite->draw(context, position, drawing_layer);
+}
--- /dev/null
+// $Id: rainsplash.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
+//
+// SuperTux
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+// 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 distributed in the hope that it will be useful,
+// 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.
+
+#ifndef __SPRITE_PARTICLE_H__
+#define __SPRITE_PARTICLE_H__
+
+
+#include "game_object.hpp"
+#include "resources.hpp"
+#include "player.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
+#include "video/drawing_context.hpp"
+
+class SpriteParticle : public GameObject
+{
+public:
+ SpriteParticle(std::string sprite_name, Vector position, Vector velocity, Vector acceleration, int drawing_layer = LAYER_OBJECTS-1);
+ ~SpriteParticle();
+protected:
+ virtual void hit(Player& player);
+ virtual void update(float elapsed_time);
+ virtual void draw(DrawingContext& context);
+private:
+ Sprite* sprite;
+ Vector position;
+ Vector velocity;
+ Vector acceleration;
+ int drawing_layer;
+};
+
+#endif
+
/** Set action (or state) */
void set_action(const std::string& act, int loops = -1);
+ /** Set number of animation cycles until animation stops */
+ void set_animation_loops(int loops = -1)
+ { animation_loops = loops; }
+
/** Set framerate */
void set_fps(float new_fps);