// $Id$
//
// SuperTux - A Jump'n Run
-// Copyright (C) 2004 Matthias Braun <matze@braunis.de
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
#include "script_manager.hpp"
#include "scripting/wrapper_util.hpp"
#include "script_interface.hpp"
-#include "msg.hpp"
+#include "log.hpp"
Sector* Sector::_current = 0;
-Sector::Sector()
- : currentmusic(LEVEL_MUSIC), gravity(10),
+bool Sector::show_collrects = false;
+bool Sector::draw_solids_only = false;
+
+Sector::Sector(Level* parent)
+ : level(parent), currentmusic(LEVEL_MUSIC), gravity(10),
player(0), solids(0), camera(0)
{
add_object(new Player(player_status));
delete *i;
}
+Level*
+Sector::get_level()
+{
+ return level;
+}
+
GameObject*
Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
{
try {
return create_object(name, reader);
} catch(std::exception& e) {
- msg_warning << e.what() << "" << std::endl;
+ log_warning << e.what() << "" << std::endl;
}
return 0;
fix_old_tiles();
if(!camera) {
- msg_warning << "sector '" << name << "' does not contain a camera." << std::endl;
+ log_warning << "sector '" << name << "' does not contain a camera." << std::endl;
update_game_objects();
add_object(new Camera(this));
}
spawnpoints.push_back(sp);
}
} else {
- msg_warning << "Unknown token '" << iter.item() << "' in reset-points." << std::endl;
+ log_warning << "Unknown token '" << iter.item() << "' in reset-points." << std::endl;
}
}
}
if(object) {
add_object(object);
} else {
- msg_warning << "Unknown object '" << iter.item() << "' in level." << std::endl;
+ log_warning << "Unknown object '" << iter.item() << "' in level." << std::endl;
}
}
}
}
}
if(!sp) {
- msg_warning << "Spawnpoint '" << spawnpoint << "' not found." << std::endl;
+ log_warning << "Spawnpoint '" << spawnpoint << "' not found." << std::endl;
if(spawnpoint != "main") {
activate("main");
} else {
player->move(player_pos);
camera->reset(player->get_pos());
+ update_game_objects();
// Run init script
if(init_script != "") {
if(solids == 0) {
solids = tilemap;
} else {
- msg_warning << "Another solid tilemaps added. Ignoring" << std::endl;
+ log_warning << "Another solid tilemaps added. Ignoring" << std::endl;
}
}
Camera* camera = dynamic_cast<Camera*> (object);
if(camera) {
if(this->camera != 0) {
- msg_warning << "Multiple cameras added. Ignoring" << std::endl;
+ log_warning << "Multiple cameras added. Ignoring" << std::endl;
return false;
}
this->camera = camera;
Player* player = dynamic_cast<Player*> (object);
if(player) {
if(this->player != 0) {
- msg_warning << "Multiple players added. Ignoring" << std::endl;
+ log_warning << "Multiple players added. Ignoring" << std::endl;
return false;
}
this->player = player;
ScriptInterface* interface = dynamic_cast<ScriptInterface*> (object);
if(interface != NULL) {
HSQUIRRELVM vm = script_manager->get_vm();
+ int oldtop = sq_gettop(vm);
sq_pushobject(vm, sector_table);
- interface->unexpose(vm, -1);
- sq_pop(vm, 1);
+ try {
+ interface->unexpose(vm, -1);
+ } catch(std::exception& e) {
+ log_warning << "Couldn't unregister object: " << e.what() << std::endl;
+ }
+ sq_settop(vm, oldtop);
}
}
GameObject* object = *i;
if(!object->is_valid())
continue;
-
+
+ if (draw_solids_only)
+ {
+ TileMap* tm = dynamic_cast<TileMap*>(object);
+ if (tm && !tm->is_solid())
+ continue;
+ }
+
object->draw(context);
}
+ if(show_collrects) {
+ Color col(0.2, 0.2, 0.2, 0.7);
+ for(MovingObjects::iterator i = moving_objects.begin();
+ i != moving_objects.end(); ++i) {
+ MovingObject* object = *i;
+ const Rect& rect = object->get_bbox();
+
+ context.draw_filled_rect(rect, col, LAYER_FOREGROUND1 + 10);
+ }
+ }
+
context.pop_transform();
}
Sector::add_bullet(const Vector& pos, float xm, Direction dir)
{
// TODO remove this function and move these checks elsewhere...
- static const size_t MAX_FIRE_BULLETS = 2;
- static const size_t MAX_ICE_BULLETS = 1;
Bullet* new_bullet = 0;
if(player_status->bonus == FIRE_BONUS) {
- if(bullets.size() > MAX_FIRE_BULLETS-1)
+ if((int)bullets.size() >= player_status->max_fire_bullets)
return false;
new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET);
} else if(player_status->bonus == ICE_BONUS) {
- if(bullets.size() > MAX_ICE_BULLETS-1)
+ if((int)bullets.size() >= player_status->max_ice_bullets)
return false;
new_bullet = new Bullet(pos, xm, dir, ICE_BULLET);
} else {
case HERRING_MUSIC:
sound_manager->play_music("music/salcon.ogg");
break;
+ case HERRING_WARNING_MUSIC:
+ sound_manager->stop_music(TUX_INVINCIBLE_TIME_WARNING);
+ break;
default:
sound_manager->play_music("");
break;
{
if(rect.p1.x > solids->get_width() * 32
|| rect.p1.y > solids->get_height() * 32
- || rect.p2.x < 0 || rect.p2.y < 0)
+ || rect.p2.x < 0)
return false;
return true;