3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@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.
31 #include "sprite_manager.h"
32 #include "resources.h"
37 Sprite* img_iceflower;
40 #define GROWUP_SPEED 1.0f
42 #define BULLET_STARTING_YM 0
46 Bullet::init(float x, float y, float xm, Direction dir)
54 base.xm = BULLET_XM + xm;
59 base.xm = -BULLET_XM + xm;
63 base.ym = BULLET_STARTING_YM;
70 std::vector<Bullet>& bullets = World::current()->bullets;
71 for(std::vector<Bullet>::iterator i = bullets.begin();
72 i != bullets.end(); ++i) {
83 Bullet::action(double frame_ratio)
89 base.x = base.x + base.xm * frame_ratio;
90 base.y = base.y + base.ym * frame_ratio;
92 collision_swept_object_map(&old_base,&base);
94 if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
100 else if (base.ym < -9)
104 base.ym = base.ym + 0.5 * frame_ratio;
106 if (base.x < scroll_x ||
107 base.x > scroll_x + screen->w ||
109 base.y > screen->h ||
110 issolid(base.x + 4, base.y + 2) ||
111 issolid(base.x, base.y + 2))
121 if (base.x >= scroll_x - base.width &&
122 base.x <= scroll_x + screen->w)
124 img_bullet->draw(base.x - scroll_x, base.y);
129 Bullet::collision(int c_object)
131 if(c_object == CO_BADGUY) {
137 Upgrade::init(float x_, float y_, Direction dir_, UpgradeKind kind_)
149 physic.enable_gravity(false);
151 if(kind == UPGRADE_1UP || kind == UPGRADE_HERRING) {
152 physic.set_velocity(dir == LEFT ? -1 : 1, 4);
153 physic.enable_gravity(true);
155 } else if (kind == UPGRADE_ICEFLOWER) {
157 } else if (kind == UPGRADE_GROWUP) {
158 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
160 physic.set_velocity(dir == LEFT ? -2 : 2, 0);
167 std::vector<Upgrade>& upgrades = World::current()->upgrades;
168 for(std::vector<Upgrade>::iterator i = upgrades.begin();
169 i != upgrades.end(); ++i) {
170 if( & (*i) == this) {
180 Upgrade::action(double frame_ratio)
182 if (kind == UPGRADE_ICEFLOWER || kind == UPGRADE_GROWUP) {
183 if (base.height < 32) {
185 base.height = base.height + 0.7 * frame_ratio;
193 /* Off screen? Kill it! */
194 if(base.x < scroll_x - base.width || base.y > screen->h) {
200 physic.apply(frame_ratio, base.x, base.y);
201 if(kind == UPGRADE_GROWUP) {
202 collision_swept_object_map(&old_base, &base);
206 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
208 if(physic.get_velocity_y() != 0) {
209 if(issolid(base.x, base.y + base.height)) {
210 base.y = int(base.y / 32) * 32;
212 if(kind == UPGRADE_GROWUP) {
213 physic.enable_gravity(false);
214 physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
215 } else if(kind == UPGRADE_HERRING) {
216 physic.set_velocity(dir == LEFT ? -2 : 2, 3);
220 if((physic.get_velocity_x() < 0
221 && !issolid(base.x+base.width, base.y + base.height))
222 || (physic.get_velocity_x() > 0
223 && !issolid(base.x, base.y + base.height))) {
224 physic.enable_gravity(true);
229 // horizontal bounce?
230 if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
231 if ( (physic.get_velocity_x() < 0
232 && issolid(base.x, (int) base.y + base.height/2))
233 || (physic.get_velocity_x() > 0
234 && issolid(base.x + base.width, (int) base.y + base.height/2))) {
235 physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
236 dir = dir == LEFT ? RIGHT : LEFT;
245 if (base.height < 32)
249 dest.x = (int)(base.x - scroll_x);
250 dest.y = (int)(base.y + 32 - base.height);
252 dest.h = (int)base.height;
254 if (kind == UPGRADE_GROWUP)
255 img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
256 else if (kind == UPGRADE_ICEFLOWER)
257 img_iceflower->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
258 else if (kind == UPGRADE_HERRING)
259 img_star->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
260 else if (kind == UPGRADE_1UP)
261 img_1up->draw_part( 0, 0, dest.x, dest.y, dest.w, dest.h);
265 if (kind == UPGRADE_GROWUP)
268 base.x - scroll_x, base.y);
270 else if (kind == UPGRADE_ICEFLOWER)
273 base.x - scroll_x, base.y);
275 else if (kind == UPGRADE_HERRING)
278 base.x - scroll_x, base.y);
280 else if (kind == UPGRADE_1UP)
282 img_1up->draw( base.x - scroll_x, base.y);
288 Upgrade::collision(void* p_c_object, int c_object)
290 Player* pplayer = NULL;
295 /* Remove the upgrade: */
297 /* p_c_object is CO_PLAYER, so assign it to pplayer */
298 pplayer = (Player*) p_c_object;
300 /* Affect the player: */
302 if (kind == UPGRADE_GROWUP)
304 play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
306 pplayer->base.height = 64;
307 pplayer->base.y -= 32;
308 if(collision_object_map(pplayer->base))
310 pplayer->base.height = 32;
311 pplayer->base.y += 32;
312 pplayer->duck = true;
315 else if (kind == UPGRADE_ICEFLOWER)
317 play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
318 pplayer->got_coffee = true;
320 pplayer->base.height = 64;
321 pplayer->base.y -= 32;
322 if(collision_object_map(pplayer->base))
324 pplayer->base.height = 32;
325 pplayer->base.y += 32;
326 pplayer->duck = true;
329 else if (kind == UPGRADE_HERRING)
331 play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
332 pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
333 World::current()->play_music(HERRING_MUSIC);
335 else if (kind == UPGRADE_1UP)
337 if(player_status.lives < MAX_LIVES) {
338 player_status.lives++;
339 play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER);
348 void load_special_gfx()
350 img_growup = sprite_manager->load("egg");
351 img_iceflower = sprite_manager->load("iceflower");
352 img_star = sprite_manager->load("star");
353 img_1up = sprite_manager->load("1up");
355 img_bullet = sprite_manager->load("bullet");
358 void free_special_gfx()