Some more messing around with aspect-ratio, window resize and stuff
[supertux.git] / src / sector.cpp
index 253212b..625a00b 100644 (file)
@@ -83,6 +83,8 @@ Sector::Sector(Level* parent)
   add_object(new DisplayEffect("Effect"));
   add_object(new TextObject("Text"));
 
+  sound_manager->preload("sounds/shoot.wav");
+
   // create a new squirrel table for the sector
   using namespace Scripting;
 
@@ -443,8 +445,8 @@ Sector::fix_old_tiles()
        // lava or lavaflow
        if ((id == 173) || (id == 1700) || (id == 1705) || (id == 1706)) {
          // space lights a bit
-         if (((tm->get_tile_id(x-1, y)) != tm->get_tile_id(x,y))
-             && (tm->get_tile_id(x, y-1) != tm->get_tile_id(x,y))
+         if ((((tm->get_tile_id(x-1, y)) != tm->get_tile_id(x,y))
+             && (tm->get_tile_id(x, y-1) != tm->get_tile_id(x,y)))
              || ((x % 3 == 0) && (y % 3 == 0))) {
            float pseudo_rnd = (float)((int)pos.x % 10) / 10;
            add_object(new PulsingLight(center, 1.0f + pseudo_rnd, 0.8f, 1.0f, Color(1.0f, 0.3f, 0.0f, 1.0f)));
@@ -887,7 +889,7 @@ static const float SHIFT_DELTA = 7.0f;
 /** r1 is supposed to be moving, r2 a solid object */
 void check_collisions(collision::Constraints* constraints,
                       const Vector& movement, const Rect& r1, const Rect& r2,
-                      GameObject* object = NULL, MovingObject* other = NULL)
+                      GameObject* object = NULL, MovingObject* other = NULL, const Vector& addl_ground_movement = Vector(0,0))
 {
   if(!collision::intersects(r1, r2))
     return;
@@ -924,6 +926,7 @@ void check_collisions(collision::Constraints* constraints,
     }
   }
 
+  constraints->ground_movement += addl_ground_movement;
   if(other != NULL) {
     HitResponse response = other->collision(*object, dummy);
     if(response == PASSTHROUGH)
@@ -931,7 +934,7 @@ void check_collisions(collision::Constraints* constraints,
 
     if(other->get_movement() != Vector(0, 0)) {
       // TODO what todo when we collide with 2 moving objects?!?
-      constraints->ground_movement = other->get_movement();
+      constraints->ground_movement += other->get_movement();
     }
   }
 
@@ -998,10 +1001,10 @@ Sector::collision_tilemap(collision::Constraints* constraints,
          Vector p2((x+1)*32 + solids->get_x_offset(), (y+1)*32 + solids->get_y_offset());
          triangle = AATriangle(p1, p2, tile->getData());
 
-         collision::rectangle_aatriangle(constraints, dest, triangle);
+         collision::rectangle_aatriangle(constraints, dest, triangle, solids->get_movement());
        } else { // normal rectangular tile
          Rect rect(x*32 + solids->get_x_offset(), y*32 + solids->get_y_offset(), (x+1)*32 + solids->get_x_offset(), (y+1)*32 + solids->get_y_offset());
-         check_collisions(constraints, movement, dest, rect);
+         check_collisions(constraints, movement, dest, rect, NULL, NULL, solids->get_movement());
        }
       }
     }
@@ -1460,7 +1463,7 @@ Sector::play_music(MusicType type)
       sound_manager->play_music(music);
       break;
     case HERRING_MUSIC:
-      sound_manager->play_music("music/salcon.ogg");
+      sound_manager->play_music("music/invincible.ogg");
       break;
     case HERRING_WARNING_MUSIC:
       sound_manager->stop_music(TUX_INVINCIBLE_TIME_WARNING);
@@ -1570,3 +1573,22 @@ Sector::get_ambient_blue()
 {
   return ambient_light.blue;
 }
+
+void
+Sector::set_gravity(float gravity)
+{
+  log_warning << "Changing a Sector's gravitational constant might have unforseen side-effects" << std::endl;
+
+  this->gravity = gravity;
+
+  for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) {
+    GameObject* game_object = *i;
+    if(!game_object) continue;
+    if(!game_object->is_valid()) continue;
+    UsesPhysic *physics_object = dynamic_cast<UsesPhysic*>(game_object);
+    if (!physics_object) continue;
+
+    physics_object->physic.set_gravity(gravity);
+  }
+}
+