예제 #1
0
        public static Obstacle NewObstacle(Vector3 position, Direction direction)
        {
            var rotation = DirectionHelper.GetRotationFromDirection(direction);
            var p1       = new Vector3(new Vector4(-0.4f, 0f, -0.4f, 1) * rotation);
            var p2       = new Vector3(new Vector4(0.4f, 1f, 0.4f, 1) * rotation);

            return(new ObstacleTrash(new AxisAlignedBB(Vector3.ComponentMin(p1, p2), Vector3.ComponentMax(p1, p2)), position, direction));
        }
예제 #2
0
        public static Intersection NewIntersection(Player player, World world, Vector3 position, Direction direction, int directions)
        {
            var rotation = DirectionHelper.GetRotationFromDirection(direction);
            var p1       = new Vector3(new Vector4(-6f, -0.5f, -6f, 1) * rotation);
            var p2       = new Vector3(new Vector4(6f, 0f, 0f, 1) * rotation);
            var ap1      = new Vector3(new Vector4(-3f, 0f, -6f, 1) * rotation);
            var ap2      = new Vector3(new Vector4(3f, 5f, 0f, 1) * rotation);

            return(new Intersection(player, world, position, direction)
            {
                BoundingBox = new AxisAlignedBB(Vector3.ComponentMin(p1, p2), Vector3.ComponentMax(p1, p2)), ActivableBoundingBox = new AxisAlignedBB(Vector3.ComponentMin(ap1, ap2), Vector3.ComponentMax(ap1, ap2)), Directions = directions, Used = false
            });
        }
예제 #3
0
        public GroundStairs(Direction direction)
        {
            Mesh      = MeshToUse;
            Direction = direction;
            Length    = 1.2f;
            var rotation = DirectionHelper.GetRotationFromDirection(direction);
            var p1       = new Vector4(-3f, 0f, -Length, 1) * rotation;
            var p2       = new Vector4(3f, 0.3f, 0f, 1) * rotation;
            var p1v3     = new Vector3(p1);
            var p2v3     = new Vector3(p2);

            BoundingBox = new AxisAlignedBB(Vector3.ComponentMin(p1v3, p2v3), Vector3.ComponentMax(p1v3, p2v3));
        }
예제 #4
0
        public Intersection(Player player, World world, Vector3 position, Direction direction)
        {
            Position  = position;
            Direction = direction;
            Length    = 6f;
            var rot = DirectionHelper.GetRotationFromDirection(direction);
            var p1  = new Vector3(new Vector4(-3f, 0f, 0f, 1) * rot);
            var p2  = new Vector3(new Vector4(3f, 5f, -6f, 1) * rot);

            world.TriggersToAdd.Add(new TerrainGenerator(player, this)
            {
                Position = Position + -DirectionHelper.GetVectorFromDirection(direction) * 8f, BoundingBox = new AxisAlignedBB(Vector3.ComponentMin(p1, p2), Vector3.ComponentMax(p1, p2))
            });
        }
예제 #5
0
        public GroundSimple(Direction direction)
        {
            Mesh      = MeshToUse;
            Direction = direction;
            Length    = 6f;
            var rotation = DirectionHelper.GetRotationFromDirection(direction);
            var p1       = new Vector4(-3f, -0.5f, -Length, 1) * rotation;
            var p2       = new Vector4(3f, 0f, 0f, 1) * rotation;

            PossibleObstaclePositions = new Vector3[2];
            for (int i = 0; i < 2; i++)
            {
                PossibleObstaclePositions[i] = (new Vector4(0, 0, -i * 3, 1) * rotation).Xyz;
            }
            BoundingBox = new AxisAlignedBB(Vector3.ComponentMin(p1.Xyz, p2.Xyz), Vector3.ComponentMax(p1.Xyz, p2.Xyz));
        }
예제 #6
0
        private void GenerateTerrain()
        {
            TerrainRemover leftTerrainRemover = null;
            var            coinsOffset        = new Vector3(0, 0.3f, 0);

            if ((_intersection.Directions & (int)Intersection.IntersectionDirection.LEFT) > 0)
            {
                var dir = (int)_intersection.Direction - 1;
                if (dir < 0)
                {
                    dir = (int)Direction.WEST;
                }
                var            direction         = (Direction)dir;
                int            toGenerate        = _rand.Next(10) + 5;
                List <Ground>  generatedGrounds  = new List <Ground>();
                var            dirVector         = DirectionHelper.GetVectorFromDirection(direction);
                var            interDir          = DirectionHelper.GetVectorFromDirection(_intersection.Direction);
                var            nextPosition      = _intersection.Position + dirVector * 5f + interDir * 3f;
                List <Vector3> obstaclePositions = new List <Vector3>();
                for (int i = 0; i < toGenerate; i++)
                {
                    var grounds = GroundFactory.NewGround(nextPosition, direction, out nextPosition);
                    Array.ForEach(grounds, ground => Array.ForEach(ground.PossibleObstaclePositions, possiblePos => obstaclePositions.Add(possiblePos + ground.Position)));
                    generatedGrounds.AddRange(grounds);
                }
                var intersection = GroundFactory.NewIntersection(_player, _player.World, nextPosition, direction, _rand.Next(1, 4));
                generatedGrounds.Add(intersection);
                _player.World.Grounds.AddRange(generatedGrounds);

                var rotation       = DirectionHelper.GetRotationFromDirection(direction);
                var wallsColliders = new List <Obstacle>();
                var coins          = new List <Coin>();

                obstaclePositions.ForEach(pos => {
                    if ((pos - _intersection.Position).LengthFast > 20)
                    {
                        var randValue = _rand.Next(4);
                        if (randValue == 0)
                        {
                            wallsColliders.Add(ObstacleFactory.NewObstacle(pos + interDir * _rand.Next(-1, 1) * 2, direction));
                        }
                        else if (randValue == 1)
                        {
                            coins.Add(new Coin(pos + interDir * _rand.Next(-1, 1) * 2 + coinsOffset));
                        }
                    }
                });
                _player.World.Coins.AddRange(coins);

                var w1p1 = new Vector3(new Vector4(-3f, 0f, -7f, 1) * rotation);
                var w1p2 = new Vector3(new Vector4(3f, 5f, -6f, 1) * rotation);
                wallsColliders.Add(new Obstacle(new AxisAlignedBB(Vector3.ComponentMin(w1p1, w1p2), Vector3.ComponentMax(w1p1, w1p2)), intersection.Position, Direction.NORTH));
                if (intersection.Directions == (int)Intersection.IntersectionDirection.LEFT)
                {
                    var w2p1 = new Vector3(new Vector4(3f, 0f, -6f, 1) * rotation);
                    var w2p2 = new Vector3(new Vector4(4f, 5f, 0f, 1) * rotation);
                    wallsColliders.Add(new Obstacle(new AxisAlignedBB(Vector3.ComponentMin(w2p1, w2p2), Vector3.ComponentMax(w2p1, w2p2)), intersection.Position, Direction.NORTH));
                }
                if (intersection.Directions == (int)Intersection.IntersectionDirection.RIGHT)
                {
                    var w2p1 = new Vector3(new Vector4(-4f, 0f, -6f, 1) * rotation);
                    var w2p2 = new Vector3(new Vector4(-3f, 5f, 0f, 1) * rotation);
                    wallsColliders.Add(new Obstacle(new AxisAlignedBB(Vector3.ComponentMin(w2p1, w2p2), Vector3.ComponentMax(w2p1, w2p2)), intersection.Position, Direction.NORTH));
                }
                _player.World.Obstacles.AddRange(wallsColliders);
                var ap1 = new Vector3(new Vector4(-3f, 0f, -6f, 1) * rotation);
                var ap2 = new Vector3(new Vector4(3f, 5f, 0f, 1) * rotation);
                leftTerrainRemover = new TerrainRemover(_player, generatedGrounds, new List <Trigger>(_player.World.TriggersToAdd.ToArray()), wallsColliders, coins)
                {
                    Position = _intersection.Position + dirVector * 12f + DirectionHelper.GetVectorFromDirection(_intersection.Direction) * 3f, BoundingBox = new AxisAlignedBB(Vector3.ComponentMin(ap1, ap2), Vector3.ComponentMax(ap1, ap2))
                };
                _player.World.TriggersToAdd.Add(leftTerrainRemover);
            }
            if ((_intersection.Directions & (int)Intersection.IntersectionDirection.RIGHT) > 0)
            {
                var dir = (int)_intersection.Direction + 1;
                if (dir > 3)
                {
                    dir = (int)Direction.NORTH;
                }
                var            direction         = (Direction)dir;
                int            toGenerate        = _rand.Next(10) + 5;
                List <Ground>  generatedGrounds  = new List <Ground>();
                var            dirVector         = DirectionHelper.GetVectorFromDirection(direction);
                var            interDir          = DirectionHelper.GetVectorFromDirection(_intersection.Direction);
                var            nextPosition      = _intersection.Position + dirVector * 5f + interDir * 3f;
                List <Vector3> obstaclePositions = new List <Vector3>();
                for (int i = 0; i < toGenerate; i++)
                {
                    var grounds = GroundFactory.NewGround(nextPosition, direction, out nextPosition);
                    Array.ForEach(grounds, ground => Array.ForEach(ground.PossibleObstaclePositions, possiblePos => obstaclePositions.Add(possiblePos + ground.Position)));
                    generatedGrounds.AddRange(grounds);
                }
                var intersection = GroundFactory.NewIntersection(_player, _player.World, nextPosition, direction, _rand.Next(1, 4));
                generatedGrounds.Add(intersection);
                _player.World.Grounds.AddRange(generatedGrounds);

                var triggersToKeep = new List <Trigger>(_player.World.TriggersToAdd.ToArray());

                if (leftTerrainRemover != null && triggersToKeep.Contains(leftTerrainRemover))
                {
                    triggersToKeep.Remove(leftTerrainRemover);
                }

                var rotation       = DirectionHelper.GetRotationFromDirection(direction);
                var wallsColliders = new List <Obstacle>();
                var coins          = new List <Coin>();

                obstaclePositions.ForEach(pos => {
                    if ((pos - _intersection.Position).LengthFast > 20)
                    {
                        var randValue = _rand.Next(4);
                        if (randValue == 0)
                        {
                            wallsColliders.Add(ObstacleFactory.NewObstacle(pos + interDir * _rand.Next(-1, 1) * 2, direction));
                        }
                        else if (randValue == 1)
                        {
                            coins.Add(new Coin(pos + interDir * _rand.Next(-1, 1) * 2 + coinsOffset));
                        }
                    }
                });
                _player.World.Coins.AddRange(coins);

                var w1p1 = new Vector3(new Vector4(-3f, 0f, -7f, 1) * rotation);
                var w1p2 = new Vector3(new Vector4(3f, 5f, -6f, 1) * rotation);
                wallsColliders.Add(new Obstacle(new AxisAlignedBB(Vector3.ComponentMin(w1p1, w1p2), Vector3.ComponentMax(w1p1, w1p2)), intersection.Position, Direction.NORTH));
                if (intersection.Directions == (int)Intersection.IntersectionDirection.LEFT)
                {
                    var w2p1 = new Vector3(new Vector4(3f, 0f, -6f, 1) * rotation);
                    var w2p2 = new Vector3(new Vector4(4f, 5f, 0f, 1) * rotation);
                    wallsColliders.Add(new Obstacle(new AxisAlignedBB(Vector3.ComponentMin(w2p1, w2p2), Vector3.ComponentMax(w2p1, w2p2)), intersection.Position, Direction.NORTH));
                }
                if (intersection.Directions == (int)Intersection.IntersectionDirection.RIGHT)
                {
                    var w2p1 = new Vector3(new Vector4(-4f, 0f, -6f, 1) * rotation);
                    var w2p2 = new Vector3(new Vector4(-3f, 5f, 0f, 1) * rotation);
                    wallsColliders.Add(new Obstacle(new AxisAlignedBB(Vector3.ComponentMin(w2p1, w2p2), Vector3.ComponentMax(w2p1, w2p2)), intersection.Position, Direction.NORTH));
                }
                _player.World.Obstacles.AddRange(wallsColliders);
                var ap1            = new Vector3(new Vector4(-3f, 0f, -6f, 1) * rotation);
                var ap2            = new Vector3(new Vector4(3f, 5f, 0f, 1) * rotation);
                var terrainRemover = new TerrainRemover(_player, generatedGrounds, triggersToKeep, wallsColliders, coins)
                {
                    Position = _intersection.Position + dirVector * 12f + DirectionHelper.GetVectorFromDirection(_intersection.Direction) * 3f, BoundingBox = new AxisAlignedBB(Vector3.ComponentMin(ap1, ap2), Vector3.ComponentMax(ap1, ap2))
                };
                _player.World.TriggersToAdd.Add(terrainRemover);
            }
        }