- fixed drawing crash
[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   /* Draw background: */
200   for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y)
201     {
202       for (x = 0; x < VISIBLE_TILES_X; ++x)
203         {
204           Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32),
205                      level->bg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]);
206         }
207     }
208
209   /* Draw interactive tiles: */
210   for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y)
211     {
212       for (x = 0; x < VISIBLE_TILES_X; ++x)
213         {
214           Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32),
215                      level->ia_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]);
216         }
217     }
218
219   /* (Bouncy bricks): */
220   for (unsigned int i = 0; i < bouncy_bricks.size(); ++i)
221     bouncy_bricks[i]->draw();
222
223   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
224     (*i)->draw();
225
226   tux.draw();
227
228   for (unsigned int i = 0; i < bullets.size(); ++i)
229     bullets[i].draw();
230
231   for (unsigned int i = 0; i < floating_scores.size(); ++i)
232     floating_scores[i]->draw();
233
234   for (unsigned int i = 0; i < upgrades.size(); ++i)
235     upgrades[i].draw();
236
237   for (unsigned int i = 0; i < bouncy_distros.size(); ++i)
238     bouncy_distros[i]->draw();
239
240   for (unsigned int i = 0; i < broken_bricks.size(); ++i)
241     broken_bricks[i]->draw();
242
243   /* Draw foreground: */
244   for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y)
245     {
246       for (x = 0; x < VISIBLE_TILES_X; ++x)
247         {
248           Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32),
249                      level->fg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]);
250         }
251     }
252
253   /* Draw particle systems (foreground) */
254   for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
255     {
256       (*p)->draw(scroll_x, 0, 1);
257     }
258 }
259
260 void
261 World::action(double frame_ratio)
262 {
263   tux.action(frame_ratio);
264   tux.check_bounds(level->back_scrolling, (bool)level->hor_autoscroll_speed);
265   scrolling(frame_ratio);
266
267   /* Handle bouncy distros: */
268   for (unsigned int i = 0; i < bouncy_distros.size(); i++)
269     bouncy_distros[i]->action(frame_ratio);
270
271   /* Handle broken bricks: */
272   for (unsigned int i = 0; i < broken_bricks.size(); i++)
273     broken_bricks[i]->action(frame_ratio);
274
275   // Handle all kinds of game objects
276   for (unsigned int i = 0; i < bouncy_bricks.size(); i++)
277     bouncy_bricks[i]->action(frame_ratio);
278   
279   for (unsigned int i = 0; i < floating_scores.size(); i++)
280     floating_scores[i]->action(frame_ratio);
281
282   for (unsigned int i = 0; i < bullets.size(); ++i)
283     bullets[i].action(frame_ratio);
284   
285   for (unsigned int i = 0; i < upgrades.size(); i++)
286     upgrades[i].action(frame_ratio);
287
288   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
289     (*i)->action(frame_ratio);
290
291   /* update particle systems */
292   std::vector<ParticleSystem*>::iterator p;
293   for(p = particle_systems.begin(); p != particle_systems.end(); ++p)
294     {
295       (*p)->simulate(frame_ratio);
296     }
297
298   /* Handle all possible collisions. */
299   collision_handler();
300   
301   // Cleanup marked badguys
302   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end();
303       /* ++i handled at end of the loop */) {
304     if ((*i)->is_removable()) {
305       delete *i;
306       i =  bad_guys.erase(i);
307     } else {
308       ++i;
309     }
310   }
311 }
312
313 /* the space that it takes for the screen to start scrolling, regarding */
314 /* screen bounds (in pixels) */
315 // should be higher than screen->w/2 (400)
316 #define X_SPACE (500-16)
317 // should be less than screen->h/2 (300)
318 #define Y_SPACE 250
319
320 // the time it takes to move the camera (in ms)
321 #define CHANGE_DIR_SCROLL_SPEED 2000
322
323 /* This functions takes cares of the scrolling */
324 void World::scrolling(double frame_ratio)
325 {
326   /* Y-axis scrolling */
327
328   float tux_pos_y = tux.base.y + (tux.base.height/2);
329
330   if (scroll_y < tux_pos_y - (screen->h - Y_SPACE))
331     scroll_y = tux_pos_y - (screen->h - Y_SPACE);
332   else if (scroll_y > tux_pos_y - Y_SPACE)
333     scroll_y = tux_pos_y - Y_SPACE;
334
335   // this code prevent the screen to scroll before the start or after the level's end
336   if(scroll_y < 0)
337     scroll_y = 0;
338   else if(scroll_y > level->height * 32 - screen->h)
339     scroll_y = level->height * 32 - screen->h;
340
341   if (scroll_y < 0)
342   {
343     std::cerr << "Level too short!!" << std::endl;
344     scroll_y = 0;
345   }
346
347   /* X-axis scrolling */
348
349   /* Auto scrolling */
350   if(level->hor_autoscroll_speed)
351   {
352     scroll_x += level->hor_autoscroll_speed * frame_ratio;
353     return;
354   }
355
356
357   /* Horizontal backscrolling */
358   float tux_pos_x = tux.base.x + (tux.base.width/2);
359
360   if(tux.old_dir != tux.dir && level->back_scrolling)
361     scrolling_timer.start(CHANGE_DIR_SCROLL_SPEED);
362
363   bool right = false;
364   bool left = false;
365   if (tux.physic.get_velocity_x() > 0)
366     right = true;
367   else if (tux.physic.get_velocity_x() < 0)
368     left = true;
369   else
370     {
371     if (tux.dir == RIGHT)
372       right = true;
373     else
374       left = true;
375     }
376
377   if(scrolling_timer.check())
378   {
379     float final_scroll_x;
380     if (right)
381       final_scroll_x = tux_pos_x - (screen->w - X_SPACE);
382     else
383       final_scroll_x = tux_pos_x - X_SPACE;
384
385     scroll_x +=   (final_scroll_x - scroll_x)
386                 / (frame_ratio * (CHANGE_DIR_SCROLL_SPEED / 100))
387                 + (tux.physic.get_velocity_x() * frame_ratio + tux.physic.get_acceleration_x() * frame_ratio * frame_ratio);
388   }
389   else
390   {
391     if (right && scroll_x < tux_pos_x - (screen->w - X_SPACE))
392       scroll_x = tux_pos_x - (screen->w - X_SPACE);
393     else if (left && scroll_x > tux_pos_x - X_SPACE && level->back_scrolling)
394       scroll_x = tux_pos_x - X_SPACE;
395   }
396
397   // this code prevent the screen to scroll before the start or after the level's end
398   if(scroll_x < 0)
399     scroll_x = 0;
400   else if(scroll_x > level->width * 32 - screen->w)
401     scroll_x = level->width * 32 - screen->w;
402 }
403
404 void
405 World::collision_handler()
406 {
407   // CO_BULLET & CO_BADGUY check
408   for(unsigned int i = 0; i < bullets.size(); ++i)
409     {
410       for (BadGuys::iterator j = bad_guys.begin(); j != bad_guys.end(); ++j)
411         {
412           if((*j)->dying != DYING_NOT)
413             continue;
414           
415           if(rectcollision(bullets[i].base, (*j)->base))
416             {
417               // We have detected a collision and now call the
418               // collision functions of the collided objects.
419               // collide with bad_guy first, since bullet_collision will
420               // delete the bullet
421               (*j)->collision(&bullets[i], CO_BULLET);
422               bullets[i].collision(CO_BADGUY);
423               break; // bullet is invalid now, so break
424             }
425         }
426     }
427
428   /* CO_BADGUY & CO_BADGUY check */
429   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
430     {
431       if((*i)->dying != DYING_NOT)
432         continue;
433       
434       BadGuys::iterator j = i;
435       ++j;
436       for (; j != bad_guys.end(); ++j)
437         {
438           if(j == i || (*j)->dying != DYING_NOT)
439             continue;
440
441           if(rectcollision((*i)->base, (*j)->base))
442             {
443               // We have detected a collision and now call the
444               // collision functions of the collided objects.
445               (*j)->collision(*i, CO_BADGUY);
446               (*i)->collision(*j, CO_BADGUY);
447             }
448         }
449     }
450
451   if(tux.dying != DYING_NOT) return;
452     
453   // CO_BADGUY & CO_PLAYER check 
454   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
455     {
456       if((*i)->dying != DYING_NOT)
457         continue;
458       
459       if(rectcollision_offset((*i)->base, tux.base, 0, 0))
460         {
461           // We have detected a collision and now call the collision
462           // functions of the collided objects.
463           if (tux.previous_base.y < tux.base.y &&
464               tux.previous_base.y + tux.previous_base.height 
465               < (*i)->base.y + (*i)->base.height/2
466               && !tux.invincible_timer.started())
467             {
468               (*i)->collision(&tux, CO_PLAYER, COLLISION_SQUISH);
469             }
470           else
471             {
472               tux.collision(*i, CO_BADGUY);
473               (*i)->collision(&tux, CO_PLAYER, COLLISION_NORMAL);
474             }
475         }
476     }
477
478   // CO_UPGRADE & CO_PLAYER check
479   for(unsigned int i = 0; i < upgrades.size(); ++i)
480     {
481       if(rectcollision(upgrades[i].base, tux.base))
482         {
483           // We have detected a collision and now call the collision
484           // functions of the collided objects.
485           upgrades[i].collision(&tux, CO_PLAYER, COLLISION_NORMAL);
486         }
487     }
488 }
489
490 void
491 World::add_score(float x, float y, int s)
492 {
493   player_status.score += s;
494
495   FloatingScore* new_floating_score = new FloatingScore();
496   new_floating_score->init(x-scroll_x, y-scroll_y, s);
497   floating_scores.push_back(new_floating_score);
498 }
499
500 void
501 World::add_bouncy_distro(float x, float y)
502 {
503   BouncyDistro* new_bouncy_distro = new BouncyDistro();
504   new_bouncy_distro->init(x, y);
505   bouncy_distros.push_back(new_bouncy_distro);
506 }
507
508 void
509 World::add_broken_brick(Tile* tile, float x, float y)
510 {
511   add_broken_brick_piece(tile, x, y, -1, -4);
512   add_broken_brick_piece(tile, x, y + 16, -1.5, -3);
513
514   add_broken_brick_piece(tile, x + 16, y, 1, -4);
515   add_broken_brick_piece(tile, x + 16, y + 16, 1.5, -3);
516 }
517
518 void
519 World::add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym)
520 {
521   BrokenBrick* new_broken_brick = new BrokenBrick();
522   new_broken_brick->init(tile, x, y, xm, ym);
523   broken_bricks.push_back(new_broken_brick);
524 }
525
526 void
527 World::add_bouncy_brick(float x, float y)
528 {
529   BouncyBrick* new_bouncy_brick = new BouncyBrick();
530   new_bouncy_brick->init(x,y);
531   bouncy_bricks.push_back(new_bouncy_brick);
532 }
533
534 BadGuy*
535 World::add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform)
536 {
537   BadGuy* badguy = new BadGuy(x,y,kind, stay_on_platform);
538   bad_guys.push_back(badguy);
539   return badguy;
540 }
541
542 void
543 World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind)
544 {
545   Upgrade new_upgrade;
546   new_upgrade.init(x,y,dir,kind);
547   upgrades.push_back(new_upgrade);
548 }
549
550 void 
551 World::add_bullet(float x, float y, float xm, Direction dir)
552 {
553   if(tux.got_power == tux.FIRE_POWER)
554     {
555     if(bullets.size() > MAX_FIRE_BULLETS-1)
556       return;
557     }
558   else if(tux.got_power == tux.ICE_POWER)
559     {
560     if(bullets.size() > MAX_ICE_BULLETS-1)
561       return;
562     }
563
564   Bullet new_bullet;
565   if(tux.got_power == tux.FIRE_POWER)
566     new_bullet.init(x,y,xm,dir, FIRE_BULLET);
567   else if(tux.got_power == tux.ICE_POWER)
568     new_bullet.init(x,y,xm,dir, ICE_BULLET);
569   bullets.push_back(new_bullet);
570   
571   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
572 }
573
574 void
575 World::play_music(int musictype)
576 {
577   currentmusic = musictype;
578   switch(currentmusic) {
579     case HURRYUP_MUSIC:
580       music_manager->play_music(get_level()->get_level_music_fast());
581       break;
582     case LEVEL_MUSIC:
583       music_manager->play_music(get_level()->get_level_music());
584       break;
585     case HERRING_MUSIC:
586       music_manager->play_music(herring_song);
587       break;
588     default:
589       music_manager->halt_music();
590       break;
591   }
592 }
593
594 int
595 World::get_music_type()
596 {
597   return currentmusic;
598 }
599
600 /* Break a brick: */
601 void
602 World::trybreakbrick(float x, float y, bool small)
603 {
604   Level* plevel = get_level();
605   
606   Tile* tile = gettile(x, y);
607   if (tile->brick)
608     {
609       if (tile->data > 0)
610         {
611           /* Get a distro from it: */
612           add_bouncy_distro(((int)(x + 1) / 32) * 32,
613                                   (int)(y / 32) * 32);
614
615           // TODO: don't handle this in a global way but per-tile...
616           if (!counting_distros)
617             {
618               counting_distros = true;
619               distro_counter = 5;
620             }
621           else
622             {
623               distro_counter--;
624             }
625
626           if (distro_counter <= 0)
627             {
628               counting_distros = false;
629               plevel->change(x, y, TM_IA, tile->next_tile);
630             }
631
632           play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
633           player_status.score = player_status.score + SCORE_DISTRO;
634           player_status.distros++;
635         }
636       else if (!small)
637         {
638           /* Get rid of it: */
639           plevel->change(x, y, TM_IA, tile->next_tile);
640           
641           /* Replace it with broken bits: */
642           add_broken_brick(tile, 
643                                  ((int)(x + 1) / 32) * 32,
644                                  (int)(y / 32) * 32);
645           
646           /* Get some score: */
647           play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
648           player_status.score = player_status.score + SCORE_BRICK;
649         }
650     }
651 }
652
653 /* Empty a box: */
654 void
655 World::tryemptybox(float x, float y, Direction col_side)
656 {
657   Tile* tile = gettile(x,y);
658   if (!tile->fullbox)
659     return;
660
661   // according to the collision side, set the upgrade direction
662   if(col_side == LEFT)
663     col_side = RIGHT;
664   else
665     col_side = LEFT;
666
667   int posx = ((int)(x+1) / 32) * 32;
668   int posy = (int)(y/32) * 32 - 32;
669   switch(tile->data)
670     {
671     case 1: // Box with a distro!
672       add_bouncy_distro(posx, posy);
673       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
674       player_status.score = player_status.score + SCORE_DISTRO;
675       player_status.distros++;
676       break;
677
678     case 2: // Add a fire flower upgrade!
679       if (tux.size == SMALL)     /* Tux is small, add mints! */
680         add_upgrade(posx, posy, col_side, UPGRADE_GROWUP);
681       else     /* Tux is big, add a fireflower: */
682         add_upgrade(posx, posy, col_side, UPGRADE_FIREFLOWER);
683       play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
684       break;
685     
686     case 5: // Add an ice flower upgrade!
687       if (tux.size == SMALL)     /* Tux is small, add mints! */
688         add_upgrade(posx, posy, col_side, UPGRADE_GROWUP);
689       else     /* Tux is big, add an iceflower: */
690         add_upgrade(posx, posy, col_side, UPGRADE_ICEFLOWER);
691       play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
692       break;
693
694     case 3: // Add a golden herring
695       add_upgrade(posx, posy, col_side, UPGRADE_HERRING);
696       break;
697
698     case 4: // Add a 1up extra
699       add_upgrade(posx, posy, col_side, UPGRADE_1UP);
700       break;
701     default:
702       break;
703     }
704
705   /* Empty the box: */
706   level->change(x, y, TM_IA, tile->next_tile);
707 }
708
709 /* Try to grab a distro: */
710 void
711 World::trygrabdistro(float x, float y, int bounciness)
712 {
713   Tile* tile = gettile(x, y);
714   if (tile && tile->distro)
715     {
716       level->change(x, y, TM_IA, tile->next_tile);
717       play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
718
719       if (bounciness == BOUNCE)
720         {
721           add_bouncy_distro(((int)(x + 1) / 32) * 32,
722                                   (int)(y / 32) * 32);
723         }
724
725       player_status.score = player_status.score + SCORE_DISTRO;
726       player_status.distros++;
727     }
728 }
729
730 /* Try to bump a bad guy from below: */
731 void
732 World::trybumpbadguy(float x, float y)
733 {
734   // Bad guys: 
735   for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
736     {
737       if ((*i)->base.x >= x - 32 && (*i)->base.x <= x + 32 &&
738           (*i)->base.y >= y - 16 && (*i)->base.y <= y + 16)
739         {
740           (*i)->collision(&tux, CO_PLAYER, COLLISION_BUMP);
741         }
742     }
743
744   // Upgrades:
745   for (unsigned int i = 0; i < upgrades.size(); i++)
746     {
747       if (upgrades[i].base.height == 32 &&
748           upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 &&
749           upgrades[i].base.y >= y - 16 && upgrades[i].base.y <= y + 16)
750         {
751           upgrades[i].collision(&tux, CO_PLAYER, COLLISION_BUMP);
752         }
753     }
754 }
755
756 /* EOF */
757