~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/particles/rain_particle_holder.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Goulais
  • Date: 2004-08-09 10:26:00 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040809102600-lg2q9lfars0q1p42
Tags: 0.6.0-8
Applied patch from Andreas Jochens (Closes: #263992)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: rain_particle_holder.cxx,v 1.5 2003/03/25 00:37:44 grumbel Exp $
 
2
//
 
3
//  Pingus - A free Lemmings clone
 
4
//  Copyright (C) 1999 Ingo Ruhnke <grumbel@gmx.de>
 
5
//
 
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.
 
10
//
 
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.
 
15
//
 
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.
 
19
 
 
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"
 
27
 
 
28
namespace Particles {
 
29
 
 
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))
 
32
{
 
33
  use_rain2_surf = ((rand() % 3) == 0);
 
34
  pos.z = 1.0 + Math::frand() * 3.0;
 
35
}
 
36
 
 
37
 
 
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"))
 
42
{
 
43
}
 
44
 
 
45
 
 
46
void
 
47
RainParticleHolder::add_particle (int x, int y)
 
48
{
 
49
  // search for dead entry to replace
 
50
  for (std::vector<RainParticle>::iterator it=particles.begin(); it != particles.end(); ++it)
 
51
    if (!it->alive)
 
52
      {
 
53
        *it = RainParticle(x, y);
 
54
        return;
 
55
      }
 
56
        
 
57
  // create new entry
 
58
  particles.push_back(RainParticle(x, y));
 
59
}
 
60
 
 
61
void
 
62
RainParticleHolder::update ()
 
63
{
 
64
  // update all contained particles
 
65
  for (std::vector<RainParticle>::iterator it=particles.begin(); it != particles.end(); ++it)
 
66
    {
 
67
      // skip dead particles
 
68
      if (!it->alive)
 
69
        continue;
 
70
        
 
71
      if (it->splash)
 
72
        {
 
73
          if (it->splash_frame >= rain_splash.get_num_frames())
 
74
            {
 
75
              it->alive = false;
 
76
              continue;
 
77
            }
 
78
                  
 
79
            it->splash_frame += 10 * game_speed / 1000.0f;
 
80
            (it->splash_counter == 3) ? it->alive = false : ++it->splash_counter;
 
81
        }
 
82
      else
 
83
        {
 
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))
 
87
            {
 
88
              it->splash = true;
 
89
            }
 
90
          else
 
91
            {
 
92
              if (it->pos.y > world->get_height())
 
93
                {
 
94
                  it->alive = false;
 
95
                  continue;
 
96
                }
 
97
                
 
98
                it->pos.x -= 5  * it->pos.z;
 
99
                it->pos.y += 16 * it->pos.z;
 
100
            }
 
101
        }
 
102
    }
 
103
 
 
104
}
 
105
 
 
106
 
 
107
void
 
108
RainParticleHolder::draw (GraphicContext& gc)
 
109
{
 
110
  for (std::vector<RainParticle>::iterator it=particles.begin(); it != particles.end(); ++it)
 
111
    {
 
112
      // skip dead/invisible particles
 
113
      if (!it->alive || it->pos.x > WorldObj::get_world()->get_width())
 
114
        continue;
 
115
 
 
116
      if (it->splash)
 
117
        gc.draw(rain_splash, it->pos, static_cast<int>(it->splash_frame));
 
118
      else
 
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()));
 
121
        else
 
122
          gc.draw(rain1_surf, static_cast<int>(it->pos.x), static_cast<int>(it->pos.y - rain1_surf.get_height()));
 
123
    }
 
124
}
 
125
 
 
126
} // namespace Particles
 
127
 
 
128
/* EOF */