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

« back to all changes in this revision

Viewing changes to src/particles/PinguParticle.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: PinguParticle.cc,v 1.15 2001/08/12 18:36:42 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 "../ColMap.hh"
21
 
#include "../World.hh"
22
 
#include "../algo.hh"
23
 
#include "../PingusResource.hh"
24
 
#include "PinguParticle.hh"
25
 
 
26
 
static const float x_collision_decrease = 0.3f;
27
 
static const float y_collision_decrease = 0.6f;
28
 
 
29
 
CL_Surface PinguParticle::sur;
30
 
 
31
 
PinguParticle::PinguParticle()
32
 
{
33
 
  surface = PingusResource::load_surface("Particles/particle", "pingus");
34
 
  livetime = 50 + (rand() % 25);
35
 
  size  = 1.0;
36
 
  size_add = (frand() - 0.2) / 35;
37
 
}
38
 
 
39
 
PinguParticle::PinguParticle(int x, int y, float x_a, float y_a)
40
 
  : Particle (x, y, x_a, y_a)
41
 
{
42
 
  size  = 1.0;
43
 
  size_add = (frand() - 0.2) / 35;
44
 
  livetime = 50 + (rand() % 50);
45
 
 
46
 
  if (sur)
47
 
    surface = sur;
48
 
  else
49
 
    sur = PingusResource::load_surface("Particles/particle", "pingus");
50
 
}
51
 
 
52
 
void
53
 
PinguParticle::init(int x, int y, float x_a, float y_a)
54
 
{
55
 
  pos.x = x;
56
 
  pos.y = y;
57
 
  velocity.x = x_a;
58
 
  velocity.y = y_a;
59
 
  size  = 1.0;
60
 
  size_add = (frand() - 0.2) / 35;
61
 
  livetime = 50 + (rand() % 25);
62
 
}
63
 
 
64
 
void
65
 
PinguParticle::draw_offset(int ofx, int ofy, float s)
66
 
{
67
 
  surface.put_screen(int(pos.x + ofx), int(pos.y + ofy));
68
 
  /* Particle resizeing is disabled, because it is to slow
69
 
  if (s * size == 1.0) {
70
 
    surface->put_screen(x_pos + ofx, y_pos + ofy);
71
 
  } else {
72
 
    int width  = (int)(surface->get_width() * s * size);
73
 
    int height = (int)(surface->get_height() * s * size);
74
 
    surface->put_screen((int)((x_pos + ofx) * s) - width/2, (int)((y_pos + ofy) * s) - height/2,
75
 
                        width, height);
76
 
  }
77
 
  */
78
 
}
79
 
 
80
 
void
81
 
PinguParticle::update(float delta)
82
 
{
83
 
  float tmp_x_add = 0.0;
84
 
  float tmp_y_add = 0.0;
85
 
  
86
 
  // Simulated gravity
87
 
  velocity.y += 0.2f;
88
 
  
89
 
  if (velocity.y > 0)
90
 
    {
91
 
      for (tmp_y_add = velocity.y; tmp_y_add >= 1.0; tmp_y_add -= 1.0)
92
 
        {
93
 
          if (world->get_colmap()->getpixel((int)pos.x, (int)pos.y)) 
94
 
            {
95
 
              velocity.y = velocity.y * -y_collision_decrease;
96
 
              tmp_y_add = -tmp_y_add;
97
 
              pos.y -= 1.0;
98
 
              break;
99
 
            }
100
 
          pos.y += 1.0;
101
 
        }
102
 
      pos.y += tmp_y_add;
103
 
    }
104
 
  else
105
 
    {
106
 
      for (tmp_y_add = velocity.y; tmp_y_add <= -1.0; tmp_y_add += 1.0)
107
 
        {
108
 
          if (world->get_colmap()->getpixel((int)pos.x, (int)pos.y)) {
109
 
            velocity.y = velocity.y * -y_collision_decrease;
110
 
            tmp_y_add = -tmp_y_add;
111
 
            pos.y += 1.0;
112
 
            break;
113
 
          }
114
 
          pos.y -= 1.0;
115
 
        }
116
 
      pos.y += tmp_y_add;
117
 
    }
118
 
 
119
 
  if (velocity.x > 0)
120
 
    {
121
 
      for (tmp_x_add = velocity.x; tmp_x_add >= 1.0; tmp_x_add -= 1.0)
122
 
        {
123
 
          if (world->get_colmap()->getpixel((int)pos.x, (int)pos.y)) {
124
 
            velocity.x = velocity.x * -x_collision_decrease;
125
 
            tmp_x_add = -tmp_x_add;
126
 
            pos.x -= 1.0;
127
 
            break;
128
 
          }
129
 
          pos.x += 1.0;
130
 
        }
131
 
      pos.x += tmp_x_add;
132
 
    }
133
 
  else
134
 
    {
135
 
      for (tmp_x_add = velocity.x; tmp_x_add <= -1.0; tmp_x_add += 1.0)
136
 
        {
137
 
          if (world->get_colmap()->getpixel((int)pos.x, (int)pos.y)) {
138
 
            velocity.x = velocity.x * -x_collision_decrease;
139
 
            tmp_x_add = -tmp_x_add;
140
 
            pos.x += 1.0;
141
 
            break;
142
 
          }
143
 
          pos.x -= 1.0;
144
 
        }
145
 
      pos.x += tmp_x_add;
146
 
    }
147
 
 
148
 
  // Simple physics
149
 
#if 0
150
 
  size += size_add;
151
 
  
152
 
  pos.x += x_add * size;
153
 
  pos.y += y_add * size;
154
 
  y_add += 0.1;
155
 
#endif
156
 
 
157
 
  if (livetime > 0)
158
 
    --livetime;
159
 
}
160
 
 
161
 
/* EOF */