From: Mathnerd314 Date: Sun, 3 May 2009 22:04:19 +0000 (+0000) Subject: Ice blocks (graphics are placeholders) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8c0b10ba9ff57a36c3747c84a035faca5975556d;p=supertux.git Ice blocks (graphics are placeholders) SVN-Revision: 5885 --- diff --git a/data/images/tiles.strf b/data/images/tiles.strf index adae3eef2..f010a74fc 100644 --- a/data/images/tiles.strf +++ b/data/images/tiles.strf @@ -3410,5 +3410,12 @@ (image "tiles/pipe/blue.png") ) -;; next-id: 2406 + (tile + (id 2406) + (ice #t) + (solid #t) + (images + "objects/icecube/icecube.png")) + +;; next-id: 2407 ) diff --git a/data/levels/test/icetest.stl b/data/levels/test/icetest.stl new file mode 100644 index 000000000..f7124423c --- /dev/null +++ b/data/levels/test/icetest.stl @@ -0,0 +1,51 @@ +(supertux-level + (version 2) + (name (_ "Ice test")) + (author "Mathnerd314") + (sector + (name "main") + (music "music/chipdisko.ogg") + (ambient-light 1 1 1) + (spawnpoint + (name "main") + (x 100) + (y 100) + ) + (background + (speed 0.5) + (image "images/background/arctis.jpg") + ) + (tilemap + (z-pos 0) + (solid #t) + (speed 1) + (width 27) + (height 19) + (tiles +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +7 8 8 8 8 8 8 9 0 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 2406 +13 14 14 14 14 14 14 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +10 11 11 11 11 11 11 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + ) + ) + + (camera + (mode "normal") + ) + ) +) diff --git a/src/object/player.cpp b/src/object/player.cpp index 033f569b2..f04cb9090 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -94,6 +94,12 @@ namespace { /** instant velocity when tux starts to walk */ static const float WALK_SPEED = 100; + /** multiplied by WALK_ACCELERATION to give friction */ + static const float NORMAL_FRICTION_MULTIPLIER = 1.5f; + /** multiplied by WALK_ACCELERATION to give friction */ + static const float ICE_FRICTION_MULTIPLIER = 0.1f; + static const float ICE_ACCELERATION_MULTIPLIER = 0.25f; + /** time of the kick (kicking mriceblock) animation */ static const float KICK_TIME = .3f; /** time of tux cheering (currently unused) */ @@ -171,6 +177,8 @@ Player::init() backflip_direction = 0; visible = true; swimming = false; + on_ice = false; + ice_this_frame = false; speedlimit = 0; //no special limit on_ground_flag = false; @@ -350,7 +358,11 @@ Player::update(float elapsed_time) grabbed_object = NULL; } + if(!ice_this_frame && on_ground()) + on_ice = false; + on_ground_flag = false; + ice_this_frame = false; // when invincible, spawn particles if (invincible_timer.started() && !dying) @@ -402,10 +414,14 @@ Player::apply_friction() if ((on_ground()) && (fabs(physic.get_velocity_x()) < WALK_SPEED)) { physic.set_velocity_x(0); physic.set_acceleration_x(0); - } else if(physic.get_velocity_x() < 0) { - physic.set_acceleration_x(WALK_ACCELERATION_X * 1.5); - } else if(physic.get_velocity_x() > 0) { - physic.set_acceleration_x(WALK_ACCELERATION_X * -1.5); + } else { + float friction = on_ice ? (WALK_ACCELERATION_X * ICE_FRICTION_MULTIPLIER) : + (WALK_ACCELERATION_X * NORMAL_FRICTION_MULTIPLIER); + if(physic.get_velocity_x() < 0) { + physic.set_acceleration_x(friction); + } else /*if(physic.get_velocity_x() > 0)*/ { + physic.set_acceleration_x(-friction); + } } } @@ -490,6 +506,10 @@ Player::handle_horizontal_input() } } + if(on_ice) { + ax *= ICE_ACCELERATION_MULTIPLIER; + } + physic.set_velocity(vx, vy); physic.set_acceleration(ax, ay); @@ -1071,6 +1091,11 @@ Player::collision_tile(uint32_t tile_attributes) } } #endif + + if(tile_attributes & (Tile::ICE | Tile::SOLID)) { + ice_this_frame = true; + on_ice = true; + } } void diff --git a/src/object/player.hpp b/src/object/player.hpp index 91a1fcfc5..07e62d17e 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -75,6 +75,8 @@ private: float speedlimit; Controller* scripting_controller_old; /**< Saves the old controller while the scripting_controller is used */ bool jump_early_apex; + bool on_ice; + bool ice_this_frame; public: Direction dir;