示例#1
0
    internal void UpdateGrenade(Game game, int grenadeEntityId, float dt)
    {
        float LocalPlayerPositionX = game.player.position.x;
        float LocalPlayerPositionY = game.player.position.y;
        float LocalPlayerPositionZ = game.player.position.z;

        Entity   grenadeEntity = game.entities[grenadeEntityId];
        Sprite   grenadeSprite = grenadeEntity.sprite;
        Grenade_ grenade       = grenadeEntity.grenade;

        float oldposX = grenadeEntity.sprite.positionX;
        float oldposY = grenadeSprite.positionY;
        float oldposZ = grenadeSprite.positionZ;
        float newposX = grenadeSprite.positionX + grenade.velocityX * dt;
        float newposY = grenadeSprite.positionY + grenade.velocityY * dt;
        float newposZ = grenadeSprite.positionZ + grenade.velocityZ * dt;

        grenade.velocityY += -projectilegravity * dt;

        Vector3Ref velocity       = Vector3Ref.Create(grenade.velocityX, grenade.velocityY, grenade.velocityZ);
        Vector3Ref bouncePosition = GrenadeBounce(game, Vector3Ref.Create(oldposX, oldposY, oldposZ), Vector3Ref.Create(newposX, newposY, newposZ), velocity, dt);

        grenade.velocityX       = velocity.X;
        grenade.velocityY       = velocity.Y;
        grenade.velocityZ       = velocity.Z;
        grenadeSprite.positionX = bouncePosition.X;
        grenadeSprite.positionY = bouncePosition.Y;
        grenadeSprite.positionZ = bouncePosition.Z;
    }
    public override void OnNewFrameFixed(Game game_, int entity, float dt)
    {
        game = game_;
        if (game.guistate == GuiState.MapLoading)
        {
            return;
        }
        movespeednow         = game.MoveSpeedNow();
        game.controls.movedx = MathCi.ClampFloat(game.controls.movedx, -1, 1);
        game.controls.movedy = MathCi.ClampFloat(game.controls.movedy, -1, 1);
        Controls move = game.controls;

        jumpstartacceleration     = 13.333f * constGravity; // default
        jumpstartaccelerationhalf = 9 * constGravity;
        acceleration.SetDefault();
        game.soundnow = new BoolRef();
        if (game.FollowId() != null && game.FollowId().value == game.LocalPlayerId)
        {
            move.movedx    = 0;
            move.movedy    = 0;
            move.moveup    = false;
            move.wantsjump = false;
        }
        Update(game.player.position, move, dt, game.soundnow, Vector3Ref.Create(game.pushX, game.pushY, game.pushZ), game.entities[game.LocalPlayerId].drawModel.ModelHeight);
    }
示例#3
0
        private void OverheadCamera()
        {
            GL.MatrixMode(MatrixMode.Modelview);

            Vector3Ref position = new Vector3Ref();

            overheadcameraK.GetPosition(platform, position);
            Vector3 position_ = new Vector3(position.GetX(), position.GetY(), position.GetZ());

            Vector3Ref center = new Vector3Ref();

            overheadcameraK.GetCenter(center);
            Vector3 center_ = new Vector3(center.GetX(), center.GetY(), center.GetZ());

            Matrix4 camera = Matrix4.LookAt(position_, center_, up);

            m = new float[]
            {
                camera.M11, camera.M12, camera.M13, camera.M14,
                camera.M21, camera.M22, camera.M23, camera.M24,
                camera.M31, camera.M32, camera.M33, camera.M34,
                camera.M41, camera.M42, camera.M43, camera.M44
            };
            GL.LoadMatrix(ref camera);
        }
示例#4
0
    internal void LimitThirdPersonCameraToWalls(Game game, Vector3Ref eye, Vector3Ref target, FloatRef curtppcameradistance)
    {
        float      one             = 1;
        Vector3Ref ray_start_point = target;
        Vector3Ref raytarget       = eye;

        Line3D pick    = new Line3D();
        float  raydirX = (raytarget.X - ray_start_point.X);
        float  raydirY = (raytarget.Y - ray_start_point.Y);
        float  raydirZ = (raytarget.Z - ray_start_point.Z);

        float raydirLength1 = game.Length(raydirX, raydirY, raydirZ);

        raydirX    /= raydirLength1;
        raydirY    /= raydirLength1;
        raydirZ    /= raydirLength1;
        raydirX     = raydirX * (game.tppcameradistance + 1);
        raydirY     = raydirY * (game.tppcameradistance + 1);
        raydirZ     = raydirZ * (game.tppcameradistance + 1);
        pick.Start  = Vec3.FromValues(ray_start_point.X, ray_start_point.Y, ray_start_point.Z);
        pick.End    = new float[3];
        pick.End[0] = ray_start_point.X + raydirX;
        pick.End[1] = ray_start_point.Y + raydirY;
        pick.End[2] = ray_start_point.Z + raydirZ;

        //pick terrain
        IntRef pick2Count = new IntRef();

        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2Count);

        if (pick2Count.value > 0)
        {
            BlockPosSide pick2nearest = game.Nearest(pick2, pick2Count.value, ray_start_point.X, ray_start_point.Y, ray_start_point.Z);
            //pick2.Sort((a, b) => { return (FloatArrayToVector3(a.blockPos) - ray_start_point).Length.CompareTo((FloatArrayToVector3(b.blockPos) - ray_start_point).Length); });

            float pickX        = pick2nearest.blockPos[0] - target.X;
            float pickY        = pick2nearest.blockPos[1] - target.Y;
            float pickZ        = pick2nearest.blockPos[2] - target.Z;
            float pickdistance = game.Length(pickX, pickY, pickZ);
            curtppcameradistance.value = MathCi.MinFloat(pickdistance - 1, curtppcameradistance.value);
            if (curtppcameradistance.value < one * 3 / 10)
            {
                curtppcameradistance.value = one * 3 / 10;
            }
        }

        float cameraDirectionX = target.X - eye.X;
        float cameraDirectionY = target.Y - eye.Y;
        float cameraDirectionZ = target.Z - eye.Z;
        float raydirLength     = game.Length(raydirX, raydirY, raydirZ);

        raydirX /= raydirLength;
        raydirY /= raydirLength;
        raydirZ /= raydirLength;
        eye.X    = target.X + raydirX * curtppcameradistance.value;
        eye.Y    = target.Y + raydirY * curtppcameradistance.value;
        eye.Z    = target.Z + raydirZ * curtppcameradistance.value;
    }
示例#5
0
    internal static Vector3Ref Create(float x, float y, float z)
    {
        Vector3Ref v = new Vector3Ref();

        v.X = x;
        v.Y = y;
        v.Z = z;
        return(v);
    }
示例#6
0
    internal void LimitThirdPersonCameraToWalls(Game game, Vector3Ref eye, Vector3Ref target, FloatRef curtppcameradistance)
    {
        float one = 1;
        Vector3Ref ray_start_point = target;
        Vector3Ref raytarget = eye;

        Line3D pick = new Line3D();
        float raydirX = (raytarget.X - ray_start_point.X);
        float raydirY = (raytarget.Y - ray_start_point.Y);
        float raydirZ = (raytarget.Z - ray_start_point.Z);

        float raydirLength1 = game.Length(raydirX, raydirY, raydirZ);
        raydirX /= raydirLength1;
        raydirY /= raydirLength1;
        raydirZ /= raydirLength1;
        raydirX = raydirX * (game.tppcameradistance + 1);
        raydirY = raydirY * (game.tppcameradistance + 1);
        raydirZ = raydirZ * (game.tppcameradistance + 1);
        pick.Start = Vec3.FromValues(ray_start_point.X, ray_start_point.Y, ray_start_point.Z);
        pick.End = new float[3];
        pick.End[0] = ray_start_point.X + raydirX;
        pick.End[1] = ray_start_point.Y + raydirY;
        pick.End[2] = ray_start_point.Z + raydirZ;

        //pick terrain
        IntRef pick2Count = new IntRef();
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2Count);

        if (pick2Count.value > 0)
        {
            BlockPosSide pick2nearest = game.Nearest(pick2, pick2Count.value, ray_start_point.X, ray_start_point.Y, ray_start_point.Z);
            //pick2.Sort((a, b) => { return (FloatArrayToVector3(a.blockPos) - ray_start_point).Length.CompareTo((FloatArrayToVector3(b.blockPos) - ray_start_point).Length); });

            float pickX = pick2nearest.blockPos[0] - target.X;
            float pickY = pick2nearest.blockPos[1] - target.Y;
            float pickZ = pick2nearest.blockPos[2] - target.Z;
            float pickdistance = game.Length(pickX, pickY, pickZ);
            curtppcameradistance.value = MathCi.MinFloat(pickdistance - 1, curtppcameradistance.value);
            if (curtppcameradistance.value < one * 3 / 10) { curtppcameradistance.value = one * 3 / 10; }
        }

        float cameraDirectionX = target.X - eye.X;
        float cameraDirectionY = target.Y - eye.Y;
        float cameraDirectionZ = target.Z - eye.Z;
        float raydirLength = game.Length(raydirX, raydirY, raydirZ);
        raydirX /= raydirLength;
        raydirY /= raydirLength;
        raydirZ /= raydirLength;
        eye.X = target.X + raydirX * curtppcameradistance.value;
        eye.Y = target.Y + raydirY * curtppcameradistance.value;
        eye.Z = target.Z + raydirZ * curtppcameradistance.value;
    }
示例#7
0
    public static ModelData Get()
    {
        ModelData m = new ModelData();

        m.setMode(DrawModeEnum.Lines);
        m.xyz     = new float[3 * 4 * 6];
        m.uv      = new float[2 * 4 * 6];
        m.rgba    = new byte[4 * 4 * 6];
        m.indices = new int[8 * 6];

        DrawLineLoop(m,
                     Vector3Ref.Create(-1, -1, -1),
                     Vector3Ref.Create(-1, 1, -1),
                     Vector3Ref.Create(1, 1, -1),
                     Vector3Ref.Create(1, -1, -1)
                     );
        DrawLineLoop(m,
                     Vector3Ref.Create(-1, -1, -1),
                     Vector3Ref.Create(1, -1, -1),
                     Vector3Ref.Create(1, -1, 1),
                     Vector3Ref.Create(-1, -1, 1)
                     );
        DrawLineLoop(m,
                     Vector3Ref.Create(-1, -1, -1),
                     Vector3Ref.Create(-1, -1, 1),
                     Vector3Ref.Create(-1, 1, 1),
                     Vector3Ref.Create(-1, 1, -1)
                     );
        DrawLineLoop(m,
                     Vector3Ref.Create(-1, -1, 1),
                     Vector3Ref.Create(1, -1, 1),
                     Vector3Ref.Create(1, 1, 1),
                     Vector3Ref.Create(-1, 1, 1)
                     );
        DrawLineLoop(m,
                     Vector3Ref.Create(-1, 1, -1),
                     Vector3Ref.Create(-1, 1, 1),
                     Vector3Ref.Create(1, 1, 1),
                     Vector3Ref.Create(1, 1, -1)
                     );
        DrawLineLoop(m,
                     Vector3Ref.Create(1, -1, -1),
                     Vector3Ref.Create(1, 1, -1),
                     Vector3Ref.Create(1, 1, 1),
                     Vector3Ref.Create(1, -1, 1)
                     );

        return(m);
    }
示例#8
0
    internal float[] OverheadCamera(Game game)
    {
        game.overheadcameraK.GetPosition(game.platform, OverheadCamera_cameraEye);
        Vector3Ref cameraEye    = OverheadCamera_cameraEye;
        Vector3Ref cameraTarget = Vector3Ref.Create(game.overheadcameraK.Center.X, game.overheadcameraK.Center.Y + game.GetCharacterEyesHeight(), game.overheadcameraK.Center.Z);
        FloatRef   currentOverheadcameradistance = FloatRef.Create(game.overheadcameradistance);

        LimitThirdPersonCameraToWalls(game, cameraEye, cameraTarget, currentOverheadcameradistance);
        float[] ret = new float[16];
        Mat4.LookAt(ret, Vec3.FromValues(cameraEye.X, cameraEye.Y, cameraEye.Z),
                    Vec3.FromValues(cameraTarget.X, cameraTarget.Y, cameraTarget.Z),
                    upVec3);
        game.CameraEyeX = cameraEye.X;
        game.CameraEyeY = cameraEye.Y;
        game.CameraEyeZ = cameraEye.Z;
        return(ret);
    }
示例#9
0
    static void DrawLineLoop(ModelData m, Vector3Ref p0, Vector3Ref p1, Vector3Ref p2, Vector3Ref p3)
    {
        int startVertex = m.GetVerticesCount();

        AddVertex(m, p0.X, p0.Y, p0.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
        AddVertex(m, p1.X, p1.Y, p1.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
        AddVertex(m, p2.X, p2.Y, p2.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
        AddVertex(m, p3.X, p3.Y, p3.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
        m.indices[m.indicesCount++] = startVertex + 0;
        m.indices[m.indicesCount++] = startVertex + 1;
        m.indices[m.indicesCount++] = startVertex + 1;
        m.indices[m.indicesCount++] = startVertex + 2;
        m.indices[m.indicesCount++] = startVertex + 2;
        m.indices[m.indicesCount++] = startVertex + 3;
        m.indices[m.indicesCount++] = startVertex + 3;
        m.indices[m.indicesCount++] = startVertex + 0;
    }
    public ScriptCharacterPhysics()
    {
        movedz                    = 0;
        curspeed                  = new Vector3Ref();
        jumpacceleration          = 0;
        isplayeronground          = false;
        acceleration              = new Acceleration();
        jumpstartacceleration     = 0;
        jumpstartaccelerationhalf = 0;
        movespeednow              = 0;

        tmpPlayerPosition    = new float[3];
        tmpBlockingBlockType = new IntRef();

        constGravity = 0.3f;
        constWaterGravityMultiplier = 3;
        constEnableAcceleration     = true;
        constJump = 2.1f;
    }
    float[] tmpPlayerPosition; //Temporarily stores the player's position. Used in WallSlide()

    #endregion Fields

    #region Constructors

    public ScriptCharacterPhysics()
    {
        movedz = 0;
        curspeed = new Vector3Ref();
        jumpacceleration = 0;
        isplayeronground = false;
        acceleration = new Acceleration();
        jumpstartacceleration = 0;
        jumpstartaccelerationhalf = 0;
        movespeednow = 0;

        tmpPlayerPosition = new float[3];
        tmpBlockingBlockType = new IntRef();

        constGravity = 0.3f;
        constWaterGravityMultiplier = 3;
        constEnableAcceleration = true;
        constJump = 2.1f;
    }
示例#12
0
    internal float[] FppCamera(Game game)
    {
        Vector3Ref forward = new Vector3Ref();

        VectorTool.ToVectorInFixedSystem(0, 0, 1, game.player.position.rotx, game.player.position.roty, forward);
        Vector3Ref cameraEye    = new Vector3Ref();
        Vector3Ref cameraTarget = new Vector3Ref();
        float      playerEyeX   = game.player.position.x;
        float      playerEyeY   = game.player.position.y + game.GetCharacterEyesHeight();
        float      playerEyeZ   = game.player.position.z;

        if (!game.ENABLE_TPP_VIEW)
        {
            cameraEye.X    = playerEyeX;
            cameraEye.Y    = playerEyeY;
            cameraEye.Z    = playerEyeZ;
            cameraTarget.X = playerEyeX + forward.X;
            cameraTarget.Y = playerEyeY + forward.Y;
            cameraTarget.Z = playerEyeZ + forward.Z;
        }
        else
        {
            cameraEye.X    = playerEyeX + forward.X * -game.tppcameradistance;
            cameraEye.Y    = playerEyeY + forward.Y * -game.tppcameradistance;
            cameraEye.Z    = playerEyeZ + forward.Z * -game.tppcameradistance;
            cameraTarget.X = playerEyeX;
            cameraTarget.Y = playerEyeY;
            cameraTarget.Z = playerEyeZ;
            FloatRef currentTppcameradistance = FloatRef.Create(game.tppcameradistance);
            LimitThirdPersonCameraToWalls(game, cameraEye, cameraTarget, currentTppcameradistance);
        }
        float[] ret = new float[16];
        Mat4.LookAt(ret, Vec3.FromValues(cameraEye.X, cameraEye.Y, cameraEye.Z),
                    Vec3.FromValues(cameraTarget.X, cameraTarget.Y, cameraTarget.Z),
                    upVec3);
        game.CameraEyeX = cameraEye.X;
        game.CameraEyeY = cameraEye.Y;
        game.CameraEyeZ = cameraEye.Z;
        return(ret);
    }
示例#13
0
 internal float[] FppCamera(Game game)
 {
     Vector3Ref forward = new Vector3Ref();
     VectorTool.ToVectorInFixedSystem(0, 0, 1, game.player.position.rotx, game.player.position.roty, forward);
     Vector3Ref cameraEye = new Vector3Ref();
     Vector3Ref cameraTarget = new Vector3Ref();
     float playerEyeX = game.player.position.x;
     float playerEyeY = game.player.position.y + game.GetCharacterEyesHeight();
     float playerEyeZ = game.player.position.z;
     if (!game.ENABLE_TPP_VIEW)
     {
         cameraEye.X = playerEyeX;
         cameraEye.Y = playerEyeY;
         cameraEye.Z = playerEyeZ;
         cameraTarget.X = playerEyeX + forward.X;
         cameraTarget.Y = playerEyeY + forward.Y;
         cameraTarget.Z = playerEyeZ + forward.Z;
     }
     else
     {
         cameraEye.X = playerEyeX + forward.X * -game.tppcameradistance;
         cameraEye.Y = playerEyeY + forward.Y * -game.tppcameradistance;
         cameraEye.Z = playerEyeZ + forward.Z * -game.tppcameradistance;
         cameraTarget.X = playerEyeX;
         cameraTarget.Y = playerEyeY;
         cameraTarget.Z = playerEyeZ;
         FloatRef currentTppcameradistance = FloatRef.Create(game.tppcameradistance);
         LimitThirdPersonCameraToWalls(game, cameraEye, cameraTarget, currentTppcameradistance);
     }
     float[] ret = new float[16];
     Mat4.LookAt(ret, Vec3.FromValues(cameraEye.X, cameraEye.Y, cameraEye.Z),
         Vec3.FromValues(cameraTarget.X, cameraTarget.Y, cameraTarget.Z),
         upVec3);
     game.CameraEyeX = cameraEye.X;
     game.CameraEyeY = cameraEye.Y;
     game.CameraEyeZ = cameraEye.Z;
     return ret;
 }
示例#14
0
    public void AddDeformingForce(Vector3 point, Vector3 normal, float force)
    {
        List <Vector3Ref> sortedVertices = new List <Vector3Ref>();

        for (int i = 0; i < displacedVertices.Length; i++)
        {
            sortedVertices.Add(new Vector3Ref(i, displacedVertices[i]));
        }

        sortedVertices.Sort((v1, v2) => {
            float d1 = (transform.TransformPoint(v1.vector) - point).sqrMagnitude;
            float d2 = (transform.TransformPoint(v2.vector) - point).sqrMagnitude;

            return(d1.CompareTo(d2));
        });

        for (int i = 0; i < 3; i++)
        {
            Vector3Ref r = sortedVertices[i];

            r.vector = sortedVertices[i].vector + normal * force;

            sortedVertices[i] = r;
        }

        foreach (Vector3Ref vectorRef in sortedVertices)
        {
            displacedVertices[vectorRef.index] = vectorRef.vector;
        }

        //displacedVertices = sortedVertices.ToArray();

        /*if (smallestIndex >= 0 && ((displacedVertices[smallestIndex] - originalVertices[smallestIndex]).sqrMagnitude < 0.002f))
         * {
         *
         *  displacedVertices[smallestIndex] = displacedVertices[smallestIndex] + normal * force;
         * }*/
    }
示例#15
0
 internal static Vector3Ref Create(float x, float y, float z)
 {
     Vector3Ref v = new Vector3Ref();
     v.X = x;
     v.Y = y;
     v.Z = z;
     return v;
 }
示例#16
0
    internal void DrawPlayers(Game game, float dt)
    {
        game.totaltimeMilliseconds = game.platform.TimeMillisecondsFromStart();
        for (int i = 0; i < game.entitiesCount; i++)
        {
            if (game.entities[i] == null)
            {
                continue;
            }
            if (game.entities[i].drawModel == null)
            {
                continue;
            }
            Entity p_ = game.entities[i];
            if (i == game.LocalPlayerId && (!game.ENABLE_TPP_VIEW))
            {
                continue;
            }
            if ((p_.networkPosition != null) && (!p_.networkPosition.PositionLoaded))
            {
                continue;
            }
            if (!game.d_FrustumCulling.SphereInFrustum(p_.position.x, p_.position.y, p_.position.z, 3))
            {
                continue;
            }
            if (p_.drawModel.CurrentTexture == -1)
            {
                continue;
            }
            int cx = game.platform.FloatToInt(p_.position.x) / Game.chunksize;
            int cy = game.platform.FloatToInt(p_.position.z) / Game.chunksize;
            int cz = game.platform.FloatToInt(p_.position.y) / Game.chunksize;
            if (game.map.IsValidChunkPos(cx, cy, cz))
            {
                if (!game.map.IsChunkRendered(cx, cy, cz))
                {
                    continue;
                }
            }
            float shadow = (one * game.GetLight(game.platform.FloatToInt(p_.position.x), game.platform.FloatToInt(p_.position.z), game.platform.FloatToInt(p_.position.y))) / Game.maxlight;
            if (p_.playerDrawInfo == null)
            {
                p_.playerDrawInfo = new PlayerDrawInfo();
            }
            p_.playerDrawInfo.anim.light = shadow;
            float         FeetPosX = p_.position.x;
            float         FeetPosY = p_.position.y;
            float         FeetPosZ = p_.position.z;
            AnimationHint animHint = game.entities[i].playerDrawInfo.AnimationHint_;

            float playerspeed_;
            if (i == game.LocalPlayerId)
            {
                if (game.player.playerDrawInfo == null)
                {
                    game.player.playerDrawInfo = new PlayerDrawInfo();
                }
                Vector3Ref playerspeed  = Vector3Ref.Create(game.playervelocity.X / 60, game.playervelocity.Y / 60, game.playervelocity.Z / 60);
                float      playerspeedf = playerspeed.Length() * (one * 15 / 10);
                game.player.playerDrawInfo.moves = playerspeedf != 0;
                playerspeed_ = playerspeedf;
            }
            else
            {
                playerspeed_ = (game.Length(p_.playerDrawInfo.velocityX, p_.playerDrawInfo.velocityY, p_.playerDrawInfo.velocityZ) / dt) * (one * 4 / 100);
            }

            {
                if (p_.drawModel.renderer == null)
                {
                    p_.drawModel.renderer = new AnimatedModelRenderer();
                    byte[] data       = game.GetFile(p_.drawModel.Model_);
                    int    dataLength = game.GetFileLength(p_.drawModel.Model_);
                    if (data != null)
                    {
                        string        dataString = game.platform.StringFromUtf8ByteArray(data, dataLength);
                        AnimatedModel model      = AnimatedModelSerializer.Deserialize(game.platform, dataString);
                        p_.drawModel.renderer.Start(game, model);
                    }
                }
                game.GLPushMatrix();
                game.GLTranslate(FeetPosX, FeetPosY, FeetPosZ);
                //game.GLRotate(PlayerInterpolate.RadToDeg(p_.position.rotx), 1, 0, 0);
                game.GLRotate(PlayerInterpolate.RadToDeg(-p_.position.roty + Game.GetPi()), 0, 1, 0);
                //game.GLRotate(PlayerInterpolate.RadToDeg(p_.position.rotz), 0, 0, 1);
                game.platform.BindTexture2d(game.entities[i].drawModel.CurrentTexture);
                p_.drawModel.renderer.Render(dt, PlayerInterpolate.RadToDeg(p_.position.rotx + Game.GetPi()), true, p_.playerDrawInfo.moves, shadow);
                game.GLPopMatrix();
            }
        }
    }
示例#17
0
    internal Vector3Ref GrenadeBounce(Game game, Vector3Ref oldposition, Vector3Ref newposition, Vector3Ref velocity, float dt)
    {
        bool ismoving = velocity.Length() > 100 * dt;
        float modelheight = walldistance;
        oldposition.Y += walldistance;
        newposition.Y += walldistance;

        //Math.Floor() is needed because casting negative values to integer is not floor.
        Vector3IntRef oldpositioni = Vector3IntRef.Create(game.MathFloor(oldposition.X),
           game.MathFloor(oldposition.Z),
          game.MathFloor(oldposition.Y));
        float playerpositionX = newposition.X;
        float playerpositionY = newposition.Y;
        float playerpositionZ = newposition.Z;
        //left
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z + walldistance;
            bool newempty = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY))
            && game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.Z - oldposition.Z > 0)
            {
                if (!newempty)
                {
                    velocity.Z = -velocity.Z;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Z = oldposition.Z - newposition.Z;
                }
            }
        }
        //front
        {
            float qnewpositionX = newposition.X + walldistance;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z;
            bool newempty = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY))
            && game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.X - oldposition.X > 0)
            {
                if (!newempty)
                {
                    velocity.X = -velocity.X;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.X = oldposition.X - newposition.X;
                }
            }
        }
        //top
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y - walldistance;
            float qnewpositionZ = newposition.Z;
            int x = game.MathFloor(qnewpositionX);
            int y = game.MathFloor(qnewpositionZ);
            int z = game.MathFloor(qnewpositionY);
            float a_ = walldistance;
            bool newfull = (!game.IsTileEmptyForPhysics(x, y, z))
                || (qnewpositionX - game.MathFloor(qnewpositionX) <= a_ && (!game.IsTileEmptyForPhysics(x - 1, y, z)) && (game.IsTileEmptyForPhysics(x - 1, y, z + 1)))
                || (qnewpositionX - game.MathFloor(qnewpositionX) >= (1 - a_) && (!game.IsTileEmptyForPhysics(x + 1, y, z)) && (game.IsTileEmptyForPhysics(x + 1, y, z + 1)))
                || (qnewpositionZ - game.MathFloor(qnewpositionZ) <= a_ && (!game.IsTileEmptyForPhysics(x, y - 1, z)) && (game.IsTileEmptyForPhysics(x, y - 1, z + 1)))
                || (qnewpositionZ - game.MathFloor(qnewpositionZ) >= (1 - a_) && (!game.IsTileEmptyForPhysics(x, y + 1, z)) && (game.IsTileEmptyForPhysics(x, y + 1, z + 1)));
            if (newposition.Y - oldposition.Y < 0)
            {
                if (newfull)
                {
                    velocity.Y = -velocity.Y;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Y = oldposition.Y - newposition.Y;
                }
            }
        }
        //right
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z - walldistance;
            bool newempty = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY))
            && game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.Z - oldposition.Z < 0)
            {
                if (!newempty)
                {
                    velocity.Z = -velocity.Z;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Z = oldposition.Z - newposition.Z;
                }
            }
        }
        //back
        {
            float qnewpositionX = newposition.X - walldistance;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z;
            bool newempty = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY))
            && game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.X - oldposition.X < 0)
            {
                if (!newempty)
                {
                    velocity.X = -velocity.X;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.X = oldposition.X - newposition.X;
                }
            }
        }
        //bottom
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y + modelheight;
            float qnewpositionZ = newposition.Z;
            bool newempty = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY));
            if (newposition.Y - oldposition.Y > 0)
            {
                if (!newempty)
                {
                    velocity.Y = -velocity.Y;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Y = oldposition.Y - newposition.Y;
                }
            }
        }
        //ok:
        playerpositionY -= walldistance;
        return Vector3Ref.Create(playerpositionX, playerpositionY, playerpositionZ);
    }
示例#18
0
 static void DrawLineLoop(ModelData m, Vector3Ref p0, Vector3Ref p1, Vector3Ref p2, Vector3Ref p3)
 {
     int startVertex = m.GetVerticesCount();
     AddVertex(m, p0.X, p0.Y, p0.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
     AddVertex(m, p1.X, p1.Y, p1.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
     AddVertex(m, p2.X, p2.Y, p2.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
     AddVertex(m, p3.X, p3.Y, p3.Z, 0, 0, Game.ColorFromArgb(255, 255, 255, 255));
     m.indices[m.indicesCount++] = startVertex + 0;
     m.indices[m.indicesCount++] = startVertex + 1;
     m.indices[m.indicesCount++] = startVertex + 1;
     m.indices[m.indicesCount++] = startVertex + 2;
     m.indices[m.indicesCount++] = startVertex + 2;
     m.indices[m.indicesCount++] = startVertex + 3;
     m.indices[m.indicesCount++] = startVertex + 3;
     m.indices[m.indicesCount++] = startVertex + 0;
 }
示例#19
0
    internal void NextBullet(Game game, int bulletsshot)
    {
        float one    = 1;
        bool  left   = game.mouseLeft;
        bool  middle = game.mouseMiddle;
        bool  right  = game.mouseRight;

        bool IsNextShot = bulletsshot != 0;

        if (!game.leftpressedpicking)
        {
            if (game.mouseleftclick)
            {
                game.leftpressedpicking = true;
            }
            else
            {
                left = false;
            }
        }
        else
        {
            if (game.mouseleftdeclick)
            {
                game.leftpressedpicking = false;
                left = false;
            }
        }
        if (!left)
        {
            game.currentAttackedBlock = null;
        }

        Packet_Item item          = game.d_Inventory.RightHand[game.ActiveMaterial];
        bool        ispistol      = (item != null && game.blocktypes[item.BlockId].IsPistol);
        bool        ispistolshoot = ispistol && left;
        bool        isgrenade     = ispistol && game.blocktypes[item.BlockId].PistolType == Packet_PistolTypeEnum.Grenade;

        if (ispistol && isgrenade)
        {
            ispistolshoot = game.mouseleftdeclick;
        }
        //grenade cooking - TODO: fix instant explosion when closing ESC menu
        if (game.mouseleftclick)
        {
            game.grenadecookingstartMilliseconds = game.platform.TimeMillisecondsFromStart();
            if (ispistol && isgrenade)
            {
                if (game.blocktypes[item.BlockId].Sounds.ShootCount > 0)
                {
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.Shoot[0]));
                }
            }
        }
        float wait = ((one * (game.platform.TimeMillisecondsFromStart() - game.grenadecookingstartMilliseconds)) / 1000);

        if (isgrenade && left)
        {
            if (wait >= game.grenadetime && isgrenade && game.grenadecookingstartMilliseconds != 0)
            {
                ispistolshoot         = true;
                game.mouseleftdeclick = true;
            }
            else
            {
                return;
            }
        }
        else
        {
            game.grenadecookingstartMilliseconds = 0;
        }

        if (ispistol && game.mouserightclick && (game.platform.TimeMillisecondsFromStart() - game.lastironsightschangeMilliseconds) >= 500)
        {
            game.IronSights = !game.IronSights;
            game.lastironsightschangeMilliseconds = game.platform.TimeMillisecondsFromStart();
        }

        IntRef pick2count = new IntRef();
        Line3D pick       = new Line3D();

        GetPickingLine(game, pick, ispistolshoot);
        BlockPosSide[] pick2 = game.Pick(game.s, pick, pick2count);

        if (left)
        {
            game.handSetAttackDestroy = true;
        }
        else if (right)
        {
            game.handSetAttackBuild = true;
        }

        if (game.overheadcamera && pick2count.value > 0 && left)
        {
            //if not picked any object, and mouse button is pressed, then walk to destination.
            if (game.Follow == null)
            {
                //Only walk to destination when not following someone
                game.playerdestination = Vector3Ref.Create(pick2[0].blockPos[0], pick2[0].blockPos[1] + 1, pick2[0].blockPos[2]);
            }
        }
        bool pickdistanceok = (pick2count.value > 0); //&& (!ispistol);

        if (pickdistanceok)
        {
            if (game.Dist(pick2[0].blockPos[0] + one / 2, pick2[0].blockPos[1] + one / 2, pick2[0].blockPos[2] + one / 2,
                          pick.Start[0], pick.Start[1], pick.Start[2]) > CurrentPickDistance(game))
            {
                pickdistanceok = false;
            }
        }
        bool playertileempty = game.IsTileEmptyForPhysics(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        bool playertileemptyclose = game.IsTileEmptyForPhysicsClose(
            game.platform.FloatToInt(game.player.position.x),
            game.platform.FloatToInt(game.player.position.z),
            game.platform.FloatToInt(game.player.position.y + (one / 2)));
        BlockPosSide pick0 = new BlockPosSide();

        if (pick2count.value > 0 &&
            ((pickdistanceok && (playertileempty || (playertileemptyclose))) ||
             game.overheadcamera)
            )
        {
            game.SelectedBlockPositionX = game.platform.FloatToInt(pick2[0].Current()[0]);
            game.SelectedBlockPositionY = game.platform.FloatToInt(pick2[0].Current()[1]);
            game.SelectedBlockPositionZ = game.platform.FloatToInt(pick2[0].Current()[2]);
            pick0 = pick2[0];
        }
        else
        {
            game.SelectedBlockPositionX = -1;
            game.SelectedBlockPositionY = -1;
            game.SelectedBlockPositionZ = -1;
            pick0.blockPos    = new float[3];
            pick0.blockPos[0] = -1;
            pick0.blockPos[1] = -1;
            pick0.blockPos[2] = -1;
        }
        PickEntity(game, pick, pick2, pick2count);
        if (game.cameratype == CameraType.Fpp || game.cameratype == CameraType.Tpp)
        {
            int ntileX = game.platform.FloatToInt(pick0.Current()[0]);
            int ntileY = game.platform.FloatToInt(pick0.Current()[1]);
            int ntileZ = game.platform.FloatToInt(pick0.Current()[2]);
            if (game.IsUsableBlock(game.map.GetBlock(ntileX, ntileZ, ntileY)))
            {
                game.currentAttackedBlock = Vector3IntRef.Create(ntileX, ntileZ, ntileY);
            }
        }
        if (game.GetFreeMouse())
        {
            if (pick2count.value > 0)
            {
                OnPick_(pick0);
            }
            return;
        }

        if ((one * (game.platform.TimeMillisecondsFromStart() - lastbuildMilliseconds) / 1000) >= BuildDelay(game) ||
            IsNextShot)
        {
            if (left && game.d_Inventory.RightHand[game.ActiveMaterial] == null)
            {
                game.SendPacketClient(ClientPackets.MonsterHit(game.platform.FloatToInt(2 + game.rnd.NextFloat() * 4)));
            }
            if (left && !fastclicking)
            {
                //todo animation
                fastclicking = false;
            }
            if ((left || right || middle) && (!isgrenade))
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (isgrenade && game.mouseleftdeclick)
            {
                lastbuildMilliseconds = game.platform.TimeMillisecondsFromStart();
            }
            if (game.reloadstartMilliseconds != 0)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistolshoot)
            {
                if ((!(game.LoadedAmmo[item.BlockId] > 0)) ||
                    (!(game.TotalAmmo[item.BlockId] > 0)))
                {
                    game.AudioPlay("Dry Fire Gun-SoundBible.com-2053652037.ogg");
                    PickingEnd(left, right, middle, ispistol);
                    return;
                }
            }
            if (ispistolshoot)
            {
                float toX = pick.End[0];
                float toY = pick.End[1];
                float toZ = pick.End[2];
                if (pick2count.value > 0)
                {
                    toX = pick2[0].blockPos[0];
                    toY = pick2[0].blockPos[1];
                    toZ = pick2[0].blockPos[2];
                }

                Packet_ClientShot shot = new Packet_ClientShot();
                shot.FromX     = game.SerializeFloat(pick.Start[0]);
                shot.FromY     = game.SerializeFloat(pick.Start[1]);
                shot.FromZ     = game.SerializeFloat(pick.Start[2]);
                shot.ToX       = game.SerializeFloat(toX);
                shot.ToY       = game.SerializeFloat(toY);
                shot.ToZ       = game.SerializeFloat(toZ);
                shot.HitPlayer = -1;

                for (int i = 0; i < game.entitiesCount; i++)
                {
                    if (game.entities[i] == null)
                    {
                        continue;
                    }
                    if (game.entities[i].drawModel == null)
                    {
                        continue;
                    }
                    Entity p_ = game.entities[i];
                    if (p_.networkPosition == null)
                    {
                        continue;
                    }
                    if (!p_.networkPosition.PositionLoaded)
                    {
                        continue;
                    }
                    float feetposX = p_.position.x;
                    float feetposY = p_.position.y;
                    float feetposZ = p_.position.z;
                    //var p = PlayerPositionSpawn;
                    Box3D bodybox  = new Box3D();
                    float headsize = (p_.drawModel.ModelHeight - p_.drawModel.eyeHeight) * 2; //0.4f;
                    float h        = p_.drawModel.ModelHeight - headsize;
                    float r        = one * 35 / 100;

                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + 0, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + 0, feetposZ + r);

                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    bodybox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    Box3D headbox = new Box3D();

                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h, feetposZ + r);

                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX - r, feetposY + h + headsize, feetposZ + r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ - r);
                    headbox.AddPoint(feetposX + r, feetposY + h + headsize, feetposZ + r);

                    float[] p;
                    float   localeyeposX = game.EyesPosX();
                    float   localeyeposY = game.EyesPosY();
                    float   localeyeposZ = game.EyesPosZ();
                    p = Intersection.CheckLineBoxExact(pick, headbox);
                    if (p != null)
                    {
                        //do not allow to shoot through terrain
                        if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                      > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                        {
                            if (!isgrenade)
                            {
                                Entity entity = new Entity();
                                Sprite sprite = new Sprite();
                                sprite.positionX = p[0];
                                sprite.positionY = p[1];
                                sprite.positionZ = p[2];
                                sprite.image     = "blood.png";
                                entity.sprite    = sprite;
                                entity.expires   = Expires.Create(one * 2 / 10);
                                game.EntityAddLocal(entity);
                            }
                            shot.HitPlayer = i;
                            shot.IsHitHead = 1;
                        }
                    }
                    else
                    {
                        p = Intersection.CheckLineBoxExact(pick, bodybox);
                        if (p != null)
                        {
                            //do not allow to shoot through terrain
                            if (pick2count.value == 0 || (game.Dist(pick2[0].blockPos[0], pick2[0].blockPos[1], pick2[0].blockPos[2], localeyeposX, localeyeposY, localeyeposZ)
                                                          > game.Dist(p[0], p[1], p[2], localeyeposX, localeyeposY, localeyeposZ)))
                            {
                                if (!isgrenade)
                                {
                                    Entity entity = new Entity();
                                    Sprite sprite = new Sprite();
                                    sprite.positionX = p[0];
                                    sprite.positionY = p[1];
                                    sprite.positionZ = p[2];
                                    sprite.image     = "blood.png";
                                    entity.sprite    = sprite;
                                    entity.expires   = Expires.Create(one * 2 / 10);
                                    game.EntityAddLocal(entity);
                                }
                                shot.HitPlayer = i;
                                shot.IsHitHead = 0;
                            }
                        }
                    }
                }
                shot.WeaponBlock = item.BlockId;
                game.LoadedAmmo[item.BlockId] = game.LoadedAmmo[item.BlockId] - 1;
                game.TotalAmmo[item.BlockId]  = game.TotalAmmo[item.BlockId] - 1;
                float projectilespeed = game.DeserializeFloat(game.blocktypes[item.BlockId].ProjectileSpeedFloat);
                if (projectilespeed == 0)
                {
                    {
                        Entity entity = game.CreateBulletEntity(
                            pick.Start[0], pick.Start[1], pick.Start[2],
                            toX, toY, toZ, 150);
                        game.EntityAddLocal(entity);
                    }
                }
                else
                {
                    float vX      = toX - pick.Start[0];
                    float vY      = toY - pick.Start[1];
                    float vZ      = toZ - pick.Start[2];
                    float vLength = game.Length(vX, vY, vZ);
                    vX /= vLength;
                    vY /= vLength;
                    vZ /= vLength;
                    vX *= projectilespeed;
                    vY *= projectilespeed;
                    vZ *= projectilespeed;
                    shot.ExplodesAfter = game.SerializeFloat(game.grenadetime - wait);

                    {
                        Entity grenadeEntity = new Entity();

                        Sprite sprite = new Sprite();
                        sprite.image          = "ChemicalGreen.png";
                        sprite.size           = 14;
                        sprite.animationcount = 0;
                        sprite.positionX      = pick.Start[0];
                        sprite.positionY      = pick.Start[1];
                        sprite.positionZ      = pick.Start[2];
                        grenadeEntity.sprite  = sprite;

                        Grenade_ projectile = new Grenade_();
                        projectile.velocityX    = vX;
                        projectile.velocityY    = vY;
                        projectile.velocityZ    = vZ;
                        projectile.block        = item.BlockId;
                        projectile.sourcePlayer = game.LocalPlayerId;

                        grenadeEntity.expires = Expires.Create(game.grenadetime - wait);

                        grenadeEntity.grenade = projectile;
                        game.EntityAddLocal(grenadeEntity);
                    }
                }
                Packet_Client packet = new Packet_Client();
                packet.Id   = Packet_ClientIdEnum.Shot;
                packet.Shot = shot;
                game.SendPacketClient(packet);

                if (game.blocktypes[item.BlockId].Sounds.ShootEndCount > 0)
                {
                    game.pistolcycle = game.rnd.Next() % game.blocktypes[item.BlockId].Sounds.ShootEndCount;
                    game.AudioPlay(game.platform.StringFormat("{0}.ogg", game.blocktypes[item.BlockId].Sounds.ShootEnd[game.pistolcycle]));
                }

                bulletsshot++;
                if (bulletsshot < game.DeserializeFloat(game.blocktypes[item.BlockId].BulletsPerShotFloat))
                {
                    NextBullet(game, bulletsshot);
                }

                //recoil
                game.player.position.rotx -= game.rnd.NextFloat() * game.CurrentRecoil();
                game.player.position.roty += game.rnd.NextFloat() * game.CurrentRecoil() * 2 - game.CurrentRecoil();

                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (ispistol && right)
            {
                PickingEnd(left, right, middle, ispistol);
                return;
            }
            if (pick2count.value > 0)
            {
                if (middle)
                {
                    int newtileX = game.platform.FloatToInt(pick0.Current()[0]);
                    int newtileY = game.platform.FloatToInt(pick0.Current()[1]);
                    int newtileZ = game.platform.FloatToInt(pick0.Current()[2]);
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        int  clonesource  = game.map.GetBlock(newtileX, newtileZ, newtileY);
                        int  clonesource2 = game.d_Data.WhenPlayerPlacesGetsConvertedTo()[clonesource];
                        bool gotoDone     = false;
                        //find this block in another right hand.
                        for (int i = 0; i < 10; i++)
                        {
                            if (game.d_Inventory.RightHand[i] != null &&
                                game.d_Inventory.RightHand[i].ItemClass == Packet_ItemClassEnum.Block &&
                                game.d_Inventory.RightHand[i].BlockId == clonesource2)
                            {
                                game.ActiveMaterial = i;
                                gotoDone            = true;
                            }
                        }
                        if (!gotoDone)
                        {
                            IntRef freehand = game.d_InventoryUtil.FreeHand(game.ActiveMaterial);
                            //find this block in inventory.
                            for (int i = 0; i < game.d_Inventory.ItemsCount; i++)
                            {
                                Packet_PositionItem k = game.d_Inventory.Items[i];
                                if (k == null)
                                {
                                    continue;
                                }
                                if (k.Value_.ItemClass == Packet_ItemClassEnum.Block &&
                                    k.Value_.BlockId == clonesource2)
                                {
                                    //free hand
                                    if (freehand != null)
                                    {
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(freehand.value));
                                        break;
                                    }
                                    //try to replace current slot
                                    if (game.d_Inventory.RightHand[game.ActiveMaterial] != null &&
                                        game.d_Inventory.RightHand[game.ActiveMaterial].ItemClass == Packet_ItemClassEnum.Block)
                                    {
                                        game.MoveToInventory(
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                        game.WearItem(
                                            game.InventoryPositionMainArea(k.X, k.Y),
                                            game.InventoryPositionMaterialSelector(game.ActiveMaterial));
                                    }
                                }
                            }
                        }
                        string[] sound = game.d_Data.CloneSound()[clonesource];
                        if (sound != null)            // && sound.Length > 0)
                        {
                            game.AudioPlay(sound[0]); //todo sound cycle
                        }
                    }
                }
                if (left || right)
                {
                    BlockPosSide tile = pick0;
                    int          newtileX;
                    int          newtileY;
                    int          newtileZ;
                    if (right)
                    {
                        newtileX = game.platform.FloatToInt(tile.Translated()[0]);
                        newtileY = game.platform.FloatToInt(tile.Translated()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Translated()[2]);
                    }
                    else
                    {
                        newtileX = game.platform.FloatToInt(tile.Current()[0]);
                        newtileY = game.platform.FloatToInt(tile.Current()[1]);
                        newtileZ = game.platform.FloatToInt(tile.Current()[2]);
                    }
                    if (game.map.IsValidPos(newtileX, newtileZ, newtileY))
                    {
                        //Console.WriteLine(". newtile:" + newtile + " type: " + d_Map.GetBlock(newtileX, newtileZ, newtileY));
                        if (!(pick0.blockPos[0] == -1 &&
                              pick0.blockPos[1] == -1 &&
                              pick0.blockPos[2] == -1))
                        {
                            int blocktype;
                            if (left)
                            {
                                blocktype = game.map.GetBlock(newtileX, newtileZ, newtileY);
                            }
                            else
                            {
                                blocktype = ((game.BlockInHand() == null) ? 1 : game.BlockInHand().value);
                            }
                            if (left && blocktype == game.d_Data.BlockIdAdminium())
                            {
                                PickingEnd(left, right, middle, ispistol);
                                return;
                            }
                            string[] sound = left ? game.d_Data.BreakSound()[blocktype] : game.d_Data.BuildSound()[blocktype];
                            if (sound != null)            // && sound.Length > 0)
                            {
                                game.AudioPlay(sound[0]); //todo sound cycle
                            }
                        }
                        //normal attack
                        if (!right)
                        {
                            //attack
                            int posx = newtileX;
                            int posy = newtileZ;
                            int posz = newtileY;
                            game.currentAttackedBlock = Vector3IntRef.Create(posx, posy, posz);
                            if (!game.blockHealth.ContainsKey(posx, posy, posz))
                            {
                                game.blockHealth.Set(posx, posy, posz, game.GetCurrentBlockHealth(posx, posy, posz));
                            }
                            game.blockHealth.Set(posx, posy, posz, game.blockHealth.Get(posx, posy, posz) - game.WeaponAttackStrength());
                            float health = game.GetCurrentBlockHealth(posx, posy, posz);
                            if (health <= 0)
                            {
                                if (game.currentAttackedBlock != null)
                                {
                                    game.blockHealth.Remove(posx, posy, posz);
                                }
                                game.currentAttackedBlock = null;
                                OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                                       game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                                       tile.collisionPos,
                                       right);
                            }
                            PickingEnd(left, right, middle, ispistol);
                            return;
                        }
                        if (!right)
                        {
                            game.particleEffectBlockBreak.StartParticleEffect(newtileX, newtileY, newtileZ);//must be before deletion - gets ground type.
                        }
                        if (!game.map.IsValidPos(newtileX, newtileZ, newtileY))
                        {
                            game.platform.ThrowException("Error in picking - NextBullet()");
                        }
                        OnPick(game, game.platform.FloatToInt(newtileX), game.platform.FloatToInt(newtileZ), game.platform.FloatToInt(newtileY),
                               game.platform.FloatToInt(tile.Current()[0]), game.platform.FloatToInt(tile.Current()[2]), game.platform.FloatToInt(tile.Current()[1]),
                               tile.collisionPos,
                               right);
                        //network.SendSetBlock(new Vector3((int)newtile.X, (int)newtile.Z, (int)newtile.Y),
                        //    right ? BlockSetMode.Create : BlockSetMode.Destroy, (byte)MaterialSlots[activematerial]);
                    }
                }
            }
        }
        PickingEnd(left, right, middle, ispistol);
    }
示例#20
0
        private void OverheadCamera()
        {
            GL.MatrixMode(MatrixMode.Modelview);

            Vector3Ref position = new Vector3Ref();
            overheadcameraK.GetPosition(platform, position);
            Vector3 position_ = new Vector3(position.GetX(), position.GetY(), position.GetZ());

            Vector3Ref center = new Vector3Ref();
            overheadcameraK.GetCenter(center);
            Vector3 center_ = new Vector3(center.GetX(), center.GetY(), center.GetZ());

            Matrix4 camera = Matrix4.LookAt(position_, center_, up);
            m = new float[]
            {
                camera.M11, camera.M12, camera.M13, camera.M14,
                camera.M21, camera.M22, camera.M23, camera.M24,
                camera.M31, camera.M32, camera.M33, camera.M34,
                camera.M41, camera.M42, camera.M43, camera.M44
            };
            GL.LoadMatrix(ref camera);
        }
示例#21
0
    public static void ToVectorInFixedSystem(float dx, float dy, float dz, float orientationx, float orientationy, Vector3Ref output)
    {
        //Don't calculate for nothing ...
        if (dx == 0 && dy == 0 && dz == 0)
        {
            output.X = 0;
            output.Y = 0;
            output.Z = 0;
            return;
        }

        //Convert to Radian : 360° = 2PI
        float xRot = orientationx;//Math.toRadians(orientation.X);
        float yRot = orientationy;//Math.toRadians(orientation.Y);

        //Calculate the formula
        float x = (dx * Platform.Cos(yRot) + dy * Platform.Sin(xRot) * Platform.Sin(yRot) - dz * Platform.Cos(xRot) * Platform.Sin(yRot));
        float y = (dy * Platform.Cos(xRot) + dz * Platform.Sin(xRot));
        float z = (dx * Platform.Sin(yRot) - dy * Platform.Sin(xRot) * Platform.Cos(yRot) + dz * Platform.Cos(xRot) * Platform.Cos(yRot));

        //Return the vector expressed in the global axis system
        output.X = x;
        output.Y = y;
        output.Z = z;
    }
    public void Update(EntityPosition_ stateplayerposition, Controls move, float dt, BoolRef soundnow, Vector3Ref push, float modelheight)
    {
        if (game.stopPlayerMove)
        {
            movedz = 0;
            game.stopPlayerMove = false;
        }

        // No air control
        if (!isplayeronground)
        {
            acceleration.acceleration1 = 0.99f;
            acceleration.acceleration2 = 0.2f;
            acceleration.acceleration3 = 70;
        }

        // Trampoline
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if (blockunderplayer != -1 && blockunderplayer == game.d_Data.BlockIdTrampoline()
                && (!isplayeronground) && !game.controls.shiftkeydown)
            {
                game.controls.wantsjump = true;
                jumpstartacceleration = 20.666f * constGravity;
            }
        }

        // Slippery walk on ice and when swimming
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if ((blockunderplayer != -1 && game.d_Data.IsSlipperyWalk()[blockunderplayer]) || game.SwimmingBody())
            {
                acceleration.acceleration1 = 0.99f;
                acceleration.acceleration2 = 0.2f;
                acceleration.acceleration3 = 70;
            }
        }

        soundnow.value = false;
        Vector3Ref diff1ref = new Vector3Ref();
        VectorTool.ToVectorInFixedSystem
            (move.movedx * movespeednow * dt,
            0,
            move.movedy * movespeednow * dt, stateplayerposition.rotx, stateplayerposition.roty, diff1ref);
        Vector3Ref diff1 = new Vector3Ref();
        diff1.X = diff1ref.X;
        diff1.Y = diff1ref.Y;
        diff1.Z = diff1ref.Z;
        if (MiscCi.Vec3Length(push.X, push.Y, push.Z) > 0.01f)
        {
            push.Normalize();
            push.X *= 5;
            push.Y *= 5;
            push.Z *= 5;
        }
        diff1.X += push.X * dt;
        diff1.Y += push.Y * dt;
        diff1.Z += push.Z * dt;

        bool loaded = false;
        int cx = game.platform.FloatToInt(game.player.position.x / Game.chunksize);
        int cy = game.platform.FloatToInt(game.player.position.z / Game.chunksize);
        int cz = game.platform.FloatToInt(game.player.position.y / Game.chunksize);
        if (game.map.IsValidChunkPos(cx, cy, cz))
        {
            if (game.map.chunks[MapUtilCi.Index3d(cx, cy, cz,
                game.map.MapSizeX / Game.chunksize,
                game.map.MapSizeY / Game.chunksize)] != null)
            {
                loaded = true;
            }
        }
        else
        {
            loaded = true;
        }
        if ((!(move.freemove)) && loaded)
        {
            if (!game.SwimmingBody())
            {
                movedz += -constGravity;//gravity
            }
            else
            {
                movedz += -constGravity * constWaterGravityMultiplier; //more gravity because it's slippery.
            }
        }
        game.movedz = movedz;
        if (constEnableAcceleration)
        {
            curspeed.X *= acceleration.acceleration1;
            curspeed.Y *= acceleration.acceleration1;
            curspeed.Z *= acceleration.acceleration1;
            curspeed.X = MakeCloserToZero(curspeed.X, acceleration.acceleration2 * dt);
            curspeed.Y = MakeCloserToZero(curspeed.Y, acceleration.acceleration2 * dt);
            curspeed.Z = MakeCloserToZero(curspeed.Z, acceleration.acceleration2 * dt);
            diff1.Y += move.moveup ? 2 * movespeednow * dt : 0;
            diff1.Y -= move.movedown ? 2 * movespeednow * dt : 0;
            curspeed.X += diff1.X * acceleration.acceleration3 * dt;
            curspeed.Y += diff1.Y * acceleration.acceleration3 * dt;
            curspeed.Z += diff1.Z * acceleration.acceleration3 * dt;
            if (curspeed.Length() > movespeednow)
            {
                curspeed.Normalize();
                curspeed.X *= movespeednow;
                curspeed.Y *= movespeednow;
                curspeed.Z *= movespeednow;
            }
        }
        else
        {
            if (MiscCi.Vec3Length(diff1.X, diff1.Y, diff1.Z) > 0)
            {
                diff1.Normalize();
            }
            curspeed.X = diff1.X * movespeednow;
            curspeed.Y = diff1.Y * movespeednow;
            curspeed.Z = diff1.Z * movespeednow;
        }
        Vector3Ref newposition = Vector3Ref.Create(0, 0, 0);
        if (!(move.freemove))
        {
            newposition.X = stateplayerposition.x + curspeed.X;
            newposition.Y = stateplayerposition.y + curspeed.Y;
            newposition.Z = stateplayerposition.z + curspeed.Z;
            if (!game.SwimmingBody())
            {
                newposition.Y = stateplayerposition.y;
            }
            // Fast move when looking at the ground
            float diffx = newposition.X - stateplayerposition.x;
            float diffy = newposition.Y - stateplayerposition.y;
            float diffz = newposition.Z - stateplayerposition.z;
            float difflength = MiscCi.Vec3Length(diffx, diffy, diffz);
            if (difflength > 0)
            {
                diffx /= difflength;
                diffy /= difflength;
                diffz /= difflength;
                diffx *= curspeed.Length();
                diffy *= curspeed.Length();
                diffz *= curspeed.Length();
            }
            newposition.X = stateplayerposition.x + diffx * dt;
            newposition.Y = stateplayerposition.y + diffy * dt;
            newposition.Z = stateplayerposition.z + diffz * dt;
        }
        else
        {
            newposition.X = stateplayerposition.x + (curspeed.X) * dt;
            newposition.Y = stateplayerposition.y + (curspeed.Y) * dt;
            newposition.Z = stateplayerposition.z + (curspeed.Z) * dt;
        }
        newposition.Y += movedz * dt;
        Vector3Ref previousposition = Vector3Ref.Create(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z);
        if (!move.noclip)
        {
            float[] v = WallSlide(
                Vec3.FromValues(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z),
                Vec3.FromValues(newposition.X, newposition.Y, newposition.Z),
                modelheight);
            stateplayerposition.x = v[0];
            stateplayerposition.y = v[1];
            stateplayerposition.z = v[2];
        }
        else
        {
            stateplayerposition.x = newposition.X;
            stateplayerposition.y = newposition.Y;
            stateplayerposition.z = newposition.Z;
        }
        if (!(move.freemove))
        {
            if ((isplayeronground) || game.SwimmingBody())
            {
                jumpacceleration = 0;
                movedz = 0;
            }
            if ((move.wantsjump || move.wantsjumphalf) && (((jumpacceleration == 0 && isplayeronground) || game.SwimmingBody()) && loaded) && (!game.SwimmingEyes()))
            {
                jumpacceleration = move.wantsjumphalf ? jumpstartaccelerationhalf : jumpstartacceleration;
                soundnow.value = true;
            }

            if (jumpacceleration > 0)
            {
                isplayeronground = false;
                jumpacceleration = jumpacceleration / 2;
            }

            //if (!this.reachedceiling)
            {
                movedz += jumpacceleration * constJump;
            }
        }
        else
        {
            isplayeronground = true;
        }
        game.isplayeronground = isplayeronground;
    }
示例#23
0
    internal Vector3Ref CurrentRailPos(Game game)
    {
        RailSlope slope = d_RailMapUtil.GetRailSlope(currentrailblockX,
                                                     currentrailblockY, currentrailblockZ);
        float aX           = currentrailblockX;
        float aY           = currentrailblockY;
        float aZ           = currentrailblockZ;
        float x_correction = 0;
        float y_correction = 0;
        float z_correction = 0;
        float half         = one / 2;

        switch (currentdirection)
        {
        case VehicleDirection12.HorizontalRight:
            x_correction += currentrailblockprogress;
            y_correction += half;
            if (slope == RailSlope.TwoRightRaised)
            {
                z_correction += currentrailblockprogress;
            }
            if (slope == RailSlope.TwoLeftRaised)
            {
                z_correction += 1 - currentrailblockprogress;
            }
            break;

        case VehicleDirection12.HorizontalLeft:
            x_correction += 1 - currentrailblockprogress;
            y_correction += half;
            if (slope == RailSlope.TwoRightRaised)
            {
                z_correction += 1 - currentrailblockprogress;
            }
            if (slope == RailSlope.TwoLeftRaised)
            {
                z_correction += currentrailblockprogress;
            }
            break;

        case VehicleDirection12.VerticalDown:
            x_correction += half;
            y_correction += currentrailblockprogress;
            if (slope == RailSlope.TwoDownRaised)
            {
                z_correction += currentrailblockprogress;
            }
            if (slope == RailSlope.TwoUpRaised)
            {
                z_correction += 1 - currentrailblockprogress;
            }
            break;

        case VehicleDirection12.VerticalUp:
            x_correction += half;
            y_correction += 1 - currentrailblockprogress;
            if (slope == RailSlope.TwoDownRaised)
            {
                z_correction += 1 - currentrailblockprogress;
            }
            if (slope == RailSlope.TwoUpRaised)
            {
                z_correction += currentrailblockprogress;
            }
            break;

        case VehicleDirection12.UpLeftLeft:
            x_correction += half * (1 - currentrailblockprogress);
            y_correction += half * currentrailblockprogress;
            break;

        case VehicleDirection12.UpLeftUp:
            x_correction += half * currentrailblockprogress;
            y_correction += half - half * currentrailblockprogress;
            break;

        case VehicleDirection12.UpRightRight:
            x_correction += half + half * currentrailblockprogress;
            y_correction += half * currentrailblockprogress;
            break;

        case VehicleDirection12.UpRightUp:
            x_correction += 1 - half * currentrailblockprogress;
            y_correction += half - half * currentrailblockprogress;
            break;

        case VehicleDirection12.DownLeftLeft:
            x_correction += half * (1 - currentrailblockprogress);
            y_correction += 1 - half * currentrailblockprogress;
            break;

        case VehicleDirection12.DownLeftDown:
            x_correction += half * currentrailblockprogress;
            y_correction += half + half * currentrailblockprogress;
            break;

        case VehicleDirection12.DownRightRight:
            x_correction += half + half * currentrailblockprogress;
            y_correction += 1 - half * currentrailblockprogress;
            break;

        case VehicleDirection12.DownRightDown:
            x_correction += 1 - half * currentrailblockprogress;
            y_correction += half + half * currentrailblockprogress;
            break;
        }
        //+1 because player can't be inside rail block (picking wouldn't work)
        return(Vector3Ref.Create(aX + x_correction, aZ + railheight + 1 + z_correction, aY + y_correction));
    }
示例#24
0
    internal Vector3Ref GrenadeBounce(Game game, Vector3Ref oldposition, Vector3Ref newposition, Vector3Ref velocity, float dt)
    {
        bool  ismoving    = velocity.Length() > 100 * dt;
        float modelheight = walldistance;

        oldposition.Y += walldistance;
        newposition.Y += walldistance;

        //Math.Floor() is needed because casting negative values to integer is not floor.
        Vector3IntRef oldpositioni = Vector3IntRef.Create(game.MathFloor(oldposition.X),
                                                          game.MathFloor(oldposition.Z),
                                                          game.MathFloor(oldposition.Y));
        float playerpositionX = newposition.X;
        float playerpositionY = newposition.Y;
        float playerpositionZ = newposition.Z;

        //left
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z + walldistance;
            bool  newempty      = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY)) &&
                                  game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.Z - oldposition.Z > 0)
            {
                if (!newempty)
                {
                    velocity.Z  = -velocity.Z;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Z = oldposition.Z - newposition.Z;
                }
            }
        }
        //front
        {
            float qnewpositionX = newposition.X + walldistance;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z;
            bool  newempty      = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY)) &&
                                  game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.X - oldposition.X > 0)
            {
                if (!newempty)
                {
                    velocity.X  = -velocity.X;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.X = oldposition.X - newposition.X;
                }
            }
        }
        //top
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y - walldistance;
            float qnewpositionZ = newposition.Z;
            int   x             = game.MathFloor(qnewpositionX);
            int   y             = game.MathFloor(qnewpositionZ);
            int   z             = game.MathFloor(qnewpositionY);
            float a_            = walldistance;
            bool  newfull       = (!game.IsTileEmptyForPhysics(x, y, z)) ||
                                  (qnewpositionX - game.MathFloor(qnewpositionX) <= a_ && (!game.IsTileEmptyForPhysics(x - 1, y, z)) && (game.IsTileEmptyForPhysics(x - 1, y, z + 1))) ||
                                  (qnewpositionX - game.MathFloor(qnewpositionX) >= (1 - a_) && (!game.IsTileEmptyForPhysics(x + 1, y, z)) && (game.IsTileEmptyForPhysics(x + 1, y, z + 1))) ||
                                  (qnewpositionZ - game.MathFloor(qnewpositionZ) <= a_ && (!game.IsTileEmptyForPhysics(x, y - 1, z)) && (game.IsTileEmptyForPhysics(x, y - 1, z + 1))) ||
                                  (qnewpositionZ - game.MathFloor(qnewpositionZ) >= (1 - a_) && (!game.IsTileEmptyForPhysics(x, y + 1, z)) && (game.IsTileEmptyForPhysics(x, y + 1, z + 1)));
            if (newposition.Y - oldposition.Y < 0)
            {
                if (newfull)
                {
                    velocity.Y  = -velocity.Y;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Y = oldposition.Y - newposition.Y;
                }
            }
        }
        //right
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z - walldistance;
            bool  newempty      = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY)) &&
                                  game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.Z - oldposition.Z < 0)
            {
                if (!newempty)
                {
                    velocity.Z  = -velocity.Z;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Z = oldposition.Z - newposition.Z;
                }
            }
        }
        //back
        {
            float qnewpositionX = newposition.X - walldistance;
            float qnewpositionY = newposition.Y;
            float qnewpositionZ = newposition.Z;
            bool  newempty      = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY)) &&
                                  game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY) + 1);
            if (newposition.X - oldposition.X < 0)
            {
                if (!newempty)
                {
                    velocity.X  = -velocity.X;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.X = oldposition.X - newposition.X;
                }
            }
        }
        //bottom
        {
            float qnewpositionX = newposition.X;
            float qnewpositionY = newposition.Y + modelheight;
            float qnewpositionZ = newposition.Z;
            bool  newempty      = game.IsTileEmptyForPhysics(game.MathFloor(qnewpositionX), game.MathFloor(qnewpositionZ), game.MathFloor(qnewpositionY));
            if (newposition.Y - oldposition.Y > 0)
            {
                if (!newempty)
                {
                    velocity.Y  = -velocity.Y;
                    velocity.X *= bouncespeedmultiply;
                    velocity.Y *= bouncespeedmultiply;
                    velocity.Z *= bouncespeedmultiply;
                    if (ismoving)
                    {
                        game.AudioPlayAt("grenadebounce.ogg", newposition.X, newposition.Y, newposition.Z);
                    }
                    //playerposition.Y = oldposition.Y - newposition.Y;
                }
            }
        }
        //ok:
        playerpositionY -= walldistance;
        return(Vector3Ref.Create(playerpositionX, playerpositionY, playerpositionZ));
    }
示例#25
0
 public ModCamera()
 {
     OverheadCamera_cameraEye = new Vector3Ref();
     upVec3 = Vec3.FromValues(0, 1, 0);
 }
示例#26
0
    public void AddTorch(GameData d_Data, Game d_TerainRenderer, ModelData m, int x, int y, int z, TorchType type)
    {
        float one         = 1;
        int   curcolor    = Game.ColorFromArgb(255, 255, 255, 255);
        float torchsizexy = one * 16 / 100;
        float topx        = one / 2 - torchsizexy / 2;
        float topy        = one / 2 - torchsizexy / 2;
        float bottomx     = one / 2 - torchsizexy / 2;
        float bottomy     = one / 2 - torchsizexy / 2;

        topx    += x;
        topy    += y;
        bottomx += x;
        bottomy += y;

        if (type == TorchType.Front)
        {
            bottomx = x - torchsizexy;
        }
        if (type == TorchType.Back)
        {
            bottomx = x + 1;
        }
        if (type == TorchType.Left)
        {
            bottomy = y - torchsizexy;
        }
        if (type == TorchType.Right)
        {
            bottomy = y + 1;
        }

        Vector3Ref top00 = Vector3Ref.Create(topx, z + (one * 9 / 10), topy);
        Vector3Ref top01 = Vector3Ref.Create(topx, z + (one * 9 / 10), topy + torchsizexy);
        Vector3Ref top10 = Vector3Ref.Create(topx + torchsizexy, z + (one * 9 / 10), topy);
        Vector3Ref top11 = Vector3Ref.Create(topx + torchsizexy, z + (one * 9 / 10), topy + torchsizexy);

        if (type == TorchType.Left)
        {
            top01.Y += -(one * 1 / 10);
            top11.Y += -(one * 1 / 10);
        }

        if (type == TorchType.Right)
        {
            top10.Y += -(one * 1 / 10);
            top00.Y += -(one * 1 / 10);
        }

        if (type == TorchType.Front)
        {
            top10.Y += -(one * 1 / 10);
            top11.Y += -(one * 1 / 10);
        }

        if (type == TorchType.Back)
        {
            top01.Y += -(one * 1 / 10);
            top00.Y += -(one * 1 / 10);
        }

        Vector3Ref bottom00 = Vector3Ref.Create(bottomx, z + 0, bottomy);
        Vector3Ref bottom01 = Vector3Ref.Create(bottomx, z + 0, bottomy + torchsizexy);
        Vector3Ref bottom10 = Vector3Ref.Create(bottomx + torchsizexy, z + 0, bottomy);
        Vector3Ref bottom11 = Vector3Ref.Create(bottomx + torchsizexy, z + 0, bottomy + torchsizexy);

        //top
        {
            int      sidetexture = TopTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, top00.X, top00.Y, top00.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, top01.X, top01.Y, top01.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top10.X, top10.Y, top10.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, top11.X, top11.Y, top11.Z, texrec.Right(), texrec.Bottom(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //bottom - same as top, but z is 1 less.
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom00.X, bottom00.Y, bottom00.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, bottom01.X, bottom01.Y, bottom01.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, bottom10.X, bottom10.Y, bottom10.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, bottom11.X, bottom11.Y, bottom11.Z, texrec.Right(), texrec.Bottom(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //front
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom00.X, bottom00.Y, bottom00.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, bottom01.X, bottom01.Y, bottom01.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, top00.X, top00.Y, top00.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, top01.X, top01.Y, top01.Z, texrec.Right(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //back - same as front, but x is 1 greater.
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom10.X, bottom10.Y, bottom10.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, bottom11.X, bottom11.Y, bottom11.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top10.X, top10.Y, top10.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, top11.X, top11.Y, top11.Z, texrec.Left(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom00.X, bottom00.Y, bottom00.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, top00.X, top00.Y, top00.Z, texrec.Right(), texrec.Top(), curcolor);
            AddVertex(m, bottom10.X, bottom10.Y, bottom10.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top10.X, top10.Y, top10.Z, texrec.Left(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }

        //right - same as left, but y is 1 greater.
        {
            int      sidetexture = SideTexture;
            RectFRef texrec      = TextureAtlas.TextureCoords2d(sidetexture, d_TerainRenderer.texturesPacked());
            int      lastelement = m.GetVerticesCount();
            AddVertex(m, bottom01.X, bottom01.Y, bottom01.Z, texrec.Left(), texrec.Bottom(), curcolor);
            AddVertex(m, top01.X, top01.Y, top01.Z, texrec.Left(), texrec.Top(), curcolor);
            AddVertex(m, bottom11.X, bottom11.Y, bottom11.Z, texrec.Right(), texrec.Bottom(), curcolor);
            AddVertex(m, top11.X, top11.Y, top11.Z, texrec.Right(), texrec.Top(), curcolor);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 0);
            m.indices[m.indicesCount++] = (lastelement + 2);
            m.indices[m.indicesCount++] = (lastelement + 3);
            m.indices[m.indicesCount++] = (lastelement + 1);
            m.indices[m.indicesCount++] = (lastelement + 2);
        }
    }
示例#27
0
 public static void Pos(int index, int sizex, int sizey, Vector3Ref ret)
 {
     int x = index % sizex;
     int y = (index / sizex) % sizey;
     int h = index / (sizex * sizey);
     ret.X = x;
     ret.Y = y;
     ret.Z = h;
 }
示例#28
0
 public Kamera()
 {
     one = 1;
     distance = 5;
     Angle = 45;
     MinimumDistance = 2;
     tt = 0;
     MaximumAngle = 89;
     MinimumAngle = 0;
     Center = new Vector3Ref();
 }
示例#29
0
 public void CameraChange()
 {
     if (Follow != null)
     {
         //Prevents switching camera mode when following
         return;
     }
     if (cameratype == CameraType.Fpp)
     {
         cameratype = CameraType.Tpp;
         ENABLE_TPP_VIEW = true;
     }
     else if (cameratype == CameraType.Tpp)
     {
         cameratype = CameraType.Overhead;
         overheadcamera = true;
         SetFreeMouse(true);
         ENABLE_TPP_VIEW = true;
         playerdestination = Vector3Ref.Create(player.position.x, player.position.y, player.position.z);
     }
     else if (cameratype == CameraType.Overhead)
     {
         cameratype = CameraType.Fpp;
         SetFreeMouse(false);
         ENABLE_TPP_VIEW = false;
         overheadcamera = false;
     }
     else
     {
         platform.ThrowException("");
     }
 }
示例#30
0
    public static void ToVectorInFixedSystem(float dx, float dy, float dz, float orientationx, float orientationy, Vector3Ref output)
    {
        //Don't calculate for nothing ...
        if (dx == 0 && dy == 0 && dz == 0)
        {
            output.X = 0;
            output.Y = 0;
            output.Z = 0;
            return;
        }

        //Convert to Radian : 360° = 2PI
        float xRot = orientationx; //Math.toRadians(orientation.X);
        float yRot = orientationy; //Math.toRadians(orientation.Y);

        //Calculate the formula
        float x = (dx * Platform.Cos(yRot) + dy * Platform.Sin(xRot) * Platform.Sin(yRot) - dz * Platform.Cos(xRot) * Platform.Sin(yRot));
        float y = (dy * Platform.Cos(xRot) + dz * Platform.Sin(xRot));
        float z = (dx * Platform.Sin(yRot) - dy * Platform.Sin(xRot) * Platform.Cos(yRot) + dz * Platform.Cos(xRot) * Platform.Cos(yRot));

        //Return the vector expressed in the global axis system
        output.X = x;
        output.Y = y;
        output.Z = z;
    }
示例#31
0
 public void GetPosition(GamePlatform platform, Vector3Ref ret)
 {
     float cx = platform.MathCos(tt * one / 2) * GetFlatDistance(platform) + Center.X;
     float cy = platform.MathSin(tt * one / 2) * GetFlatDistance(platform) + Center.Z;
     ret.X = cx;
     ret.Y = Center.Y + GetCameraHeightFromCenter(platform);
     ret.Z = cy;
 }
示例#32
0
 public void GetCenter(Vector3Ref ret)
 {
     ret.X = Center.X;
     ret.Y = Center.Y;
     ret.Z = Center.Z;
 }
示例#33
0
    public Game()
    {
        one = 1;
        map = new Map();
        performanceinfo = new DictionaryStringString();
        AudioEnabled = true;
        AutoJumpEnabled = false;
        playerPositionSpawnX = 15 + one / 2;
        playerPositionSpawnY = 64;
        playerPositionSpawnZ = 15 + one / 2;

        TextureId = new int[MaxBlockTypes][];
        for (int i = 0; i < MaxBlockTypes; i++)
        {
            TextureId[i] = new int[6];
        }
        TextureIdForInventory = new int[MaxBlockTypes];
        language = new Language();
        lastplacedblockX = -1;
        lastplacedblockY = -1;
        lastplacedblockZ = -1;
        mLightLevels = new float[16];
        sunlight_ = 15;
        mvMatrix = new StackMatrix4();
        pMatrix = new StackMatrix4();
        mvMatrix.Push(Mat4.Create());
        pMatrix.Push(Mat4.Create());
        whitetexture = -1;
        cachedTextTexturesMax = 1024;
        cachedTextTextures = new CachedTextTexture[cachedTextTexturesMax];
        for (int i = 0; i < cachedTextTexturesMax; i++)
        {
            cachedTextTextures[i] = null;
        }
        packetLen = new IntRef();
        ENABLE_DRAW2D = true;
        AllowFreemove = true;
        enableCameraControl = true;
        textures = new DictionaryStringInt1024();
        ServerInfo = new ServerInformation();
        menustate = new MenuState();
        mouseleftclick = false;
        mouseleftdeclick = false;
        wasmouseleft = false;
        mouserightclick = false;
        mouserightdeclick = false;
        wasmouseright = false;
        ENABLE_LAG = 0;
        znear = one / 10;
        CameraMatrix = new GetCameraMatrix();
        ENABLE_ZFAR = true;
        TotalAmmo = new int[GlobalVar.MAX_BLOCKTYPES];
        LoadedAmmo = new int[GlobalVar.MAX_BLOCKTYPES];
        AllowedFontsCount = 1;
        AllowedFonts = new string[AllowedFontsCount];
        AllowedFonts[0] = "Verdana";
        fov = Game.GetPi() / 3;
        cameratype = CameraType.Fpp;
        ENABLE_TPP_VIEW = false;
        basemovespeed = 5;
        movespeed = 5;
        RadiusWhenMoving = one * 3 / 10;
        playervelocity = new Vector3Ref();
        LocalPlayerId = -1;
        dialogs = new VisibleDialog[512];
        dialogsCount = 512;
        blockHealth = new DictionaryVector3Float();
        playertexturedefault = -1;
        a = new AnimationState();
        constRotationSpeed = one * 180 / 20;
        modmanager = new ClientModManager1();
        particleEffectBlockBreak = new ModDrawParticleEffectBlockBreak();
        PICK_DISTANCE = 4.1f;
        selectedmodelid = -1;
        grenadetime = 3;
        rotationspeed = one * 15 / 100;
        entities = new Entity[entitiesMax];
        for (int i = 0; i < entitiesMax; i++)
        {
            entities[i] = null;
        }
        entitiesCount = 512;
        PlayerPushDistance = 2;
        const int KeysMax = 256;
        keyboardState = new bool[KeysMax];
        for (int i = 0; i < KeysMax; i++)
        {
            keyboardState[i] = false;
        }
        keyboardStateRaw = new bool[KeysMax];
        for (int i = 0; i < KeysMax; i++)
        {
            keyboardStateRaw[i] = false;
        }
        overheadcameradistance = 10;
        tppcameradistance = 3;
        TPP_CAMERA_DISTANCE_MIN = 1;
        TPP_CAMERA_DISTANCE_MAX = 10;
        options = new OptionsCi();
        overheadcameraK = new Kamera();
        fillAreaLimit = 200;
        speculativeCount = 0;
        speculative = new Speculative[speculativeMax];
        typinglog = new string[1024 * 16];
        typinglogCount = 0;
        NewBlockTypes = new Packet_BlockType[GlobalVar.MAX_BLOCKTYPES];
        localplayeranim = new AnimationState();
        localplayeranimationhint = new AnimationHint();
        enable_move = true;
        handTexture = -1;
        modelViewInverted = new float[16];
        GLScaleTempVec3 = Vec3.Create();
        GLRotateTempVec3 = Vec3.Create();
        GLTranslateTempVec3 = Vec3.Create();
        identityMatrix = Mat4.Identity_(Mat4.Create());
        Set3dProjectionTempMat4 = Mat4.Create();
        getAsset = new string[1024 * 2];
        PlayerStats = new Packet_ServerPlayerStats();
        mLightLevels = new float[16];
        for (int i = 0; i < 16; i++)
        {
            mLightLevels[i] = one * i / 15;
        }
        soundnow = new BoolRef();
        camera = Mat4.Create();
        packetHandlers = new ClientPacketHandler[256];
        player = new Entity();
        player.position = new EntityPosition_();
        currentlyAttackedEntity = -1;
        ChatLinesMax = 1;
        ChatLines = new Chatline[ChatLinesMax];
        ChatLineLength = 64;
        audio = new AudioControl();
        CameraEyeX = -1;
        CameraEyeY = -1;
        CameraEyeZ = -1;
        controls = new Controls();
        movedz = 0;
        taskScheduler = new TaskScheduler();
        commitActions = ListAction.Create(16 * 1024);
        constWallDistance = 0.3f;
        mouseSmoothing = true;
    }
    public void Update(EntityPosition_ stateplayerposition, Controls move, float dt, BoolRef soundnow, Vector3Ref push, float modelheight)
    {
        if (game.stopPlayerMove)
        {
            movedz = 0;
            game.stopPlayerMove = false;
        }

        // No air control
        if (!isplayeronground)
        {
            acceleration.acceleration1 = 0.99f;
            acceleration.acceleration2 = 0.2f;
            acceleration.acceleration3 = 70;
        }

        // Trampoline
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if (blockunderplayer != -1 && blockunderplayer == game.d_Data.BlockIdTrampoline() &&
                (!isplayeronground) && !game.controls.shiftkeydown)
            {
                game.controls.wantsjump = true;
                jumpstartacceleration   = 20.666f * constGravity;
            }
        }

        // Slippery walk on ice and when swimming
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if ((blockunderplayer != -1 && game.d_Data.IsSlipperyWalk()[blockunderplayer]) || game.SwimmingBody())
            {
                acceleration.acceleration1 = 0.99f;
                acceleration.acceleration2 = 0.2f;
                acceleration.acceleration3 = 70;
            }
        }

        soundnow.value = false;
        Vector3Ref diff1ref = new Vector3Ref();

        VectorTool.ToVectorInFixedSystem
            (move.movedx * movespeednow * dt,
            0,
            move.movedy * movespeednow * dt, stateplayerposition.rotx, stateplayerposition.roty, diff1ref);
        Vector3Ref diff1 = new Vector3Ref();

        diff1.X = diff1ref.X;
        diff1.Y = diff1ref.Y;
        diff1.Z = diff1ref.Z;
        if (MiscCi.Vec3Length(push.X, push.Y, push.Z) > 0.01f)
        {
            push.Normalize();
            push.X *= 5;
            push.Y *= 5;
            push.Z *= 5;
        }
        diff1.X += push.X * dt;
        diff1.Y += push.Y * dt;
        diff1.Z += push.Z * dt;

        bool loaded = false;
        int  cx     = game.platform.FloatToInt(game.player.position.x / Game.chunksize);
        int  cy     = game.platform.FloatToInt(game.player.position.z / Game.chunksize);
        int  cz     = game.platform.FloatToInt(game.player.position.y / Game.chunksize);

        if (game.map.IsValidChunkPos(cx, cy, cz))
        {
            if (game.map.chunks[MapUtilCi.Index3d(cx, cy, cz,
                                                  game.map.MapSizeX / Game.chunksize,
                                                  game.map.MapSizeY / Game.chunksize)] != null)
            {
                loaded = true;
            }
        }
        else
        {
            loaded = true;
        }
        if ((!(move.freemove)) && loaded)
        {
            if (!game.SwimmingBody())
            {
                movedz += -constGravity;//gravity
            }
            else
            {
                movedz += -constGravity * constWaterGravityMultiplier; //more gravity because it's slippery.
            }
        }
        game.movedz = movedz;
        if (constEnableAcceleration)
        {
            curspeed.X *= acceleration.acceleration1;
            curspeed.Y *= acceleration.acceleration1;
            curspeed.Z *= acceleration.acceleration1;
            curspeed.X  = MakeCloserToZero(curspeed.X, acceleration.acceleration2 * dt);
            curspeed.Y  = MakeCloserToZero(curspeed.Y, acceleration.acceleration2 * dt);
            curspeed.Z  = MakeCloserToZero(curspeed.Z, acceleration.acceleration2 * dt);
            diff1.Y    += move.moveup ? 2 * movespeednow * dt : 0;
            diff1.Y    -= move.movedown ? 2 * movespeednow * dt : 0;
            curspeed.X += diff1.X * acceleration.acceleration3 * dt;
            curspeed.Y += diff1.Y * acceleration.acceleration3 * dt;
            curspeed.Z += diff1.Z * acceleration.acceleration3 * dt;
            if (curspeed.Length() > movespeednow)
            {
                curspeed.Normalize();
                curspeed.X *= movespeednow;
                curspeed.Y *= movespeednow;
                curspeed.Z *= movespeednow;
            }
        }
        else
        {
            if (MiscCi.Vec3Length(diff1.X, diff1.Y, diff1.Z) > 0)
            {
                diff1.Normalize();
            }
            curspeed.X = diff1.X * movespeednow;
            curspeed.Y = diff1.Y * movespeednow;
            curspeed.Z = diff1.Z * movespeednow;
        }
        Vector3Ref newposition = Vector3Ref.Create(0, 0, 0);

        if (!(move.freemove))
        {
            newposition.X = stateplayerposition.x + curspeed.X;
            newposition.Y = stateplayerposition.y + curspeed.Y;
            newposition.Z = stateplayerposition.z + curspeed.Z;
            if (!game.SwimmingBody())
            {
                newposition.Y = stateplayerposition.y;
            }
            // Fast move when looking at the ground
            float diffx      = newposition.X - stateplayerposition.x;
            float diffy      = newposition.Y - stateplayerposition.y;
            float diffz      = newposition.Z - stateplayerposition.z;
            float difflength = MiscCi.Vec3Length(diffx, diffy, diffz);
            if (difflength > 0)
            {
                diffx /= difflength;
                diffy /= difflength;
                diffz /= difflength;
                diffx *= curspeed.Length();
                diffy *= curspeed.Length();
                diffz *= curspeed.Length();
            }
            newposition.X = stateplayerposition.x + diffx * dt;
            newposition.Y = stateplayerposition.y + diffy * dt;
            newposition.Z = stateplayerposition.z + diffz * dt;
        }
        else
        {
            newposition.X = stateplayerposition.x + (curspeed.X) * dt;
            newposition.Y = stateplayerposition.y + (curspeed.Y) * dt;
            newposition.Z = stateplayerposition.z + (curspeed.Z) * dt;
        }
        newposition.Y += movedz * dt;
        Vector3Ref previousposition = Vector3Ref.Create(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z);

        if (!move.noclip)
        {
            float[] v = WallSlide(
                Vec3.FromValues(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z),
                Vec3.FromValues(newposition.X, newposition.Y, newposition.Z),
                modelheight);
            stateplayerposition.x = v[0];
            stateplayerposition.y = v[1];
            stateplayerposition.z = v[2];
        }
        else
        {
            stateplayerposition.x = newposition.X;
            stateplayerposition.y = newposition.Y;
            stateplayerposition.z = newposition.Z;
        }
        if (!(move.freemove))
        {
            if ((isplayeronground) || game.SwimmingBody())
            {
                jumpacceleration = 0;
                movedz           = 0;
            }
            if ((move.wantsjump || move.wantsjumphalf) && (((jumpacceleration == 0 && isplayeronground) || game.SwimmingBody()) && loaded) && (!game.SwimmingEyes()))
            {
                jumpacceleration = move.wantsjumphalf ? jumpstartaccelerationhalf : jumpstartacceleration;
                soundnow.value   = true;
            }

            if (jumpacceleration > 0)
            {
                isplayeronground = false;
                jumpacceleration = jumpacceleration / 2;
            }

            //if (!this.reachedceiling)
            {
                movedz += jumpacceleration * constJump;
            }
        }
        else
        {
            isplayeronground = true;
        }
        game.isplayeronground = isplayeronground;
    }
示例#35
0
 internal void SetCamera(CameraType type)
 {
     if (type == CameraType.Fpp)
     {
         cameratype = CameraType.Fpp;
         SetFreeMouse(false);
         ENABLE_TPP_VIEW = false;
         overheadcamera = false;
     }
     else if (type == CameraType.Tpp)
     {
         cameratype = CameraType.Tpp;
         ENABLE_TPP_VIEW = true;
     }
     else
     {
         cameratype = CameraType.Overhead;
         overheadcamera = true;
         SetFreeMouse(true);
         ENABLE_TPP_VIEW = true;
         playerdestination = Vector3Ref.Create(player.position.x, player.position.y, player.position.z);
     }
 }
示例#36
0
    internal void RailOnNewFrame(Game game, float dt)
    {
        if (localMinecart == null)
        {
            localMinecart          = new Entity();
            localMinecart.minecart = new Minecart();
            game.EntityAddLocal(localMinecart);
        }
        localMinecart.minecart.enabled = railriding;
        if (railriding)
        {
            Minecart m = localMinecart.minecart;
            m.positionX     = game.player.position.x;
            m.positionY     = game.player.position.y;
            m.positionZ     = game.player.position.z;
            m.direction     = currentdirection;
            m.lastdirection = lastdirection;
            m.progress      = currentrailblockprogress;
        }

        game.localplayeranimationhint.InVehicle = railriding;
        game.localplayeranimationhint.DrawFixX  = 0;
        game.localplayeranimationhint.DrawFixY  = railriding ? (-one * 7 / 10) : 0;
        game.localplayeranimationhint.DrawFixZ  = 0;

        bool turnright = game.keyboardState[game.GetKey(GlKeys.D)];
        bool turnleft  = game.keyboardState[game.GetKey(GlKeys.A)];

        RailSound(game);
        if (railriding)
        {
            game.controls.SetFreemove(FreemoveLevelEnum.Freemove);
            game.enable_move = false;
            Vector3Ref railPos = CurrentRailPos(game);
            game.player.position.x    = railPos.X;
            game.player.position.y    = railPos.Y;
            game.player.position.z    = railPos.Z;
            currentrailblockprogress += currentvehiclespeed * dt;
            if (currentrailblockprogress >= 1)
            {
                lastdirection            = currentdirection;
                currentrailblockprogress = 0;
                TileEnterData newenter = new TileEnterData();
                Vector3IntRef nexttile = NextTile(currentdirection, currentrailblockX, currentrailblockY, currentrailblockZ);
                newenter.BlockPositionX = nexttile.X;
                newenter.BlockPositionY = nexttile.Y;
                newenter.BlockPositionZ = nexttile.Z;
                //slope
                if (GetUpDownMove(game, currentrailblockX, currentrailblockY, currentrailblockZ,
                                  DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Up)
                {
                    newenter.BlockPositionZ++;
                }
                if (GetUpDownMove(game, newenter.BlockPositionX,
                                  newenter.BlockPositionY,
                                  newenter.BlockPositionZ - 1,
                                  DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Down)
                {
                    newenter.BlockPositionZ--;
                }

                newenter.EnterDirection = DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection));
                BoolRef            newdirFound = new BoolRef();
                VehicleDirection12 newdir      = BestNewDirection(PossibleRails(game, newenter), turnleft, turnright, newdirFound);
                if (!newdirFound.value)
                {
                    //end of rail
                    currentdirection = DirectionUtils.Reverse(currentdirection);
                }
                else
                {
                    currentdirection  = newdir;
                    currentrailblockX = game.platform.FloatToInt(newenter.BlockPositionX);
                    currentrailblockY = game.platform.FloatToInt(newenter.BlockPositionY);
                    currentrailblockZ = game.platform.FloatToInt(newenter.BlockPositionZ);
                }
            }
        }
        if (game.keyboardState[game.GetKey(GlKeys.W)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed += 1 * dt;
        }
        if (game.keyboardState[game.GetKey(GlKeys.S)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed -= 5 * dt;
        }
        if (currentvehiclespeed < 0)
        {
            currentvehiclespeed = 0;
        }
        //todo fix
        //if (viewport.keypressed != null && viewport.keypressed.Key == GlKeys.Q)
        if (!wasqpressed && game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing)
        {
            Reverse();
        }
        if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && !railriding && (game.controls.GetFreemove() == FreemoveLevelEnum.None) && game.GuiTyping != TypingState.Typing)
        {
            currentrailblockX = game.platform.FloatToInt(game.player.position.x);
            currentrailblockY = game.platform.FloatToInt(game.player.position.z);
            currentrailblockZ = game.platform.FloatToInt(game.player.position.y) - 1;
            if (!game.map.IsValidPos(currentrailblockX, currentrailblockY, currentrailblockZ))
            {
                ExitVehicle(game);
            }
            else
            {
                int railunderplayer = game.d_Data.Rail()[game.map.GetBlock(currentrailblockX, currentrailblockY, currentrailblockZ)];
                railriding          = true;
                originalmodelheight = game.GetCharacterEyesHeight();
                game.SetCharacterEyesHeight(minecartheight());
                currentvehiclespeed = 0;
                if ((railunderplayer & RailDirectionFlags.Horizontal) != 0)
                {
                    currentdirection = VehicleDirection12.HorizontalRight;
                }
                else if ((railunderplayer & RailDirectionFlags.Vertical) != 0)
                {
                    currentdirection = VehicleDirection12.VerticalUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpLeft) != 0)
                {
                    currentdirection = VehicleDirection12.UpLeftUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpRight) != 0)
                {
                    currentdirection = VehicleDirection12.UpRightUp;
                }
                else if ((railunderplayer & RailDirectionFlags.DownLeft) != 0)
                {
                    currentdirection = VehicleDirection12.DownLeftLeft;
                }
                else if ((railunderplayer & RailDirectionFlags.DownRight) != 0)
                {
                    currentdirection = VehicleDirection12.DownRightRight;
                }
                else
                {
                    ExitVehicle(game);
                }
                lastdirection = currentdirection;
            }
        }
        else if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && railriding && game.GuiTyping != TypingState.Typing)
        {
            ExitVehicle(game);
            game.player.position.y += one * 7 / 10;
        }
        wasqpressed = game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing;
        wasepressed = game.keyboardState[game.GetKey(GlKeys.E)] && game.GuiTyping != TypingState.Typing;
    }
示例#37
0
 public ModCamera()
 {
     OverheadCamera_cameraEye = new Vector3Ref();
     upVec3 = Vec3.FromValues(0, 1, 0);
 }