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.
31 #include "player_status.hpp"
32 #include "object/gameobjs.hpp"
33 #include "object/camera.hpp"
34 #include "object/background.hpp"
35 #include "object/particlesystem.hpp"
36 #include "object/particlesystem_interactive.hpp"
37 #include "object/tilemap.hpp"
38 #include "lisp/parser.hpp"
39 #include "lisp/lisp.hpp"
40 #include "lisp/writer.hpp"
41 #include "lisp/list_iterator.hpp"
43 #include "audio/sound_manager.hpp"
44 #include "game_session.hpp"
45 #include "resources.hpp"
46 #include "statistics.hpp"
47 #include "collision_grid.hpp"
48 #include "collision_grid_iterator.hpp"
49 #include "object_factory.hpp"
50 #include "collision.hpp"
51 #include "spawn_point.hpp"
52 #include "math/rect.hpp"
53 #include "math/aatriangle.hpp"
54 #include "object/coin.hpp"
55 #include "object/block.hpp"
56 #include "object/invisible_block.hpp"
57 #include "object/bullet.hpp"
58 #include "object/text_object.hpp"
59 #include "badguy/jumpy.hpp"
60 #include "trigger/sequence_trigger.hpp"
61 #include "player_status.hpp"
62 #include "scripting/script_interpreter.hpp"
63 #include "scripting/sound.hpp"
64 #include "scripting/scripted_object.hpp"
65 #include "scripting/text.hpp"
68 Sector* Sector::_current = 0;
71 : gravity(10), player(0), solids(0), camera(0),
72 currentmusic(LEVEL_MUSIC)
74 player = new Player(player_status);
78 grid = new CollisionGrid(32000, 32000);
86 update_game_objects();
87 assert(gameobjects_new.size() == 0);
91 for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
96 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
105 Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
107 if(name == "camera") {
108 Camera* camera = new Camera(this);
109 camera->parse(reader);
111 } else if(name == "particles-snow") {
112 SnowParticleSystem* partsys = new SnowParticleSystem();
113 partsys->parse(reader);
115 } else if(name == "particles-rain") {
116 RainParticleSystem* partsys = new RainParticleSystem();
117 partsys->parse(reader);
119 } else if(name == "particles-comets") {
120 CometParticleSystem* partsys = new CometParticleSystem();
121 partsys->parse(reader);
123 } else if(name == "particles-ghosts") {
124 GhostParticleSystem* partsys = new GhostParticleSystem();
125 partsys->parse(reader);
127 } else if(name == "particles-clouds") {
128 CloudParticleSystem* partsys = new CloudParticleSystem();
129 partsys->parse(reader);
131 } else if(name == "money") { // for compatibility with old maps
132 return new Jumpy(reader);
136 return create_object(name, reader);
137 } catch(std::exception& e) {
138 msg_warning(e.what() << "");
145 Sector::parse(const lisp::Lisp& sector)
149 lisp::ListIterator iter(§or);
151 const std::string& token = iter.item();
152 if(token == "name") {
153 iter.value()->get(name);
154 } else if(token == "gravity") {
155 iter.value()->get(gravity);
156 } else if(token == "music") {
157 iter.value()->get(music);
158 } else if(token == "spawnpoint") {
159 SpawnPoint* sp = new SpawnPoint(iter.lisp());
160 spawnpoints.push_back(sp);
161 } else if(token == "init-script") {
162 iter.value()->get(init_script);
164 GameObject* object = parse_object(token, *(iter.lisp()));
171 update_game_objects();
174 throw std::runtime_error("sector does not contain a solid tile layer.");
178 msg_warning("sector '" << name << "' does not contain a camera.");
179 update_game_objects();
180 add_object(new Camera(this));
183 update_game_objects();
187 Sector::parse_old_format(const lisp::Lisp& reader)
192 reader.get("gravity", gravity);
194 std::string backgroundimage;
195 reader.get("background", backgroundimage);
197 reader.get("bkgd_speed", bgspeed);
200 Color bkgd_top, bkgd_bottom;
201 int r = 0, g = 0, b = 128;
202 reader.get("bkgd_red_top", r);
203 reader.get("bkgd_green_top", g);
204 reader.get("bkgd_blue_top", b);
205 bkgd_top.red = static_cast<float> (r) / 255.0f;
206 bkgd_top.green = static_cast<float> (g) / 255.0f;
207 bkgd_top.blue = static_cast<float> (b) / 255.0f;
209 reader.get("bkgd_red_bottom", r);
210 reader.get("bkgd_green_bottom", g);
211 reader.get("bkgd_blue_bottom", b);
212 bkgd_bottom.red = static_cast<float> (r) / 255.0f;
213 bkgd_bottom.green = static_cast<float> (g) / 255.0f;
214 bkgd_bottom.blue = static_cast<float> (b) / 255.0f;
216 if(backgroundimage != "") {
217 Background* background = new Background;
218 background->set_image(
219 std::string("images/background/") + backgroundimage, bgspeed);
220 add_object(background);
222 Background* background = new Background;
223 background->set_gradient(bkgd_top, bkgd_bottom);
224 add_object(background);
227 std::string particlesystem;
228 reader.get("particle_system", particlesystem);
229 if(particlesystem == "clouds")
230 add_object(new CloudParticleSystem());
231 else if(particlesystem == "snow")
232 add_object(new SnowParticleSystem());
233 else if(particlesystem == "rain")
234 add_object(new RainParticleSystem());
236 Vector startpos(100, 170);
237 reader.get("start_pos_x", startpos.x);
238 reader.get("start_pos_y", startpos.y);
240 SpawnPoint* spawn = new SpawnPoint;
241 spawn->pos = startpos;
242 spawn->name = "main";
243 spawnpoints.push_back(spawn);
245 music = "chipdisko.ogg";
246 reader.get("music", music);
247 music = "music/" + music;
249 int width = 30, height = 15;
250 reader.get("width", width);
251 reader.get("height", height);
253 std::vector<unsigned int> tiles;
254 if(reader.get_vector("interactive-tm", tiles)
255 || reader.get_vector("tilemap", tiles)) {
256 TileMap* tilemap = new TileMap();
257 tilemap->set(width, height, tiles, LAYER_TILES, true);
261 if(reader.get_vector("background-tm", tiles)) {
262 TileMap* tilemap = new TileMap();
263 tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
267 if(reader.get_vector("foreground-tm", tiles)) {
268 TileMap* tilemap = new TileMap();
269 tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
273 // read reset-points (now spawn-points)
274 const lisp::Lisp* resetpoints = reader.get_lisp("reset-points");
276 lisp::ListIterator iter(resetpoints);
278 if(iter.item() == "point") {
280 if(reader.get("x", sp_pos.x) && reader.get("y", sp_pos.y))
282 SpawnPoint* sp = new SpawnPoint;
285 spawnpoints.push_back(sp);
288 msg_warning("Unknown token '" << iter.item() << "' in reset-points.");
294 const lisp::Lisp* objects = reader.get_lisp("objects");
296 lisp::ListIterator iter(objects);
298 GameObject* object = parse_object(iter.item(), *(iter.lisp()));
302 msg_warning("Unknown object '" << iter.item() << "' in level.");
308 Camera* camera = new Camera(this);
311 update_game_objects();
314 throw std::runtime_error("sector does not contain a solid tile layer.");
317 update_game_objects();
321 Sector::fix_old_tiles()
324 for(size_t x=0; x < solids->get_width(); ++x) {
325 for(size_t y=0; y < solids->get_height(); ++y) {
326 const Tile* tile = solids->get_tile(x, y);
327 Vector pos(x*32, y*32);
329 if(tile->getID() == 112) {
330 add_object(new InvisibleBlock(pos));
331 solids->change(x, y, 0);
332 } else if(tile->getAttributes() & Tile::COIN) {
333 add_object(new Coin(pos));
334 solids->change(x, y, 0);
335 } else if(tile->getAttributes() & Tile::FULLBOX) {
336 add_object(new BonusBlock(pos, tile->getData()));
337 solids->change(x, y, 0);
338 } else if(tile->getAttributes() & Tile::BRICK) {
339 add_object(new Brick(pos, tile->getData()));
340 solids->change(x, y, 0);
341 } else if(tile->getAttributes() & Tile::GOAL) {
342 std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
343 add_object(new SequenceTrigger(pos, sequence));
344 solids->change(x, y, 0);
351 Sector::write(lisp::Writer& writer)
353 writer.write_string("name", name);
354 writer.write_float("gravity", gravity);
355 writer.write_string("music", music);
358 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
360 SpawnPoint* spawn = *i;
361 writer.start_list("spawn-points");
362 writer.write_string("name", spawn->name);
363 writer.write_float("x", spawn->pos.x);
364 writer.write_float("y", spawn->pos.y);
365 writer.end_list("spawn-points");
369 for(GameObjects::iterator i = gameobjects.begin();
370 i != gameobjects.end(); ++i) {
371 Serializable* serializable = dynamic_cast<Serializable*> (*i);
373 serializable->write(writer);
378 Sector::add_object(GameObject* object)
380 // make sure the object isn't already in the list
382 for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
385 assert("object already added to sector" == 0);
388 for(GameObjects::iterator i = gameobjects_new.begin();
389 i != gameobjects_new.end(); ++i) {
391 assert("object already added to sector" == 0);
396 gameobjects_new.push_back(object);
400 Sector::activate(const std::string& spawnpoint)
403 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
405 if((*i)->name == spawnpoint) {
411 msg_warning("Spawnpoint '" << spawnpoint << "' not found.");
412 if(spawnpoint != "main") {
415 activate(Vector(0, 0));
422 if(init_script != "") {
423 ScriptInterpreter::add_script_object(this,
424 std::string("Sector(") + name + ") - init", init_script);
429 Sector::activate(const Vector& player_pos)
433 player->move(player_pos);
434 camera->reset(player->get_pos());
438 Sector::get_active_region()
441 camera->get_translation() - Vector(1600, 1200),
442 camera->get_translation() + Vector(1600, 1200));
446 Sector::update(float elapsed_time)
448 player->check_bounds(camera);
451 CollisionGridIterator iter(*grid, get_active_region());
452 while(MovingObject* object = iter.next()) {
453 if(!object->is_valid())
456 object->update(elapsed_time);
460 for(GameObjects::iterator i = gameobjects.begin();
461 i != gameobjects.end(); ++i) {
462 GameObject* object = *i;
463 if(!object->is_valid())
466 object->update(elapsed_time);
470 /* Handle all possible collisions. */
472 update_game_objects();
476 Sector::update_game_objects()
478 /** cleanup marked objects */
479 for(std::vector<Bullet*>::iterator i = bullets.begin();
480 i != bullets.end(); /* nothing */) {
482 if(bullet->is_valid()) {
487 i = bullets.erase(i);
489 for(MovingObjects::iterator i = moving_objects.begin();
490 i != moving_objects.end(); /* nothing */) {
491 MovingObject* moving_object = *i;
492 if(moving_object->is_valid()) {
498 grid->remove_object(moving_object);
501 i = moving_objects.erase(i);
503 for(std::vector<GameObject*>::iterator i = gameobjects.begin();
504 i != gameobjects.end(); /* nothing */) {
505 GameObject* object = *i;
507 if(object->is_valid()) {
513 i = gameobjects.erase(i);
516 /* add newly created objects */
517 for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
518 i != gameobjects_new.end(); ++i)
520 GameObject* object = *i;
522 Bullet* bullet = dynamic_cast<Bullet*> (object);
524 bullets.push_back(bullet);
526 MovingObject* movingobject = dynamic_cast<MovingObject*> (object);
528 moving_objects.push_back(movingobject);
530 grid->add_object(movingobject);
534 TileMap* tilemap = dynamic_cast<TileMap*> (object);
535 if(tilemap && tilemap->is_solid()) {
539 msg_warning("Another solid tilemaps added. Ignoring");
543 Camera* camera = dynamic_cast<Camera*> (object);
545 if(this->camera != 0) {
546 msg_warning("Multiple cameras added. Ignoring");
549 this->camera = camera;
552 gameobjects.push_back(object);
554 gameobjects_new.clear();
558 Sector::draw(DrawingContext& context)
560 context.push_transform();
561 context.set_translation(camera->get_translation());
563 for(GameObjects::iterator i = gameobjects.begin();
564 i != gameobjects.end(); ++i) {
565 GameObject* object = *i;
566 if(!object->is_valid())
569 object->draw(context);
572 context.pop_transform();
575 static const float DELTA = .001;
578 Sector::collision_tilemap(const Rect& dest, const Vector& movement,
579 CollisionHit& hit) const
581 // calculate rectangle where the object will move
582 float x1 = dest.get_left();
583 float x2 = dest.get_right();
584 float y1 = dest.get_top();
585 float y2 = dest.get_bottom();
587 // test with all tiles in this rectangle
588 int starttilex = int(x1) / 32;
589 int starttiley = int(y1) / 32;
591 // the +1 is somehow needed to make characters stay on the floor
592 int max_y = int(y2+1);
594 CollisionHit temphit;
595 for(int x = starttilex; x*32 < max_x; ++x) {
596 for(int y = starttiley; y*32 < max_y; ++y) {
597 const Tile* tile = solids->get_tile(x, y);
600 // skip non-solid tiles
601 if(tile->getAttributes() == 0)
603 // only handle unisolid when the player is falling down and when he was
604 // above the tile before
605 if(tile->getAttributes() & Tile::UNISOLID) {
606 if(movement.y < 0 || dest.get_top() - movement.y > y*32)
610 if(tile->getAttributes() & Tile::SLOPE) { // slope tile
612 Vector p1(x*32, y*32);
613 Vector p2((x+1)*32, (y+1)*32);
614 triangle = AATriangle(p1, p2, tile->getData());
616 if(Collision::rectangle_aatriangle(temphit, dest, movement,
618 if(temphit.time > hit.time && (tile->getAttributes() & Tile::SOLID)) {
622 } else { // normal rectangular tile
623 Rect rect(x*32, y*32, (x+1)*32, (y+1)*32);
624 if(Collision::rectangle_rectangle(temphit, dest, movement, rect)) {
625 if(temphit.time > hit.time && (tile->getAttributes() & Tile::SOLID)) {
635 Sector::collision_tile_attributes(const Rect& dest) const
637 /** XXX This function doesn't work correctly as it will check all tiles
638 * in the bounding box of the object movement, this might include tiles
639 * that have actually never been touched by the object
640 * (though this only occures for very fast objects...)
644 // calculate rectangle where the object will move
646 if(object->get_movement().x >= 0) {
647 x1 = object->get_bbox().p1.x;
648 x2 = object->get_bbox().p2.x + object->get_movement().x;
650 x1 = object->get_bbox().p1.x + object->get_movement().x;
651 x2 = object->get_bbox().p2.x;
654 if(object->get_movement().y >= 0) {
655 y1 = object->get_bbox().p1.y;
656 y2 = object->get_bbox().p2.y + object->get_movement().y;
658 y1 = object->get_bbox().p1.y + object->get_movement().y;
659 y2 = object->get_bbox().p2.y;
662 float x1 = dest.p1.x;
663 float y1 = dest.p1.y;
664 float x2 = dest.p2.x;
665 float y2 = dest.p2.y;
667 // test with all tiles in this rectangle
668 int starttilex = int(x1) / 32;
669 int starttiley = int(y1) / 32;
674 for(int x = starttilex; x*32 < max_x; ++x) {
675 for(int y = starttiley; y*32 < max_y; ++y) {
676 const Tile* tile = solids->get_tile(x, y);
679 result |= tile->getAttributes();
687 Sector::collision_object(MovingObject* object1, MovingObject* object2) const
691 Vector movement = object1->get_movement() - object2->get_movement();
692 if(Collision::rectangle_rectangle(hit, object1->dest, movement, object2->dest)) {
693 HitResponse response1 = object1->collision(*object2, hit);
695 HitResponse response2 = object2->collision(*object1, hit);
697 if(response1 != CONTINUE) {
698 if(response1 == ABORT_MOVE)
699 object1->dest = object1->get_bbox();
700 if(response2 == CONTINUE)
701 object2->dest.move(hit.normal * (hit.depth + DELTA));
702 } else if(response2 != CONTINUE) {
703 if(response2 == ABORT_MOVE)
704 object2->dest = object2->get_bbox();
705 if(response1 == CONTINUE)
706 object1->dest.move(-hit.normal * (hit.depth + DELTA));
708 object1->dest.move(-hit.normal * (hit.depth/2 + DELTA));
709 object2->dest.move(hit.normal * (hit.depth/2 + DELTA));
715 Sector::collision_static(MovingObject* object, const Vector& movement)
717 GameObject* collided_with = solids;
721 collision_tilemap(object->dest, movement, hit);
723 // collision with other (static) objects
724 CollisionHit temphit;
725 for(MovingObjects::iterator i2 = moving_objects.begin();
726 i2 != moving_objects.end(); ++i2) {
727 MovingObject* moving_object_2 = *i2;
728 if(moving_object_2->get_group() != COLGROUP_STATIC
729 || !moving_object_2->is_valid())
732 Rect dest2 = moving_object_2->get_bbox();
733 // We're using the old position of the object here,
734 // this might seem a bit wrong but improves some situations
735 // like stacked boxes and badguys alot
737 dest2.move(moving_object_2->get_movement());
739 = movement - moving_object_2->get_movement();
742 if(Collision::rectangle_rectangle(temphit, object->dest, rel_movement, dest2)
743 && temphit.time > hit.time) {
745 collided_with = moving_object_2;
752 HitResponse response = object->collision(*collided_with, hit);
754 if(collided_with != solids) {
755 MovingObject* moving_object = (MovingObject*) collided_with;
756 HitResponse other_response = moving_object->collision(*object, hit);
757 if(other_response == ABORT_MOVE) {
758 moving_object->dest = moving_object->get_bbox();
759 } else if(other_response == FORCE_MOVE) {
760 // the static object "wins" move tux out of the collision
761 object->dest.move(-hit.normal * (hit.depth + DELTA));
763 } else if(other_response == PASS_MOVEMENT) {
764 object->dest.move(moving_object->get_movement());
765 //object->movement += moving_object->get_movement();
769 if(response == CONTINUE) {
770 object->dest.move(-hit.normal * (hit.depth + DELTA));
772 } else if(response == ABORT_MOVE) {
773 object->dest = object->get_bbox();
782 Sector::handle_collisions()
784 // calculate destination positions of the objects
785 for(MovingObjects::iterator i = moving_objects.begin();
786 i != moving_objects.end(); ++i) {
787 MovingObject* moving_object = *i;
789 moving_object->dest = moving_object->get_bbox();
790 moving_object->dest.move(moving_object->get_movement());
793 // part1: COLGROUP_MOVING vs COLGROUP_STATIC and tilemap
794 // we do this up to 4 times and have to sort all results for the smallest
795 // one before we can continue here
796 for(MovingObjects::iterator i = moving_objects.begin();
797 i != moving_objects.end(); ++i) {
798 MovingObject* moving_object = *i;
799 if((moving_object->get_group() != COLGROUP_MOVING
800 && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
801 || !moving_object->is_valid())
804 Vector movement = moving_object->get_movement();
806 // test if x or y movement is dominant
807 if(fabsf(moving_object->get_movement().x) > fabsf(moving_object->get_movement().y)) {
809 // test in x direction first, then y direction
810 moving_object->dest.move(Vector(0, -movement.y));
811 for(int i = 0; i < 2; ++i) {
812 bool res = collision_static(moving_object, /*Vector(movement.x, 0)*/ movement);
816 moving_object->dest.move(Vector(0, movement.y));
817 for(int i = 0; i < 2; ++i) {
818 bool res = collision_static(moving_object, /*Vector(0, movement.y)*/ movement);
825 // test in y direction first, then x direction
826 moving_object->dest.move(Vector(-movement.x, 0));
827 for(int i = 0; i < 2; ++i) {
828 bool res = collision_static(moving_object, movement/*Vector(0, movement.y)*/);
832 moving_object->dest.move(Vector(movement.x, 0));
833 for(int i = 0; i < 2; ++i) {
834 bool res = collision_static(moving_object, movement /*Vector(movement.x, 0)*/);
841 // part2: COLGROUP_MOVING vs tile attributes
842 for(MovingObjects::iterator i = moving_objects.begin();
843 i != moving_objects.end(); ++i) {
844 MovingObject* moving_object = *i;
845 if((moving_object->get_group() != COLGROUP_MOVING
846 && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
847 || !moving_object->is_valid())
850 uint32_t tile_attributes = collision_tile_attributes(moving_object->dest);
851 if(tile_attributes > Tile::FIRST_INTERESTING_FLAG) {
852 moving_object->collision_tile(tile_attributes);
856 // part2.5: COLGROUP_MOVING vs COLGROUP_TOUCHABLE
857 for(MovingObjects::iterator i = moving_objects.begin();
858 i != moving_objects.end(); ++i) {
859 MovingObject* moving_object = *i;
860 if(moving_object->get_group() != COLGROUP_MOVING
861 || !moving_object->is_valid())
864 for(MovingObjects::iterator i2 = moving_objects.begin();
865 i2 != moving_objects.end(); ++i2) {
866 MovingObject* moving_object_2 = *i2;
867 if(moving_object_2->get_group() != COLGROUP_TOUCHABLE
868 || !moving_object_2->is_valid())
871 collision_object(moving_object, moving_object_2);
875 // part3: COLGROUP_MOVING vs COLGROUP_MOVING
876 for(MovingObjects::iterator i = moving_objects.begin();
877 i != moving_objects.end(); ++i) {
878 MovingObject* moving_object = *i;
880 if(moving_object->get_group() != COLGROUP_MOVING
881 || !moving_object->is_valid())
884 for(MovingObjects::iterator i2 = i+1;
885 i2 != moving_objects.end(); ++i2) {
886 MovingObject* moving_object_2 = *i2;
887 if(moving_object_2->get_group() != COLGROUP_MOVING
888 || !moving_object_2->is_valid())
891 collision_object(moving_object, moving_object_2);
895 // apply object movement
896 for(MovingObjects::iterator i = moving_objects.begin();
897 i != moving_objects.end(); ++i) {
898 MovingObject* moving_object = *i;
900 moving_object->bbox = moving_object->dest;
901 moving_object->movement = Vector(0, 0);
906 Sector::is_free_space(const Rect& rect) const
908 // test with all tiles in this rectangle
909 int starttilex = int(rect.p1.x) / 32;
910 int starttiley = int(rect.p1.y) / 32;
911 int max_x = int(rect.p2.x);
912 int max_y = int(rect.p2.y);
914 for(int x = starttilex; x*32 < max_x; ++x) {
915 for(int y = starttiley; y*32 < max_y; ++y) {
916 const Tile* tile = solids->get_tile(x, y);
919 if(tile->getAttributes() & Tile::SOLID)
924 for(MovingObjects::const_iterator i = moving_objects.begin();
925 i != moving_objects.end(); ++i) {
926 const MovingObject* moving_object = *i;
927 if(moving_object->get_group() != COLGROUP_STATIC
928 || !moving_object->is_valid())
931 if(Collision::intersects(rect, moving_object->get_bbox()))
939 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
941 // TODO remove this function and move these checks elsewhere...
942 static const size_t MAX_FIRE_BULLETS = 2;
943 static const size_t MAX_ICE_BULLETS = 1;
945 Bullet* new_bullet = 0;
946 if(player_status->bonus == FIRE_BONUS) {
947 if(bullets.size() > MAX_FIRE_BULLETS-1)
949 new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET);
950 } else if(player_status->bonus == ICE_BONUS) {
951 if(bullets.size() > MAX_ICE_BULLETS-1)
953 new_bullet = new Bullet(pos, xm, dir, ICE_BULLET);
957 add_object(new_bullet);
959 sound_manager->play("sounds/shoot.wav");
965 Sector::add_smoke_cloud(const Vector& pos)
967 add_object(new SmokeCloud(pos));
972 Sector::add_floating_text(const Vector& pos, const std::string& text)
974 add_object(new FloatingText(pos, text));
978 Sector::play_music(MusicType type)
981 switch(currentmusic) {
983 sound_manager->play_music(music);
986 sound_manager->play_music("music/salcon.ogg");
989 sound_manager->play_music("");
995 Sector::get_music_type()
1001 Sector::get_total_badguys()
1003 int total_badguys = 0;
1004 for(GameObjects::iterator i = gameobjects.begin();
1005 i != gameobjects.end(); ++i) {
1006 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
1007 if (badguy && badguy->countMe)
1011 return total_badguys;
1015 Sector::inside(const Rect& rect) const
1017 if(rect.p1.x > solids->get_width() * 32
1018 || rect.p1.y > solids->get_height() * 32
1019 || rect.p2.x < 0 || rect.p2.y < 0)