From c0f89d7deb1370b40b39ff1d4f53870bb4fba72e Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Sun, 18 Sep 2005 16:07:53 +0000 Subject: [PATCH] more fixes for Kugelblitz and Rain SVN-Revision: 2779 --- data/levels/test/kugelblitz.stl | 8 ++--- src/badguy/kugelblitz.cpp | 50 +++++++++++++++++++++++++++++-- src/badguy/kugelblitz.hpp | 2 ++ src/object/electrifier.cpp | 2 ++ src/object/electrifier.hpp | 1 - src/object/particlesystem_interactive.cpp | 26 ++++++++++------ 6 files changed, 73 insertions(+), 16 deletions(-) diff --git a/data/levels/test/kugelblitz.stl b/data/levels/test/kugelblitz.stl index 7e633f8f2..d3465140b 100644 --- a/data/levels/test/kugelblitz.stl +++ b/data/levels/test/kugelblitz.stl @@ -97,7 +97,7 @@ (particles-rain ) - (spawnpoint (name "main") (x 1728) (y 192)) + (spawnpoint (name "main") (x 2496) (y 128)) (background (image "ghostforest.jpg") (speed 1.000000) @@ -106,9 +106,9 @@ (poisonivy (x 100) (y 438)) (kugelblitz (x 219) (y 32)) (kugelblitz (x 700) (y 32)) - (kugelblitz (x 1363) (y 183)) - (kugelblitz (x 2459) (y 64)) - (kugelblitz (x 3215) (y 79)) + (kugelblitz (x 1076) (y 366)) + (kugelblitz (x 2728) (y 13)) + (kugelblitz (x 2201) (y 6)) (kugelblitz (x 3762) (y 130)) ) ) diff --git a/src/badguy/kugelblitz.cpp b/src/badguy/kugelblitz.cpp index dd47c3168..66354c891 100644 --- a/src/badguy/kugelblitz.cpp +++ b/src/badguy/kugelblitz.cpp @@ -21,6 +21,7 @@ #include "kugelblitz.hpp" #include "object/tilemap.hpp" +#include "object/camera.hpp" #include "tile.hpp" #define LIFETIME 5 @@ -28,6 +29,9 @@ #define BASE_SPEED 200 #define RAND_SPEED 150 +static const float X_OFFSCREEN_DISTANCE = 1600; +static const float Y_OFFSCREEN_DISTANCE = 1200; + Kugelblitz::Kugelblitz(const lisp::Lisp& reader) : groundhit_pos_set(false) { @@ -136,8 +140,6 @@ Kugelblitz::active_update(float elapsed_time) movement_timer.start(MOVETIME); } } - if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() != 0) - std::cout << Sector::current()->solids->get_tile_at(get_pos())->getAttributes() << std::endl; if (Sector::current()->solids->get_tile_at(get_pos())->getAttributes() == 16) { //HIT WATER Sector::current()->add_object(new Electrifier(75,1421,1.5)); @@ -168,4 +170,48 @@ Kugelblitz::explode() else remove_me(); } +void +Kugelblitz::try_activate() +{ + //FIXME: Don't activate Kugelblitz before it's on-screen + float scroll_x = Sector::current()->camera->get_translation().x; + float scroll_y = Sector::current()->camera->get_translation().y; + + /* Activate badguys if they're just around the screen to avoid + * the effect of having badguys suddenly popping up from nowhere. + */ + if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && + start_position.x < scroll_x - bbox.get_width() && + start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { + dir = RIGHT; + set_state(STATE_ACTIVE); + activate(); + } else if (start_position.x > scroll_x && + start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && + start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { + dir = LEFT; + set_state(STATE_ACTIVE); + activate(); + } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE && + start_position.x < scroll_x + X_OFFSCREEN_DISTANCE && + ((start_position.y > scroll_y && + start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) || + (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE && + start_position.y < scroll_y))) { + dir = start_position.x < scroll_x ? RIGHT : LEFT; + set_state(STATE_ACTIVE); + activate(); + } else if(state == STATE_INIT + && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE + && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE + && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE + && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE) { + dir = LEFT; + set_state(STATE_ACTIVE); + activate(); + } +} + IMPLEMENT_FACTORY(Kugelblitz, "kugelblitz") diff --git a/src/badguy/kugelblitz.hpp b/src/badguy/kugelblitz.hpp index 302a5e5a5..2d7ff7007 100644 --- a/src/badguy/kugelblitz.hpp +++ b/src/badguy/kugelblitz.hpp @@ -40,6 +40,7 @@ public: void explode(); private: + void try_activate(); HitResponse hit(const CollisionHit& hit); Vector pos_groundhit; bool groundhit_pos_set; @@ -47,6 +48,7 @@ private: Timer movement_timer; Timer lifetime; int direction; + State state; }; #endif diff --git a/src/object/electrifier.cpp b/src/object/electrifier.cpp index 682952327..d9ad1fb67 100644 --- a/src/object/electrifier.cpp +++ b/src/object/electrifier.cpp @@ -14,6 +14,8 @@ // 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 "electrifier.hpp" #include "sector.hpp" #include "object/tilemap.hpp" diff --git a/src/object/electrifier.hpp b/src/object/electrifier.hpp index 3cfa1b8b3..26d957948 100644 --- a/src/object/electrifier.hpp +++ b/src/object/electrifier.hpp @@ -18,7 +18,6 @@ #ifndef __ELECTRIFIER_H__ #define __ELECTRIFIER_H__ -#include #include "resources.hpp" #include "game_object.hpp" #include "timer.hpp" diff --git a/src/object/particlesystem_interactive.cpp b/src/object/particlesystem_interactive.cpp index b3da7341f..5bdf862b9 100644 --- a/src/object/particlesystem_interactive.cpp +++ b/src/object/particlesystem_interactive.cpp @@ -80,6 +80,7 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) x2 = x1 + 32 + movement.x; y1 = object->pos.y; y2 = y1 + 32 + movement.y; + bool water = false; // test with all tiles in this rectangle int starttilex = int(x1-1) / 32; @@ -96,8 +97,10 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) const Tile* tile = solids->get_tile(x, y); if(!tile) continue; - // skip non-solid tiles - if(!(tile->getAttributes() & Tile::SOLID)) + // skip non-solid tiles, except water + if (tile->getAttributes() & Tile::WATER) + water = true; + if(!water && !(tile->getAttributes() & Tile::SOLID)) continue; if(tile->getAttributes() & Tile::SLOPE) { // slope tile @@ -127,9 +130,13 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement) return -1; //no collision } else { - if ((hit.normal.x == 1) && (hit.normal.y == 0)) - return 1; //collision from right - else return 0; //collision from above + if (water) + return 0; //collision with water tile - don't draw splash + else { + if ((hit.normal.x == 1) && (hit.normal.y == 0)) + return 2; //collision from right + else return 1; //collision from above + } } } @@ -191,8 +198,8 @@ void RainParticleSystem::update(float elapsed_time) int col = collision(particle, Vector(-movement, movement)); if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { //Create rainsplash - if (particle->pos.y <= SCREEN_HEIGHT + abs_y){ - bool vertical = (col == 1); + if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)){ + bool vertical = (col == 2); int splash_x, splash_y; if (!vertical) { //check if collision happened from above splash_x = int(particle->pos.x); @@ -270,8 +277,9 @@ void CometParticleSystem::update(float elapsed_time) float abs_y = Sector::current()->camera->get_translation().y; particle->pos.y += movement; particle->pos.x -= movement; - if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (collision(particle, Vector(-movement, movement)) >= 0)) { - if (particle->pos.y <= SCREEN_HEIGHT + abs_y) { + int col = collision(particle, Vector(-movement, movement)); + if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) { + if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) { Sector::current()->add_object(new Bomb(particle->pos, LEFT)); } int new_x = (rand() % int(virtual_width)) + int(abs_x); -- 2.11.0