Exemple #1
0
        private void Collision()
        {
            Vector2 oldPosition = MyGame.OldCameraPosition;
            Vector2 newPosition = MyGame.NewCameraPosition;

            if (newPosition == new Vector2(0, 0) && oldPosition.X > 1)
            {
                newPosition = oldPosition;
            }
            foreach (MazeLevel.WallPoints w in MyGame.currentLevelLoaded.wallPlanePositions)
            {
                float dx = w.endPosition.X - w.startPosition.X;
                float dy = w.endPosition.Y - w.startPosition.Y;

                Vector2 normal = new Vector2(-dy, dx);
                normal.Normalize();

                float oldPos = MyGame.DotProduct(normal, oldPosition - w.startPosition);
                float newPos = MyGame.DotProduct(normal, newPosition - w.startPosition);

                float q = (newPos * oldPos) - 0.01f;

                if (q < 0)
                {
                    dx     = newPosition.X - oldPosition.X;
                    dy     = newPosition.Y - oldPosition.Y;
                    normal = new Vector2(-dy, dx);

                    oldPos = MyGame.DotProduct(normal, w.startPosition - oldPosition);
                    newPos = MyGame.DotProduct(normal, w.endPosition - oldPosition);
                    float z = (newPos * oldPos) + 0.01f;
                    if ((newPos * oldPos) < 0)
                    {
                        if (w.startPosition.X == w.endPosition.X)
                        {
                            MyGame.gameInstance.playerCamera.Position  = new Vector3(oldPosition.X, 0, newPosition.Y);
                            MyGame.gameInstance.playerCamera.Collision = true;
                        }
                        if (w.startPosition.Y == w.endPosition.Y)
                        {
                            MyGame.gameInstance.playerCamera.Position  = new Vector3(newPosition.X, 0, oldPosition.Y);
                            MyGame.gameInstance.playerCamera.Collision = true;
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void PlayerDetection(ComponentPosition pos, ComponentVelocity vel, AIStates state)
        {
            if (state == AIStates.Wandering)
            {
                Vector2 AIpos = new Vector2(pos.Position.X, pos.Position.Z);
                Vector2 v     = MyGame.NewCameraPosition - AIpos;

                float dot = MyGame.DotProduct(v.Normalized(), AIpos.Normalized());

                if (dot > 0.7)
                {
                    droneSpeed = 0.8f;
                }
                else
                {
                    droneSpeed = 0.5f;
                }
            }
        }