From cf585f019ce5aacf92e252a2f2c60c47255bea52 Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Wed, 16 Mar 2005 11:35:16 +0000 Subject: [PATCH] added rain particle system, check it out in verticalforest.stl SVN-Revision: 2292 --- data/images/shared/rain0.png | Bin 0 -> 773 bytes data/images/shared/rain1.png | Bin 0 -> 716 bytes data/levels/test/verticalforest.stl | 2 +- data/levels/world1/level19.stl | 2 +- src/object/particlesystem.cpp | 58 ++++++++++++++++++++++++++++++++++++ src/object/particlesystem.h | 24 +++++++++++++++ src/sector.cpp | 6 ++++ 7 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 data/images/shared/rain0.png create mode 100644 data/images/shared/rain1.png diff --git a/data/images/shared/rain0.png b/data/images/shared/rain0.png new file mode 100644 index 0000000000000000000000000000000000000000..4ef221c07a3b56fb6c0fd27cc9cfe37e76884914 GIT binary patch literal 773 zcmV+g1N!`lP)03CEi zSad^gZEa<4bO1wgWnpw>WFU8GbZ8({Xk{QrNlj4iWF>9@00L=AL_t(o!{yiStIu~B z$MMHG=Yu3W%8bytWulZj>;?(tXHko7QfqNTTH6hO!FA*P59}66%9Kthq>kJmN@TSr zwxR9R*1~imb~-pG&e)ynlr+w-@8^5R`}XJkeqQhEeZ8*h^=Z-MRZ3Za`FMh#+L{bs ziQVWx3w~~GB78c&z&w16zapZyY7+btY{LQ!;CEbys%G#+ti{)ui$^$%%eY@#0Hu@` ze1!Gbj#+q#UvMNM9uIw6)dcUrF095R^x_5%zYdp`*hqLg7Gn>V3}7){WurNXu6J#!8g%>C1TVz%toAPKjffYu22e_w zfv>O`6VQY6IE9D9?XSiOpN%c}JkNT7?{F3U5iwXx0Hu^FwY?q7(S|#?fXfl_Y@}z6 zH3Q4>X})+?1ZXGGNo9K#&{zeUuw`E{HzRlFPr`)=;;_o$b zgjfG_`^nguR_cR<_uvq&G}^#aZ@@pyV%wbXSLxl(;OuadZCnAAQl_ShS)b|{z#lk< z(-HBg4*%Hl+Hm<2n=l(s@gw#{#N9fb^H2shVn@#Nhxi^pM8w~9|1(s1`(^kyb$=e` zBBHMuKP^?ttUujrcUtGBz=r}D%qnliorvi5KCS-%yf(f*q)a#F00000NkvXXu0mjf DTMlhC literal 0 HcmV?d00001 diff --git a/data/images/shared/rain1.png b/data/images/shared/rain1.png new file mode 100644 index 0000000000000000000000000000000000000000..c9c6455d469a046a569e031e3220524ed64fbf90 GIT binary patch literal 716 zcmV;-0yF)IP)WFU8GbZ8({Xk{QrNlj4iWF>9@00J;cL_t(o!@bv8i;rO# z2Jqkfy$lB=Vr)g+kv)8wYuIpZ&>$=}IHGZX(31~+H0}=79Qtvk(D=`rd@T^f|^zB%S^;n20P}KxJ z7wfPZlkf)bYavidS%&@SNYID4TML0w%1rFS0{lcT?nlJS!97)r!8c$UKH?m@BI4_x z``TIrz8Kpu2X8awT@mqX=-#RY;2k)O<>(uHZhr%BI)PHkBJ9D^TzZCk5%KX~XR0PD z+-w|8q3OpBT#ATy!=0^~06savw_rtf`*WO)h*$qRUyT!dK?+Pqc6-UXUmXc}Gcs@> zBk#v`TtZJod>ZKm)fgk6guOU~33!qU_cS8^`Gdc;~>`jVJtn(^p9#7@YUFfB`Gw$X{iG( zB~VI%WjKieyvA+ZiHP^jw(q}XU=2=SErI*0S~rV+@7 z+kts$r=7SpbcSmQfl|usY`9HX_raRC6dW2Uu^V%gnw9f<7rxc;)6&3swB~mn<+HiW3koo5O|IAS^K^^!QnT3PrO@5&l5-h0000w * 2; + + // create some random snowflakes + size_t raindropcount = size_t(virtual_width/8.0); + for(size_t i=0; ipos.x = rand() % int(virtual_width); + particle->pos.y = rand() % screen->h; + int rainsize = rand() % 2; + particle->texture = rainimages[rainsize]; + do { + particle->speed = (rainsize+1)*45 + (float(rand()%10)*.4); + } while(particle->speed < 1); + particle->speed *= 10; // gravity + + particles.push_back(particle); + } +} + +void +RainParticleSystem::parse(const lisp::Lisp& reader) +{ + reader.get("layer", layer); +} + +void +RainParticleSystem::write(lisp::Writer& writer) +{ + writer.start_list("particles-rain"); + writer.write_int("layer", layer); + writer.end_list("particles-rain"); +} + +RainParticleSystem::~RainParticleSystem() +{ + for(int i=0;i<2;++i) + delete rainimages[i]; +} + +void RainParticleSystem::action(float elapsed_time) +{ + std::vector::iterator i; + for(i = particles.begin(); i != particles.end(); ++i) { + RainParticle* particle = (RainParticle*) *i; + particle->pos.y += particle->speed * elapsed_time; + particle->pos.x -= particle->speed * elapsed_time; + if(particle->pos.y > screen->h) { + particle->pos.y = fmodf(particle->pos.y , virtual_height); + particle->pos.x = rand() % int(virtual_width); + } + } +} + CloudParticleSystem::CloudParticleSystem() { cloudimage = new Surface(datadir + "/images/shared/cloud.png", true); diff --git a/src/object/particlesystem.h b/src/object/particlesystem.h index 2aae2959d..b2a0c71f2 100644 --- a/src/object/particlesystem.h +++ b/src/object/particlesystem.h @@ -98,6 +98,30 @@ private: Surface* snowimages[3]; }; +class RainParticleSystem : public ParticleSystem, public Serializable +{ +public: + RainParticleSystem(); + virtual ~RainParticleSystem(); + + void parse(const lisp::Lisp& lisp); + void write(lisp::Writer& writer); + + virtual void action(float elapsed_time); + + std::string type() const + { return "RainParticleSystem"; } + +private: + class RainParticle : public Particle + { + public: + float speed; + }; + + Surface* rainimages[2]; +}; + class CloudParticleSystem : public ParticleSystem, public Serializable { public: diff --git a/src/sector.cpp b/src/sector.cpp index 96f7f3491..655eb22a3 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -100,6 +100,10 @@ Sector::parse_object(const std::string& name, const lisp::Lisp& reader) SnowParticleSystem* partsys = new SnowParticleSystem(); partsys->parse(reader); return partsys; + } else if(name == "particles-rain") { + RainParticleSystem* partsys = new RainParticleSystem(); + partsys->parse(reader); + return partsys; } else if(name == "particles-clouds") { CloudParticleSystem* partsys = new CloudParticleSystem(); partsys->parse(reader); @@ -206,6 +210,8 @@ Sector::parse_old_format(const lisp::Lisp& reader) add_object(new CloudParticleSystem()); else if(particlesystem == "snow") add_object(new SnowParticleSystem()); + else if(particlesystem == "rain") + add_object(new RainParticleSystem()); Vector startpos(100, 170); reader.get("start_pos_x", startpos.x); -- 2.11.0