Ejemplo n.º 1
0
        public void CycleIsCollidingInBounds()
        {
            var gameConfig       = new GameConfiguration(new CycleConfiguration(), new MapConfiguration());
            var map              = new Map(gameConfig.MapConfig);
            var startPosition    = new Vector3(0, gameConfig.CycleConfig.Y_OFFSET, 0);
            var cycle            = new Cycle(1, startPosition, new Vector3(1, 0, 0), Math.PI + Math.PI * .5, 0xff0000, map, gameConfig);
            var cycle2           = new Cycle(2, startPosition, new Vector3(1, 0, 0), Math.PI + Math.PI * .5, 0xff0000, map, gameConfig);
            var collisionChecker = new CollisionChecker(map);
            var startLocation    = map.Utilities.ToMapLocation(startPosition);
            var cycles           = new ConcurrentDictionary <long, Cycle>();

            cycles.TryAdd(cycle.ID, cycle);
            cycles.TryAdd(cycle2.ID, cycle2);
            map.RegisterCycles(cycles);

            map[startLocation] = 2;
            collisionChecker.ValidateCollision(cycle);

            Assert.True(cycle.Colliding);

            map.Clear();
            cycle.Colliding    = false;
            map[startLocation] = -cycle.ID;
            collisionChecker.ValidateCollision(cycle);
            Assert.False(cycle.Colliding);

            map.Clear();
            cycle.Colliding    = false;
            map[startLocation] = 0;
            collisionChecker.ValidateCollision(cycle);
            Assert.False(cycle.Colliding);
        }
Ejemplo n.º 2
0
        public void CycleIsCollidingInBounds()
        {
            var gameConfig = new GameConfiguration(new CycleConfiguration(), new MapConfiguration());
            var map = new Map(gameConfig.MapConfig);
            var startPosition = new Vector3(0, gameConfig.CycleConfig.Y_OFFSET, 0);
            var cycle = new Cycle(1, startPosition, new Vector3(1, 0, 0), Math.PI + Math.PI * .5, 0xff0000, map, gameConfig);
            var cycle2 = new Cycle(2, startPosition, new Vector3(1, 0, 0), Math.PI + Math.PI * .5, 0xff0000, map, gameConfig);
            var collisionChecker = new CollisionChecker(map);
            var startLocation = map.Utilities.ToMapLocation(startPosition);
            var cycles = new ConcurrentDictionary<long, Cycle>();
            cycles.TryAdd(cycle.ID, cycle);
            cycles.TryAdd(cycle2.ID, cycle2);
            map.RegisterCycles(cycles);

            map[startLocation] = 2;
            collisionChecker.ValidateCollision(cycle);

            Assert.True(cycle.Colliding);

            map.Clear();
            cycle.Colliding = false;
            map[startLocation] = -cycle.ID;
            collisionChecker.ValidateCollision(cycle);
            Assert.False(cycle.Colliding);

            map.Clear();
            cycle.Colliding = false;
            map[startLocation] = 0;
            collisionChecker.ValidateCollision(cycle);
            Assert.False(cycle.Colliding);
        }
Ejemplo n.º 3
0
        public void CycleIsCollidingOutOfBounds()
        {
            var gameConfig       = new GameConfiguration(new CycleConfiguration(), new MapConfiguration());
            var map              = new Map(gameConfig.MapConfig);
            var startPosition    = new Vector3(gameConfig.MapConfig.MAP_SIZE.Width * .5 + gameConfig.MapConfig.FLOOR_TILE_SIZE.Width * 10, gameConfig.CycleConfig.Y_OFFSET, 0);
            var cycle            = new Cycle(1, startPosition, new Vector3(1, 0, 0), Math.PI + Math.PI * .5, 0xff0000, map, gameConfig);
            var collisionChecker = new CollisionChecker(map);

            collisionChecker.ValidateCollision(cycle);
            Assert.True(cycle.Colliding);

            cycle.Colliding = false;
            cycle.MovementController.Position = new Vector3();
            collisionChecker.ValidateCollision(cycle);
            Assert.False(cycle.Colliding);
        }
Ejemplo n.º 4
0
        public void CycleIsCollidingOutOfBounds()
        {
            var gameConfig = new GameConfiguration(new CycleConfiguration(), new MapConfiguration());
            var map = new Map(gameConfig.MapConfig);
            var startPosition = new Vector3(gameConfig.MapConfig.MAP_SIZE.Width * .5 + gameConfig.MapConfig.FLOOR_TILE_SIZE.Width * 10, gameConfig.CycleConfig.Y_OFFSET, 0);
            var cycle = new Cycle(1, startPosition, new Vector3(1, 0, 0), Math.PI + Math.PI * .5, 0xff0000, map, gameConfig);
            var collisionChecker = new CollisionChecker(map);

            collisionChecker.ValidateCollision(cycle);
            Assert.True(cycle.Colliding);

            cycle.Colliding = false;
            cycle.MovementController.Position = new Vector3();
            collisionChecker.ValidateCollision(cycle);
            Assert.False(cycle.Colliding);
        }
Ejemplo n.º 5
0
        public void Update(GameTime gameTime)
        {
            foreach (var cycle in _cycles.Values)
            {
                // If the cycle is Colliding then the position hasn't changed and we've already dealt with it
                if (!cycle.Colliding)
                {
                    Debug.WriteLine("Cycle at: " + cycle.MovementController.HeadLocation + " is requesting to be at " + Utilities.ToMapLocation(cycle.MovementController.RequestedPosition, cycle.MovementController.Velocity) + " | " + cycle.MovementController.Position + " => " + cycle.MovementController.RequestedPosition);
                    // Validate the requested position on the cycle, updates the cycles position
                    _requestValidator.ValidateRequestedPosition(cycle);
                    _collisionChecker.ValidateCollision(cycle);

                    Debug.WriteLine("Cycle now at: " + Utilities.ToMapLocation(cycle.MovementController) + " | " + cycle.MovementController.Position);

                    var newLocation = Utilities.ToMapLocation(cycle.MovementController);

                    // If our current location is colliding then we need our MovementController.HeadLocation to be just before the
                    // collision location mark.
                    if (cycle.Colliding)
                    {
                        Debug.Write("Cycle was colliding at: " + Utilities.ToMapLocation(cycle.MovementController) + " and new location is " + newLocation);
                        var difference  = cycle.MovementController.HeadLocation - newLocation;
                        var incrementor = difference.Normalized().Abs();

                        Debug.WriteLine(" and incrementor = " + incrementor);

                        // If the requested location is going in the negative direction then we need our incrementor
                        // to also be pointing in the negative direction.
                        if (difference > 0)
                        {
                            incrementor *= -1;
                        }

                        newLocation -= incrementor;
                    }

                    Debug.Write("Checking if cycles head location " + cycle.MovementController.HeadLocation + " differs from " + newLocation + " = ");
                    // We only need to perform markings if we've moved from our location
                    if (!cycle.MovementController.HeadLocation.SameAs(newLocation))
                    {
                        Debug.WriteLine("TRUE");
                        var distance = cycle.MovementController.HeadLocation - newLocation;

                        // used by mark location to
                        bool inclusive = true;

                        if (cycle.Colliding)
                        {
                            // If we're 1 away from the head location while colliding, no need to mark anything, just noop
                            if (distance.NonZeroValue() == 1)
                            {
                                this[cycle.MovementController.HeadLocation] = cycle.ID;
                                this[newLocation] = -cycle.ID;
                                cycle.MovementController.HeadLocation = newLocation;
                                continue;
                            }

                            inclusive = false;
                        }

                        // Fills in any unmarked spots between the last head location and the current new location
                        _mapMarker.MarkArea(cycle.MovementController.HeadLocation, newLocation, cycle.ID, inclusive);

                        // Update the headlocation
                        Debug.WriteLine("Marking old MovementController.HeadLocation: " + cycle.MovementController.HeadLocation + " as " + cycle.ID + " and new MovementController.HeadLocation: " + newLocation + " as " + -cycle.ID);
                        this[cycle.MovementController.HeadLocation] = cycle.ID;
                        this[newLocation] = -cycle.ID;
                        cycle.MovementController.HeadLocation = newLocation;
                    }
                    else
                    {
                        Debug.WriteLine("FALSE");
                    }
                }
            }
        }