1
// $Id: sprite.cxx,v 1.13 2002/12/28 16:31:37 torangan Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 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.
23
#include "pingus_resource.hxx"
25
#include "globals.hxx"
39
Sprite::Sprite (const Sprite& sprite) :
41
frames_per_second (sprite.frames_per_second),
43
direction (sprite.direction),
44
looptype (sprite.looptype),
45
is_finished (sprite.is_finished),
46
x_align (sprite.x_align),
47
y_align (sprite.y_align)
52
Sprite::operator= (const Sprite& sprite)
58
frames_per_second = sprite.frames_per_second;
60
direction = sprite.direction;
61
looptype = sprite.looptype;
62
is_finished = sprite.is_finished;
63
x_align = sprite.x_align;
64
y_align = sprite.y_align;
69
Sprite::Sprite (std::string arg_sur_name,
70
std::string arg_datafile,
71
float arg_frames_per_second,
72
Sprite::Direction dir,
73
LoopType arg_loop_type)
75
frames_per_second (arg_frames_per_second),
76
sur(PingusResource::load_surface (arg_sur_name, arg_datafile)),
78
looptype (arg_loop_type),
80
x_align (0), y_align (0)
84
Sprite::Sprite (const CL_Surface& arg_sur,
85
float arg_frames_per_second,
86
Sprite::Direction dir,
87
LoopType arg_loop_type)
89
frames_per_second (arg_frames_per_second),
91
looptype (arg_loop_type),
93
x_align (0), y_align (0)
98
Sprite::Sprite (const ResDescriptor& desc,
99
float arg_frames_per_second,
100
Sprite::Direction dir,
101
LoopType arg_loop_type)
103
frames_per_second (arg_frames_per_second),
105
looptype (arg_loop_type),
107
x_align (0), y_align (0)
109
sur = PingusResource::load_surface (desc);
113
Sprite::put_screen (int x, int y)
119
//std::cout << "Frame: " << round(frame) << " " << frame << " " << max_frames () << std::endl;
124
sur.put_screen (x + x_align, y + y_align, round(frame));
127
sur.put_screen (x + x_align, y + y_align, round(frame));
130
sur.put_screen (x + x_align, y + y_align, round(frame) + max_frames ());
133
std::cout << "Direction: " << direction << std::endl;
140
Sprite::put_screen (const Vector& pos)
142
put_screen (int(pos.x), int(pos.y));
147
Sprite::set_align (int arg_x, int arg_y)
154
Sprite::set_align_center ()
156
x_align = -int(sur.get_width ())/2;
157
y_align = -int(sur.get_height ())/2;
161
Sprite::set_align_center_bottom ()
163
x_align = -int(sur.get_width ())/2;
164
y_align = -int(sur.get_height ());
169
Sprite::next_frame ()
173
if (round(frame) >= int(sur.get_num_frames ()))
180
Sprite::previous_frame ()
184
if (round(frame) < 0)
185
frame = sur.get_num_frames () - 1;
196
Sprite::get_progress ()
198
return float(frame)/max_frames ();
202
Sprite::max_frames ()
207
return sur.get_num_frames ();
210
return sur.get_num_frames ()/2;
220
// FIXME: game_speed is incorrect, but should work
221
update(game_speed / 1000.0f);
225
Sprite::update (float delta)
230
// The sprite contains no frames, so we have nothing to update
231
if (max_frames () <= 1)
237
frame += frames_per_second * delta;
239
if (round(frame) < 0) {
240
std::cout << "frame below zero: " << frame << std::endl;
241
frame = (max_frames ()-1.0f);
244
if (round(frame) >= max_frames ()) {
251
frame += frames_per_second * delta;
252
if (round(frame) >= max_frames ())
255
frame = max_frames () - 1;
274
assert (!"Wrong looptype!");
287
Sprite::get_surface ()
293
Sprite::set_frame (int n)