~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): Cyril Brulebois
  • Date: 2008-02-28 19:44:25 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080228194425-e8ilohlijv02kgcf
Tags: 0.7.2-2
* Fix FTBFS with gcc-4.3 by adding the missing include in
  src/input/evdev_device.cpp (Closes: #462238):
   + debian/patches/20_fix_FTBFS_with_gcc-4.3.
* Rename former patch so that the filename reflects the order in which
  the patches are applied:
   - debian/patches/data_dir.patch
   + debian/patches/10_fix_data_directory.
* Bump Standards-Version from 3.7.2 to 3.7.3, no changes needed.
* Add a dh_desktop call in the arch-dep part of debian/rules.
* Adjust the “missing-dep-for-interpreter guile” override since lintian
  now lists an alternative for that dependency.

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 */