Exemplo n.º 1
0
        public override void Update()
        {
            // Check if collided.
            if (physics.IsColliding && eventCollision != null)
            {
                eventCollision();
                if (IsDestroyed)
                {
                    return;
                }
            }

            // Collide with tiles.
            if (physics.IsColliding)
            {
                CollisionType type = CollisionType.RoomEdge;
                Tile          tile = null;

                foreach (CollisionInfo collision in Physics.GetCollisions())
                {
                    type = collision.Type;
                    tile = collision.Tile;
                    break;
                }

                if (tile != null)
                {
                    if (owner == RoomControl.Player)
                    {
                        tile.OnHitByProjectile(this);
                        if (IsDestroyed)
                        {
                            return;
                        }
                    }
                    OnCollideTile(tile, false);
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
                else if (type == CollisionType.RoomEdge)
                {
                    OnCollideRoomEdge();
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
            }

            // Notify surface tiles the projectile is hovering over.
            Point2I tileLoc = RoomControl.GetTileLocation(position);

            if (tileLoc != tileLocation && RoomControl.IsTileInBounds(tileLoc) && zPosition < 10.0f)               // TODO: magic number
            {
                Tile tile = RoomControl.GetTopTile(tileLoc);
                if (tile != null)
                {
                    tile.OnHitByProjectile(this);
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
            }
            tileLocation = tileLoc;

            if (owner is Player)
            {
                // Collide with monster tools.
                foreach (Monster monster in RoomControl.GetEntitiesOfType <Monster>())
                {
                    foreach (UnitTool tool in monster.EquippedTools)
                    {
                        if (Physics.PositionedCollisionBox.Intersects(tool.PositionedCollisionBox))
                        {
                            tool.OnHitProjectile(this);
                            if (IsDestroyed)
                            {
                                return;
                            }
                        }
                    }
                }

                // Collide with monsters.
                foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft))
                {
                    OnCollideMonster(monster);
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
            }
            else
            {
                Player player = RoomControl.Player;

                // Collide with the player's tools.
                foreach (UnitTool tool in player.EquippedTools)
                {
                    if (Physics.PositionedCollisionBox.Intersects(tool.PositionedCollisionBox))
                    {
                        tool.OnHitProjectile(this);
                        if (IsDestroyed)
                        {
                            return;
                        }
                    }
                }

                // Collide with the player.
                if (Physics.IsMeetingEntity(player, CollisionBoxType.Soft))
                {
                    OnCollidePlayer(player);
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
            }

            if (syncAnimationWithDirection)
            {
                Graphics.SubStripIndex = direction;
            }
            else if (syncAnimationWithAngle)
            {
                Graphics.SubStripIndex = angle;
            }

            base.Update();
        }