First try to switch to 800x600.
[supertux.git] / src / world.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 //  02111-1307, USA.
22
23 #include <iostream>
24 #include <math.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "globals.h"
28 #include "scene.h"
29 #include "screen.h"
30 #include "defines.h"
31 #include "world.h"
32 #include "level.h"
33 #include "tile.h"
34 #include "resources.h"
35
36 Surface* img_distro[4];
37
38 World* World::current_ = 0;
39
40 World::World(const std::string& filename)
41 {
42   // FIXME: Move this to action and draw and everywhere else where the
43   // world calls child functions
44   current_ = this;
45
46   level = new Level(filename);
47   tux.init();
48
49   set_defaults();
50
51   get_level()->load_gfx();
52   activate_bad_guys();
53   activate_particle_systems();
54   get_level()->load_song();
55
56   apply_bonuses();
57
58   scrolling_timer.init(true);
59 }
60
61 World::World(const std::string& subset, int level_nr)
62 {
63   // FIXME: Move this to action and draw and everywhere else where the
64   // world calls child functions
65   current_ = this;
66
67   level = new Level(subset, level_nr);
68   tux.init();
69
70   set_defaults();
71
72   get_level()->load_gfx();
73   activate_bad_guys();
74   activate_particle_systems();
75   get_level()->load_song();
76
77   apply_bonuses();
78
79   scrolling_timer.init(true);
80 }
81
82 void
83 World::apply_bonuses()
84 {
85   // Apply bonuses from former levels
86   switch (player_status.bonus)
87     {
88     case PlayerStatus::NO_BONUS:
89       break;
90
91     case PlayerStatus::FLOWER_BONUS:
92       tux.got_power = tux.FIRE_POWER;  // FIXME: add ice power to here
93       // fall through
94
95     case PlayerStatus::GROWUP_BONUS:
96       // FIXME: Move this to Player class
97       tux.size = BIG;
98       tux.base.height = 64;
99       tux.base.y -= 32;
100       break;
101     }
102 }
103
104 World::~World()
105 {
106   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
107     delete *i;
108
109   for (ParticleSystems::iterator i = particle_systems.begin();
110           i != particle_systems.end(); ++i)
111     delete *i;
112
113   for (std::vector<BouncyDistro*>::iterator i = bouncy_distros.begin();
114        i != bouncy_distros.end(); ++i)
115     delete *i;
116   
117   for (std::vector<BrokenBrick*>::iterator i = broken_bricks.begin();
118        i != broken_bricks.end(); ++i)
119     delete *i;
120   
121   for (std::vector<BouncyBrick*>::iterator i = bouncy_bricks.begin();
122        i != bouncy_bricks.end(); ++i)
123     delete *i;
124
125   for (std::vector<FloatingScore*>::iterator i = floating_scores.begin();
126        i != floating_scores.end(); ++i)
127     delete *i;
128   
129   delete level;
130 }
131
132 void
133 World::set_defaults()
134 {
135   // Set defaults: 
136   scroll_x = 0;
137
138   player_status.score_multiplier = 1;
139
140   counting_distros = false;
141   distro_counter = 0;
142
143   /* set current song/music */
144   currentmusic = LEVEL_MUSIC;
145 }
146
147 void
148 World::activate_bad_guys()
149 {
150   for (std::vector<BadGuyData>::iterator i = level->badguy_data.begin();
151        i != level->badguy_data.end();
152        ++i)
153     {
154       add_bad_guy(i->x, i->y, i->kind, i->stay_on_platform);
155     }
156 }
157
158 void
159 World::activate_particle_systems()
160 {
161   if (level->particle_system == "clouds")
162     {
163       particle_systems.push_back(new CloudParticleSystem);
164     }
165   else if (level->particle_system == "snow")
166     {
167       particle_systems.push_back(new SnowParticleSystem);
168     }
169   else if (level->particle_system != "")
170     {
171       st_abort("unknown particle system specified in level", "");
172     }
173 }
174
175 void
176 World::draw()
177 {
178   int y,x;
179
180   /* Draw the real background */
181   if(level->img_bkgd)
182     {
183       int s = (int)((float)scroll_x * ((float)level->bkgd_speed/100.0f)) % screen->w;
184       level->img_bkgd->draw_part(s, 0,0,0,level->img_bkgd->w - s, level->img_bkgd->h);
185       level->img_bkgd->draw_part(0, 0,screen->w - s ,0,s,level->img_bkgd->h);
186     }
187   else
188     {
189       drawgradient(level->bkgd_top, level->bkgd_bottom);
190     }
191     
192   /* Draw particle systems (background) */
193   std::vector<ParticleSystem*>::iterator p;
194   for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
195     {
196       (*p)->draw(scroll_x, 0, 0);
197     }
198
199 fprintf(stderr, "level->height: %i\n", level->height);
200 fprintf(stderr, "scroll_x: %i\n", scroll_x);
201 fprintf(stderr, "scroll_y: %i\n", scroll_y);
202   /* Draw background: */
203   for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y)
204     {
205 fprintf(stderr, "drawing row: %i\n", y);
206       for (x = 0; x < VISIBLE_TILES_X; ++x)
207         {
208 fprintf(stderr, "x: %i\n", x);
209           Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32),
210                      level->bg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]);
211         }
212     }
213
214   /* Draw interactive tiles: */
215   for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y)
216     {
217       for (x = 0; x < VISIBLE_TILES_X; ++x)
218         {
219           Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32),
220                      level->ia_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]);
221         }
222     }
223
224   /* (Bouncy bricks): */
225   for (unsigned int i = 0; i < bouncy_bricks.size(); ++i)
226     bouncy_bricks[i]->draw();
227
228   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
229     (*i)->draw();
230
231   tux.draw();
232
233   for (unsigned int i = 0; i < bullets.size(); ++i)
234     bullets[i].draw();
235
236   for (unsigned int i = 0; i < floating_scores.size(); ++i)
237     floating_scores[i]->draw();
238
239   for (unsigned int i = 0; i < upgrades.size(); ++i)
240     upgrades[i].draw();
241
242   for (unsigned int i = 0; i < bouncy_distros.size(); ++i)
243     bouncy_distros[i]->draw();
244
245   for (unsigned int i = 0; i < broken_bricks.size(); ++i)
246     broken_bricks[i]->draw();
247
248   /* Draw foreground: */
249   for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y)
250     {
251       for (x = 0; x < VISIBLE_TILES_X; ++x)
252         {
253           Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32),
254                      level->fg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]);
255         }
256     }
257
258   /* Draw particle systems (foreground) */
259   for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
260     {
261       (*p)->draw(scroll_x, 0, 1);
262     }
263 }
264
265 void
266 World::action(double frame_ratio)
267 {
268   tux.action(frame_ratio);
269   tux.check_bounds(level->back_scrolling, (bool)level->hor_autoscroll_speed);
270   scrolling(frame_ratio);
271
272   /* Handle bouncy distros: */
273   for (unsigned int i = 0; i < bouncy_distros.size(); i++)
274     bouncy_distros[i]->action(frame_ratio);
275
276   /* Handle broken bricks: */
277   for (unsigned int i = 0; i < broken_bricks.size(); i++)
278     broken_bricks[i]->action(frame_ratio);
279
280   // Handle all kinds of game objects
281   for (unsigned int i = 0; i < bouncy_bricks.size(); i++)
282     bouncy_bricks[i]->action(frame_ratio);
283   
284   for (unsigned int i = 0; i < floating_scores.size(); i++)
285     floating_scores[i]->action(frame_ratio);
286
287   for (unsigned int i = 0; i < bullets.size(); ++i)
288     bullets[i].action(frame_ratio);
289   
290   for (unsigned int i = 0; i < upgrades.size(); i++)
291     upgrades[i].action(frame_ratio);
292
293   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
294     (*i)->action(frame_ratio);
295
296   /* update particle systems */
297   std::vector<ParticleSystem*>::iterator p;
298   for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
299     {
300       (*p)->simulate(frame_ratio);
301     }
302
303   /* Handle all possible collisions. */
304   collision_handler();
305   
306   // Cleanup marked badguys
307   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end();
308       /* ++i handled at end of the loop */) {
309     if ((*i)->is_removable()) {
310       delete *i;
311       i =  bad_guys.erase(i);
312     } else {
313       ++i;
314     }
315   }
316 }
317
318 /* the space that it takes for the screen to start scrolling, regarding */
319 /* screen bounds (in pixels) */
320 // should be higher than screen->w/2 (400)
321 #define X_SPACE (500-16)
322 // should be less than screen->h/2 (300)
323 #define Y_SPACE 250
324
325 // the time it takes to move the camera (in ms)
326 #define CHANGE_DIR_SCROLL_SPEED 2000
327
328 /* This functions takes cares of the scrolling */
329 void World::scrolling(double frame_ratio)
330 {
331   /* Y-axis scrolling */
332
333   float tux_pos_y = tux.base.y + (tux.base.height/2);
334
335   if (scroll_y < tux_pos_y - (screen->h - Y_SPACE))
336     scroll_y = tux_pos_y - (screen->h - Y_SPACE);
337   else if (scroll_y > tux_pos_y - Y_SPACE)
338     scroll_y = tux_pos_y - Y_SPACE;
339
340   // this code prevent the screen to scroll before the start or after the level's end
341   if(scroll_y < 0)
342     scroll_y = 0;
343   if(scroll_y > level->height * 32 - screen->h)
344     scroll_y = level->height * 32 - screen->h;
345
346   /* X-axis scrolling */
347
348   /* Auto scrolling */
349   if(level->hor_autoscroll_speed)
350   {
351     scroll_x += level->hor_autoscroll_speed * frame_ratio;
352     return;
353   }
354
355
356   /* Horizontal backscrolling */
357   float tux_pos_x = tux.base.x + (tux.base.width/2);
358
359   if(tux.old_dir != tux.dir && level->back_scrolling)
360     scrolling_timer.start(CHANGE_DIR_SCROLL_SPEED);
361
362   bool right = false;
363   bool left = false;
364   if (tux.physic.get_velocity_x() > 0)
365     right = true;
366   else if (tux.physic.get_velocity_x() < 0)
367     left = true;
368   else
369     {
370     if (tux.dir == RIGHT)
371       right = true;
372     else
373       left = true;
374     }
375
376   if(scrolling_timer.check())
377   {
378     float final_scroll_x;
379     if (right)
380       final_scroll_x = tux_pos_x - (screen->w - X_SPACE);
381     else
382       final_scroll_x = tux_pos_x - X_SPACE;
383
384     scroll_x +=   (final_scroll_x - scroll_x)
385                 / (frame_ratio * (CHANGE_DIR_SCROLL_SPEED / 100))
386                 + (tux.physic.get_velocity_x() * frame_ratio + tux.physic.get_acceleration_x() * frame_ratio * frame_ratio);
387     // std::cerr << tux_pos_x << " " << final_scroll_x << " " << scroll_x << std::endl;
388
389   }
390   else
391   {
392     if (right && scroll_x < tux_pos_x - (screen->w - X_SPACE))
393       scroll_x = tux_pos_x - (screen->w - X_SPACE);
394     else if (left && scroll_x > tux_pos_x - X_SPACE && level->back_scrolling)
395       scroll_x = tux_pos_x - X_SPACE;
396   }
397
398   // this code prevent the screen to scroll before the start or after the level's end
399   if(scroll_x < 0)
400     scroll_x = 0;
401   if(scroll_x > level->width * 32 - screen->w)
402     scroll_x = level->width * 32 - screen->w;
403 }
404
405 void
406 World::collision_handler()
407 {
408   // CO_BULLET & CO_BADGUY check
409   for(unsigned int i = 0; i < bullets.size(); ++i)
410     {
411       for (BadGuys::iterator j = bad_guys.begin(); j != bad_guys.end(); ++j)
412         {
413           if((*j)->dying != DYING_NOT)
414             continue;
415           
416           if(rectcollision(bullets[i].base, (*j)->base))
417             {
418               // We have detected a collision and now call the
419               // collision functions of the collided objects.
420               // collide with bad_guy first, since bullet_collision will
421               // delete the bullet
422               (*j)->collision(&bullets[i], CO_BULLET);
423               bullets[i].collision(CO_BADGUY);
424               break; // bullet is invalid now, so break
425             }
426         }
427     }
428
429   /* CO_BADGUY & CO_BADGUY check */
430   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
431     {
432       if((*i)->dying != DYING_NOT)
433         continue;
434       
435       BadGuys::iterator j = i;
436       ++j;
437       for (; j != bad_guys.end(); ++j)
438         {
439           if(j == i || (*j)->dying != DYING_NOT)
440             continue;
441
442           if(rectcollision((*i)->base, (*j)->base))
443             {
444               // We have detected a collision and now call the
445               // collision functions of the collided objects.
446               (*j)->collision(*i, CO_BADGUY);
447               (*i)->collision(*j, CO_BADGUY);
448             }
449         }
450     }
451
452   if(tux.dying != DYING_NOT) return;
453     
454   // CO_BADGUY & CO_PLAYER check 
455   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
456     {
457       if((*i)->dying != DYING_NOT)
458         continue;
459       
460       if(rectcollision_offset((*i)->base, tux.base, 0, 0))
461         {
462           // We have detected a collision and now call the collision
463           // functions of the collided objects.
464           if (tux.previous_base.y < tux.base.y &&
465               tux.previous_base.y + tux.previous_base.height 
466               < (*i)->base.y + (*i)->base.height/2
467               && !tux.invincible_timer.started())
468             {
469               (*i)->collision(&tux, CO_PLAYER, COLLISION_SQUISH);
470             }
471           else
472             {
473               tux.collision(*i, CO_BADGUY);
474               (*i)->collision(&tux, CO_PLAYER, COLLISION_NORMAL);
475             }
476         }
477     }
478
479   // CO_UPGRADE & CO_PLAYER check
480   for(unsigned int i = 0; i < upgrades.size(); ++i)
481     {
482       if(rectcollision(upgrades[i].base, tux.base))
483         {
484           // We have detected a collision and now call the collision
485           // functions of the collided objects.
486           upgrades[i].collision(&tux, CO_PLAYER, COLLISION_NORMAL);
487         }
488     }
489 }
490
491 void
492 World::add_score(float x, float y, int s)
493 {
494   player_status.score += s;
495
496   FloatingScore* new_floating_score = new FloatingScore();
497   new_floating_score->init(x-scroll_x, y-scroll_y, s);
498   floating_scores.push_back(new_floating_score);
499 }
500
501 void
502 World::add_bouncy_distro(float x, float y)
503 {
504   BouncyDistro* new_bouncy_distro = new BouncyDistro();
505   new_bouncy_distro->init(x, y);
506   bouncy_distros.push_back(new_bouncy_distro);
507 }
508
509 void
510 World::add_broken_brick(Tile* tile, float x, float y)
511 {
512   add_broken_brick_piece(tile, x, y, -1, -4);
513   add_broken_brick_piece(tile, x, y + 16, -1.5, -3);
514
515   add_broken_brick_piece(tile, x + 16, y, 1, -4);
516   add_broken_brick_piece(tile, x + 16, y + 16, 1.5, -3);
517 }
518
519 void
520 World::add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym)
521 {
522   BrokenBrick* new_broken_brick = new BrokenBrick();
523   new_broken_brick->init(tile, x, y, xm, ym);
524   broken_bricks.push_back(new_broken_brick);
525 }
526
527 void
528 World::add_bouncy_brick(float x, float y)
529 {
530   BouncyBrick* new_bouncy_brick = new BouncyBrick();
531   new_bouncy_brick->init(x,y);
532   bouncy_bricks.push_back(new_bouncy_brick);
533 }
534
535 BadGuy*
536 World::add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform)
537 {
538   BadGuy* badguy = new BadGuy(x,y,kind, stay_on_platform);
539   bad_guys.push_back(badguy);
540   return badguy;
541 }
542
543 void
544 World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind)
545 {
546   Upgrade new_upgrade;
547   new_upgrade.init(x,y,dir,kind);
548   upgrades.push_back(new_upgrade);
549 }
550
551 void 
552 World::add_bullet(float x, float y, float xm, Direction dir)
553 {
554   if(tux.got_power == tux.FIRE_POWER)
555     {
556     if(bullets.size() > MAX_FIRE_BULLETS-1)
557       return;
558     }
559   else if(tux.got_power == tux.ICE_POWER)
560     {
561     if(bullets.size() > MAX_ICE_BULLETS-1)
562       return;
563     }
564
565   Bullet new_bullet;
566   if(tux.got_power == tux.FIRE_POWER)
567     new_bullet.init(x,y,xm,dir, FIRE_BULLET);
568   else if(tux.got_power == tux.ICE_POWER)
569     new_bullet.init(x,y,xm,dir, ICE_BULLET);
570   bullets.push_back(new_bullet);
571   
572   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
573 }
574
575 void
576 World::play_music(int musictype)
577 {
578   currentmusic = musictype;
579   switch(currentmusic) {
580     case HURRYUP_MUSIC:
581       music_manager->play_music(get_level()->get_level_music_fast());
582       break;
583     case LEVEL_MUSIC:
584       music_manager->play_music(get_level()->get_level_music());
585       break;
586     case HERRING_MUSIC:
587       music_manager->play_music(herring_song);
588       break;
589     default:
590       music_manager->halt_music();
591       break;
592   }
593 }
594
595 int
596 World::get_music_type()
597 {
598   return currentmusic;
599 }
600
601 /* Break a brick: */
602 void
603 World::trybreakbrick(float x, float y, bool small)
604 {
605   Level* plevel = get_level();
606   
607   Tile* tile = gettile(x, y);
608   if (tile->brick)
609     {
610       if (tile->data > 0)
611         {
612           /* Get a distro from it: */
613           add_bouncy_distro(((int)(x + 1) / 32) * 32,
614                                   (int)(y / 32) * 32);
615
616           // TODO: don't handle this in a global way but per-tile...
617           if (!counting_distros)
618             {
619               counting_distros = true;
620               distro_counter = 5;
621             }
622           else
623             {
624               distro_counter--;
625             }
626
627           if (distro_counter <= 0)
628             {
629               counting_distros = false;
630               plevel->change(x, y, TM_IA, tile->next_tile);
631             }
632
633           play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
634           player_status.score = player_status.score + SCORE_DISTRO;
635           player_status.distros++;
636         }
637       else if (!small)
638         {
639           /* Get rid of it: */
640           plevel->change(x, y, TM_IA, tile->next_tile);
641           
642           /* Replace it with broken bits: */
643           add_broken_brick(tile, 
644                                  ((int)(x + 1) / 32) * 32,
645                                  (int)(y / 32) * 32);
646           
647           /* Get some score: */
648           play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
649           player_status.score = player_status.score + SCORE_BRICK;
650         }
651     }
652 }
653
654 /* Empty a box: */
655 void
656 World::tryemptybox(float x, float y, Direction col_side)
657 {
658   Tile* tile = gettile(x,y);
659   if (!tile->fullbox)
660     return;
661
662   // according to the collision side, set the upgrade direction
663   if(col_side == LEFT)
664     col_side = RIGHT;
665   else
666     col_side = LEFT;
667
668   int posx = ((int)(x+1) / 32) * 32;
669   int posy = (int)(y/32) * 32 - 32;
670   switch(tile->data)
671     {
672     case 1: // Box with a distro!
673       add_bouncy_distro(posx, posy);
674       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
675       player_status.score = player_status.score + SCORE_DISTRO;
676       player_status.distros++;
677       break;
678
679     case 2: // Add a fire flower upgrade!
680       if (tux.size == SMALL)     /* Tux is small, add mints! */
681         add_upgrade(posx, posy, col_side, UPGRADE_GROWUP);
682       else     /* Tux is big, add a fireflower: */
683         add_upgrade(posx, posy, col_side, UPGRADE_FIREFLOWER);
684       play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
685       break;
686     
687     case 5: // Add an ice flower upgrade!
688       if (tux.size == SMALL)     /* Tux is small, add mints! */
689         add_upgrade(posx, posy, col_side, UPGRADE_GROWUP);
690       else     /* Tux is big, add an iceflower: */
691         add_upgrade(posx, posy, col_side, UPGRADE_ICEFLOWER);
692       play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
693       break;
694
695     case 3: // Add a golden herring
696       add_upgrade(posx, posy, col_side, UPGRADE_HERRING);
697       break;
698
699     case 4: // Add a 1up extra
700       add_upgrade(posx, posy, col_side, UPGRADE_1UP);
701       break;
702     default:
703       break;
704     }
705
706   /* Empty the box: */
707   level->change(x, y, TM_IA, tile->next_tile);
708 }
709
710 /* Try to grab a distro: */
711 void
712 World::trygrabdistro(float x, float y, int bounciness)
713 {
714   Tile* tile = gettile(x, y);
715   if (tile && tile->distro)
716     {
717       level->change(x, y, TM_IA, tile->next_tile);
718       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
719
720       if (bounciness == BOUNCE)
721         {
722           add_bouncy_distro(((int)(x + 1) / 32) * 32,
723                                   (int)(y / 32) * 32);
724         }
725
726       player_status.score = player_status.score + SCORE_DISTRO;
727       player_status.distros++;
728     }
729 }
730
731 /* Try to bump a bad guy from below: */
732 void
733 World::trybumpbadguy(float x, float y)
734 {
735   // Bad guys: 
736   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
737     {
738       if ((*i)->base.x >= x - 32 && (*i)->base.x <= x + 32 &&
739           (*i)->base.y >= y - 16 && (*i)->base.y <= y + 16)
740         {
741           (*i)->collision(&tux, CO_PLAYER, COLLISION_BUMP);
742         }
743     }
744
745   // Upgrades:
746   for (unsigned int i = 0; i < upgrades.size(); i++)
747     {
748       if (upgrades[i].base.height == 32 &&
749           upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 &&
750           upgrades[i].base.y >= y - 16 && upgrades[i].base.y <= y + 16)
751         {
752           upgrades[i].collision(&tux, CO_PLAYER, COLLISION_BUMP);
753         }
754     }
755 }
756
757 /* EOF */
758