From: Ondřej Hošek Date: Fri, 14 Apr 2006 22:48:51 +0000 (+0000) Subject: * Implemented StayOnPlatform on badguys where useful X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ff3f2e3e93b2af69c0f686f8f636ba0d66c67f73;p=supertux.git * Implemented StayOnPlatform on badguys where useful * "Outsourced" FallingCoin * Mac header fix * Level script import path fix SVN-Revision: 3342 --- diff --git a/data/levels/world2/level2.stl b/data/levels/world2/level2.stl index 6901b9a98..b83076954 100644 --- a/data/levels/world2/level2.stl +++ b/data/levels/world2/level2.stl @@ -191,7 +191,7 @@ ) (init-script " import(\"levels/world2/default.nut\"); - import(\"script/default.nut\"); + import(\"scripts/default.nut\"); level2_init(); ") (secretarea (x 673.0) diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 8e0f3de70..ec8653fe5 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -92,7 +92,7 @@ Dispenser::launch_badguy() //FIXME: Does is_offscreen() work right here? if (!is_offscreen()) { if (badguy == "snowball") - Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); + Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir, false)); else if (badguy == "bouncingsnowball") Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); else if (badguy == "mrbomb") @@ -100,23 +100,23 @@ Dispenser::launch_badguy() else if (badguy == "mriceblock") Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false)); else if (badguy == "snowsnail") - Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir)); + Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir, false)); else if (badguy == "mrrocket") { Sector::current()->add_object(new MrRocket(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y, dir));} else if (badguy == "poisonivy") - Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); + Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir, false)); else if (badguy == "skullyhop") Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir)); else if (badguy == "random") { switch (rand()%7) { - case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); break; + case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir, false)); break; case 1: Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); break; case 2: Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir, false)); break; case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false)); break; - case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); break; - case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir)); break; + case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir, false)); break; + case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir, false)); break; case 6: Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir)); break; } } diff --git a/src/badguy/mrtree.cpp b/src/badguy/mrtree.cpp index 496f092dc..dbcc450cf 100644 --- a/src/badguy/mrtree.cpp +++ b/src/badguy/mrtree.cpp @@ -106,12 +106,12 @@ MrTree::collision_squished(Player& player) Rect leaf1_bbox = Rect(pos.x-32-1, pos.y-23+1, pos.x-32-1+32, pos.y-23+1+32); if (Sector::current()->is_free_space(leaf1_bbox)) { - PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1.x, leaf1_bbox.p1.y, LEFT); + PoisonIvy* leaf1 = new PoisonIvy(leaf1_bbox.p1.x, leaf1_bbox.p1.y, LEFT, true); Sector::current()->add_object(leaf1); } Rect leaf2_bbox = Rect(pos.x+42+1, pos.y-23+1, pos.x+32+1+32, pos.y-23+1+32); if (Sector::current()->is_free_space(leaf2_bbox)) { - PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1.x, leaf2_bbox.p1.y, RIGHT); + PoisonIvy* leaf2 = new PoisonIvy(leaf2_bbox.p1.x, leaf2_bbox.p1.y, RIGHT, true); Sector::current()->add_object(leaf2); } diff --git a/src/badguy/nolok_01.cpp b/src/badguy/nolok_01.cpp index aa0779120..c97ae4e51 100644 --- a/src/badguy/nolok_01.cpp +++ b/src/badguy/nolok_01.cpp @@ -94,8 +94,8 @@ Nolok_01::active_update(float elapsed_time) } case SHOOTING: { - Sector::current()->add_object(new SnowSnail(get_pos().x - 64, get_pos().y, LEFT)); - Sector::current()->add_object(new SnowSnail(get_pos().x + 64, get_pos().y, RIGHT)); + Sector::current()->add_object(new SnowSnail(get_pos().x - 64, get_pos().y, LEFT, true)); + Sector::current()->add_object(new SnowSnail(get_pos().x + 64, get_pos().y, RIGHT, true)); physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); action = WALKING; diff --git a/src/badguy/poisonivy.cpp b/src/badguy/poisonivy.cpp index cad1a6402..c93f42e03 100644 --- a/src/badguy/poisonivy.cpp +++ b/src/badguy/poisonivy.cpp @@ -27,15 +27,18 @@ PoisonIvy::PoisonIvy(const lisp::Lisp& reader) { reader.get("x", start_position.x); reader.get("y", start_position.y); + stay_on_platform = false; + reader.get("stay-on-platform", stay_on_platform); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/poison_ivy/poison_ivy.sprite"); set_direction = false; } -PoisonIvy::PoisonIvy(float pos_x, float pos_y, Direction d) +PoisonIvy::PoisonIvy(float pos_x, float pos_y, Direction d, bool stay_on_plat = false) { start_position.x = pos_x; start_position.y = pos_y; + stay_on_platform = stay_on_plat; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/poison_ivy/poison_ivy.sprite"); set_direction = true; @@ -49,6 +52,7 @@ PoisonIvy::write(lisp::Writer& writer) writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); + if (stay_on_platform) writer.write_bool("stay-on-platform", true); writer.end_list("poisonivy"); } @@ -61,6 +65,17 @@ PoisonIvy::activate() sprite->set_action(dir == LEFT ? "left" : "right"); } +void +PoisonIvy::active_update(float elapsed_time) +{ + if (stay_on_platform && may_fall_off_platform()) + { + dir = (dir == LEFT ? RIGHT : LEFT); + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } +} + bool PoisonIvy::collision_squished(Player& player) { diff --git a/src/badguy/poisonivy.hpp b/src/badguy/poisonivy.hpp index 33d7e2c8d..710c6fff7 100644 --- a/src/badguy/poisonivy.hpp +++ b/src/badguy/poisonivy.hpp @@ -26,16 +26,18 @@ class PoisonIvy : public BadGuy { public: PoisonIvy(const lisp::Lisp& reader); - PoisonIvy(float pos_x, float pos_y, Direction d); + PoisonIvy(float pos_x, float pos_y, Direction d, bool stay_on_plat); void activate(); void write(lisp::Writer& writer); + void active_update(float elapsed_time); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit); protected: bool collision_squished(Player& player); bool set_direction; + bool stay_on_platform; Direction initial_direction; }; diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index 1c2e6b678..357c15200 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -30,16 +30,19 @@ SnowBall::SnowBall(const lisp::Lisp& reader) //This is for a hidden badguy :) fluffy = false; reader.get("fluffy",fluffy); + stay_on_platform = false; + reader.get("stay-on-platform", stay_on_platform); bbox.set_size(31.8, 31.8); if (fluffy) sprite = sprite_manager->create("images/creatures/fluffy/fluffy.sprite"); else sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite"); set_direction = false; } -SnowBall::SnowBall(float pos_x, float pos_y, Direction d) +SnowBall::SnowBall(float pos_x, float pos_y, Direction d, bool stay_on_plat = false) { start_position.x = pos_x; start_position.y = pos_y; + stay_on_platform = stay_on_plat; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/snowball/snowball.sprite"); set_direction = true; @@ -58,6 +61,9 @@ SnowBall::write(lisp::Writer& writer) writer.write_bool("fluffy", true); } + if (stay_on_platform) + writer.write_bool("stay-on-platform", true); + writer.end_list("snowball"); } @@ -69,6 +75,17 @@ SnowBall::activate() sprite->set_action(dir == LEFT ? "left" : "right"); } +void +SnowBall::active_update(float elapsed_time) +{ + if (stay_on_platform && may_fall_off_platform()) + { + dir = (dir == LEFT ? RIGHT : LEFT); + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } +} + bool SnowBall::collision_squished(Player& player) { diff --git a/src/badguy/snowball.hpp b/src/badguy/snowball.hpp index ce642fb9c..370ae169c 100644 --- a/src/badguy/snowball.hpp +++ b/src/badguy/snowball.hpp @@ -26,16 +26,18 @@ class SnowBall : public BadGuy { public: SnowBall(const lisp::Lisp& reader); - SnowBall(float pos_x, float pos_y, Direction d); + SnowBall(float pos_x, float pos_y, Direction d, bool stay_on_plat); void activate(); void write(lisp::Writer& writer); + void active_update(float elapsed_time); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit); protected: bool collision_squished(Player& player); bool set_direction; + bool stay_on_platform; Direction initial_direction; bool fluffy; }; diff --git a/src/badguy/snowsnail.cpp b/src/badguy/snowsnail.cpp index 679988539..bd68f593e 100644 --- a/src/badguy/snowsnail.cpp +++ b/src/badguy/snowsnail.cpp @@ -31,16 +31,19 @@ SnowSnail::SnowSnail(const lisp::Lisp& reader) { reader.get("x", start_position.x); reader.get("y", start_position.y); + stay_on_platform = false; + reader.get("stay-on-platform", stay_on_platform); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite"); set_direction = false; } -SnowSnail::SnowSnail(float pos_x, float pos_y, Direction d) +SnowSnail::SnowSnail(float pos_x, float pos_y, Direction d, bool stay_on_plat = false) : ice_state(ICESTATE_NORMAL), squishcount(0) { start_position.x = pos_x; start_position.y = pos_y; + stay_on_platform = stay_on_plat; bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/snowsnail/snowsnail.sprite"); set_direction = true; @@ -54,6 +57,7 @@ SnowSnail::write(lisp::Writer& writer) writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); + if (stay_on_platform) writer.write_bool("stay-on-platform", true); writer.end_list("snowsnail"); } @@ -77,6 +81,13 @@ SnowSnail::active_update(float elapsed_time) physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); sprite->set_action(dir == LEFT ? "left" : "right"); } + if(ice_state == ICESTATE_NORMAL && stay_on_platform + && may_fall_off_platform()) + { + dir = (dir == LEFT ? RIGHT : LEFT); + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } BadGuy::active_update(elapsed_time); } diff --git a/src/badguy/snowsnail.hpp b/src/badguy/snowsnail.hpp index 4a304d33d..7364b4907 100644 --- a/src/badguy/snowsnail.hpp +++ b/src/badguy/snowsnail.hpp @@ -26,7 +26,7 @@ class SnowSnail : public BadGuy { public: SnowSnail(const lisp::Lisp& reader); - SnowSnail(float pos_x, float pos_y, Direction d); + SnowSnail(float pos_x, float pos_y, Direction d, bool stay_on_plat); void activate(); void write(lisp::Writer& writer); @@ -48,6 +48,7 @@ private: Timer flat_timer; int squishcount; bool set_direction; + bool stay_on_platform; Direction initial_direction; }; diff --git a/src/badguy/spiky.cpp b/src/badguy/spiky.cpp index 7dbe450d5..81e94dc90 100644 --- a/src/badguy/spiky.cpp +++ b/src/badguy/spiky.cpp @@ -27,6 +27,8 @@ Spiky::Spiky(const lisp::Lisp& reader) { reader.get("x", start_position.x); reader.get("y", start_position.y); + stay_on_platform = false; + reader.get("stay-on-platform", stay_on_platform); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/spiky/spiky.sprite"); } @@ -38,6 +40,7 @@ Spiky::write(lisp::Writer& writer) writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); + if (stay_on_platform) writer.write_bool("stay-on-platform", true); writer.end_list("spiky"); } @@ -49,6 +52,17 @@ Spiky::activate() sprite->set_action(dir == LEFT ? "left" : "right"); } +void +Spiky::active_update(float elapsed_time) +{ + if (stay_on_platform && may_fall_off_platform()) + { + dir = (dir == LEFT ? RIGHT : LEFT); + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } +} + HitResponse Spiky::collision_solid(GameObject& , const CollisionHit& hit) { diff --git a/src/badguy/spiky.hpp b/src/badguy/spiky.hpp index 579df982b..fc04ffbcb 100644 --- a/src/badguy/spiky.hpp +++ b/src/badguy/spiky.hpp @@ -29,8 +29,11 @@ public: void activate(); void write(lisp::Writer& writer); + void active_update(float elapsed_time); HitResponse collision_solid(GameObject& other, const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); +private: + bool stay_on_platform; }; #endif diff --git a/src/badguy/sspiky.cpp b/src/badguy/sspiky.cpp index 7c77d26a7..017023016 100644 --- a/src/badguy/sspiky.cpp +++ b/src/badguy/sspiky.cpp @@ -28,6 +28,8 @@ SSpiky::SSpiky(const lisp::Lisp& reader) { reader.get("x", start_position.x); reader.get("y", start_position.y); + stay_on_platform = false; + reader.get("stay-on-platform", stay_on_platform); bbox.set_size(31.8, 31.8); sprite = sprite_manager->create("images/creatures/sspiky/sspiky.sprite"); state = SSPIKY_SLEEPING; @@ -40,6 +42,7 @@ SSpiky::write(lisp::Writer& writer) writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); + if (stay_on_platform) writer.write_bool("stay-on-platform", true); writer.end_list("sspiky"); } @@ -55,6 +58,8 @@ SSpiky::activate() sprite->set_action(dir == LEFT ? "sleeping-left" : "sleeping-right"); } + + HitResponse SSpiky::collision_solid(GameObject& , const CollisionHit& hit) { @@ -117,6 +122,12 @@ SSpiky::active_update(float elapsed_time) { } } + if (state == SSPIKY_WALKING && stay_on_platform && may_fall_off_platform()) + { + dir = (dir == LEFT ? RIGHT : LEFT); + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } } IMPLEMENT_FACTORY(SSpiky, "sspiky") diff --git a/src/badguy/sspiky.hpp b/src/badguy/sspiky.hpp index 3a546f68c..8aa24b3b0 100644 --- a/src/badguy/sspiky.hpp +++ b/src/badguy/sspiky.hpp @@ -42,7 +42,8 @@ protected: SSPIKY_WALKING }; SSpikyState state; - +private: + bool stay_on_platform; }; #endif diff --git a/src/object/falling_coin.cpp b/src/object/falling_coin.cpp new file mode 100644 index 000000000..e6f79a458 --- /dev/null +++ b/src/object/falling_coin.cpp @@ -0,0 +1,53 @@ +// $Id: infoblock.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Ondrej Hosek +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#include + +#include "falling_coin.hpp" +#include "player.hpp" +#include "sprite/sprite_manager.hpp" +#include "resources.hpp" +#include "main.hpp" + +FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) +{ + pos = start_position; + sprite = sprite_manager->create("images/objects/coin/coin.sprite"); + physic.set_velocity_y(800); + physic.set_velocity_x(vel_x); +} + +FallingCoin::~FallingCoin() +{ + delete sprite; +} + +void +FallingCoin::draw(DrawingContext& context) +{ + sprite->draw(context, pos, LAYER_OBJECTS + 5); +} + +void +FallingCoin::update(float elapsed_time) +{ + pos += physic.get_movement(elapsed_time); + if (pos.y > SCREEN_HEIGHT) + remove_me(); +} diff --git a/src/object/falling_coin.hpp b/src/object/falling_coin.hpp new file mode 100644 index 000000000..c80190246 --- /dev/null +++ b/src/object/falling_coin.hpp @@ -0,0 +1,43 @@ +// $Id: infoblock.hpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $ +// +// SuperTux +// Copyright (C) 2006 Ondrej Hosek +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef __FALLING_COIN_H__ +#define __FALLING_COIN_H__ + +#include "game_object.hpp" +#include "math/vector.hpp" +#include "sprite/sprite.hpp" +#include "video/drawing_context.hpp" +#include "physic.hpp" + +class FallingCoin : public GameObject +{ +public: + FallingCoin(const Vector& start_position, const int x_vel); + ~FallingCoin(); + + void draw(DrawingContext& context); + void update(float elapsed_time); +private: + Vector pos; + Sprite* sprite; + Physic physic; +}; + +#endif diff --git a/src/object/player.cpp b/src/object/player.cpp index dcdb85221..b0579d263 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -48,6 +48,7 @@ #include "badguy/badguy.hpp" #include "player_status.hpp" #include "log.hpp" +#include "falling_coin.hpp" static const int TILES_FOR_BUTTJUMP = 3; static const float SHOOTING_TIME = .150; @@ -101,33 +102,6 @@ TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer) feet->draw(context, pos, layer-2); } -FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) -{ - pos = start_position; - sprite = sprite_manager->create("images/objects/coin/coin.sprite"); - physic.set_velocity_y(800); - physic.set_velocity_x(vel_x); -} - -FallingCoin::~FallingCoin() -{ - delete sprite; -} - -void -FallingCoin::draw(DrawingContext& context) -{ - sprite->draw(context, pos, LAYER_OBJECTS + 5); -} - -void -FallingCoin::update(float elapsed_time) -{ - pos += physic.get_movement(elapsed_time); - if (pos.y > SCREEN_HEIGHT) - remove_me(); -} - Player::Player(PlayerStatus* _player_status) : player_status(_player_status), grabbed_object(0) { diff --git a/src/object/player.hpp b/src/object/player.hpp index cc250cbe5..09b95dda2 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -81,20 +81,6 @@ extern TuxBodyParts* big_tux; extern TuxBodyParts* fire_tux; extern TuxBodyParts* ice_tux; -class FallingCoin : public GameObject -{ -public: - FallingCoin(const Vector& start_position, const int x_vel); - ~FallingCoin(); - - void draw(DrawingContext& context); - void update(float elapsed_time); -private: - Vector pos; - Sprite* sprite; - Physic physic; -}; - class Player : public MovingObject, public Scripting::Player, public ScriptInterface { public: diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index c4fc95113..e6c7429a6 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -19,6 +19,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include #include #include "level.hpp" #include "sprite/sprite_manager.hpp"