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

« back to all changes in this revision

Viewing changes to src/particles/ExplosiveParticle.cc

  • 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: ExplosiveParticle.cc,v 1.3 2001/08/12 18:36:42 grumbel Exp $
2
 
//
3
 
//  Pingus - A free Lemmings clone
4
 
//  Copyright (C) 2000 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 "../ColMap.hh"
21
 
#include "../PinguMap.hh"
22
 
#include "../World.hh"
23
 
#include "../particles/ParticleHolder.hh"
24
 
#include "ExplosiveParticle.hh"
25
 
 
26
 
ExplosiveParticle::ExplosiveParticle (int x, int y, float x_a, float y_a)
27
 
  : Particle (x, y, x_a, y_a),
28
 
    alive (true) 
29
 
{  
30
 
  sprite = Sprite (PingusResource::load_surface 
31
 
                   ("Particles/explosive",
32
 
                    "pingus"));
33
 
}
34
 
 
35
 
ExplosiveParticle::~ExplosiveParticle ()
36
 
{
37
 
}
38
 
 
39
 
void 
40
 
ExplosiveParticle::update(float delta)
41
 
{
42
 
  CL_Vector new_pos = pos + velocity * delta;
43
 
  
44
 
  CL_Vector incr = pos - new_pos;
45
 
  incr.normalize ();
46
 
 
47
 
  // FIXME: This thing needs to be more abstract, we just need it far
48
 
  // to often to reimplement it over and over again.
49
 
  while (int(new_pos.x) != int(pos.x)
50
 
         || int(new_pos.y) != int(pos.y))
51
 
    {
52
 
      pos -= incr;
53
 
 
54
 
      if (pos.x < 0 || pos.y < 0 
55
 
          || pos.x + 1 > world->get_width ()
56
 
          || pos.y + 1 > world->get_height ())
57
 
        {
58
 
          alive = false;
59
 
          return;
60
 
        }
61
 
 
62
 
      if (world->get_colmap ()->getpixel ((int) pos.x, (int) pos.y))
63
 
        {
64
 
          detonate ();
65
 
        }
66
 
    }
67
 
 
68
 
  pos = new_pos;
69
 
}
70
 
 
71
 
void 
72
 
ExplosiveParticle::detonate ()
73
 
{
74
 
  alive = false;
75
 
  CL_Surface bomber_radius = PingusResource::load_surface ("Other/bomber_radius", "pingus");
76
 
  world->get_particle_holder ()->add_pingu_explo((int)pos.x, (int)pos.y);
77
 
 
78
 
  // FIXME: Ugly do handle the colmap and the gfx map seperatly
79
 
  world->get_colmap()->remove(bomber_radius,
80
 
                              int(pos.x) - (bomber_radius.get_width()/2),
81
 
                              int(pos.y) - (bomber_radius.get_height()/2));
82
 
  world->get_gfx_map()->remove(bomber_radius, 
83
 
                               int(pos.x) - (bomber_radius.get_width()/2),
84
 
                               int(pos.y) - (bomber_radius.get_height()/2));
85
 
}
86
 
 
87
 
void 
88
 
ExplosiveParticle::draw_offset(int ofx, int ofy, float s)
89
 
{
90
 
  sprite.put_screen (int(pos.x + ofx), int(pos.y + ofy));
91
 
}
92
 
 
93
 
bool 
94
 
ExplosiveParticle::is_alive(void)
95
 
{
96
 
  return alive;
97
 
}
98
 
 
99
 
/* EOF */