function add_key(key)
{
local keys = state.world2_keys;
- if (key == "air")
- keys.air = true;
- else if (key == "earth")
- keys.earth = true;
- else if (key == "wood")
- keys.wood = true;
- else if (key == "fire")
- keys.fire = true;
- else if (key == "water")
- keys.water = true;
+ keys[key] = true;
update_keys();
-}
-
-function get_water_key()
-{
- add_key("air");
- end_level();
-}
-function get_earth_key()
-{
- add_key("earth");
- end_level();
-}
-function get_wood_key()
-{
- add_key("wood");
- end_level();
-}
-function get_fire_key()
-{
- add_key("fire");
- end_level();
-}
-function get_air_key()
-{
- add_key("water");
end_level();
}
local keys = state.world2_keys;
if(! ("air" in keys))
- keys.water <- false;
+ keys.air <- false;
if(! ("earth" in keys))
keys.earth <- false;
if(! ("wood" in keys))
if(! ("fire" in keys))
keys.fire <- false;
if(! ("water" in keys))
- keys.air <- false;
+ keys.water <- false;
/// this function updates the key images (call this if tux has collected a key)
function update_keys()
{
local keys = state.world2_keys;
- key_air.set_action(keys.water ? "display" : "outline");
+ key_air.set_action(keys.air ? "display" : "outline");
key_earth.set_action(keys.earth ? "display" : "outline");
key_wood.set_action(keys.wood ? "display" : "outline");
key_fire.set_action(keys.fire ? "display" : "outline");
- key_water.set_action(keys.air ? "display" : "outline");
+ key_water.set_action(keys.water ? "display" : "outline");
}
local x = 10;
)
(powerup (x 200) (y 602)
(sprite "images/objects/keys/key_water.sprite")
- (script "get_water_key();")
+ (script "add_key(\"water\");")
(disable-physics #t)
)
)
)
(powerup (x 200) (y 602)
(sprite "images/objects/keys/key_earth.sprite")
- (script "get_earth_key();")
+ (script "add_key(\"earth\");")
(disable-physics #t)
)
)
)
(powerup (x 200) (y 602)
(sprite "images/objects/keys/key_wood.sprite")
- (script "get_wood_key();")
+ (script "add_key(\"wood\");")
(disable-physics #t)
)
)
)
(powerup (x 200) (y 602)
(sprite "images/objects/keys/key_fire.sprite")
- (script "get_fire_key();")
+ (script "add_key(\"fire\");")
(disable-physics #t)
)
)
)
(powerup (x 200) (y 602)
(sprite "images/objects/keys/key_air.sprite")
- (script "get_air_key();")
+ (script "add_key(\"air\");")
(disable-physics #t)
)
)
sector.Tux.kill(true);
}
+function lifeup()
+{
+ sector.Tux.add_coins(100);
+}
+
/**
* Display a list of functions in the roottable (or in the table specified)
*/
*/
-// TODO: move this to world2
function end_level()
{
play_music("music/leveldone.ogg");
#include "file_system.hpp"
#include "physfs/physfs_sdl.hpp"
#include "random_generator.hpp"
+#include "worldmap/worldmap.hpp"
SDL_Surface* screen = 0;
JoystickKeyboardController* main_controller = 0;
init_rand(); // play_demo sets seed, record_demo uses it
- std::auto_ptr<GameSession> session
- (new GameSession(FileSystem::basename(config->start_level)));
- if(config->start_demo != "")
- session->play_demo(config->start_demo);
-
- if(config->record_demo != "")
- session->record_demo(config->record_demo);
- main_loop->push_screen(session.release());
+ if(config->start_level.size() > 4 &&
+ config->start_level.compare(config->start_level.size() - 5, 4, ".stwm") == 0) {
+ main_loop->push_screen(new WorldMapNS::WorldMap(config->start_level));
+ } else {
+ std::auto_ptr<GameSession> session (
+ new GameSession(FileSystem::basename(config->start_level)));
+
+ if(config->start_demo != "")
+ session->play_demo(config->start_demo);
+
+ if(config->record_demo != "")
+ session->record_demo(config->record_demo);
+ main_loop->push_screen(session.release());
+ }
} else {
init_rand();
main_loop->push_screen(new TitleScreen());
adjust_height = 0;
}
- if(!controller->hold(Controller::ACTION) && grabbed_object) {
- // move the grabbed object a bit away from tux
- Vector pos = get_pos() +
- Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
- bbox.get_height()*0.66666 - 32);
- Rect dest(pos, pos + Vector(32, 32));
- if(Sector::current()->is_free_space(dest)) {
- MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
- if(moving_object) {
- moving_object->set_pos(pos);
- } else {
- log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
- }
- grabbed_object->ungrab(*this, dir);
- grabbed_object = 0;
- }
- }
-
if(!dying && !deactivated)
handle_input();
movement = physic.get_movement(elapsed_time);
-#if 0
- // special exception for cases where we're stuck under tiles after
- // being ducked. In this case we drift out
- if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y
- && collision_object_map(base)) {
- base.x += elapsed_time * WALK_SPEED * (dir ? 1: -1);
- previous_base = old_base = base;
- }
-#endif
-
if(grabbed_object != 0) {
Vector pos = get_pos() +
Vector(dir == LEFT ? -16 : 16,
void
Player::handle_input()
{
+ if(!controller->hold(Controller::ACTION) && grabbed_object) {
+ // move the grabbed object a bit away from tux
+ Vector pos = get_pos() +
+ Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1,
+ bbox.get_height()*0.66666 - 32);
+ Rect dest(pos, pos + Vector(32, 32));
+ if(Sector::current()->is_free_space(dest)) {
+ MovingObject* moving_object = dynamic_cast<MovingObject*> (grabbed_object);
+ if(moving_object) {
+ moving_object->set_pos(pos);
+ } else {
+ log_debug << "Non MovingObjetc grabbed?!?" << std::endl;
+ }
+ grabbed_object->ungrab(*this, dir);
+ grabbed_object = 0;
+ }
+ }
+
/* Handle horizontal movement: */
if (!backflipping) handle_horizontal_input();
else {
deactivated = true;
physic.set_velocity_x(0);
physic.set_velocity_y(0);
+ physic.set_acceleration_x(0);
+ physic.set_acceleration_y(0);
}
void