1
// $Id: PinguParticle.cc,v 1.15 2001/08/12 18:36:42 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 "../ColMap.hh"
21
#include "../World.hh"
23
#include "../PingusResource.hh"
24
#include "PinguParticle.hh"
26
static const float x_collision_decrease = 0.3f;
27
static const float y_collision_decrease = 0.6f;
29
CL_Surface PinguParticle::sur;
31
PinguParticle::PinguParticle()
33
surface = PingusResource::load_surface("Particles/particle", "pingus");
34
livetime = 50 + (rand() % 25);
36
size_add = (frand() - 0.2) / 35;
39
PinguParticle::PinguParticle(int x, int y, float x_a, float y_a)
40
: Particle (x, y, x_a, y_a)
43
size_add = (frand() - 0.2) / 35;
44
livetime = 50 + (rand() % 50);
49
sur = PingusResource::load_surface("Particles/particle", "pingus");
53
PinguParticle::init(int x, int y, float x_a, float y_a)
60
size_add = (frand() - 0.2) / 35;
61
livetime = 50 + (rand() % 25);
65
PinguParticle::draw_offset(int ofx, int ofy, float s)
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);
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,
81
PinguParticle::update(float delta)
83
float tmp_x_add = 0.0;
84
float tmp_y_add = 0.0;
91
for (tmp_y_add = velocity.y; tmp_y_add >= 1.0; tmp_y_add -= 1.0)
93
if (world->get_colmap()->getpixel((int)pos.x, (int)pos.y))
95
velocity.y = velocity.y * -y_collision_decrease;
96
tmp_y_add = -tmp_y_add;
106
for (tmp_y_add = velocity.y; tmp_y_add <= -1.0; tmp_y_add += 1.0)
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;
121
for (tmp_x_add = velocity.x; tmp_x_add >= 1.0; tmp_x_add -= 1.0)
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;
135
for (tmp_x_add = velocity.x; tmp_x_add <= -1.0; tmp_x_add += 1.0)
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;
152
pos.x += x_add * size;
153
pos.y += y_add * size;