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 char sprite_name[16];
225 for (int i = 0; i < TRAMPOLINE_FRAMES; i++)
227 sprintf(sprite_name, "trampoline-%i", i+1);
228 img_trampoline[i] = sprite_manager->load(sprite_name);
233 Trampoline::init(float x, float y)
248 img_trampoline[frame]->draw((int)base.x, (int)base.y);
253 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75, 75, 0, 150);
257 Trampoline::action(double frame_ratio)
259 // TODO: Remove if we're too far off the screen
264 if (issolid(base.x + base.width/2, base.y + base.height))
266 base.y = int((base.y + base.height)/32) * 32 - base.height;
268 physic.enable_gravity(false);
269 physic.set_velocity_y(0.0f);
271 physic.set_velocity_x(0);
275 physic.enable_gravity(true);
278 else // Player is carrying us around
280 /* FIXME: The trampoline object shouldn't know about pplayer objects. */
281 /* If we're holding the iceblock */
282 Player& tux = *World::current()->get_tux();
283 Direction dir = tux.dir;
287 base.x = tux.base.x + 16;
288 base.y = tux.base.y + tux.base.height/1.5 - base.height;
290 else /* facing left */
292 base.x = tux.base.x - 16;
293 base.y = tux.base.y + tux.base.height/1.5 - base.height;
296 if(collision_object_map(base))
299 base.y = tux.base.y + tux.base.height/1.5 - base.height;
303 physic.apply(frame_ratio, base.x, base.y);
304 collision_swept_object_map(&old_base, &base);
308 Trampoline::collision(void *p_c_object, int c_object, CollisionType type)
310 Player* pplayer_c = NULL;
314 pplayer_c = (Player*) p_c_object;
316 if (type == COLLISION_NORMAL)
318 // Pick up if HELD (done in Player)
321 else if (type == COLLISION_SQUISH)
323 int squish_amount = (32 - (int)pplayer_c->base.y % 32);
325 if (squish_amount < 24)
327 else if (squish_amount < 28)
329 else if (squish_amount < 30)
334 if (squish_amount < 20)
335 pplayer_c->physic.set_velocity_y(power);
336 else if (pplayer_c->physic.get_velocity_y() < 0)
337 pplayer_c->physic.set_velocity_y(-squish_amount/32);