From 16262ff3cac7fdd1de8dc46a967f93cce902ed7f Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Mon, 1 May 2006 19:26:44 +0000 Subject: [PATCH] New GameObject SpriteParticle SVN-Revision: 3482 --- data/images/objects/particles/smoke-1.png | Bin 0 -> 634 bytes data/images/objects/particles/smoke-2.png | Bin 0 -> 639 bytes data/images/objects/particles/smoke-3.png | Bin 0 -> 792 bytes data/images/objects/particles/smoke-4.png | Bin 0 -> 891 bytes data/images/objects/particles/smoke-5.png | Bin 0 -> 840 bytes data/images/objects/particles/smoke-6.png | Bin 0 -> 762 bytes data/images/objects/particles/smoke.sprite | 12 +++++ src/badguy/flyingsnowball.cpp | 28 +++++++++++ src/badguy/flyingsnowball.hpp | 1 + src/object/sprite_particle.cpp | 72 +++++++++++++++++++++++++++++ src/object/sprite_particle.hpp | 50 ++++++++++++++++++++ src/sprite/sprite.hpp | 4 ++ 12 files changed, 167 insertions(+) create mode 100644 data/images/objects/particles/smoke-1.png create mode 100644 data/images/objects/particles/smoke-2.png create mode 100644 data/images/objects/particles/smoke-3.png create mode 100644 data/images/objects/particles/smoke-4.png create mode 100644 data/images/objects/particles/smoke-5.png create mode 100644 data/images/objects/particles/smoke-6.png create mode 100644 data/images/objects/particles/smoke.sprite create mode 100644 src/object/sprite_particle.cpp create mode 100644 src/object/sprite_particle.hpp diff --git a/data/images/objects/particles/smoke-1.png b/data/images/objects/particles/smoke-1.png new file mode 100644 index 0000000000000000000000000000000000000000..92526adc5d0920855462927978a9bd987279dc57 GIT binary patch literal 634 zcmV-=0)_pFP)WFU8GbZ8({Xk{QrNlj4iWF>9@00G`fL_t(I%gvIpYE(fK zhW|O|&J1&J!o4?Qv1F@Q7(2-e2x6DQ!rI;k@J)OHU%>$)!h-sYS?UtV7Nm4;Wt?(S~O%&)7edQ}v~ z!w^F0y(g`;PAT0t#yn0b4V6;g+O{1{CX)mJw6>zu6C!#+M2(1Gxm;qgSYSGxf{2iF zM$$$XYvg?$({w8rIr%iwNfPImYAhk%;`<0OXuM zdGFtKU3U!tAp|fpQc55q7-JAZ_}F#bd!^K5;}5Q`uKf1)_K&{r7b3!CSyo$HTNZ#% zDSe;KW*_GB`5ORV&(6;JJ70M)7_`iMKt%gxS?WFU8GbZ8({Xk{QrNlj4iWF>9@00HAkL_t(I%gvI#iWET< zg-_jE)ivEce?8&^gG@4kW47!I2x7K@fw8#{;G6gYzJP(j8kv|0E(k^o8Z;~e1LDj& zKiyT`^CwZPfBBDY{X^kXnr8Ws)QhV~iOy zQ(f1JneXR$eg@z{RaIa6{r->bb{hbIj!w*vyWQ^dEX#&5Mi3D;n+@u^hP4*nd!%Xl z6u>j@{oueI4U|$Bd7h8jwuMp(T5AvyhzQIKV+@Qj$g=DLz`X+}kBgLZYi-)=_29jS za}H8U2q6$-M2rzl(}0=h%$%MikWyke93CNNh7bZm{P{BxVK5kgh@iE`Ndh6nH8Y=S zt-AoQ-|vwm2>_te>7Z>}IOh;!yl$GNK1onj)#YxtTUAvB?>)5E$5BcF0Max?jPa6) zex4Y3??0~B>$gg&+ayUqLE;g%EC*%caAA ZrQhY3&iZX*QcwT@002ovPDHLkV1iC`5y}7n literal 0 HcmV?d00001 diff --git a/data/images/objects/particles/smoke-3.png b/data/images/objects/particles/smoke-3.png new file mode 100644 index 0000000000000000000000000000000000000000..0c135ac324010b701b1438eee96a8863873c66db GIT binary patch literal 792 zcmV+z1LypSP)WFU8GbZ8({Xk{QrNlj4iWF>9@00MkTL_t(I%cYY)ZzM$! z#b0$-ch9WHx>=0D97dKM0I~$q<%GajASFcNJCPF;ARUB6mmGosR;f#!ana3Yvyb|||4daW#%NPYD5ZdiP-}&VYyiB%%x@9V^PKZ9 ztJP{_03hc)XXX#5Y0{LEvDQLF5M#v6%?)CVU}lWt_(}cBBk`bwKlHT>-$}p z&*$7U&55=45i?(^>PZNJYpp9|%tBS4ipaB^bG*L3)_-l|-fQ>rdoKfs00sc}+V~gY WWn5C1%5dZW00001BCpEP)WFU8GbZ8({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1~r>ABX zBJu}-Cncg85xps;yxQ;ge?`PiL@Xm>8xg6hH6oTo^fZp+_obAJQpykGIIaK;T5COx zh}Ww6QABQ9Yd2=LYOU=LIhBam48zdey-p^R)1#xKZ_Ml(zQc{eG93+sxc&rUPi12_njf7W@Y9R zX8ue>=3UpFW#;nGf+-O_h{!E7|5QpD#&HZ0=`wTM_kCn$C8D!h>qX!9UyI1p%ziJW zya%vX5m~wWwW?mY`cYmjHnoZNRw~ SER|;f0000WFU8GbZ8({Xk{QrNlj4iWF>9@00Le~L_t(I%T1GCPaIba z#ecT%o!JGFY^gv>Bl-m2|2tKpN+A_cAUiX@w)@acR7-yGk#(f=M>x&R&5f8@A7ku+ zx%WP0rnoy*6(aH;5nffx!^1=V_!EG;yE_q)IWs>2m+pQBsF~@yt_mcuw$}cxs+Wj( zzrVi^0K2`tmCT&0>awc7WaeH(ys8#eU4Svhz|79)c|Jr0`~BVzhr@V!da4!?O+*f3 zjGNY4W#-p0#;d!#swSYBIYq>ws;+js-HnJ~W(B-85jg{XX|1uY>wQ%{SJf&aSyh;s zM8sldtGh>4{XR|8Wo90MtuQ;q+qP{dwW%rqo}Zr! z;BYv|vMiWcF3Ym1YO1OLs=aqagw|SZ+lIRXkonVUPNJczoY;TjEi+R@%-y@H${2&H zqN=#KxDYd=wT787#?an-8)KNN7Lcv?zE)KN=MnJ+L{;TH&x|opRa6xbvDVt$TKjk+ zS^;UQ`r2AMY}*!SK)W#+Z2{?>b+s_I)ryZ~FPDp%E45%~l7416}TgPD0%rJ3oeT<0Rv z-Tlvq_{+@RfwafRN3O50W81cIJRYO>{v(~csygqzU#My~vlV!Vh_CMc9f+5gm;c)M szh=(B4)_Qd&`#MH!11)-Pqza27mw #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); @@ -62,6 +70,7 @@ FlyingSnowBall::activate() mode = FLY_UP; physic.set_velocity_y(FLYSPEED); timer.start(FLYTIME/2); + puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX)); } bool @@ -89,9 +98,19 @@ FlyingSnowBall::active_update(float elapsed_time) 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); } @@ -102,6 +121,15 @@ FlyingSnowBall::active_update(float elapsed_time) 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") diff --git a/src/badguy/flyingsnowball.hpp b/src/badguy/flyingsnowball.hpp index 7762c966d..c9fa3fca3 100644 --- a/src/badguy/flyingsnowball.hpp +++ b/src/badguy/flyingsnowball.hpp @@ -41,6 +41,7 @@ protected: bool collision_squished(Player& player); private: Timer timer; + Timer puff_timer; /**< time until the next smoke puff is spawned */ }; #endif diff --git a/src/object/sprite_particle.cpp b/src/object/sprite_particle.cpp new file mode 100644 index 000000000..c166253d4 --- /dev/null +++ b/src/object/sprite_particle.cpp @@ -0,0 +1,72 @@ +// $Id: rainsplash.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// Copyright (C) 2006 Christoph Sommer +// +// 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); +} diff --git a/src/object/sprite_particle.hpp b/src/object/sprite_particle.hpp new file mode 100644 index 000000000..160cdc060 --- /dev/null +++ b/src/object/sprite_particle.hpp @@ -0,0 +1,50 @@ +// $Id: rainsplash.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// Copyright (C) 2006 Christoph Sommer +// +// 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 + diff --git a/src/sprite/sprite.hpp b/src/sprite/sprite.hpp index 9c138e200..b558cd1fc 100644 --- a/src/sprite/sprite.hpp +++ b/src/sprite/sprite.hpp @@ -46,6 +46,10 @@ public: /** 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); -- 2.11.0