コード例 #1
0
        public override void Act(KeyboardState ks, MouseState ms)
        {
            //CurrentWorld.DebugVolumeVertices.Clear();

            if (ks[Key.W])
            {
                MoveOffset(0, 0, -0.01f);
            }
            if (ks[Key.S])
            {
                MoveOffset(0, 0, +0.01f);
            }
            if (ks[Key.A])
            {
                MoveOffset(-0.01f, 0, 0);
            }
            if (ks[Key.D])
            {
                MoveOffset(+0.01f, 0, 0);
            }
            if (ks[Key.Q])
            {
                MoveOffset(0, -0.01f, 0);
            }
            if (ks[Key.E])
            {
                MoveOffset(0, +0.01f, 0);
            }


            Intersection i = GetIntersection();

            if (i != null)
            {
                IntersectionVolume v = i.CalculateVolume();
                if (v.IsValid)
                {
                    //Console.WriteLine(v.Center);
                    //CurrentWorld.DebugVolumeVertices.AddRange(v.VolumeVertices);
                }
            }
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: KWEngine/KWEngine2
        private void DoCollisionDetection()
        {
            List <Intersection> collisionlist = GetIntersections();
            bool  upCorrection     = false;
            float maxYUpCorrection = 0;

            foreach (Intersection i in collisionlist)
            {
                if (i.MTV.Y > maxYUpCorrection)
                {
                    maxYUpCorrection = i.MTV.Y;
                }

                MoveOffset(new Vector3(i.MTV.X, 0, i.MTV.Z));
                if (i.MTV.Y > 0)
                {
                    if (_state == PlayerState.OnFloor)
                    {
                        upCorrection = true;
                    }
                    else if (_state == PlayerState.Fall)
                    {
                        upCorrection = true;
                        _state       = PlayerState.OnFloor;
                    }
                }
                else if (i.MTV.Y < 0 && Math.Abs(i.MTV.Y) > Math.Abs(i.MTV.X) && Math.Abs(i.MTV.Y) > Math.Abs(i.MTV.Z))
                {
                    if (_state == PlayerState.Jump)
                    {
                        _state      = PlayerState.Fall;
                        _momentum   = 0;
                        _percentage = 0.5f;
                    }
                }
                if (i.Object is Platform)
                {
                    IntersectionVolume iv = i.CalculateVolume();
                    if (iv.IsValid)
                    {
                        Platform p            = i.Object as Platform;
                        Vector3  diff         = iv.Center - p.GetCenterPointForAllHitboxes();
                        Vector3  diffToPlayer = this.GetCenterPointForAllHitboxes() - iv.Center;
                        if (diffToPlayer.Y >= 0)
                        {
                            if (Math.Abs(diff.X) > 0.2f)
                            {
                                //Console.WriteLine(diff);
                                if (diff.X > 0)
                                {
                                    p.AddRotationZ(diff.X * -0.05f * KWEngine.DeltaTimeFactor, true);
                                }
                                else if (diff.X < 0)
                                {
                                    p.AddRotationZ(diff.X * -0.05f * KWEngine.DeltaTimeFactor, true);
                                }
                            }
                        }
                    }
                }
            }
            MoveOffset(0, maxYUpCorrection, 0);

            if (_state == PlayerState.OnFloor && !upCorrection)
            {
                _state      = PlayerState.Fall;
                _attacking  = false;
                _momentum   = 0;
                _percentage = 0.5f;
            }
        }