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