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"
67 Sector* Sector::_current = 0;
70 : gravity(10), player(0), solids(0), camera(0),
71 currentmusic(LEVEL_MUSIC)
73 player = new Player(player_status);
77 grid = new CollisionGrid(32000, 32000);
85 update_game_objects();
86 assert(gameobjects_new.size() == 0);
90 for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
95 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
104 Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
106 if(name == "camera") {
107 Camera* camera = new Camera(this);
108 camera->parse(reader);
110 } else if(name == "particles-snow") {
111 SnowParticleSystem* partsys = new SnowParticleSystem();
112 partsys->parse(reader);
114 } else if(name == "particles-rain") {
115 RainParticleSystem* partsys = new RainParticleSystem();
116 partsys->parse(reader);
118 } else if(name == "particles-comets") {
119 CometParticleSystem* partsys = new CometParticleSystem();
120 partsys->parse(reader);
122 } else if(name == "particles-ghosts") {
123 GhostParticleSystem* partsys = new GhostParticleSystem();
124 partsys->parse(reader);
126 } else if(name == "particles-clouds") {
127 CloudParticleSystem* partsys = new CloudParticleSystem();
128 partsys->parse(reader);
130 } else if(name == "money") { // for compatibility with old maps
131 return new Jumpy(reader);
135 return create_object(name, reader);
136 } catch(std::exception& e) {
137 std::cerr << e.what() << "\n";
144 Sector::parse(const lisp::Lisp& sector)
148 lisp::ListIterator iter(§or);
150 const std::string& token = iter.item();
151 if(token == "name") {
152 iter.value()->get(name);
153 } else if(token == "gravity") {
154 iter.value()->get(gravity);
155 } else if(token == "music") {
156 iter.value()->get(song_title);
157 } else if(token == "spawnpoint") {
158 SpawnPoint* sp = new SpawnPoint(iter.lisp());
159 spawnpoints.push_back(sp);
160 } else if(token == "init-script") {
161 iter.value()->get(init_script);
163 GameObject* object = parse_object(token, *(iter.lisp()));
170 update_game_objects();
173 throw std::runtime_error("sector does not contain a solid tile layer.");
177 std::cerr << "sector '" << name << "' does not contain a camera.\n";
178 update_game_objects();
179 add_object(new Camera(this));
182 update_game_objects();
186 Sector::parse_old_format(const lisp::Lisp& reader)
191 reader.get("gravity", gravity);
193 std::string backgroundimage;
194 reader.get("background", backgroundimage);
196 reader.get("bkgd_speed", bgspeed);
199 Color bkgd_top, bkgd_bottom;
200 int r = 0, g = 0, b = 128;
201 reader.get("bkgd_red_top", r);
202 reader.get("bkgd_green_top", g);
203 reader.get("bkgd_blue_top", b);
204 bkgd_top.red = static_cast<float> (r) / 255.0f;
205 bkgd_top.green = static_cast<float> (g) / 255.0f;
206 bkgd_top.blue = static_cast<float> (b) / 255.0f;
208 reader.get("bkgd_red_bottom", r);
209 reader.get("bkgd_green_bottom", g);
210 reader.get("bkgd_blue_bottom", b);
211 bkgd_bottom.red = static_cast<float> (r) / 255.0f;
212 bkgd_bottom.green = static_cast<float> (g) / 255.0f;
213 bkgd_bottom.blue = static_cast<float> (b) / 255.0f;
215 if(backgroundimage != "") {
216 Background* background = new Background;
217 background->set_image(backgroundimage, bgspeed);
218 add_object(background);
220 Background* background = new Background;
221 background->set_gradient(bkgd_top, bkgd_bottom);
222 add_object(background);
225 std::string particlesystem;
226 reader.get("particle_system", particlesystem);
227 if(particlesystem == "clouds")
228 add_object(new CloudParticleSystem());
229 else if(particlesystem == "snow")
230 add_object(new SnowParticleSystem());
231 else if(particlesystem == "rain")
232 add_object(new RainParticleSystem());
234 Vector startpos(100, 170);
235 reader.get("start_pos_x", startpos.x);
236 reader.get("start_pos_y", startpos.y);
238 SpawnPoint* spawn = new SpawnPoint;
239 spawn->pos = startpos;
240 spawn->name = "main";
241 spawnpoints.push_back(spawn);
243 song_title = "chipdisko.ogg";
244 reader.get("music", song_title);
246 int width = 30, height = 15;
247 reader.get("width", width);
248 reader.get("height", height);
250 std::vector<unsigned int> tiles;
251 if(reader.get_vector("interactive-tm", tiles)
252 || reader.get_vector("tilemap", tiles)) {
253 TileMap* tilemap = new TileMap();
254 tilemap->set(width, height, tiles, LAYER_TILES, true);
258 if(reader.get_vector("background-tm", tiles)) {
259 TileMap* tilemap = new TileMap();
260 tilemap->set(width, height, tiles, LAYER_BACKGROUNDTILES, false);
264 if(reader.get_vector("foreground-tm", tiles)) {
265 TileMap* tilemap = new TileMap();
266 tilemap->set(width, height, tiles, LAYER_FOREGROUNDTILES, false);
270 // read reset-points (now spawn-points)
271 const lisp::Lisp* resetpoints = reader.get_lisp("reset-points");
273 lisp::ListIterator iter(resetpoints);
275 if(iter.item() == "point") {
277 if(reader.get("x", sp_pos.x) && reader.get("y", sp_pos.y))
279 SpawnPoint* sp = new SpawnPoint;
282 spawnpoints.push_back(sp);
285 std::cerr << "Unknown token '" << iter.item() << "' in reset-points.\n";
291 const lisp::Lisp* objects = reader.get_lisp("objects");
293 lisp::ListIterator iter(objects);
295 GameObject* object = parse_object(iter.item(), *(iter.lisp()));
299 std::cerr << "Unknown object '" << iter.item() << "' in level.\n";
305 Camera* camera = new Camera(this);
308 update_game_objects();
311 throw std::runtime_error("sector does not contain a solid tile layer.");
314 update_game_objects();
318 Sector::fix_old_tiles()
321 for(size_t x=0; x < solids->get_width(); ++x) {
322 for(size_t y=0; y < solids->get_height(); ++y) {
323 const Tile* tile = solids->get_tile(x, y);
324 Vector pos(x*32, y*32);
326 if(tile->getID() == 112) {
327 add_object(new InvisibleBlock(pos));
328 solids->change(x, y, 0);
329 } else if(tile->getAttributes() & Tile::COIN) {
330 add_object(new Coin(pos));
331 solids->change(x, y, 0);
332 } else if(tile->getAttributes() & Tile::FULLBOX) {
333 add_object(new BonusBlock(pos, tile->getData()));
334 solids->change(x, y, 0);
335 } else if(tile->getAttributes() & Tile::BRICK) {
336 add_object(new Brick(pos, tile->getData()));
337 solids->change(x, y, 0);
338 } else if(tile->getAttributes() & Tile::GOAL) {
339 std::string sequence = tile->getData() == 0 ? "endsequence" : "stoptux";
340 add_object(new SequenceTrigger(pos, sequence));
341 solids->change(x, y, 0);
348 Sector::write(lisp::Writer& writer)
350 writer.write_string("name", name);
351 writer.write_float("gravity", gravity);
352 writer.write_string("music", song_title);
355 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
357 SpawnPoint* spawn = *i;
358 writer.start_list("spawn-points");
359 writer.write_string("name", spawn->name);
360 writer.write_float("x", spawn->pos.x);
361 writer.write_float("y", spawn->pos.y);
362 writer.end_list("spawn-points");
366 for(GameObjects::iterator i = gameobjects.begin();
367 i != gameobjects.end(); ++i) {
368 Serializable* serializable = dynamic_cast<Serializable*> (*i);
370 serializable->write(writer);
375 Sector::add_object(GameObject* object)
377 // make sure the object isn't already in the list
379 for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end();
382 assert("object already added to sector" == 0);
385 for(GameObjects::iterator i = gameobjects_new.begin();
386 i != gameobjects_new.end(); ++i) {
388 assert("object already added to sector" == 0);
393 gameobjects_new.push_back(object);
397 Sector::activate(const std::string& spawnpoint)
400 for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end();
402 if((*i)->name == spawnpoint) {
408 std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n";
409 if(spawnpoint != "main") {
412 activate(Vector(0, 0));
419 if(init_script != "") {
420 ScriptInterpreter::add_script_object(this,
421 std::string("Sector(") + name + ") - init", init_script);
426 Sector::activate(const Vector& player_pos)
430 player->move(player_pos);
431 camera->reset(player->get_pos());
435 Sector::get_active_region()
438 camera->get_translation() - Vector(1600, 1200),
439 camera->get_translation() + Vector(1600, 1200));
443 Sector::update(float elapsed_time)
445 player->check_bounds(camera);
448 CollisionGridIterator iter(*grid, get_active_region());
449 while(MovingObject* object = iter.next()) {
450 if(!object->is_valid())
453 object->update(elapsed_time);
457 for(GameObjects::iterator i = gameobjects.begin();
458 i != gameobjects.end(); ++i) {
459 GameObject* object = *i;
460 if(!object->is_valid())
463 object->update(elapsed_time);
467 /* Handle all possible collisions. */
469 update_game_objects();
473 Sector::update_game_objects()
475 /** cleanup marked objects */
476 for(std::vector<Bullet*>::iterator i = bullets.begin();
477 i != bullets.end(); /* nothing */) {
479 if(bullet->is_valid()) {
484 i = bullets.erase(i);
486 for(MovingObjects::iterator i = moving_objects.begin();
487 i != moving_objects.end(); /* nothing */) {
488 MovingObject* moving_object = *i;
489 if(moving_object->is_valid()) {
495 grid->remove_object(moving_object);
498 i = moving_objects.erase(i);
500 for(std::vector<GameObject*>::iterator i = gameobjects.begin();
501 i != gameobjects.end(); /* nothing */) {
502 GameObject* object = *i;
504 if(object->is_valid()) {
510 i = gameobjects.erase(i);
513 /* add newly created objects */
514 for(std::vector<GameObject*>::iterator i = gameobjects_new.begin();
515 i != gameobjects_new.end(); ++i)
517 GameObject* object = *i;
519 Bullet* bullet = dynamic_cast<Bullet*> (object);
521 bullets.push_back(bullet);
523 MovingObject* movingobject = dynamic_cast<MovingObject*> (object);
525 moving_objects.push_back(movingobject);
527 grid->add_object(movingobject);
531 TileMap* tilemap = dynamic_cast<TileMap*> (object);
532 if(tilemap && tilemap->is_solid()) {
536 std::cerr << "Another solid tilemaps added. Ignoring.";
540 Camera* camera = dynamic_cast<Camera*> (object);
542 if(this->camera != 0) {
543 std::cerr << "Warning: Multiple cameras added. Ignoring.";
546 this->camera = camera;
549 gameobjects.push_back(object);
551 gameobjects_new.clear();
555 Sector::draw(DrawingContext& context)
557 context.push_transform();
558 context.set_translation(camera->get_translation());
560 for(GameObjects::iterator i = gameobjects.begin();
561 i != gameobjects.end(); ++i) {
562 GameObject* object = *i;
563 if(!object->is_valid())
566 object->draw(context);
569 context.pop_transform();
572 static const float DELTA = .001;
575 Sector::collision_tilemap(MovingObject* object, CollisionHit& hit) const
577 // calculate rectangle where the object will move
579 if(object->get_movement().x >= 0) {
580 x1 = object->get_bbox().p1.x;
581 x2 = object->get_bbox().p2.x + object->get_movement().x;
583 x1 = object->get_bbox().p1.x + object->get_movement().x;
584 x2 = object->get_bbox().p2.x;
587 if(object->get_movement().y >= 0) {
588 y1 = object->get_bbox().p1.y;
589 y2 = object->get_bbox().p2.y + object->get_movement().y;
591 y1 = object->get_bbox().p1.y + object->get_movement().y;
592 y2 = object->get_bbox().p2.y;
595 // test with all tiles in this rectangle
596 int starttilex = int(x1) / 32;
597 int starttiley = int(y1) / 32;
599 // the +1 is somehow needed to make characters stay on the floor
600 int max_y = int(y2+1);
602 CollisionHit temphit;
603 Rect dest = object->get_bbox();
604 dest.move(object->movement);
605 for(int x = starttilex; x*32 < max_x; ++x) {
606 for(int y = starttiley; y*32 < max_y; ++y) {
607 const Tile* tile = solids->get_tile(x, y);
610 // skip non-solid tiles
611 if(tile->getAttributes() == 0)
613 // only handle unisolid when the player is falling down and when he was
614 // above the tile before
615 if(tile->getAttributes() & Tile::UNISOLID) {
616 if(object->movement.y < 0 || object->get_bbox().p2.y > y*32)
620 if(tile->getAttributes() & Tile::SLOPE) { // slope tile
622 Vector p1(x*32, y*32);
623 Vector p2((x+1)*32, (y+1)*32);
624 triangle = AATriangle(p1, p2, tile->getData());
626 if(Collision::rectangle_aatriangle(temphit, dest, object->movement,
628 if(temphit.time > hit.time && (tile->getAttributes() & Tile::SOLID)) {
632 } else { // normal rectangular tile
633 Rect rect(x*32, y*32, (x+1)*32, (y+1)*32);
634 if(Collision::rectangle_rectangle(temphit, dest,
635 object->movement, rect)) {
636 if(temphit.time > hit.time && (tile->getAttributes() & Tile::SOLID)) {
646 Sector::collision_tile_attributes(MovingObject* object) const
648 /** XXX This function doesn't work correctly as it will check all tiles
649 * in the bounding box of the object movement, this might include tiles
650 * that have actually never been touched by the object
651 * (though this only occures for very fast objects...)
654 // calculate rectangle where the object will move
656 if(object->get_movement().x >= 0) {
657 x1 = object->get_bbox().p1.x;
658 x2 = object->get_bbox().p2.x + object->get_movement().x;
660 x1 = object->get_bbox().p1.x + object->get_movement().x;
661 x2 = object->get_bbox().p2.x;
664 if(object->get_movement().y >= 0) {
665 y1 = object->get_bbox().p1.y;
666 y2 = object->get_bbox().p2.y + object->get_movement().y;
668 y1 = object->get_bbox().p1.y + object->get_movement().y;
669 y2 = object->get_bbox().p2.y;
672 // test with all tiles in this rectangle
673 int starttilex = int(x1-1) / 32;
674 int starttiley = int(y1-1) / 32;
675 int max_x = int(x2+1);
676 int max_y = int(y2+1);
679 for(int x = starttilex; x*32 < max_x; ++x) {
680 for(int y = starttiley; y*32 < max_y; ++y) {
681 const Tile* tile = solids->get_tile(x, y);
684 result |= tile->getAttributes();
692 Sector::collision_object(MovingObject* object1, MovingObject* object2) const
695 Rect dest1 = object1->get_bbox();
696 dest1.move(object1->get_movement());
697 Rect dest2 = object2->get_bbox();
698 dest2.move(object2->get_movement());
700 Vector movement = object1->get_movement() - object2->get_movement();
701 if(Collision::rectangle_rectangle(hit, dest1, movement, dest2)) {
702 HitResponse response1 = object1->collision(*object2, hit);
704 HitResponse response2 = object2->collision(*object1, hit);
706 if(response1 != CONTINUE) {
707 if(response1 == ABORT_MOVE)
708 object1->movement = Vector(0, 0);
709 if(response2 == CONTINUE)
710 object2->movement += hit.normal * (hit.depth + DELTA);
711 } else if(response2 != CONTINUE) {
712 if(response2 == ABORT_MOVE)
713 object2->movement = Vector(0, 0);
714 if(response1 == CONTINUE)
715 object1->movement += -hit.normal * (hit.depth + DELTA);
717 object1->movement += -hit.normal * (hit.depth/2 + DELTA);
718 object2->movement += hit.normal * (hit.depth/2 + DELTA);
724 Sector::handle_collisions()
726 // part1: COLGROUP_MOVING vs COLGROUP_STATIC and tilemap
727 // we do this up to 4 times and have to sort all results for the smallest
728 // one before we can continue here
729 for(MovingObjects::iterator i = moving_objects.begin();
730 i != moving_objects.end(); ++i) {
731 MovingObject* moving_object = *i;
732 if((moving_object->get_group() != COLGROUP_MOVING
733 && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
734 || !moving_object->is_valid())
738 for(int t = 0; t < 4; ++t) {
741 MovingObject* collided_with = NULL;
743 // collision with tilemap
744 collision_tilemap(moving_object, hit);
746 // collision with other objects
747 Rect dest1 = moving_object->get_bbox();
748 dest1.move(moving_object->get_movement());
749 CollisionHit temphit;
751 for(MovingObjects::iterator i2 = moving_objects.begin();
752 i2 != moving_objects.end(); ++i2) {
753 MovingObject* moving_object_2 = *i2;
754 if(moving_object_2->get_group() != COLGROUP_STATIC
755 || !moving_object_2->is_valid())
758 Rect dest2 = moving_object_2->get_bbox();
759 dest2.move(moving_object_2->get_movement());
761 = moving_object->get_movement() - moving_object_2->get_movement();
762 if(Collision::rectangle_rectangle(temphit, dest1, movement, dest2)
763 && temphit.time > hit.time) {
765 collided_with = moving_object_2;
772 // call collision callbacks
773 HitResponse response;
774 if(collided_with != 0) {
775 response = moving_object->collision(*collided_with, hit);
777 collided_with->collision(*moving_object, hit);
779 response = moving_object->collision(*solids, hit);
783 if(response == CONTINUE) {
784 moving_object->movement += -hit.normal * (hit.depth + DELTA);
785 } else if(response == ABORT_MOVE) {
786 moving_object->movement = Vector(0, 0);
788 } else { // force move
794 // part2: COLGROUP_MOVING vs tile attributes
795 for(MovingObjects::iterator i = moving_objects.begin();
796 i != moving_objects.end(); ++i) {
797 MovingObject* moving_object = *i;
798 if((moving_object->get_group() != COLGROUP_MOVING
799 && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
800 || !moving_object->is_valid())
803 uint32_t tile_attributes = collision_tile_attributes(moving_object);
804 if(tile_attributes > Tile::FIRST_INTERESTING_FLAG) {
805 moving_object->collision_tile(tile_attributes);
809 // part2.5: COLGROUP_MOVING vs COLGROUP_TOUCHABLE
810 for(MovingObjects::iterator i = moving_objects.begin();
811 i != moving_objects.end(); ++i) {
812 MovingObject* moving_object = *i;
813 if(moving_object->get_group() != COLGROUP_MOVING
814 || !moving_object->is_valid())
817 for(MovingObjects::iterator i2 = moving_objects.begin();
818 i2 != moving_objects.end(); ++i2) {
819 MovingObject* moving_object_2 = *i2;
820 if(moving_object_2->get_group() != COLGROUP_TOUCHABLE
821 || !moving_object_2->is_valid())
824 collision_object(moving_object, moving_object_2);
828 // part3: COLGROUP_MOVING vs COLGROUP_MOVING
829 for(MovingObjects::iterator i = moving_objects.begin();
830 i != moving_objects.end(); ++i) {
831 MovingObject* moving_object = *i;
833 if(moving_object->get_group() != COLGROUP_MOVING
834 || !moving_object->is_valid())
837 for(MovingObjects::iterator i2 = i+1;
838 i2 != moving_objects.end(); ++i2) {
839 MovingObject* moving_object_2 = *i2;
840 if(moving_object_2->get_group() != COLGROUP_MOVING
841 || !moving_object_2->is_valid())
844 collision_object(moving_object, moving_object_2);
848 // apply object movement
849 for(MovingObjects::iterator i = moving_objects.begin();
850 i != moving_objects.end(); ++i) {
851 MovingObject* moving_object = *i;
853 moving_object->bbox.move(moving_object->get_movement());
854 moving_object->movement = Vector(0, 0);
859 Sector::is_free_space(const Rect& rect) const
861 // test with all tiles in this rectangle
862 int starttilex = int(rect.p1.x) / 32;
863 int starttiley = int(rect.p1.y) / 32;
864 int max_x = int(rect.p2.x);
865 int max_y = int(rect.p2.y);
867 for(int x = starttilex; x*32 < max_x; ++x) {
868 for(int y = starttiley; y*32 < max_y; ++y) {
869 const Tile* tile = solids->get_tile(x, y);
872 if(tile->getAttributes() & Tile::SOLID)
877 for(MovingObjects::const_iterator i = moving_objects.begin();
878 i != moving_objects.end(); ++i) {
879 const MovingObject* moving_object = *i;
880 if(moving_object->get_group() != COLGROUP_STATIC
881 || !moving_object->is_valid())
884 if(Collision::intersects(rect, moving_object->get_bbox()))
892 Sector::add_bullet(const Vector& pos, float xm, Direction dir)
894 // TODO remove this function and move these checks elsewhere...
895 static const size_t MAX_FIRE_BULLETS = 2;
896 static const size_t MAX_ICE_BULLETS = 1;
898 Bullet* new_bullet = 0;
899 if(player_status->bonus == FIRE_BONUS) {
900 if(bullets.size() > MAX_FIRE_BULLETS-1)
902 new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET);
903 } else if(player_status->bonus == ICE_BONUS) {
904 if(bullets.size() > MAX_ICE_BULLETS-1)
906 new_bullet = new Bullet(pos, xm, dir, ICE_BULLET);
910 add_object(new_bullet);
912 sound_manager->play("sounds/shoot.wav");
918 Sector::add_smoke_cloud(const Vector& pos)
920 add_object(new SmokeCloud(pos));
925 Sector::add_floating_text(const Vector& pos, const std::string& text)
927 add_object(new FloatingText(pos, text));
931 Sector::play_music(MusicType type)
934 switch(currentmusic) {
936 sound_manager->play_music(std::string("music/") + song_title);
939 sound_manager->play_music("music/salcon.ogg");
942 sound_manager->play_music("");
948 Sector::get_music_type()
954 Sector::get_total_badguys()
956 int total_badguys = 0;
957 for(GameObjects::iterator i = gameobjects.begin();
958 i != gameobjects.end(); ++i) {
959 BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
960 if (badguy && badguy->countMe)
964 return total_badguys;
968 Sector::inside(const Rect& rect) const
970 if(rect.p1.x > solids->get_width() * 32
971 || rect.p1.y > solids->get_height() * 32
972 || rect.p2.x < 0 || rect.p2.y < 0)