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)
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 == "camera") {
91 std::cerr << "Warning: More than 1 camera defined in sector.\n";
94 camera = new Camera(this);
97 } else if(token == "background") {
98 background = new Background(reader);
99 add_object(background);
100 } else if(token == "spawn-points") {
101 SpawnPoint* sp = new SpawnPoint;
102 reader.read_string("name", sp->name);
103 reader.read_float("x", sp->pos.x);
104 reader.read_float("y", sp->pos.y);
105 spawnpoints.push_back(sp);
106 } else if(token == "tilemap") {
107 TileMap* tilemap = new TileMap(reader);
110 if(tilemap->is_solid()) {
112 std::cerr << "Warning multiple solid tilemaps in sector.\n";
117 } else if(badguykind_from_string(token) != BAD_INVALID) {
118 add_object(new BadGuy(badguykind_from_string(token), reader));
119 } else if(token == "trampoline") {
120 add_object(new Trampoline(reader));
121 } else if(token == "flying-platform") {
122 add_object(new FlyingPlatform(reader));
123 } else if(token == "particles-snow") {
124 SnowParticleSystem* partsys = new SnowParticleSystem();
125 partsys->parse(reader);
127 } else if(token == "particles-clouds") {
128 CloudParticleSystem* partsys = new CloudParticleSystem();
129 partsys->parse(reader);
131 } else if(token == "door") {
132 add_object(new Door(reader));
134 std::cerr << "Unknown object type '" << token << "'.\n";
139 std::cerr << "sector '" << name << "' does not contain a camera.\n";
140 camera = new Camera(this);
144 throw std::runtime_error("sector does not contain a solid tile layer.");
148 Sector::parse_old_format(LispReader& reader)
153 reader.read_float("gravity", gravity);
155 std::string backgroundimage;
156 reader.read_string("background", backgroundimage);
158 reader.read_float("bkgd_speed", bgspeed);
161 Color bkgd_top, bkgd_bottom;
162 int r = 0, g = 0, b = 128;
163 reader.read_int("bkgd_red_top", r);
164 reader.read_int("bkgd_green_top", g);
165 reader.read_int("bkgd_blue_top", b);
170 reader.read_int("bkgd_red_bottom", r);
171 reader.read_int("bkgd_green_bottom", g);
172 reader.read_int("bkgd_blue_bottom", b);
174 bkgd_bottom.green = g;
175 bkgd_bottom.blue = b;
177 if(backgroundimage != "") {
178 background = new Background;
179 background->set_image(backgroundimage, bgspeed);
180 add_object(background);
182 background = new Background;
183 background->set_gradient(bkgd_top, bkgd_bottom);
184 add_object(background);
187 std::string particlesystem;
188 reader.read_string("particle_system", particlesystem);
189 if(particlesystem == "clouds")
190 add_object(new CloudParticleSystem());
191 else if(particlesystem == "snow")
192 add_object(new SnowParticleSystem());
194 Vector startpos(100, 170);
195 reader.read_float("start_pos_x", startpos.x);
196 reader.read_float("start_pos_y", startpos.y);
198 SpawnPoint* spawn = new SpawnPoint;
199 spawn->pos = startpos;
200 spawn->name = "main";
201 spawnpoints.push_back(spawn);
203 song_title = "Mortimers_chipdisko.mod";
204 reader.read_string("music", song_title);
207 int width, height = 15;
208 reader.read_int("width", width);
209 reader.read_int("height", height);
211 std::vector<unsigned int> tiles;
212 if(reader.read_int_vector("interactive-tm", tiles)
213 || reader.read_int_vector("tilemap", tiles)) {
214 TileMap* tilemap = new TileMap();
215 tilemap->set(width, height, tiles, LAYER_TILES, true);
220 if(reader.read_int_vector("background-tm", tiles)) {
221 TileMap* tilemap = new TileMap();
222 tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
226 if(reader.read_int_vector("foreground-tm", tiles)) {
227 TileMap* tilemap = new TileMap();
228 tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
232 // read reset-points (now spawn-points)
234 lisp_object_t* cur = 0;
235 if(reader.read_lisp("reset-points", cur)) {
236 while(!lisp_nil_p(cur)) {
237 lisp_object_t* data = lisp_car(cur);
238 LispReader reader(lisp_cdr(data));
241 if(reader.read_float("x", sp_pos.x) && reader.read_float("y", sp_pos.y))
243 SpawnPoint* sp = new SpawnPoint;
246 spawnpoints.push_back(sp);
256 lisp_object_t* cur = 0;
257 if(reader.read_lisp("objects", cur)) {
258 while(!lisp_nil_p(cur)) {
259 lisp_object_t* data = lisp_car(cur);
260 std::string object_type = lisp_symbol(lisp_car(data));
262 LispReader reader(lisp_cdr(data));
264 if(object_type == "trampoline") {
265 add_object(new Trampoline(reader));
267 else if(object_type == "flying-platform") {
268 add_object(new FlyingPlatform(reader));
271 BadGuyKind kind = badguykind_from_string(object_type);
272 add_object(new BadGuy(kind, reader));
281 camera = new Camera(this);
286 Sector::write(LispWriter& writer)
288 writer.write_string("name", name);
289 writer.write_float("gravity", gravity);
290 writer.write_string("music", song_title);
293 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
295 SpawnPoint* spawn = *i;
296 writer.start_list("spawn-points");
297 writer.write_string("name", spawn->name);
298 writer.write_float("x", spawn->pos.x);
299 writer.write_float("y", spawn->pos.y);
300 writer.end_list("spawn-points");
304 for(GameObjects::iterator i = gameobjects.begin();
305 i != gameobjects.end(); ++i) {
306 Serializable* serializable = dynamic_cast<Serializable*> (*i);
308 serializable->write(writer);
313 Sector::do_vertical_flip()
315 for(GameObjects::iterator i = gameobjects_new.begin(); i != gameobjects_new.end(); ++i)
317 TileMap* tilemap = dynamic_cast<TileMap*> (*i);
320 tilemap->do_vertical_flip();
323 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
325 badguy->start_position.y = solids->get_height()*32 - badguy->start_position.y - 32;
326 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
328 trampoline->base.y = solids->get_height()*32 - trampoline->base.y - 32;
329 FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
331 flying_platform->base.y = solids->get_height()*32 - flying_platform->base.y - 32;
332 Door* door = dynamic_cast<Door*> (*i);
334 door->set_area(door->get_area().x, solids->get_height()*32 - door->get_area().y - 32);
337 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
339 SpawnPoint* spawn = *i;
340 spawn->pos.y = solids->get_height()*32 - spawn->pos.y - 32;
345 Sector::add_object(GameObject* object)
347 gameobjects_new.push_back(object);
351 Sector::activate(const std::string& spawnpoint)
355 // Apply bonuses from former levels
356 switch (player_status.bonus)
358 case PlayerStatus::NO_BONUS:
361 case PlayerStatus::FLOWER_BONUS:
362 player->got_power = Player::FIRE_POWER; // FIXME: add ice power to here
365 case PlayerStatus::GROWUP_BONUS:
371 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
373 if((*i)->name == spawnpoint) {
379 std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n";
381 player->move(sp->pos);
384 camera->reset(Vector(player->base.x, player->base.y));
388 Sector::get_best_spawn_point(Vector pos)
390 Vector best_reset_point = Vector(-1,-1);
392 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
394 if((*i)->name != "main")
396 if((*i)->pos.x > best_reset_point.x && (*i)->pos.x < pos.x)
397 best_reset_point = (*i)->pos;
400 return best_reset_point;
404 Sector::action(float elapsed_time)
406 player->check_bounds(camera);
408 /* update objects (don't use iterators here, because the list might change
409 * during the iteration)
411 for(size_t i = 0; i < gameobjects.size(); ++i)
412 if(gameobjects[i]->is_valid())
413 gameobjects[i]->action(elapsed_time);
415 /* Handle all possible collisions. */
418 update_game_objects();
422 Sector::update_game_objects()
424 /** cleanup marked objects */
425 for(std::vector<GameObject*>::iterator i = gameobjects.begin();
426 i != gameobjects.end(); /* nothing */) {
427 if((*i)->is_valid() == false) {
428 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
430 badguys.erase(std::remove(badguys.begin(), badguys.end(), badguy),
433 Bullet* bullet = dynamic_cast<Bullet*> (*i);
436 std::remove(bullets.begin(), bullets.end(), bullet),
439 InteractiveObject* interactive_object =
440 dynamic_cast<InteractiveObject*> (*i);
441 if(interactive_object) {
442 interactive_objects.erase(
443 std::remove(interactive_objects.begin(), interactive_objects.end(),
444 interactive_object), interactive_objects.end());
446 Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
449 std::remove(upgrades.begin(), upgrades.end(), upgrade),
452 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
455 std::remove(trampolines.begin(), trampolines.end(), trampoline),
458 FlyingPlatform* flying_platform= dynamic_cast<FlyingPlatform*> (*i);
459 if(flying_platform) {
460 flying_platforms.erase(
461 std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform),
462 flying_platforms.end());
464 SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
467 std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud),
470 Particles* particle = dynamic_cast<Particles*> (*i);
473 std::remove(particles.begin(), particles.end(), particle),
478 i = gameobjects.erase(i);
484 /* add newly created objects */
485 for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
486 i != gameobjects_new.end(); ++i)
488 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
490 badguys.push_back(badguy);
491 Bullet* bullet = dynamic_cast<Bullet*> (*i);
493 bullets.push_back(bullet);
494 Upgrade* upgrade = dynamic_cast<Upgrade*> (*i);
496 upgrades.push_back(upgrade);
497 Trampoline* trampoline = dynamic_cast<Trampoline*> (*i);
499 trampolines.push_back(trampoline);
500 FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (*i);
502 flying_platforms.push_back(flying_platform);
503 InteractiveObject* interactive_object
504 = dynamic_cast<InteractiveObject*> (*i);
505 if(interactive_object)
506 interactive_objects.push_back(interactive_object);
507 SmokeCloud* smoke_cloud = dynamic_cast<SmokeCloud*> (*i);
509 smoke_clouds.push_back(smoke_cloud);
510 Particles* particle = dynamic_cast<Particles*> (*i);
512 particles.push_back(particle);
514 gameobjects.push_back(*i);
516 gameobjects_new.clear();
520 Sector::draw(DrawingContext& context)
522 context.push_transform();
523 context.set_translation(camera->get_translation());
525 for(GameObjects::iterator i = gameobjects.begin();
526 i != gameobjects.end(); ++i) {
527 if( (*i)->is_valid() )
531 context.pop_transform();
535 Sector::collision_handler()
537 // CO_BULLET & CO_BADGUY check
538 for(unsigned int i = 0; i < bullets.size(); ++i)
540 for (BadGuys::iterator j = badguys.begin(); j != badguys.end(); ++j)
542 if((*j)->dying != DYING_NOT)
545 if(rectcollision(bullets[i]->base, (*j)->base))
547 // We have detected a collision and now call the
548 // collision functions of the collided objects.
549 (*j)->collision(bullets[i], CO_BULLET, COLLISION_NORMAL);
550 bullets[i]->collision(CO_BADGUY);
551 break; // bullet is invalid now, so break
556 /* CO_BADGUY & CO_BADGUY check */
557 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
559 if((*i)->dying != DYING_NOT)
562 BadGuys::iterator j = i;
564 for (; j != badguys.end(); ++j)
566 if(j == i || (*j)->dying != DYING_NOT)
569 if(rectcollision((*i)->base, (*j)->base))
571 // We have detected a collision and now call the
572 // collision functions of the collided objects.
573 (*j)->collision(*i, CO_BADGUY);
574 (*i)->collision(*j, CO_BADGUY);
578 if(player->dying != DYING_NOT) return;
580 // CO_BADGUY & CO_PLAYER check
581 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
583 if((*i)->dying != DYING_NOT)
586 if(rectcollision_offset((*i)->base, player->base, 0, 0))
588 // We have detected a collision and now call the collision
589 // functions of the collided objects.
590 if (player->previous_base.y < player->base.y &&
591 player->previous_base.y + player->previous_base.height
592 < (*i)->base.y + (*i)->base.height/2
593 && !player->invincible_timer.started())
595 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
599 player->collision(*i, CO_BADGUY);
600 (*i)->collision(player, CO_PLAYER, COLLISION_NORMAL);
605 // CO_UPGRADE & CO_PLAYER check
606 for(unsigned int i = 0; i < upgrades.size(); ++i)
608 if(rectcollision(upgrades[i]->base, player->base))
610 // We have detected a collision and now call the collision
611 // functions of the collided objects.
612 upgrades[i]->collision(player, CO_PLAYER, COLLISION_NORMAL);
616 // CO_TRAMPOLINE & (CO_PLAYER or CO_BADGUY)
617 for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i)
619 if (rectcollision((*i)->base, player->base))
621 if (player->previous_base.y < player->base.y &&
622 player->previous_base.y + player->previous_base.height
623 < (*i)->base.y + (*i)->base.height/2)
625 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
627 else if (player->previous_base.y <= player->base.y)
629 player->collision(*i, CO_TRAMPOLINE);
630 (*i)->collision(player, CO_PLAYER, COLLISION_NORMAL);
635 // CO_FLYING_PLATFORM & (CO_PLAYER or CO_BADGUY)
636 for (FlyingPlatforms::iterator i = flying_platforms.begin(); i != flying_platforms.end(); ++i)
638 if (rectcollision((*i)->base, player->base))
640 if (player->previous_base.y < player->base.y &&
641 player->previous_base.y + player->previous_base.height
642 < (*i)->base.y + (*i)->base.height/2)
644 (*i)->collision(player, CO_PLAYER, COLLISION_SQUISH);
645 player->collision(*i, CO_FLYING_PLATFORM);
647 /* else if (player->previous_base.y <= player->base.y)
655 Sector::add_score(const Vector& pos, int s)
657 global_stats.add_points(SCORE_STAT, s);
659 add_object(new FloatingScore(pos, s));
663 Sector::add_bouncy_distro(const Vector& pos)
665 add_object(new BouncyDistro(pos));
669 Sector::add_broken_brick(const Vector& pos, Tile* tile)
671 add_broken_brick_piece(pos, Vector(-1, -4), tile);
672 add_broken_brick_piece(pos + Vector(0, 16), Vector(-1.5, -3), tile);
674 add_broken_brick_piece(pos + Vector(16, 0), Vector(1, -4), tile);
675 add_broken_brick_piece(pos + Vector(16, 16), Vector(1.5, -3), tile);
679 Sector::add_broken_brick_piece(const Vector& pos, const Vector& movement,
682 add_object(new BrokenBrick(tile, pos, movement));
686 Sector::add_bouncy_brick(const Vector& pos)
688 add_object(new BouncyBrick(pos));
692 Sector::add_bad_guy(float x, float y, BadGuyKind kind)
694 BadGuy* badguy = new BadGuy(kind, x, y);
700 Sector::add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind)
702 add_object(new Upgrade(pos, dir, kind));
706 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
708 if(player->got_power == Player::FIRE_POWER)
710 if(bullets.size() > MAX_FIRE_BULLETS-1)
713 else if(player->got_power == Player::ICE_POWER)
715 if(bullets.size() > MAX_ICE_BULLETS-1)
719 Bullet* new_bullet = 0;
720 if(player->got_power == Player::FIRE_POWER)
721 new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET);
722 else if(player->got_power == Player::ICE_POWER)
723 new_bullet = new Bullet(pos, xm, dir, ICE_BULLET);
725 throw std::runtime_error("wrong bullet type.");
726 add_object(new_bullet);
728 SoundManager::get()->play_sound(IDToSound(SND_SHOOT));
734 Sector::add_smoke_cloud(const Vector& pos)
736 add_object(new SmokeCloud(pos));
741 Sector::add_particles(const Vector& epicenter, const Vector& velocity, const Vector& acceleration, int number, Color color, int size, int life_time)
743 add_object(new Particles(epicenter, velocity, acceleration, number, color, size, life_time));
749 Sector::trybreakbrick(const Vector& pos, bool small)
751 Tile* tile = solids->get_tile_at(pos);
755 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
756 throw SuperTuxException(errmsg, __FILE__, __LINE__);
759 if (tile->attributes & Tile::BRICK)
763 /* Get a distro from it: */
765 Vector(((int)(pos.x + 1) / 32) * 32, (int)(pos.y / 32) * 32));
767 // TODO: don't handle this in a global way but per-tile...
768 if (!counting_distros)
770 counting_distros = true;
778 if (distro_counter <= 0)
780 counting_distros = false;
781 solids->change_at(pos, tile->next_tile);
784 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
785 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
786 player_status.distros++;
792 solids->change_at(pos, tile->next_tile);
794 /* Replace it with broken bits: */
795 add_broken_brick(Vector(
796 ((int)(pos.x + 1) / 32) * 32,
797 (int)(pos.y / 32) * 32), tile);
799 /* Get some score: */
800 SoundManager::get()->play_sound(IDToSound(SND_BRICK));
801 global_stats.add_points(SCORE_STAT, SCORE_BRICK);
812 Sector::tryemptybox(const Vector& pos, Direction col_side)
814 Tile* tile = solids->get_tile_at(pos);
818 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
819 throw SuperTuxException(errmsg, __FILE__, __LINE__);
823 if (!(tile->attributes & Tile::FULLBOX))
826 // according to the collision side, set the upgrade direction
832 int posx = ((int)(pos.x+1) / 32) * 32;
833 int posy = (int)(pos.y/32) * 32 - 32;
836 case 1: // Box with a distro!
837 add_bouncy_distro(Vector(posx, posy));
838 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
839 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
840 player_status.distros++;
843 case 2: // Add a fire flower upgrade!
844 if (player->size == SMALL) /* Tux is small, add mints! */
845 add_upgrade(Vector(posx, posy), col_side, UPGRADE_GROWUP);
846 else /* Tux is big, add a fireflower: */
847 add_upgrade(Vector(posx, posy), col_side, UPGRADE_FIREFLOWER);
848 SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
851 case 5: // Add an ice flower upgrade!
852 if (player->size == SMALL) /* Tux is small, add mints! */
853 add_upgrade(Vector(posx, posy), col_side, UPGRADE_GROWUP);
854 else /* Tux is big, add an iceflower: */
855 add_upgrade(Vector(posx, posy), col_side, UPGRADE_ICEFLOWER);
856 SoundManager::get()->play_sound(IDToSound(SND_UPGRADE));
859 case 3: // Add a golden herring
860 add_upgrade(Vector(posx, posy), col_side, UPGRADE_STAR);
863 case 4: // Add a 1up extra
864 add_upgrade(Vector(posx, posy), col_side, UPGRADE_1UP);
871 solids->change_at(pos, tile->next_tile);
874 /* Try to grab a distro: */
876 Sector::trygrabdistro(const Vector& pos, int bounciness)
878 Tile* tile = solids->get_tile_at(pos);
882 sprintf(errmsg, "Invalid tile at %i,%i", (int)((pos.x+1)/32*32), (int)((pos.y+1)/32*32));
883 throw SuperTuxException(errmsg, __FILE__, __LINE__); */
885 //Bad tiles (i.e. tiles that are not defined in supertux.stgt but appear in the map) are changed to ID 0 (blank tile)
886 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;
887 solids->change_at(pos,0);
888 tile = solids->get_tile_at(pos);
892 if (!(tile->attributes & Tile::COIN))
895 solids->change_at(pos, tile->next_tile);
896 SoundManager::get()->play_sound(IDToSound(SND_DISTRO));
898 if (bounciness == BOUNCE)
900 add_bouncy_distro(Vector(((int)(pos.x + 1) / 32) * 32,
901 (int)(pos.y / 32) * 32));
904 global_stats.add_points(SCORE_STAT, SCORE_DISTRO);
905 player_status.distros++;
909 /* Try to bump a bad guy from below: */
911 Sector::trybumpbadguy(const Vector& pos)
914 for (BadGuys::iterator i = badguys.begin(); i != badguys.end(); ++i)
916 if ((*i)->base.x >= pos.x - 32 && (*i)->base.x <= pos.x + 32 &&
917 (*i)->base.y >= pos.y - 16 && (*i)->base.y <= pos.y + 16)
919 (*i)->collision(player, CO_PLAYER, COLLISION_BUMP);
924 for (unsigned int i = 0; i < upgrades.size(); i++)
926 if (upgrades[i]->base.height == 32 &&
927 upgrades[i]->base.x >= pos.x - 32 && upgrades[i]->base.x <= pos.x + 32 &&
928 upgrades[i]->base.y >= pos.y - 16 && upgrades[i]->base.y <= pos.y + 16)
930 upgrades[i]->collision(player, CO_PLAYER, COLLISION_BUMP);
941 level_song = SoundManager::get()->load_music(datadir + "/music/" + song_title);
943 song_path = (char *) malloc(sizeof(char) * datadir.length() +
944 strlen(song_title.c_str()) + 8 + 5);
945 song_subtitle = strdup(song_title.c_str());
946 strcpy(strstr(song_subtitle, "."), "\0");
947 sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(),
948 song_subtitle, strstr(song_title.c_str(), "."));
949 if(!SoundManager::get()->exists_music(song_path)) {
950 level_song_fast = level_song;
952 level_song_fast = SoundManager::get()->load_music(song_path);
959 Sector::play_music(int type)
962 switch(currentmusic) {
964 SoundManager::get()->play_music(level_song_fast);
967 SoundManager::get()->play_music(level_song);
970 SoundManager::get()->play_music(herring_song);
973 SoundManager::get()->halt_music();
979 Sector::get_music_type()