From e7bcfe5bd4514a2764af9f25faace5bae133c21d Mon Sep 17 00:00:00 2001 From: Ryan Flegel Date: Sun, 16 May 2004 03:28:22 +0000 Subject: [PATCH] - more game object changes. looks a bit nicer now SVN-Revision: 1206 --- src/gameobjs.cpp | 5 ++++- src/gameobjs.h | 26 +++++++++++++++----------- src/resources.cpp | 4 ++-- src/world.cpp | 10 ++++++++-- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index 3c04c05ee..7b6d3f1be 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -216,7 +216,7 @@ FloatingScore::draw() #define TRAMPOLINE_FRAMES 4 Sprite *img_trampoline[TRAMPOLINE_FRAMES]; -void load_trampoline_gfx() +void load_object_gfx() { for (int i = 0; i < TRAMPOLINE_FRAMES; i++) { @@ -231,12 +231,15 @@ Trampoline::init(float x, float y) { base.x = x; base.y = y; + + base.height = 32; } void Trampoline::action(double frame_ratio) { (void) frame_ratio; + physic.apply(frame_ratio, base.x, base.y); // TODO: // If HELD // - move with tux diff --git a/src/gameobjs.h b/src/gameobjs.h index 8037db662..2276faa7d 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -26,6 +26,7 @@ #include "texture.h" #include "timer.h" #include "scene.h" +#include "physic.h" enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE }; @@ -46,12 +47,6 @@ struct ObjectData : x(0), y(0), type(OBJ_NONE), type_specific() {}; }; -struct TrampolineData -{ - int power; -}; - - /* Bounciness of distros: */ #define NO_BOUNCE 0 #define BOUNCE 1 @@ -110,6 +105,13 @@ class FloatingScore : public GameObject std::string type() { return "FloatingScore"; }; }; + +/* Trampoline */ +struct TrampolineData +{ + int power; +}; + class Trampoline : public GameObject { public: @@ -120,17 +122,19 @@ class Trampoline : public GameObject Trampoline(ObjectData data) { - base.x = data.x; - base.y = data.y; - power = data.type_specific.power; - } + + init(data.x, data.y); + }; + + Physic physic; private: int power; }; -void load_trampoline_gfx(); + +void load_object_gfx(); #endif diff --git a/src/resources.cpp b/src/resources.cpp index b6fcf7065..3d1c391d8 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -175,8 +175,8 @@ void loadshared() /* Upgrades: */ load_special_gfx(); - /* Trampoline */ - load_trampoline_gfx(); + /* Objects */ + load_object_gfx(); /* Distros: */ img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png", diff --git a/src/world.cpp b/src/world.cpp index f4d83db8a..7ca3e96de 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -32,6 +32,7 @@ #include "level.h" #include "tile.h" #include "resources.h" +#include "gameobjs.h" Surface* img_distro[4]; @@ -166,7 +167,7 @@ World::activate_objects() for (std::vector< ObjectData >::iterator i = level->trampoline_data.begin(); i != level->trampoline_data.end(); ++i) - {puts("fo"); + { add_object >(*i); } } @@ -301,6 +302,9 @@ World::action(double frame_ratio) for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i) (*i)->action(frame_ratio); + for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i) + (*i)->action(frame_ratio); + /* update particle systems */ std::vector::iterator p; for(p = particle_systems.begin(); p != particle_systems.end(); ++p) @@ -554,7 +558,9 @@ T* World::add_object(U data) { T* tobject = new T(data); - trampolines.push_back(tobject); + + if (data.type == OBJ_TRAMPOLINE) + trampolines.push_back(tobject); return tobject; } -- 2.11.0