fix collision against spikes too wide, fix paths, try to fix jumping on badguys that...
[supertux.git] / src / badguy / stalactite.cpp
index d8e3f4e..a058c18 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <config.h>
 
-#include "stalactite.h"
+#include "stalactite.hpp"
 
 static const int SHAKE_RANGE = 40;
 static const float SHAKE_TIME = .8;
@@ -31,8 +31,9 @@ Stalactite::Stalactite(const lisp::Lisp& lisp)
   lisp.get("x", start_position.x);
   lisp.get("y", start_position.y);
   bbox.set_size(31.8, 31.8);
-  sprite = sprite_manager->create("stalactite");
+  sprite = sprite_manager->create("images/creatures/stalactite/stalactite.sprite");
   state = STALACTITE_HANGING;
+  countMe = false;
 }
 
 void
@@ -48,12 +49,14 @@ void
 Stalactite::active_update(float elapsed_time)
 {
   if(state == STALACTITE_HANGING) {
-    Player* player = Sector::current()->player;
-    if(player->get_bbox().p2.x > bbox.p1.x - SHAKE_RANGE
-        && player->get_bbox().p1.x < bbox.p2.x + SHAKE_RANGE
-        && player->get_bbox().p2.y > bbox.p1.y) {
-      timer.start(SHAKE_TIME);
-      state = STALACTITE_SHAKING;
+    Player* player = this->get_nearest_player();
+    if (player) {
+      if(player->get_bbox().p2.x > bbox.p1.x - SHAKE_RANGE
+          && player->get_bbox().p1.x < bbox.p2.x + SHAKE_RANGE
+          && player->get_bbox().p2.y > bbox.p1.y) {
+        timer.start(SHAKE_TIME);
+        state = STALACTITE_SHAKING;
+      }
     }
   } else if(state == STALACTITE_SHAKING) {
     if(timer.check()) {
@@ -73,8 +76,9 @@ Stalactite::collision_solid(GameObject& , const CollisionHit& hit)
   if(state != STALACTITE_FALLING && state != STALACTITE_SQUISHED)
     return FORCE_MOVE;
   
-  if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
+  if(hit.normal.y < .9) { // hit floor?
     state = STALACTITE_SQUISHED;
+    set_group(COLGROUP_MOVING_ONLY_STATIC);
     physic.set_velocity_y(0);
     sprite->set_action("squished");
     if(!timer.started())