3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.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.
27 #include "app/globals.h"
29 #include "utils/lispreader.h"
34 #include "background.h"
35 #include "particlesystem.h"
38 #include "audio/sound_manager.h"
40 #include "resources.h"
41 #include "interactive_object.h"
43 #include "statistics.h"
45 Sector* Sector::_current = 0;
48 : gravity(10), player(0), solids(0), background(0), camera(0),
49 currentmusic(LEVEL_MUSIC), end_sequence_animation_type(NONE_ENDSEQ_ANIM)
51 song_title = "Mortimers_chipdisko.mod";
52 player = new Player();
58 for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
62 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
71 Sector::parse(LispReader& lispreader)
75 for(lisp_object_t* cur = lispreader.get_lisp(); !lisp_nil_p(cur);
76 cur = lisp_cdr(cur)) {
77 std::string token = lisp_symbol(lisp_car(lisp_car(cur)));
78 // FIXME: doesn't handle empty data
79 lisp_object_t* data = lisp_car(lisp_cdr(lisp_car(cur)));
80 LispReader reader(lisp_cdr(lisp_car(cur)));
83 name = lisp_string(data);
84 } else if(token == "gravity") {
85 gravity = lisp_real(data);
86 } else if(token == "music") {
87 song_title = lisp_string(data);
89 } else if(token == "end-sequence-animation") {
90 std::string end_seq_anim = lisp_string(data);
91 if(end_seq_anim == "fireworks")
92 end_sequence_animation_type = FIREWORKS_ENDSEQ_ANIM;
93 } else if(token == "camera") {
95 std::cerr << "Warning: More than 1 camera defined in sector.\n";
98 camera = new Camera(this);
101 } else if(token == "background") {
102 background = new Background(reader);
103 add_object(background);
104 } else if(token == "spawn-points") {
105 SpawnPoint* sp = new SpawnPoint;
106 reader.read_string("name", sp->name);
107 reader.read_float("x", sp->pos.x);
108 reader.read_float("y", sp->pos.y);
109 spawnpoints.push_back(sp);
110 } else if(token == "tilemap") {
111 TileMap* tilemap = new TileMap(reader);
114 if(tilemap->is_solid()) {
116 std::cerr << "Warning multiple solid tilemaps in sector.\n";
121 } else if(badguykind_from_string(token) != BAD_INVALID) {
122 add_object(new BadGuy(badguykind_from_string(token), reader));
123 } else if(token == "trampoline") {
124 add_object(new Trampoline(reader));
125 } else if(token == "flying-platform") {
126 add_object(new FlyingPlatform(reader));
127 } else if(token == "particles-snow") {
128 SnowParticleSystem* partsys = new SnowParticleSystem();
129 partsys->parse(reader);
131 } else if(token == "particles-clouds") {
132 CloudParticleSystem* partsys = new CloudParticleSystem();
133 partsys->parse(reader);
135 } else if(token == "door") {
136 add_object(new Door(reader));
138 std::cerr << "Unknown object type '" << token << "'.\n";
143 std::cerr << "sector '" << name << "' does not contain a camera.\n";
144 camera = new Camera(this);
148 throw std::runtime_error("sector does not contain a solid tile layer.");
152 Sector::parse_old_format(LispReader& reader)
157 reader.read_float("gravity", gravity);
159 std::string backgroundimage;
160 reader.read_string("background", backgroundimage);
162 reader.read_float("bkgd_speed", bgspeed);
165 Color bkgd_top, bkgd_bottom;
166 int r = 0, g = 0, b = 128;
167 reader.read_int("bkgd_red_top", r);
168 reader.read_int("bkgd_green_top", g);
169 reader.read_int("bkgd_blue_top", b);
174 reader.read_int("bkgd_red_bottom", r);
175 reader.read_int("bkgd_green_bottom", g);
176 reader.read_int("bkgd_blue_bottom", b);
178 bkgd_bottom.green = g;
179 bkgd_bottom.blue = b;
181 if(backgroundimage != "") {
182 background = new Background;
183 background->set_image(backgroundimage, bgspeed);
184 add_object(background);
186 background = new Background;
187 background->set_gradient(bkgd_top, bkgd_bottom);
188 add_object(background);
191 std::string end_seq_anim;
192 reader.read_string("end-sequence-animation", end_seq_anim);
193 if(end_seq_anim == "fireworks")
194 end_sequence_animation_type = FIREWORKS_ENDSEQ_ANIM;
196 // end_sequence_animation = NONE_ENDSEQ_ANIM;
198 std::string particlesystem;
199 reader.read_string("particle_system", particlesystem);
200 if(particlesystem == "clouds")
201 add_object(new CloudParticleSystem());
202 else if(particlesystem == "snow")
203 add_object(new SnowParticleSystem());
205 Vector startpos(100, 170);
206 reader.read_float("start_pos_x", startpos.x);
207 reader.read_float("start_pos_y", startpos.y);
209 SpawnPoint* spawn = new SpawnPoint;
210 spawn->pos = startpos;
211 spawn->name = "main";
212 spawnpoints.push_back(spawn);
214 song_title = "Mortimers_chipdisko.mod";
215 reader.read_string("music", song_title);
218 int width, height = 15;
219 reader.read_int("width", width);
220 reader.read_int("height", height);
222 std::vector<unsigned int> tiles;
223 if(reader.read_int_vector("interactive-tm", tiles)
224 || reader.read_int_vector("tilemap", tiles)) {
225 TileMap* tilemap = new TileMap();
226 tilemap->set(width, height, tiles, LAYER_TILES, true);
231 if(reader.read_int_vector("background-tm", tiles)) {
232 TileMap* tilemap = new TileMap();
233 tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
237 if(reader.read_int_vector("foreground-tm", tiles)) {
238 TileMap* tilemap = new TileMap();
239 tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
243 // read reset-points (now spawn-points)
245 lisp_object_t* cur = 0;
246 if(reader.read_lisp("reset-points", cur)) {
247 while(!lisp_nil_p(cur)) {
248 lisp_object_t* data = lisp_car(cur);
249 LispReader reader(lisp_cdr(data));
252 if(reader.read_float("x", sp_pos.x) && reader.read_float("y", sp_pos.y))
254 SpawnPoint* sp = new SpawnPoint;
257 spawnpoints.push_back(sp);
267 lisp_object_t* cur = 0;
268 if(reader.read_lisp("objects", cur)) {
269 while(!lisp_nil_p(cur)) {
270 lisp_object_t* data = lisp_car(cur);
271 std::string object_type = lisp_symbol(lisp_car(data));
273 LispReader reader(lisp_cdr(data));
275 if(object_type == "trampoline") {
276 add_object(new Trampoline(reader));
278 else if(object_type == "flying-platform") {
279 add_object(new FlyingPlatform(reader));
282 BadGuyKind kind = badguykind_from_string(object_type);
283 add_object(new BadGuy(kind, reader));
292 camera = new Camera(this);
297 Sector::write(LispWriter& writer)
299 writer.write_string("name", name);
300 writer.write_float("gravity", gravity);
301 writer.write_string("music", song_title);
304 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
306 SpawnPoint* spawn = *i;
307 writer.start_list("spawn-points");
308 writer.write_string("name", spawn->name);
309 writer.write_float("x", spawn->pos.x);
310 writer.write_float("y", spawn->pos.y);
311 writer.end_list("spawn-points");
315 for(GameObjects::iterator i = gameobjects.begin();
316 i != gameobjects.end(); ++i) {
317 Serializable* serializable = dynamic_cast<Serializable*> (*i);
319 serializable->write(writer);
324 Sector::do_vertical_flip()
326 for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
328 TileMap* tilemap = dynamic_cast<TileMap*> (*i);
331 tilemap->do_vertical_flip();
334 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
336 badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32;
337 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
339 trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32;
340 FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
342 flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32;
343 Door* door = dynamic_cast<Door*> (*i);
345 door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y - 32);
348 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
350 SpawnPoint* spawn = *i;
351 spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32;
356 Sector::add_object(GameObject* object)
358 gameobjects_new.push_back(object);
362 Sector::activate(const std::string& spawnpoint)
366 // Apply bonuses from former levels
367 switch (player_status.bonus)
369 case PlayerStatus::NO_BONUS:
372 case PlayerStatus::FLOWER_BONUS:
373 player->got_power = Player::FIRE_POWER; // FIXME: add ice power to here
376 case PlayerStatus::GROWUP_BONUS:
382 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
384 if((*i)->name == spawnpoint) {
390 std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n";
392 player->move(sp->pos);
395 camera->reset(Vector(player->base.x, player->base.y));
399 Sector::get_best_spawn_point(Vector pos)
401 Vector best_reset_point = Vector(-1,-1);
403 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
405 if((*i)->name != "main")
407 if((*i)->pos.x > best_reset_point.x && (*i)->pos.x < pos.x)
408 best_reset_point = (*i)->pos;
411 return best_reset_point;
415 Sector::action(float elapsed_time)
417 player->check_bounds(camera);
419 /* update objects (don't use iterators here, because the list might change
420 * during the iteration)
422 for(size_t i = 0; i < gameobjects.size(); ++i)
423 if(gameobjects[i]->is_valid())
424 gameobjects[i]->action(elapsed_time);
426 /* Handle all possible collisions. */
429 update_game_objects();
433 Sector::update_game_objects()
435 /** cleanup marked objects */
436 for(std::vector<GameObject*>::iterator i = gameobjects.begin();
437 i != gameobjects.end(); /* nothing */) {
438 if((*i)->is_valid() == false) {
439 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
441 badguys.erase(std::remove(badguys.begin(), badguys.end(), badguy),
444 Bullet* bullet = dynamic_cast<Bullet*> (*i);
447 std::remove(bullets.begin(), bullets.end(), bullet),
450 InteractiveObject* interactive_object =
451 dynamic_cast<InteractiveObject*> (*i);
452 if(interactive_object) {
453 interactive_objects.erase(
454 std::remove(interactive_objects.begin(), interactive_objects.end(),
455 interactive_object), interactive_objects.end());
457 Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
460 std::remove(upgrades.begin(), upgrades.end(), upgrade),
463 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
466 std::remove(trampolines.begin(), trampolines.end(), trampoline),
469 FlyingPlatform* flying_platform= dynamic_cast<FlyingPlatform*> (*i);
470 if(flying_platform) {
471 flying_platforms.erase(
472 std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform),
473 flying_platforms.end());
475 SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
478 std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud),
481 Particles* particle = dynamic_cast<Particles*> (*i);
484 std::remove(particles.begin(), particles.end(), particle),
489 i = gameobjects.erase(i);
495 /* add newly created objects */
496 for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
497 i != gameobjects_new.end(); ++i)
499 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
501 badguys.push_back(badguy);
502 Bullet* bullet = dynamic_cast<Bullet*> (*i);
504 bullets.push_back(bullet);
505 Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
507 upgrades.push_back(upgrade);
508 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
510 trampolines.push_back(trampoline);
511 FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
513 flying_platforms.push_back(flying_platform);
514 InteractiveObject* interactive_object
515 = dynamic_cast<InteractiveObject*> (*i);
516 if(interactive_object)
517 interactive_objects.push_back(interactive_object);
518 SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
520 smoke_clouds.push_back(smoke_cloud);
521 Particles* particle = dynamic_cast<Particles*> (*i);
523 particles.push_back(particle);
525 gameobjects.push_back(*i);
527 gameobjects_new.clear();
531 Sector::draw(DrawingContext& context)
533 context.push_transform();
534 context.set_translation(camera->get_translation());
536 for(GameObjects::iterator i = gameobjects.begin();
537 i != gameobjects.end(); ++i) {
538 if( (*i)->is_valid() )
542 context.pop_transform();
546 Sector::collision_handler()
548 // CO_BULLET & CO_BADGUY check
549 for(unsigned int i = 0; i < bullets.size(); ++i)
551 for (BadGuys::iterator j = badguys.begin(); j != badguys.end(); ++j)
553 if((*j)->dying != DYING_NOT)
556 if(rectcollision(bullets[i]->base, (*j)->base))
558 // We have detected a collision and now call the
559 // collision functions of the collided objects.
560 (*j)->collision(bullets[i], CO_BULLET, COLLISION_NORMAL);
561 bullets[i]->collision(CO_BADGUY);
562 break; // bullet is invalid now, so break
567 /* CO_BADGUY & CO_BADGUY check */
568 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
570 if((*i)->dying != DYING_NOT)
573 BadGuys::iterator j = i;
575 for (; j != badguys.end(); ++j)
577 if(j == i || (*j)->dying != DYING_NOT)
580 if(rectcollision((*i)->base, (*j)->base))
582 // We have detected a collision and now call the
583 // collision functions of the collided objects.
584 (*j)->collision(*i, CO_BADGUY);
585 (*i)->collision(*j, CO_BADGUY);
589 if(player->dying != DYING_NOT) return;
591 // CO_BADGUY & CO_PLAYER check
592 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
594 if((*i)->dying != DYING_NOT)
597 if(rectcollision_offset((*i)->base, player->base, 0, 0))
599 // We have detected a collision and now call the collision
600 // functions of the collided objects.
601 if (player->previous_base.y < player->base.y &&
602 player->previous_base.y + player->previous_base.height
603 < (*i)->base.y + (*i)->base.height/2
604 && !player->invincible_timer.started())
606 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
610 player->collision(*i, CO_BADGUY);
611 (*i)->collision(player, CO_PLAYER, COLLISION_NORMAL);
616 // CO_UPGRADE & CO_PLAYER check
617 for(unsigned int i = 0; i < upgrades.size(); ++i)
619 if(rectcollision(upgrades[i]->base, player->base))
621 // We have detected a collision and now call the collision
622 // functions of the collided objects.
623 upgrades[i]->collision(player, CO_PLAYER, COLLISION_NORMAL);
627 // CO_TRAMPOLINE & (CO_PLAYER or CO_BADGUY)
628 for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
630 if (rectcollision((*i)->base, player->base))
632 if (player->previous_base.y < player->base.y &&
633 player->previous_base.y + player->previous_base.height
634 < (*i)->base.y + (*i)->base.height/2)
636 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
638 else if (player->previous_base.y <= player->base.y)
640 player->collision(*i, CO_TRAMPOLINE);
641 (*i)->collision(player, CO_PLAYER, COLLISION_NORMAL);
646 // CO_FLYING_PLATFORM & (CO_PLAYER or CO_BADGUY)
647 for (FlyingPlatforms::iterator i = flying_platforms.begin(); i != flying_platforms.end(); ++i)
649 if (rectcollision((*i)->base, player->base))
651 if (player->previous_base.y < player->base.y &&
652 player->previous_base.y + player->previous_base.height
653 < (*i)->base.y + (*i)->base.height/2)
655 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
656 player->collision(*i, CO_FLYING_PLATFORM);
658 /* else if (player->previous_base.y <= player->base.y)
666 Sector::add_score(const Vector& pos, int s)
668 global_stats.add_points(SCORE_STAT, s);
670 add_object(new FloatingScore(pos, s));
674 Sector::add_bouncy_distro(const Vector& pos)
676 add_object(new BouncyDistro(pos));
680 Sector::add_broken_brick(const Vector& pos, Tile* tile)
682 add_broken_brick_piece(pos, Vector(-1, -4), tile);
683 add_broken_brick_piece(pos + Vector(0, 16), Vector(-1.5, -3), tile);
685 add_broken_brick_piece(pos + Vector(16, 0), Vector(1, -4), tile);
686 add_broken_brick_piece(pos + Vector(16, 16), Vector(1.5, -3), tile);
690 Sector::add_broken_brick_piece(const Vector& pos, const Vector& movement,
693 add_object(new BrokenBrick(tile, pos, movement));
697 Sector::add_bouncy_brick(const Vector& pos)
699 add_object(new BouncyBrick(pos));
703 Sector::add_bad_guy(float x, float y, BadGuyKind kind)
705 BadGuy* badguy = new BadGuy(kind, x, y);
711 Sector::add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind)
713 add_object(new Upgrade(pos, dir, kind));
717 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
719 if(player->got_power == Player::FIRE_POWER)
721 if(bullets.size() > MAX_FIRE_BULLETS-1)
724 else if(player->got_power == Player::ICE_POWER)
726 if(bullets.size() > MAX_ICE_BULLETS-1)
730 Bullet* new_bullet = 0;
731 if(player->got_power == Player::FIRE_POWER)
732 new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET);
733 else if(player->got_power == Player::ICE_POWER)
734 new_bullet = new Bullet(pos, xm, dir, ICE_BULLET);
736 throw std::runtime_error("wrong bullet type.");
737 add_object(new_bullet);
739 SoundManager::get()->play_sound(IDToSound(SND_SHOOT));
745 Sector::add_smoke_cloud(const Vector& pos)
747 add_object(new SmokeCloud(pos));
752 Sector::add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time)
754 add_object(new Particles(epicenter, velocity, acceleration, number, color, size, life_time));
760 Sector::trybreakbrick(const Vector& pos, bool small)
762 Tile* tile = solids->get_tile_at(pos);
766 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
767 throw SuperTuxException(errmsg, __FILE__, __LINE__);
770 if (tile->attributes & Tile::BRICK)
774 /* Get a distro from it: */
776 Vector(((int)(pos.x + 1) / 32) * 32, (int)(pos.y / 32) * 32));
778 // TODO: don't handle this in a global way but per-tile...
779 if (!counting_distros)
781 counting_distros = true;
789 if (distro_counter <= 0)
791 counting_distros = false;
792 solids->change_at(pos, tile->next_tile);
795 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
796 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
797 global_stats.add_points(COINS_COLLECTED_STAT, 1);
798 player_status.distros++;
804 solids->change_at(pos, tile->next_tile);
806 /* Replace it with broken bits: */
807 add_broken_brick(Vector(
808 ((int)(pos.x + 1) / 32) * 32,
809 (int)(pos.y / 32) * 32), tile);
811 /* Get some score: */
812 SoundManager::get()->play_sound(IDToSound(SND_BRICK));
813 global_stats.add_points(SCORE_STAT, SCORE_BRICK);
824 Sector::tryemptybox(const Vector& pos, Direction col_side)
826 Tile* tile = solids->get_tile_at(pos);
830 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
831 throw SuperTuxException(errmsg, __FILE__, __LINE__);
835 if (!(tile->attributes & Tile::FULLBOX))
838 // according to the collision side, set the upgrade direction
844 int posx = ((int)(pos.x+1) / 32) * 32;
845 int posy = (int)(pos.y/32) * 32 - 32;
848 case 1: // Box with a distro!
849 add_bouncy_distro(Vector(posx, posy));
850 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
851 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
852 global_stats.add_points(COINS_COLLECTED_STAT, 1);
853 player_status.distros++;
856 case 2: // Add a fire flower upgrade!
857 if (player->size == SMALL) /* Tux is small, add mints! */
858 add_upgrade(Vector(posx, posy), col_side, UPGRADE_GROWUP);
859 else /* Tux is big, add a fireflower: */
860 add_upgrade(Vector(posx, posy), col_side, UPGRADE_FIREFLOWER);
861 SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
864 case 5: // Add an ice flower upgrade!
865 if (player->size == SMALL) /* Tux is small, add mints! */
866 add_upgrade(Vector(posx, posy), col_side, UPGRADE_GROWUP);
867 else /* Tux is big, add an iceflower: */
868 add_upgrade(Vector(posx, posy), col_side, UPGRADE_ICEFLOWER);
869 SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
872 case 3: // Add a golden herring
873 add_upgrade(Vector(posx, posy), col_side, UPGRADE_STAR);
876 case 4: // Add a 1up extra
877 add_upgrade(Vector(posx, posy), col_side, UPGRADE_1UP);
884 solids->change_at(pos, tile->next_tile);
887 /* Try to grab a distro: */
889 Sector::trygrabdistro(const Vector& pos, int bounciness)
891 Tile* tile = solids->get_tile_at(pos);
895 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
896 throw SuperTuxException(errmsg, __FILE__, __LINE__); */
898 //Bad tiles (i.e. tiles that are not defined in supertux.stgt but appear in the map) are changed to ID 0 (blank tile)
899 std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos).id << ")" << std::endl;
900 solids->change_at(pos,0);
901 tile = solids->get_tile_at(pos);
905 if (!(tile->attributes & Tile::COIN))
908 solids->change_at(pos, tile->next_tile);
909 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
911 if (bounciness == BOUNCE)
913 add_bouncy_distro(Vector(((int)(pos.x + 1) / 32) * 32,
914 (int)(pos.y / 32) * 32));
917 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
918 global_stats.add_points(COINS_COLLECTED_STAT, 1);
919 player_status.distros++;
923 /* Try to bump a bad guy from below: */
925 Sector::trybumpbadguy(const Vector& pos)
928 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
930 if ((*i)->base.x >= pos.x - 32 && (*i)->base.x <= pos.x + 32 &&
931 (*i)->base.y >= pos.y - 16 && (*i)->base.y <= pos.y + 16)
933 (*i)->collision(player, CO_PLAYER, COLLISION_BUMP);
938 for (unsigned int i = 0; i < upgrades.size(); i++)
940 if (upgrades[i]->base.height == 32 &&
941 upgrades[i]->base.x >= pos.x - 32 && upgrades[i]->base.x <= pos.x + 32 &&
942 upgrades[i]->base.y >= pos.y - 16 && upgrades[i]->base.y <= pos.y + 16)
944 upgrades[i]->collision(player, CO_PLAYER, COLLISION_BUMP);
955 level_song = SoundManager::get()->load_music(datadir + "/music/" + song_title);
957 song_path = (char *) malloc(sizeof(char) * datadir.length() +
958 strlen(song_title.c_str()) + 8 + 5);
959 song_subtitle = strdup(song_title.c_str());
960 strcpy(strstr(song_subtitle, "."), "\0");
961 sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(),
962 song_subtitle, strstr(song_title.c_str(), "."));
963 if(!SoundManager::get()->exists_music(song_path)) {
964 level_song_fast = level_song;
966 level_song_fast = SoundManager::get()->load_music(song_path);
973 Sector::play_music(int type)
976 switch(currentmusic) {
978 SoundManager::get()->play_music(level_song_fast);
981 SoundManager::get()->play_music(level_song);
984 SoundManager::get()->play_music(herring_song);
987 SoundManager::get()->halt_music();
993 Sector::get_music_type()
999 Sector::get_total_badguys()
1001 int total_badguys = 0;
1002 for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
1004 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
1008 return total_badguys;