4 // Copyright (C) 2004 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.
24 Sprite::Sprite(lisp_object_t* cur)
28 LispReader reader(cur);
30 reader.read_int("x-hotspot", &x_hotspot);
31 reader.read_int("y-hotspot", &y_hotspot);
32 reader.read_float("fps", &fps);
33 std::vector<std::string> images;
34 reader.read_string_vector("images", &images);
35 surfaces.resize(images.size());
37 for(std::vector<std::string>::size_type i = 0; i < images.size(); ++i)
39 surfaces[i] = new Surface(datadir + "/images/" + images[i], USE_ALPHA);
44 Sprite::init_defaults()
50 frame_delay = 1000.0f/fps;
54 Sprite::update(float delta)
57 //std::cout << "Delta: " << delta << std::endl;
61 Sprite::draw(int x, int y)
63 unsigned int frame = static_cast<int>(fmodf(time, surfaces.size()*frame_delay)/frame_delay);
66 std::cout << "Frame: "
69 << surfaces.size() << " "
71 << static_cast<int>(fmodf(time, surfaces.size()*frame_delay)/frame_delay) << std::endl;*/
72 if (frame < surfaces.size())
73 surfaces[frame]->draw(x - x_hotspot, y - y_hotspot);