1
// $Id: rain_particle_holder.cxx,v 1.5 2003/03/25 00:37:44 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "../gui/graphic_context.hxx"
21
#include "../math.hxx"
22
#include "../col_map.hxx"
23
#include "../globals.hxx"
24
#include "../pingus_resource.hxx"
25
#include "../world.hxx"
26
#include "rain_particle_holder.hxx"
30
RainParticleHolder::RainParticle::RainParticle(int x, int y)
31
: alive(true), splash(false), use_rain2_surf(false), splash_counter(0), splash_frame(0), pos(Vector(x, y))
33
use_rain2_surf = ((rand() % 3) == 0);
34
pos.z = 1.0 + Math::frand() * 3.0;
38
RainParticleHolder::RainParticleHolder ()
39
: rain1_surf (PingusResource::load_surface("Particles/rain1", "pingus")),
40
rain2_surf (PingusResource::load_surface("Particles/rain2", "pingus")),
41
rain_splash(PingusResource::load_surface("Particles/rain_splash", "pingus"))
47
RainParticleHolder::add_particle (int x, int y)
49
// search for dead entry to replace
50
for (std::vector<RainParticle>::iterator it=particles.begin(); it != particles.end(); ++it)
53
*it = RainParticle(x, y);
58
particles.push_back(RainParticle(x, y));
62
RainParticleHolder::update ()
64
// update all contained particles
65
for (std::vector<RainParticle>::iterator it=particles.begin(); it != particles.end(); ++it)
67
// skip dead particles
73
if (it->splash_frame >= rain_splash.get_num_frames())
79
it->splash_frame += 10 * game_speed / 1000.0f;
80
(it->splash_counter == 3) ? it->alive = false : ++it->splash_counter;
84
if ( world->get_colmap()->getpixel(static_cast<int>(it->pos.x), static_cast<int>(it->pos.y)) != Groundtype::GP_NOTHING
85
&& world->get_colmap()->getpixel(static_cast<int>(it->pos.x), static_cast<int>(it->pos.y)) != Groundtype::GP_OUTOFSCREEN
86
&& ((rand() % 2) == 0))
92
if (it->pos.y > world->get_height())
98
it->pos.x -= 5 * it->pos.z;
99
it->pos.y += 16 * it->pos.z;
108
RainParticleHolder::draw (GraphicContext& gc)
110
for (std::vector<RainParticle>::iterator it=particles.begin(); it != particles.end(); ++it)
112
// skip dead/invisible particles
113
if (!it->alive || it->pos.x > WorldObj::get_world()->get_width())
117
gc.draw(rain_splash, it->pos, static_cast<int>(it->splash_frame));
119
if (it->use_rain2_surf)
120
gc.draw(rain2_surf, static_cast<int>(it->pos.x), static_cast<int>(it->pos.y - rain1_surf.get_height()));
122
gc.draw(rain1_surf, static_cast<int>(it->pos.x), static_cast<int>(it->pos.y - rain1_surf.get_height()));
126
} // namespace Particles