From: Matthias Braun Date: Sun, 14 May 2006 10:50:25 +0000 (+0000) Subject: fix bug with player not stopping when deactivated, make key support code simpler X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=85b594964cc0fe9ca9d4602a0da978d4862fa080;p=supertux.git fix bug with player not stopping when deactivated, make key support code simpler SVN-Revision: 3515 --- diff --git a/data/levels/world2/default.nut b/data/levels/world2/default.nut index 1cc6aae34..e3ec741df 100644 --- a/data/levels/world2/default.nut +++ b/data/levels/world2/default.nut @@ -1,42 +1,8 @@ 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(); } @@ -67,7 +33,7 @@ if(! ("world2_keys" in state)) 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)) @@ -75,17 +41,17 @@ 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; diff --git a/data/levels/world2/key1.stl b/data/levels/world2/key1.stl index c5a667417..4775287ef 100644 --- a/data/levels/world2/key1.stl +++ b/data/levels/world2/key1.stl @@ -46,7 +46,7 @@ ) (powerup (x 200) (y 602) (sprite "images/objects/keys/key_water.sprite") - (script "get_water_key();") + (script "add_key(\"water\");") (disable-physics #t) ) ) diff --git a/data/levels/world2/key2.stl b/data/levels/world2/key2.stl index 3603bebf4..2a00c32c4 100644 --- a/data/levels/world2/key2.stl +++ b/data/levels/world2/key2.stl @@ -46,7 +46,7 @@ ) (powerup (x 200) (y 602) (sprite "images/objects/keys/key_earth.sprite") - (script "get_earth_key();") + (script "add_key(\"earth\");") (disable-physics #t) ) ) diff --git a/data/levels/world2/key3.stl b/data/levels/world2/key3.stl index 00c97ffde..7d1797627 100644 --- a/data/levels/world2/key3.stl +++ b/data/levels/world2/key3.stl @@ -46,7 +46,7 @@ ) (powerup (x 200) (y 602) (sprite "images/objects/keys/key_wood.sprite") - (script "get_wood_key();") + (script "add_key(\"wood\");") (disable-physics #t) ) ) diff --git a/data/levels/world2/key4.stl b/data/levels/world2/key4.stl index 389c6157e..23566875e 100644 --- a/data/levels/world2/key4.stl +++ b/data/levels/world2/key4.stl @@ -46,7 +46,7 @@ ) (powerup (x 200) (y 602) (sprite "images/objects/keys/key_fire.sprite") - (script "get_fire_key();") + (script "add_key(\"fire\");") (disable-physics #t) ) ) diff --git a/data/levels/world2/key5.stl b/data/levels/world2/key5.stl index 96d316a4e..92aabca8a 100644 --- a/data/levels/world2/key5.stl +++ b/data/levels/world2/key5.stl @@ -46,7 +46,7 @@ ) (powerup (x 200) (y 602) (sprite "images/objects/keys/key_air.sprite") - (script "get_air_key();") + (script "add_key(\"air\");") (disable-physics #t) ) ) diff --git a/data/scripts/console.nut b/data/scripts/console.nut index e01540de7..131ef436f 100644 --- a/data/scripts/console.nut +++ b/data/scripts/console.nut @@ -34,6 +34,11 @@ function kill() sector.Tux.kill(true); } +function lifeup() +{ + sector.Tux.add_coins(100); +} + /** * Display a list of functions in the roottable (or in the table specified) */ diff --git a/data/scripts/default.nut b/data/scripts/default.nut index 106e7ba82..a4f3aff82 100644 --- a/data/scripts/default.nut +++ b/data/scripts/default.nut @@ -4,7 +4,6 @@ */ -// TODO: move this to world2 function end_level() { play_music("music/leveldone.ogg"); diff --git a/src/main.cpp b/src/main.cpp index 8bf4657d6..c08222462 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,6 +54,7 @@ #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; @@ -477,14 +478,20 @@ int main(int argc, char** argv) init_rand(); // play_demo sets seed, record_demo uses it - std::auto_ptr 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 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()); diff --git a/src/object/player.cpp b/src/object/player.cpp index 3d33ce731..de697975c 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -185,39 +185,11 @@ Player::update(float elapsed_time) 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 (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, @@ -485,6 +457,24 @@ Player::handle_vertical_input() 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 (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 { @@ -999,6 +989,8 @@ Player::deactivate() deactivated = true; physic.set_velocity_x(0); physic.set_velocity_y(0); + physic.set_acceleration_x(0); + physic.set_acceleration_y(0); } void