4 // Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "sprite_manager.h"
28 #include "resources.h"
32 BouncyDistro::init(float x, float y)
40 BouncyDistro::action(double frame_ratio)
42 base.y = base.y + base.ym * frame_ratio;
44 base.ym += 0.1 * frame_ratio;
48 std::vector<BouncyDistro*>::iterator i
49 = std::find(World::current()->bouncy_distros.begin(),
50 World::current()->bouncy_distros.end(),
52 if (i != World::current()->bouncy_distros.end())
53 World::current()->bouncy_distros.erase(i);
60 img_distro[0]->draw(base.x - scroll_x,
66 BrokenBrick::init(Tile* tile_, float x, float y, float xm, float ym)
79 BrokenBrick::action(double frame_ratio)
81 base.x = base.x + base.xm * frame_ratio;
82 base.y = base.y + base.ym * frame_ratio;
86 std::vector<BrokenBrick*>::iterator i
87 = std::find(World::current()->broken_bricks.begin(),
88 World::current()->broken_bricks.end(),
90 if (i != World::current()->broken_bricks.end())
91 World::current()->broken_bricks.erase(i);
104 dest.x = (int)(base.x - scroll_x);
105 dest.y = (int)(base.y - scroll_y);
109 if (tile->images.size() > 0)
110 tile->images[0]->draw_part(src.x,src.y,dest.x,dest.y,dest.w,dest.h);
114 BouncyBrick::init(float x, float y)
119 offset_m = -BOUNCY_BRICK_SPEED;
120 shape = World::current()->get_level()->gettileid(x, y);
124 BouncyBrick::action(double frame_ratio)
126 offset = (offset + offset_m * frame_ratio);
129 if (offset < -BOUNCY_BRICK_MAX_OFFSET)
130 offset_m = BOUNCY_BRICK_SPEED;
136 std::vector<BouncyBrick*>::iterator i
137 = std::find(World::current()->bouncy_bricks.begin(),
138 World::current()->bouncy_bricks.end(),
140 if (i != World::current()->bouncy_bricks.end())
141 World::current()->bouncy_bricks.erase(i);
150 if (base.x >= scroll_x - 32 &&
151 base.x <= scroll_x + screen->w)
153 dest.x = (int)(base.x - scroll_x);
154 dest.y = (int)(base.y - scroll_y);
158 Level* plevel = World::current()->get_level();
160 // FIXME: overdrawing hack to clean the tile from the screen to
161 // paint it later at on offseted position
162 if(plevel->bkgd_image[0] == '\0')
164 fillrect(base.x - scroll_x, base.y - scroll_y,
166 plevel->bkgd_top.red, plevel->bkgd_top.green, plevel->bkgd_top.blue, 0);
167 // FIXME: doesn't respect the gradient, futhermore is this necessary at all??
171 int s = ((int)scroll_x / 2)%640;
172 plevel->img_bkgd->draw_part(dest.x + s, dest.y,
173 dest.x, dest.y,dest.w,dest.h);
176 Tile::draw(base.x - scroll_x,
177 base.y - scroll_y + offset,
183 FloatingScore::init(float x, float y, int s)
193 FloatingScore::action(double frame_ratio)
195 base.y = base.y - 2 * frame_ratio;
199 std::vector<FloatingScore*>::iterator i
200 = std::find(World::current()->floating_scores.begin(),
201 World::current()->floating_scores.end(),
203 if (i != World::current()->floating_scores.end())
204 World::current()->floating_scores.erase(i);
209 FloatingScore::draw()
212 sprintf(str, "%d", value);
213 gold_text->draw(str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1);
218 #define TRAMPOLINE_FRAMES 4
219 Sprite *img_trampoline[TRAMPOLINE_FRAMES];
221 void load_object_gfx()
223 for (int i = 0; i < TRAMPOLINE_FRAMES; i++)
225 char sprite_name[16];
226 sprintf(sprite_name, "trampoline-%i", i+1);
227 img_trampoline[i] = sprite_manager->load(sprite_name);
232 Trampoline::init(float x, float y)
247 img_trampoline[frame]->draw((int)base.x, (int)base.y);
252 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75, 75, 0, 150);
256 Trampoline::action(double frame_ratio)
258 physic.apply(frame_ratio, base.x, base.y);
263 if (issolid(base.x + base.width/2, base.y + base.height))
265 base.y = int((base.y + base.height)/32) * 32 - base.height;
267 physic.enable_gravity(false);
268 physic.set_velocity_y(0.0f);
270 physic.set_velocity_x(0);
274 physic.enable_gravity(true);
277 else // Player is carrying us around
279 /* FIXME: The trampoline object shouldn't know about pplayer objects. */
280 /* If we're holding the iceblock */
281 Player& tux = *World::current()->get_tux();
282 Direction dir = tux.dir;
286 base.x = tux.base.x + 16;
287 base.y = tux.base.y + tux.base.height/1.5 - base.height;
289 else /* facing left */
291 base.x = tux.base.x - 16;
292 base.y = tux.base.y + tux.base.height/1.5 - base.height;
295 if(collision_object_map(base))
298 base.y = tux.base.y + tux.base.height/1.5 - base.height;
304 Trampoline::collision(void *p_c_object, int c_object, CollisionType type)
306 Player* pplayer_c = NULL;
310 pplayer_c = (Player*) p_c_object;
312 if (type == COLLISION_NORMAL)
314 // Pick up if HELD (done in Player)
317 else if (type == COLLISION_SQUISH)
319 int squish_amount = (32 - (int)pplayer_c->base.y % 32);
321 if (squish_amount < 24)
323 else if (squish_amount < 28)
325 else if (squish_amount < 30)
330 if (squish_amount < 24)
331 pplayer_c->physic.set_velocity_y(power);
332 else if (pplayer_c->physic.get_velocity_y() < 0)
333 pplayer_c->physic.set_velocity_y(-squish_amount/32);