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"
31 BouncyDistro::init(float x, float y)
39 BouncyDistro::action(double frame_ratio)
41 base.y = base.y + base.ym * frame_ratio;
43 base.ym += 0.1 * frame_ratio;
47 std::vector<BouncyDistro*>::iterator i
48 = std::find(World::current()->bouncy_distros.begin(),
49 World::current()->bouncy_distros.end(),
51 if (i != World::current()->bouncy_distros.end())
52 World::current()->bouncy_distros.erase(i);
59 img_distro[0]->draw(base.x - scroll_x,
65 BrokenBrick::init(Tile* tile_, float x, float y, float xm, float ym)
78 BrokenBrick::action(double frame_ratio)
80 base.x = base.x + base.xm * frame_ratio;
81 base.y = base.y + base.ym * frame_ratio;
85 std::vector<BrokenBrick*>::iterator i
86 = std::find(World::current()->broken_bricks.begin(),
87 World::current()->broken_bricks.end(),
89 if (i != World::current()->broken_bricks.end())
90 World::current()->broken_bricks.erase(i);
103 dest.x = (int)(base.x - scroll_x);
104 dest.y = (int)(base.y - scroll_y);
108 if (tile->images.size() > 0)
109 tile->images[0]->draw_part(src.x,src.y,dest.x,dest.y,dest.w,dest.h);
113 BouncyBrick::init(float x, float y)
118 offset_m = -BOUNCY_BRICK_SPEED;
119 shape = World::current()->get_level()->gettileid(x, y);
123 BouncyBrick::action(double frame_ratio)
125 offset = (offset + offset_m * frame_ratio);
128 if (offset < -BOUNCY_BRICK_MAX_OFFSET)
129 offset_m = BOUNCY_BRICK_SPEED;
135 std::vector<BouncyBrick*>::iterator i
136 = std::find(World::current()->bouncy_bricks.begin(),
137 World::current()->bouncy_bricks.end(),
139 if (i != World::current()->bouncy_bricks.end())
140 World::current()->bouncy_bricks.erase(i);
149 if (base.x >= scroll_x - 32 &&
150 base.x <= scroll_x + screen->w)
152 dest.x = (int)(base.x - scroll_x);
153 dest.y = (int)(base.y - scroll_y);
157 Level* plevel = World::current()->get_level();
159 // FIXME: overdrawing hack to clean the tile from the screen to
160 // paint it later at on offseted position
161 if(plevel->bkgd_image[0] == '\0')
163 fillrect(base.x - scroll_x, base.y - scroll_y,
165 plevel->bkgd_top.red, plevel->bkgd_top.green, plevel->bkgd_top.blue, 0);
166 // FIXME: doesn't respect the gradient, futhermore is this necessary at all??
170 int s = ((int)scroll_x / 2)%640;
171 plevel->img_bkgd->draw_part(dest.x + s, dest.y,
172 dest.x, dest.y,dest.w,dest.h);
175 Tile::draw(base.x - scroll_x,
176 base.y - scroll_y + offset,
182 FloatingScore::init(float x, float y, int s)
192 FloatingScore::action(double frame_ratio)
194 base.y = base.y - 2 * frame_ratio;
198 std::vector<FloatingScore*>::iterator i
199 = std::find(World::current()->floating_scores.begin(),
200 World::current()->floating_scores.end(),
202 if (i != World::current()->floating_scores.end())
203 World::current()->floating_scores.erase(i);
208 FloatingScore::draw()
211 sprintf(str, "%d", value);
212 gold_text->draw(str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1);
217 #define TRAMPOLINE_FRAMES 4
218 Sprite *img_trampoline[TRAMPOLINE_FRAMES];
220 void load_object_gfx()
222 for (int i = 0; i < TRAMPOLINE_FRAMES; i++)
224 char sprite_name[16];
225 sprintf(sprite_name, "trampoline-%i", i+1);
226 img_trampoline[i] = sprite_manager->load(sprite_name);
231 Trampoline::init(float x, float y)
243 img_trampoline[0]->draw((int)base.x, (int)base.y);
246 fillrect(base.x - scroll_x, base.y - scroll_y, base.width, base.height, 75, 75, 0, 150);
250 Trampoline::action(double frame_ratio)
252 physic.apply(frame_ratio, base.x, base.y);
255 if (issolid(base.x + base.width/2, base.y + base.height))
257 base.y = int((base.y + base.height)/32) * 32 - base.height;
259 physic.enable_gravity(false);
260 physic.set_velocity_y(0.0f);
263 physic.enable_gravity(true);
271 // - compress springs (reduce height)
274 Trampoline::collision(void *p_c_object, int c_object, CollisionType type)
276 Player* pplayer_c = NULL;
280 pplayer_c = (Player*) p_c_object;
282 if (type == COLLISION_NORMAL)
284 // TODO: Pick up if HELD
287 else if (type == COLLISION_SQUISH)
289 // TODO: compress springs
290 // TODO: launch tux, if necessary
292 base.y = pplayer_c->base.y + pplayer_c->base.height;
293 base.height = (32 - (int)pplayer_c->base.y % 32);
294 if (base.height < 16)
298 pplayer_c->physic.set_velocity_y(8);