Пример #1
0
        public override void Update(double currentTime)
        {
            if (HasExploded)
            {
                return;
            }
            if (currentTime - creationTime >= timeToLive)
            {
                Explode(currentTime);
            }
            var status = LocationResolver.UpdateLocation(currentTime, currentTime - lastTime);

            if (status != null)
            {
                if (status.HaveCollided)
                {
                    Tile.Object      = this;
                    LocationResolver = new FixedLocationResolver(Tile);
                    FloatingObjectRegistry.UnRegister(this);
                    if (status.CollisionObject is Bomb)
                    {
                        (status.CollisionObject as Bomb).Kicked(status.CollisionDirection);
                    }
                }
            }

            lastTime = currentTime;
        }
Пример #2
0
        public void Kicked(Game.Direction kickedFromSide)
        {
            System.Console.WriteLine("Kicked from direction: " + kickedFromSide);

            if (!(this.LocationResolver is FloatingLocationResolver))
            {
                this.LocationResolver = new FloatingLocationResolver(this.Tile);
            }

            var resolver = this.LocationResolver as FloatingLocationResolver;

            switch (kickedFromSide)
            {
            case Game.Direction.East:
                resolver.Direction = Game.Direction.East;
                resolver.Velocity  = new PointF(300, 0);
                break;

            case Game.Direction.North:
                resolver.Direction = Game.Direction.North;
                resolver.Velocity  = new PointF(0, -300);
                break;

            case Game.Direction.South:
                resolver.Direction = Game.Direction.South;
                resolver.Velocity  = new PointF(0, 300);
                break;

            case Game.Direction.West:
                resolver.Direction = Game.Direction.West;
                resolver.Velocity  = new PointF(-300, 0);
                break;
            }

            Tile.Object = null;
            FloatingObjectRegistry.Register(this);
        }
Пример #3
0
        private void ExplodeInDirection(Game.Direction direction, FireType fireType, double currentTime)
        {
            FireType connectionType = (fireType == FireType.Up || fireType == FireType.Down) ? FireType.Vertical : FireType.Horizontal;

            var remainingRange = this.range;
            var tile           = this.Tile;

            while (remainingRange > 0)
            {
                tile = tile.GetNextTileInDirection(direction);
                remainingRange--;
                if (tile == Tile.OutOfBounds)
                {
                    break;
                }

                foreach (var item in FloatingObjectRegistry.GetMovingObjects())
                {
                    if (item.IsDescructible)
                    {
                        if (item.Tile == tile)
                        {
                            item.Destroy(currentTime);
                        }
                    }
                }

                var elem = tile.Object;
                if (elem == null)
                {
                    if (remainingRange == 0)
                    {
                        tile.Object = new Fire(fireType, currentTime);
                    }
                    else
                    {
                        tile.Object = new Fire(connectionType, currentTime);
                    }
                }
                else if (elem.IsDescructible)
                {
                    elem.Destroy(currentTime);

                    if (tile.Object == null)
                    {
                        tile.Object = new Fire(fireType, currentTime);
                    }

                    //if (tile.Object?.IsDescructible ?? true) {
                    //    tile.Object = new Fire(fireType, currentTime);
                    //}
                    break;
                }
                else if (elem is Fire)
                {
                    var elemStart = (elem as Fire).GetStartTime();
                    if (elemStart < currentTime)
                    {
                        elem.Destroy(currentTime);
                        tile.Object = new Fire(remainingRange == 0 ? fireType : connectionType, currentTime);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
Пример #4
0
        public override LocationResolvStatus UpdateLocation(double currentTime, double delta)
        {
            this.status = new LocationResolvStatus();

            var xDelta = Velocity.X * (float)delta;
            var yDelta = Velocity.Y * (float)delta;

            var nextTile = CurrentTile.GetNextTileInDirection(Direction);

            var newBounds = new RectangleF(new PointF(Bounds.Left + xDelta, Bounds.Top + yDelta), Bounds.Size);

            Console.WriteLine(newBounds);

            foreach (var item in FloatingObjectRegistry.GetMovingObjects())
            {
                if (item.Tile != CurrentTile && item.Tile.Bounds.IntersectsWith(newBounds))
                {
                    // Not allowed to enter tile, constrain the movement
                    if (xDelta != 0)
                    {
                        // Adjust x movement
                        if (xDelta < 0)
                        {
                            xDelta = Math.Max(CurrentTile.Bounds.Left - Bounds.Left, xDelta);
                        }
                        else
                        {
                            xDelta = Math.Min(CurrentTile.Bounds.Right - Bounds.Right, xDelta);
                        }
                    }
                    if (yDelta != 0)
                    {
                        // Adjust y movement
                        if (yDelta < 0)
                        {
                            yDelta = Math.Max(CurrentTile.Bounds.Top - Bounds.Top, yDelta);
                        }
                        else
                        {
                            yDelta = Math.Min(CurrentTile.Bounds.Bottom - Bounds.Bottom, yDelta);
                        }
                    }
                    Velocity = new PointF(0, 0);
                }
            }

            if (!nextTile.Bounds.IntersectsWith(Bounds) && nextTile.Bounds.IntersectsWith(newBounds))
            {
                // Entering a new tile
                if (!CanEnterTile(nextTile))
                {
                    // Not allowed to enter tile, constrain the movement
                    if (xDelta != 0)
                    {
                        // Adjust x movement
                        if (xDelta < 0)
                        {
                            xDelta = Math.Max(CurrentTile.Bounds.Left - Bounds.Left, xDelta);
                        }
                        else
                        {
                            xDelta = Math.Min(CurrentTile.Bounds.Right - Bounds.Right, xDelta);
                        }
                    }
                    if (yDelta != 0)
                    {
                        // Adjust y movement
                        if (yDelta < 0)
                        {
                            yDelta = Math.Max(CurrentTile.Bounds.Top - Bounds.Top, yDelta);
                        }
                        else
                        {
                            yDelta = Math.Min(CurrentTile.Bounds.Bottom - Bounds.Bottom, yDelta);
                        }
                    }
                    Velocity = new PointF(0, 0);
                }
            }
            else if (nextTile.Bounds.IntersectsWith(newBounds) && CurrentTile != nextTile)
            {
                CanEnterTile(nextTile);
            }

            MoveBy(xDelta, yDelta);

            // Mark tiles around the player as dirty
            CurrentTile.MarkAsDirty();
            CurrentTile.West.MarkAsDirty();
            CurrentTile.North.MarkAsDirty();
            CurrentTile.East.MarkAsDirty();
            CurrentTile.South.MarkAsDirty();

            if (!CurrentTile.Bounds.Contains(this.centerPosition) && nextTile.Bounds.Contains(this.centerPosition))
            {
                // Switched current tile
                status.ChangedTile = true;
                status.PrevTile    = CurrentTile;
                CurrentTile        = nextTile;
            }

            if (!Velocity.IsEmpty)
            {
                AlignWithTileBounds();
            }

            return(status);
        }