From 4587bd9c8fc5cbb20f1e442de76bc06571ab56ba Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Fri, 5 Jan 2007 15:43:18 +0000 Subject: [PATCH] Merged gravity patch by T. Goya SVN-Revision: 4530 --- src/badguy/badguy.hpp | 4 +--- src/object/bullet.hpp | 3 +-- src/object/falling_coin.hpp | 3 +-- src/object/flower.hpp | 1 - src/object/gameobjs.hpp | 1 - src/object/growup.hpp | 5 +---- src/object/oneup.hpp | 5 +---- src/object/player.hpp | 3 +-- src/object/powerup.hpp | 3 +-- src/object/rock.hpp | 3 +-- src/object/scripted_object.hpp | 5 ++--- src/object/skull_tile.hpp | 3 +-- src/object/star.hpp | 5 +---- src/object/trampoline.hpp | 1 - src/object/unstable_tile.hpp | 4 +--- src/object/weak_block.hpp | 4 +--- src/physic.hpp | 7 +++++++ src/sector.cpp | 9 ++++++++- 18 files changed, 29 insertions(+), 40 deletions(-) diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 5824610d0..a6f019797 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -38,7 +38,7 @@ #include "audio/sound_manager.hpp" #include "audio/sound_source.hpp" -class BadGuy : public MovingSprite, public Serializable +class BadGuy : public MovingSprite, protected UsesPhysic, public Serializable { public: BadGuy(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS); @@ -175,8 +175,6 @@ protected: */ Player* get_nearest_player(); - Physic physic; - /// is the enemy activated bool activated; /** diff --git a/src/object/bullet.hpp b/src/object/bullet.hpp index b18e375cd..789144722 100644 --- a/src/object/bullet.hpp +++ b/src/object/bullet.hpp @@ -25,7 +25,7 @@ #include "sprite/sprite.hpp" #include "player_status.hpp" -class Bullet : public MovingObject +class Bullet : public MovingObject, private UsesPhysic { public: Bullet(const Vector& pos, float xm, int dir, BonusType type); @@ -50,7 +50,6 @@ public: private: int life_count; - Physic physic; std::auto_ptr sprite; BonusType type; }; diff --git a/src/object/falling_coin.hpp b/src/object/falling_coin.hpp index 04358dd2d..8eeabb395 100644 --- a/src/object/falling_coin.hpp +++ b/src/object/falling_coin.hpp @@ -26,7 +26,7 @@ #include "video/drawing_context.hpp" #include "physic.hpp" -class FallingCoin : public GameObject +class FallingCoin : public GameObject, private UsesPhysic { public: FallingCoin(const Vector& start_position, const int x_vel); @@ -37,7 +37,6 @@ public: private: Vector pos; Sprite* sprite; - Physic physic; }; #endif diff --git a/src/object/flower.hpp b/src/object/flower.hpp index 46a2e6c22..e1c06acb4 100644 --- a/src/object/flower.hpp +++ b/src/object/flower.hpp @@ -22,7 +22,6 @@ #include "moving_object.hpp" #include "sprite/sprite.hpp" -#include "physic.hpp" #include "player_status.hpp" class Flower : public MovingObject diff --git a/src/object/gameobjs.hpp b/src/object/gameobjs.hpp index d15ed27d4..5a4063f52 100644 --- a/src/object/gameobjs.hpp +++ b/src/object/gameobjs.hpp @@ -22,7 +22,6 @@ #include "video/surface.hpp" #include "timer.hpp" -#include "physic.hpp" #include "game_object.hpp" #include "moving_object.hpp" #include "serializable.hpp" diff --git a/src/object/growup.hpp b/src/object/growup.hpp index 315740de3..869b3fe0b 100644 --- a/src/object/growup.hpp +++ b/src/object/growup.hpp @@ -24,7 +24,7 @@ #include "physic.hpp" #include "direction.hpp" -class GrowUp : public MovingSprite +class GrowUp : public MovingSprite, private UsesPhysic { public: GrowUp(Direction direction = RIGHT); @@ -33,9 +33,6 @@ public: virtual void update(float elapsed_time); virtual void collision_solid(const CollisionHit& hit); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); - -private: - Physic physic; }; #endif diff --git a/src/object/oneup.hpp b/src/object/oneup.hpp index 415c61cfb..1e2384124 100644 --- a/src/object/oneup.hpp +++ b/src/object/oneup.hpp @@ -24,7 +24,7 @@ #include "physic.hpp" #include "direction.hpp" -class OneUp : public MovingSprite +class OneUp : public MovingSprite, private UsesPhysic { public: OneUp(const Vector& pos, Direction direction = RIGHT); @@ -32,9 +32,6 @@ public: virtual void update(float elapsed_time); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); - -private: - Physic physic; }; #endif diff --git a/src/object/player.hpp b/src/object/player.hpp index de229492e..73027ecc6 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -81,7 +81,7 @@ extern TuxBodyParts* big_tux; extern TuxBodyParts* fire_tux; extern TuxBodyParts* ice_tux; -class Player : public MovingObject, public Scripting::Player, public ScriptInterface +class Player : public MovingObject, public UsesPhysic, public Scripting::Player, public ScriptInterface { public: enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING }; @@ -119,7 +119,6 @@ public: Timer growing_timer; Timer idle_timer; Timer backflip_timer; - Physic physic; public: Player(PlayerStatus* player_status, const std::string& name); diff --git a/src/object/powerup.hpp b/src/object/powerup.hpp index 5ed2b4970..4779db170 100644 --- a/src/object/powerup.hpp +++ b/src/object/powerup.hpp @@ -25,7 +25,7 @@ #include "collision_hit.hpp" #include "physic.hpp" -class PowerUp : public MovingSprite +class PowerUp : public MovingSprite, private UsesPhysic { public: PowerUp(const lisp::Lisp& lisp); @@ -35,7 +35,6 @@ public: virtual HitResponse collision(GameObject& other, const CollisionHit& hit); private: - Physic physic; std::string script; bool no_physics; }; diff --git a/src/object/rock.hpp b/src/object/rock.hpp index 379ed07a4..099d7cace 100644 --- a/src/object/rock.hpp +++ b/src/object/rock.hpp @@ -28,7 +28,7 @@ class Sprite; -class Rock : public MovingSprite, public Portable, public Serializable +class Rock : public MovingSprite, public Portable, protected UsesPhysic, public Serializable { public: Rock(const lisp::Lisp& reader); @@ -46,7 +46,6 @@ public: protected: bool on_ground; bool grabbed; - Physic physic; Vector last_movement; }; diff --git a/src/object/scripted_object.hpp b/src/object/scripted_object.hpp index 1e432a729..9ac72c56e 100644 --- a/src/object/scripted_object.hpp +++ b/src/object/scripted_object.hpp @@ -27,8 +27,8 @@ #include "script_interface.hpp" #include "scripting/scripted_object.hpp" -class ScriptedObject : public MovingSprite, public Scripting::ScriptedObject, - public ScriptInterface +class ScriptedObject : public MovingSprite, public UsesPhysic, + public Scripting::ScriptedObject, public ScriptInterface { public: ScriptedObject(const lisp::Lisp& lisp); @@ -69,7 +69,6 @@ private: bool visible; bool new_vel_set; Vector new_vel; - Physic physic; }; #endif diff --git a/src/object/skull_tile.hpp b/src/object/skull_tile.hpp index f9a19fcba..5a6579833 100644 --- a/src/object/skull_tile.hpp +++ b/src/object/skull_tile.hpp @@ -28,7 +28,7 @@ class Player; /** A tile that starts falling down if tux stands to long on it */ -class SkullTile : public MovingSprite +class SkullTile : public MovingSprite, private UsesPhysic { public: SkullTile(const lisp::Lisp& lisp); @@ -39,7 +39,6 @@ public: void draw(DrawingContext& context); private: - Physic physic; Timer timer; bool hit; bool falling; diff --git a/src/object/star.hpp b/src/object/star.hpp index 68b4fc949..e3f4f04c8 100644 --- a/src/object/star.hpp +++ b/src/object/star.hpp @@ -24,7 +24,7 @@ #include "physic.hpp" #include "direction.hpp" -class Star : public MovingSprite +class Star : public MovingSprite, private UsesPhysic { public: Star(const Vector& pos, Direction direction = RIGHT); @@ -33,9 +33,6 @@ public: virtual void update(float elapsed_time); virtual void collision_solid(const CollisionHit& hit); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); - -private: - Physic physic; }; #endif diff --git a/src/object/trampoline.hpp b/src/object/trampoline.hpp index c1eca0ffb..c7653c0ea 100644 --- a/src/object/trampoline.hpp +++ b/src/object/trampoline.hpp @@ -23,7 +23,6 @@ #include "moving_sprite.hpp" #include "lisp/lisp.hpp" #include "object/rock.hpp" -#include "physic.hpp" /** * Jumping on a trampolin makes tux jump higher. diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index 9c6e0bd76..a6bb71e48 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -29,7 +29,7 @@ /** * A block that disintegrates when stood on */ -class UnstableTile : public MovingSprite +class UnstableTile : public MovingSprite, public UsesPhysic { public: UnstableTile(const lisp::Lisp& lisp); @@ -45,8 +45,6 @@ private: STATE_DISINTEGRATING /**< disintegrating, no longer solid */ }; State state; - - Physic physic; }; #endif diff --git a/src/object/weak_block.hpp b/src/object/weak_block.hpp index e36d1eb66..01e2464be 100644 --- a/src/object/weak_block.hpp +++ b/src/object/weak_block.hpp @@ -29,7 +29,7 @@ /** * A block that can be destroyed by Bullet hits */ -class WeakBlock : public MovingSprite +class WeakBlock : public MovingSprite, public UsesPhysic { public: WeakBlock(const lisp::Lisp& lisp); @@ -55,8 +55,6 @@ private: STATE_DISINTEGRATING /**< crumbling to dust, no longer solid */ }; State state; - - Physic physic; }; #endif diff --git a/src/physic.hpp b/src/physic.hpp index abfdba530..037d85ed2 100644 --- a/src/physic.hpp +++ b/src/physic.hpp @@ -87,4 +87,11 @@ private: float gravity; }; +class UsesPhysic +{ +public: + Physic physic; + friend class Sector; +}; + #endif diff --git a/src/sector.cpp b/src/sector.cpp index af819872b..c306517db 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -74,7 +74,7 @@ bool Sector::draw_solids_only = false; Sector::Sector(Level* parent) : level(parent), currentmusic(LEVEL_MUSIC), - ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gravity(10), player(0), camera(0) + ambient_light( 1.0f, 1.0f, 1.0f, 1.0f ), gravity(1000.0), player(0), camera(0) { add_object(new Player(player_status, "Tux")); add_object(new DisplayEffect("Effect")); @@ -708,6 +708,13 @@ Sector::before_object_add(GameObject* object) this->player = player; } + UsesPhysic *physic_object = dynamic_cast(object); + if(physic_object) + { + physic_object->physic.set_gravity(gravity); + } + + if(_current == this) { try_expose(object); } -- 2.11.0