示例#1
0
        public override void Update()
        {
            AudioSystem.LoopSoundWhileActive(GameData.SOUND_BOOMERANG_LOOP);

            // Check for boomerangable tiles.
            if (itemBoomerang.Level == Item.Level2)
            {
                Point2I tileLoc = RoomControl.GetTileLocation(position);
                if (tileLoc != tileLocation && RoomControl.IsTileInBounds(tileLoc))
                {
                    Tile tile = RoomControl.GetTopTile(tileLoc);
                    if (tile != null)
                    {
                        tile.OnBoomerang();
                    }
                }
                tileLocation = tileLoc;
            }

            // Pickup collectibles.
            foreach (Collectible collectible in Physics.GetEntitiesMeeting <Collectible>(CollisionBoxType.Soft))
            {
                if (collectible.IsPickupable && collectible.IsCollectibleWithItems)
                {
                    collectibles.Add(collectible);
                    collectible.Destroy();
                    BeginReturn();
                }
            }

            base.Update();
        }
示例#2
0
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------

        private void Explode()
        {
            BombExplosion bombExplosion = new BombExplosion();

            RoomControl.SpawnEntity(bombExplosion, Center, zPosition);
            AudioSystem.PlaySound(GameData.SOUND_BOMB_EXPLODE);

            // Explode nearby top tiles.
            if (zPosition < 4)
            {
                Rectangle2F tileExplodeArea = Rectangle2F.Zero.Inflated(12, 12);
                tileExplodeArea.Point += Center;

                Rectangle2I area = RoomControl.GetTileAreaFromRect(tileExplodeArea);

                for (int x = area.Left; x < area.Right; x++)
                {
                    for (int y = area.Top; y < area.Bottom; y++)
                    {
                        Tile        tile     = RoomControl.GetTopTile(x, y);
                        Rectangle2F tileRect = new Rectangle2F(x * 16, y * 16, 16, 16);
                        if (tile != null && tileRect.Intersects(tileExplodeArea))
                        {
                            tile.OnBombExplode();
                        }
                    }
                }
            }

            DestroyAndTransform(bombExplosion);
        }
示例#3
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override void OnInitialize()
        {
            startPosition = (IsVertical ? Location.Y : Location.X);
            returnTimer   = 0;
            TileRoller roller = this;

            do
            {
                firstRoller = roller;
                // Don't look any further, this is automatically the first roller.
                if (roller.Properties.GetBoolean("first_roller"))
                {
                    break;
                }
                roller = RoomControl.GetTopTile(roller.Location + Directions.ToPoint(IsVertical ? Directions.Left : Directions.Up)) as TileRoller;
            } while (roller != null);

            nextRoller = RoomControl.GetTopTile(Location + Directions.ToPoint(IsVertical ? Directions.Right : Directions.Down)) as TileRoller;
            // Don't include the next roller if it's the start of a new group.
            if (nextRoller != null && nextRoller.Properties.GetBoolean("first_roller"))
            {
                nextRoller = null;
            }

            pushed    = false;
            pushTimer = 0;

            Graphics.PlayAnimation(TileData.SpriteList[1].Animation);
            Graphics.AnimationPlayer.SkipToEnd();
        }
示例#4
0
        public override void OnLand()
        {
            // Collide with monsters.
            foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft))
            {
                monster.TriggerInteraction(InteractionType.ThrownObject, this);
                if (IsDestroyed)
                {
                    return;
                }
            }

            // Collide with surface tiles.
            Point2I tileLoc = RoomControl.GetTileLocation(position);

            if (RoomControl.IsTileInBounds(tileLoc))
            {
                Tile tile = RoomControl.GetTopTile(tileLoc);
                if (tile != null)
                {
                    tile.OnHitByThrownObject(this);
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
            }

            Break();
        }
示例#5
0
 protected void CheckInitialCollision()
 {
     if (physics.IsPlaceMeetingSolid(position, physics.CollisionBox))
     {
         Point2I tileLocation = RoomControl.GetTileLocation(Position);
         Tile    tile         = RoomControl.GetTopTile(tileLocation);
         OnCollideTile(tile, true);
     }
 }
示例#6
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override void OnLand()
        {
            if (IsDestroyed)
            {
                return;
            }

            // Collide with monsters.
            foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft))
            {
                monster.OnSeedHit(this);
                if (IsDestroyed)
                {
                    return;
                }
            }

            // Notify the tile of the seed hitting it.
            Point2I location = RoomControl.GetTileLocation(position);
            Tile    tile     = RoomControl.GetTopTile(location);

            if (tile != null)
            {
                tile.OnHitByProjectile(this);
                if (IsDestroyed)
                {
                    return;
                }
            }

            // Spawn the seed effect.
            Entity effect = DestroyWithSatchelEffect();

            if (type == SeedType.Scent)
            {
                if (RoomControl.IsSideScrolling)
                {
                    effect.Y += 3;
                }
            }
            else if (type == SeedType.Ember)
            {
                if (RoomControl.IsSideScrolling)
                {
                    effect.Y += 1;
                }
                effect.Physics.HasGravity = false;
            }
            else if (type == SeedType.Mystery)
            {
                if (RoomControl.IsSideScrolling)
                {
                    effect.Y -= 1;
                }
            }
        }
示例#7
0
        public override void OnDestroyTimerDone()
        {
            // Burn tiles.
            Point2I location = RoomControl.GetTileLocation(position);

            if (RoomControl.IsTileInBounds(location))
            {
                Tile tile = RoomControl.GetTopTile(location);
                if (tile != null)
                {
                    tile.OnBurn();
                }
            }
            Destroy();
        }
示例#8
0
        public override void OnLand()
        {
            base.OnLand();

            // Notify the tile we landed on.
            Tile tile = RoomControl.GetTopTile(RoomControl.GetTileLocation(Position));

            if (tile != null)
            {
                tile.OnLand(movement.JumpStartTile);
            }
            movement.JumpStartTile = -Point2I.One;

            if (eventLand != null)
            {
                eventLand(this);
            }

            Physics.Gravity = GameSettings.DEFAULT_GRAVITY;
            AudioSystem.PlaySound(GameData.SOUND_PLAYER_LAND);
        }
示例#9
0
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------

        private void PerformDig(PlayerState state)
        {
            // Look for tiles to dig up.
            float    distance = 6.5f;
            Vector2F center   = Player.Center;

            if (Directions.IsVertical(Player.Direction))
            {
                distance = 7.5f;
            }
            else
            {
                center.Y += 4.0f;
            }
            Vector2F hotspot = GMath.Round(center) + (Directions.ToVector(Player.Direction) * distance);
            Point2I  tileLoc = RoomControl.GetTileLocation(hotspot);

            if (!RoomControl.IsTileInBounds(tileLoc))
            {
                return;
            }

            Tile tile = RoomControl.GetTopTile(tileLoc);

            if (tile != null && tile.OnDig(Player.Direction))
            {
                // Spawn dirt effect.
                Effect effect = new Effect();
                effect.Graphics.DepthLayer = DepthLayer.EffectDirt;
                effect.CreateDestroyTimer(15);
                effect.EnablePhysics(PhysicsFlags.HasGravity);
                effect.Physics.Velocity         = Directions.ToVector(Player.Direction) * 0.5f;
                effect.Graphics.IsShadowVisible = false;
                effect.Graphics.PlayAnimation(GameData.ANIM_EFFECT_DIRT);
                effect.Graphics.SubStripIndex = Player.Direction;
                if (Directions.IsHorizontal(Player.Direction))
                {
                    effect.Physics.ZVelocity = 3.0f;
                    effect.Physics.Gravity   = 0.5f;
                }
                else
                {
                    effect.Physics.ZVelocity = 2.5f;
                    effect.Physics.Gravity   = 0.4f;
                }
                RoomControl.SpawnEntity(effect, tile.Center);


                AudioSystem.PlaySound(GameData.SOUND_SHOVEL);
            }
            else
            {
                AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING);
            }

            // Check for monster interactions.
            Rectangle2I shovelHitBox = new Rectangle2I(-4, -4, 8, 8);

            shovelHitBox.Point += (Point2I)Player.CenterOffset;
            shovelHitBox.ExtendEdge(Player.Direction, 7);
            foreach (Monster monster in Player.Physics.GetEntitiesMeeting <Monster>(shovelHitBox, CollisionBoxType.Soft))
            {
                monster.TriggerInteraction(InteractionType.Shovel, Player);
            }
        }
示例#10
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();
        }