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 : end_sequence_animation_type(NONE_ENDSEQ_ANIM),
49 gravity(10), player(0), solids(0), background(0), camera(0),
50 currentmusic(LEVEL_MUSIC)
52 song_title = "Mortimers_chipdisko.mod";
53 player = new Player();
59 for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
63 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
72 Sector::parse(LispReader& lispreader)
76 for(lisp_object_t* cur = lispreader.get_lisp(); !lisp_nil_p(cur);
77 cur = lisp_cdr(cur)) {
78 std::string token = lisp_symbol(lisp_car(lisp_car(cur)));
79 // FIXME: doesn't handle empty data
80 lisp_object_t* data = lisp_car(lisp_cdr(lisp_car(cur)));
81 LispReader reader(lisp_cdr(lisp_car(cur)));
84 name = lisp_string(data);
85 } else if(token == "gravity") {
86 gravity = lisp_real(data);
87 } else if(token == "music") {
88 song_title = lisp_string(data);
90 } else if(token == "end-sequence-animation") {
91 std::string end_seq_anim = lisp_string(data);
92 if(end_seq_anim == "fireworks")
93 end_sequence_animation_type = FIREWORKS_ENDSEQ_ANIM;
94 } else if(token == "camera") {
96 std::cerr << "Warning: More than 1 camera defined in sector.\n";
99 camera = new Camera(this);
100 camera->read(reader);
102 } else if(token == "background") {
103 background = new Background(reader);
104 add_object(background);
105 } else if(token == "spawn-points") {
106 SpawnPoint* sp = new SpawnPoint;
107 reader.read_string("name", sp->name);
108 reader.read_float("x", sp->pos.x);
109 reader.read_float("y", sp->pos.y);
110 spawnpoints.push_back(sp);
111 } else if(token == "tilemap") {
112 TileMap* tilemap = new TileMap(reader);
115 if(tilemap->is_solid()) {
117 std::cerr << "Warning multiple solid tilemaps in sector.\n";
122 } else if(badguykind_from_string(token) != BAD_INVALID) {
123 add_object(new BadGuy(badguykind_from_string(token), reader));
124 } else if(token == "trampoline") {
125 add_object(new Trampoline(reader));
126 } else if(token == "flying-platform") {
127 add_object(new FlyingPlatform(reader));
128 } else if(token == "particles-snow") {
129 SnowParticleSystem* partsys = new SnowParticleSystem();
130 partsys->parse(reader);
132 } else if(token == "particles-clouds") {
133 CloudParticleSystem* partsys = new CloudParticleSystem();
134 partsys->parse(reader);
136 } else if(token == "door") {
137 add_object(new Door(reader));
139 std::cerr << "Unknown object type '" << token << "'.\n";
144 std::cerr << "sector '" << name << "' does not contain a camera.\n";
145 camera = new Camera(this);
149 throw std::runtime_error("sector does not contain a solid tile layer.");
153 Sector::parse_old_format(LispReader& reader)
158 reader.read_float("gravity", gravity);
160 std::string backgroundimage;
161 reader.read_string("background", backgroundimage);
163 reader.read_float("bkgd_speed", bgspeed);
166 Color bkgd_top, bkgd_bottom;
167 int r = 0, g = 0, b = 128;
168 reader.read_int("bkgd_red_top", r);
169 reader.read_int("bkgd_green_top", g);
170 reader.read_int("bkgd_blue_top", b);
175 reader.read_int("bkgd_red_bottom", r);
176 reader.read_int("bkgd_green_bottom", g);
177 reader.read_int("bkgd_blue_bottom", b);
179 bkgd_bottom.green = g;
180 bkgd_bottom.blue = b;
182 if(backgroundimage != "") {
183 background = new Background;
184 background->set_image(backgroundimage, bgspeed);
185 add_object(background);
187 background = new Background;
188 background->set_gradient(bkgd_top, bkgd_bottom);
189 add_object(background);
192 std::string end_seq_anim;
193 reader.read_string("end-sequence-animation", end_seq_anim);
194 if(end_seq_anim == "fireworks")
195 end_sequence_animation_type = FIREWORKS_ENDSEQ_ANIM;
197 // end_sequence_animation = NONE_ENDSEQ_ANIM;
199 std::string particlesystem;
200 reader.read_string("particle_system", particlesystem);
201 if(particlesystem == "clouds")
202 add_object(new CloudParticleSystem());
203 else if(particlesystem == "snow")
204 add_object(new SnowParticleSystem());
206 Vector startpos(100, 170);
207 reader.read_float("start_pos_x", startpos.x);
208 reader.read_float("start_pos_y", startpos.y);
210 SpawnPoint* spawn = new SpawnPoint;
211 spawn->pos = startpos;
212 spawn->name = "main";
213 spawnpoints.push_back(spawn);
215 song_title = "Mortimers_chipdisko.mod";
216 reader.read_string("music", song_title);
219 int width, height = 15;
220 reader.read_int("width", width);
221 reader.read_int("height", height);
223 std::vector<unsigned int> tiles;
224 if(reader.read_int_vector("interactive-tm", tiles)
225 || reader.read_int_vector("tilemap", tiles)) {
226 TileMap* tilemap = new TileMap();
227 tilemap->set(width, height, tiles, LAYER_TILES, true);
232 if(reader.read_int_vector("background-tm", tiles)) {
233 TileMap* tilemap = new TileMap();
234 tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
238 if(reader.read_int_vector("foreground-tm", tiles)) {
239 TileMap* tilemap = new TileMap();
240 tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
244 // read reset-points (now spawn-points)
246 lisp_object_t* cur = 0;
247 if(reader.read_lisp("reset-points", cur)) {
248 while(!lisp_nil_p(cur)) {
249 lisp_object_t* data = lisp_car(cur);
250 LispReader reader(lisp_cdr(data));
253 if(reader.read_float("x", sp_pos.x) && reader.read_float("y", sp_pos.y))
255 SpawnPoint* sp = new SpawnPoint;
258 spawnpoints.push_back(sp);
268 lisp_object_t* cur = 0;
269 if(reader.read_lisp("objects", cur)) {
270 while(!lisp_nil_p(cur)) {
271 lisp_object_t* data = lisp_car(cur);
272 std::string object_type = lisp_symbol(lisp_car(data));
274 LispReader reader(lisp_cdr(data));
276 if(object_type == "trampoline") {
277 add_object(new Trampoline(reader));
279 else if(object_type == "flying-platform") {
280 add_object(new FlyingPlatform(reader));
283 BadGuyKind kind = badguykind_from_string(object_type);
284 add_object(new BadGuy(kind, reader));
293 camera = new Camera(this);
298 Sector::write(LispWriter& writer)
300 writer.write_string("name", name);
301 writer.write_float("gravity", gravity);
302 writer.write_string("music", song_title);
305 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
307 SpawnPoint* spawn = *i;
308 writer.start_list("spawn-points");
309 writer.write_string("name", spawn->name);
310 writer.write_float("x", spawn->pos.x);
311 writer.write_float("y", spawn->pos.y);
312 writer.end_list("spawn-points");
316 for(GameObjects::iterator i = gameobjects.begin();
317 i != gameobjects.end(); ++i) {
318 Serializable* serializable = dynamic_cast<Serializable*> (*i);
320 serializable->write(writer);
325 Sector::do_vertical_flip()
327 for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
329 TileMap* tilemap = dynamic_cast<TileMap*> (*i);
332 tilemap->do_vertical_flip();
335 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
337 badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32;
338 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
340 trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32;
341 FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
343 flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32;
344 Door* door = dynamic_cast<Door*> (*i);
346 door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y - 32);
349 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
351 SpawnPoint* spawn = *i;
352 spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32;
357 Sector::add_object(GameObject* object)
359 gameobjects_new.push_back(object);
363 Sector::activate(const std::string& spawnpoint)
367 // Apply bonuses from former levels
368 switch (player_status.bonus)
370 case PlayerStatus::NO_BONUS:
373 case PlayerStatus::FLOWER_BONUS:
374 player->got_power = Player::FIRE_POWER; // FIXME: add ice power to here
377 case PlayerStatus::GROWUP_BONUS:
383 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
385 if((*i)->name == spawnpoint) {
391 std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n";
393 player->move(sp->pos);
396 camera->reset(Vector(player->base.x, player->base.y));
400 Sector::get_best_spawn_point(Vector pos)
402 Vector best_reset_point = Vector(-1,-1);
404 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
406 if((*i)->name != "main")
408 if((*i)->pos.x > best_reset_point.x && (*i)->pos.x < pos.x)
409 best_reset_point = (*i)->pos;
412 return best_reset_point;
416 Sector::action(float elapsed_time)
418 player->check_bounds(camera);
420 /* update objects (don't use iterators here, because the list might change
421 * during the iteration)
423 for(size_t i = 0; i < gameobjects.size(); ++i)
424 if(gameobjects[i]->is_valid())
425 gameobjects[i]->action(elapsed_time);
427 /* Handle all possible collisions. */
430 update_game_objects();
434 Sector::update_game_objects()
436 /** cleanup marked objects */
437 for(std::vector<GameObject*>::iterator i = gameobjects.begin();
438 i != gameobjects.end(); /* nothing */) {
439 if((*i)->is_valid() == false) {
440 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
442 badguys.erase(std::remove(badguys.begin(), badguys.end(), badguy),
445 Bullet* bullet = dynamic_cast<Bullet*> (*i);
448 std::remove(bullets.begin(), bullets.end(), bullet),
451 InteractiveObject* interactive_object =
452 dynamic_cast<InteractiveObject*> (*i);
453 if(interactive_object) {
454 interactive_objects.erase(
455 std::remove(interactive_objects.begin(), interactive_objects.end(),
456 interactive_object), interactive_objects.end());
458 Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
461 std::remove(upgrades.begin(), upgrades.end(), upgrade),
464 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
467 std::remove(trampolines.begin(), trampolines.end(), trampoline),
470 FlyingPlatform* flying_platform= dynamic_cast<FlyingPlatform*> (*i);
471 if(flying_platform) {
472 flying_platforms.erase(
473 std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform),
474 flying_platforms.end());
476 SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
479 std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud),
482 Particles* particle = dynamic_cast<Particles*> (*i);
485 std::remove(particles.begin(), particles.end(), particle),
490 i = gameobjects.erase(i);
496 /* add newly created objects */
497 for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
498 i != gameobjects_new.end(); ++i)
500 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
502 badguys.push_back(badguy);
503 Bullet* bullet = dynamic_cast<Bullet*> (*i);
505 bullets.push_back(bullet);
506 Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
508 upgrades.push_back(upgrade);
509 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
511 trampolines.push_back(trampoline);
512 FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
514 flying_platforms.push_back(flying_platform);
515 InteractiveObject* interactive_object
516 = dynamic_cast<InteractiveObject*> (*i);
517 if(interactive_object)
518 interactive_objects.push_back(interactive_object);
519 SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
521 smoke_clouds.push_back(smoke_cloud);
522 Particles* particle = dynamic_cast<Particles*> (*i);
524 particles.push_back(particle);
526 gameobjects.push_back(*i);
528 gameobjects_new.clear();
532 Sector::draw(DrawingContext& context)
534 context.push_transform();
535 context.set_translation(camera->get_translation());
537 for(GameObjects::iterator i = gameobjects.begin();
538 i != gameobjects.end(); ++i) {
539 if( (*i)->is_valid() )
543 context.pop_transform();
547 Sector::collision_handler()
549 // CO_BULLET & CO_BADGUY check
550 for(unsigned int i = 0; i < bullets.size(); ++i)
552 for (BadGuys::iterator j = badguys.begin(); j != badguys.end(); ++j)
554 if((*j)->dying != DYING_NOT)
557 if(rectcollision(bullets[i]->base, (*j)->base))
559 // We have detected a collision and now call the
560 // collision functions of the collided objects.
561 (*j)->collision(bullets[i], CO_BULLET, COLLISION_NORMAL);
562 bullets[i]->collision(CO_BADGUY);
563 break; // bullet is invalid now, so break
568 /* CO_BADGUY & CO_BADGUY check */
569 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
571 if((*i)->dying != DYING_NOT)
574 BadGuys::iterator j = i;
576 for (; j != badguys.end(); ++j)
578 if(j == i || (*j)->dying != DYING_NOT)
581 if(rectcollision((*i)->base, (*j)->base))
583 // We have detected a collision and now call the
584 // collision functions of the collided objects.
585 (*j)->collision(*i, CO_BADGUY);
586 (*i)->collision(*j, CO_BADGUY);
590 if(player->dying != DYING_NOT) return;
592 // CO_BADGUY & CO_PLAYER check
593 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
595 if((*i)->dying != DYING_NOT)
598 if(rectcollision_offset((*i)->base, player->base, 0, 0))
600 // We have detected a collision and now call the collision
601 // functions of the collided objects.
602 if (player->previous_base.y < player->base.y &&
603 player->previous_base.y + player->previous_base.height
604 < (*i)->base.y + (*i)->base.height/2
605 && !player->invincible_timer.started())
607 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
611 player->collision(*i, CO_BADGUY);
612 (*i)->collision(player, CO_PLAYER, COLLISION_NORMAL);
617 // CO_UPGRADE & CO_PLAYER check
618 for(unsigned int i = 0; i < upgrades.size(); ++i)
620 if(rectcollision(upgrades[i]->base, player->base))
622 // We have detected a collision and now call the collision
623 // functions of the collided objects.
624 upgrades[i]->collision(player, CO_PLAYER, COLLISION_NORMAL);
628 // CO_TRAMPOLINE & (CO_PLAYER or CO_BADGUY)
629 for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
631 if (rectcollision((*i)->base, player->base))
633 if (player->previous_base.y < player->base.y &&
634 player->previous_base.y + player->previous_base.height
635 < (*i)->base.y + (*i)->base.height/2)
637 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
639 else if (player->previous_base.y <= player->base.y)
641 player->collision(*i, CO_TRAMPOLINE);
642 (*i)->collision(player, CO_PLAYER, COLLISION_NORMAL);
647 // CO_FLYING_PLATFORM & (CO_PLAYER or CO_BADGUY)
648 for (FlyingPlatforms::iterator i = flying_platforms.begin(); i != flying_platforms.end(); ++i)
650 if (rectcollision((*i)->base, player->base))
652 if (player->previous_base.y < player->base.y &&
653 player->previous_base.y + player->previous_base.height
654 < (*i)->base.y + (*i)->base.height/2)
656 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
657 player->collision(*i, CO_FLYING_PLATFORM);
659 /* else if (player->previous_base.y <= player->base.y)
667 Sector::add_score(const Vector& pos, int s)
669 global_stats.add_points(SCORE_STAT, s);
671 add_object(new FloatingText(pos, s));
675 Sector::add_bouncy_distro(const Vector& pos)
677 add_object(new BouncyDistro(pos));
681 Sector::add_broken_brick(const Vector& pos, Tile* tile)
683 add_broken_brick_piece(pos, Vector(-1, -4), tile);
684 add_broken_brick_piece(pos + Vector(0, 16), Vector(-1.5, -3), tile);
686 add_broken_brick_piece(pos + Vector(16, 0), Vector(1, -4), tile);
687 add_broken_brick_piece(pos + Vector(16, 16), Vector(1.5, -3), tile);
691 Sector::add_broken_brick_piece(const Vector& pos, const Vector& movement,
694 add_object(new BrokenBrick(tile, pos, movement));
698 Sector::add_bouncy_brick(const Vector& pos)
700 add_object(new BouncyBrick(pos));
704 Sector::add_bad_guy(float x, float y, BadGuyKind kind)
706 BadGuy* badguy = new BadGuy(kind, x, y);
712 Sector::add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind)
714 add_object(new Upgrade(pos, dir, kind));
718 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
720 if(player->got_power == Player::FIRE_POWER)
722 if(bullets.size() > MAX_FIRE_BULLETS-1)
725 else if(player->got_power == Player::ICE_POWER)
727 if(bullets.size() > MAX_ICE_BULLETS-1)
731 Bullet* new_bullet = 0;
732 if(player->got_power == Player::FIRE_POWER)
733 new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET);
734 else if(player->got_power == Player::ICE_POWER)
735 new_bullet = new Bullet(pos, xm, dir, ICE_BULLET);
737 throw std::runtime_error("wrong bullet type.");
738 add_object(new_bullet);
740 SoundManager::get()->play_sound(IDToSound(SND_SHOOT));
746 Sector::add_smoke_cloud(const Vector& pos)
748 add_object(new SmokeCloud(pos));
753 Sector::add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time)
755 add_object(new Particles(epicenter, velocity, acceleration, number, color, size, life_time));
760 Sector::add_floating_text(const Vector& pos, const std::string& text)
762 add_object(new FloatingText(pos, text));
767 Sector::trybreakbrick(const Vector& pos, bool small)
769 Tile* tile = solids->get_tile_at(pos);
773 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
774 throw SuperTuxException(errmsg, __FILE__, __LINE__);
777 if (tile->attributes & Tile::BRICK)
781 /* Get a distro from it: */
783 Vector(((int)(pos.x + 1) / 32) * 32, (int)(pos.y / 32) * 32));
785 // TODO: don't handle this in a global way but per-tile...
786 if (!counting_distros)
788 counting_distros = true;
796 if (distro_counter <= 0)
798 counting_distros = false;
799 solids->change_at(pos, tile->next_tile);
802 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
803 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
804 global_stats.add_points(COINS_COLLECTED_STAT, 1);
805 player_status.distros++;
811 solids->change_at(pos, tile->next_tile);
813 /* Replace it with broken bits: */
814 add_broken_brick(Vector(
815 ((int)(pos.x + 1) / 32) * 32,
816 (int)(pos.y / 32) * 32), tile);
818 /* Get some score: */
819 SoundManager::get()->play_sound(IDToSound(SND_BRICK));
820 global_stats.add_points(SCORE_STAT, SCORE_BRICK);
831 Sector::tryemptybox(const Vector& pos, Direction col_side)
833 Tile* tile = solids->get_tile_at(pos);
837 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
838 throw SuperTuxException(errmsg, __FILE__, __LINE__);
842 if (!(tile->attributes & Tile::FULLBOX))
845 // according to the collision side, set the upgrade direction
851 int posx = ((int)(pos.x+1) / 32) * 32;
852 int posy = (int)(pos.y/32) * 32 - 32;
855 case 1: // Box with a distro!
856 add_bouncy_distro(Vector(posx, posy));
857 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
858 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
859 global_stats.add_points(COINS_COLLECTED_STAT, 1);
860 player_status.distros++;
863 case 2: // Add a fire flower upgrade!
864 if (player->size == SMALL) /* Tux is small, add mints! */
865 add_upgrade(Vector(posx, posy), col_side, UPGRADE_GROWUP);
866 else /* Tux is big, add a fireflower: */
867 add_upgrade(Vector(posx, posy), col_side, UPGRADE_FIREFLOWER);
868 SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
871 case 5: // Add an ice flower upgrade!
872 if (player->size == SMALL) /* Tux is small, add mints! */
873 add_upgrade(Vector(posx, posy), col_side, UPGRADE_GROWUP);
874 else /* Tux is big, add an iceflower: */
875 add_upgrade(Vector(posx, posy), col_side, UPGRADE_ICEFLOWER);
876 SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
879 case 3: // Add a golden herring
880 add_upgrade(Vector(posx, posy), col_side, UPGRADE_STAR);
883 case 4: // Add a 1up extra
884 add_upgrade(Vector(posx, posy), col_side, UPGRADE_1UP);
891 solids->change_at(pos, tile->next_tile);
894 /* Try to grab a distro: */
896 Sector::trygrabdistro(const Vector& pos, int bounciness)
898 Tile* tile = solids->get_tile_at(pos);
902 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
903 throw SuperTuxException(errmsg, __FILE__, __LINE__); */
905 //Bad tiles (i.e. tiles that are not defined in supertux.stgt but appear in the map) are changed to ID 0 (blank tile)
906 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;
907 solids->change_at(pos,0);
908 tile = solids->get_tile_at(pos);
912 if (!(tile->attributes & Tile::COIN))
915 solids->change_at(pos, tile->next_tile);
916 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
918 if (bounciness == BOUNCE)
920 add_bouncy_distro(Vector(((int)(pos.x + 1) / 32) * 32,
921 (int)(pos.y / 32) * 32));
924 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
925 global_stats.add_points(COINS_COLLECTED_STAT, 1);
926 player_status.distros++;
930 /* Try to bump a bad guy from below: */
932 Sector::trybumpbadguy(const Vector& pos)
935 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
937 if ((*i)->base.x >= pos.x - 32 && (*i)->base.x <= pos.x + 32 &&
938 (*i)->base.y >= pos.y - 16 && (*i)->base.y <= pos.y + 16)
940 (*i)->collision(player, CO_PLAYER, COLLISION_BUMP);
945 for (unsigned int i = 0; i < upgrades.size(); i++)
947 if (upgrades[i]->base.height == 32 &&
948 upgrades[i]->base.x >= pos.x - 32 && upgrades[i]->base.x <= pos.x + 32 &&
949 upgrades[i]->base.y >= pos.y - 16 && upgrades[i]->base.y <= pos.y + 16)
951 upgrades[i]->collision(player, CO_PLAYER, COLLISION_BUMP);
962 level_song = SoundManager::get()->load_music(datadir + "/music/" + song_title);
964 song_path = (char *) malloc(sizeof(char) * datadir.length() +
965 strlen(song_title.c_str()) + 8 + 5);
966 song_subtitle = strdup(song_title.c_str());
967 strcpy(strstr(song_subtitle, "."), "\0");
968 sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(),
969 song_subtitle, strstr(song_title.c_str(), "."));
970 if(!SoundManager::get()->exists_music(song_path)) {
971 level_song_fast = level_song;
973 level_song_fast = SoundManager::get()->load_music(song_path);
980 Sector::play_music(int type)
983 switch(currentmusic) {
985 SoundManager::get()->play_music(level_song_fast);
988 SoundManager::get()->play_music(level_song);
991 SoundManager::get()->play_music(herring_song);
994 SoundManager::get()->halt_music();
1000 Sector::get_music_type()
1002 return currentmusic;
1006 Sector::get_total_badguys()
1008 int total_badguys = 0;
1009 for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
1011 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
1015 return total_badguys;