Ladders implemented!
authorMark Holmquist <marktraceur@gmail.com>
Wed, 27 Jul 2011 21:38:48 +0000 (14:38 -0700)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 1 Aug 2011 07:22:36 +0000 (09:22 +0200)
src/content_mapnode.cpp
src/mapnode.h
src/player.cpp
src/player.h

index e3235778a234e9d9d8f50d06fe4bcf2636ff6e43..8e97fa6cd1dd1510c2fee71eddb064b629cc5ee3 100644 (file)
@@ -314,6 +314,7 @@ void content_mapnode_init()
        f->solidness = 0;
        f->air_equivalent = true;
        f->walkable = false;
+       f->climbable = true;
        setWoodLikeDiggingProperties(f->digging_properties, 0.5);
 
        // Deprecated
index 1fb84e1c977468f6b7d57dd13c45f2e9ff36449f..484ad4e196c6ef8acddd9266a543cc95cfa0feaf 100644 (file)
@@ -128,6 +128,8 @@ struct ContentFeatures
        bool pointable;
        // Player can dig these
        bool diggable;
+        // Player can climb these
+        bool climbable;
        // Player can build on these
        bool buildable_to;
        // Whether the node has no liquid, source liquid or flowing liquid
@@ -171,6 +173,7 @@ struct ContentFeatures
                walkable = true;
                pointable = true;
                diggable = true;
+               climbable = false;
                buildable_to = false;
                liquid_type = LIQUID_NONE;
                wall_mounted = false;
index c43276ef132db71f8dbc1766953ef674ea8cd585..3846cd8f9e676c2324b9d24ddb2f9a6f78f8a648 100644 (file)
@@ -375,6 +375,21 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                in_water_stable = false;
        }
 
+       /*
+               Check if player is climbing
+       */
+
+       try {
+               v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
+               v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
+               is_climbing = (content_features(map.getNode(pp).d).climbable ||
+                              content_features(map.getNode(pp2).d).climbable);
+       }
+       catch(InvalidPositionException &e)
+       {
+               is_climbing = false;
+       }
+
        /*
                Collision uncertainty radius
                Make it a bit larger than the maximum distance of movement
@@ -461,7 +476,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d,
                Player is allowed to jump when this is true.
        */
        touching_ground = false;
-       
+
        /*std::cout<<"Checking collisions for ("
                        <<oldpos_i.X<<","<<oldpos_i.Y<<","<<oldpos_i.Z
                        <<") -> ("
@@ -814,6 +829,19 @@ void LocalPlayer::applyControl(float dtime)
                }
        }
 
+       if (is_climbing) {
+               if (control.up || control.left || control.right || control.down) {
+                       v3f speed = getSpeed();
+                       speed.Y = 2*BS;
+                       setSpeed(speed);
+               }
+               else {
+                       v3f speed = getSpeed();
+                       speed.Y = -2*BS;
+                       setSpeed(speed);
+               }
+       }
+
        // The speed of the player (Y is ignored)
        if(superspeed)
                speed = speed.normalize() * walkspeed_max * 5.0;
index 29460e1e1e7323ad7a554371b8774af97515df46..78ca149488370fe0424c3f0e237acad9367792a0 100644 (file)
@@ -118,6 +118,7 @@ public:
        bool in_water;
        // This is more stable and defines the maximum speed of the player
        bool in_water_stable;
+       bool is_climbing;
        bool swimming_up;
        
        Inventory inventory;