public override void OnHit(GameObject hitObject) { if (hitObject is Player) { if (RandomGenerator.GetRandom(0, 100) < PROB_LIFE) { ExtraLife extraLife = (ExtraLife)ItemPickableManager.GetItem(PickableType.ExtraLife); extraLife.IsActive = true; extraLife.Position = Position; extraLife.OnPlayerPick(); } else { int randomApples = RandomGenerator.GetRandom(MIN_APPLE, MAX_APPLE + 1); List <Pickable> apples = ItemPickableManager.GetItems(PickableType.Apple, randomApples); Vector2 offsetBetweenApples = Vector2.Zero; for (int i = 0; i < apples.Count; i++) { Apple apple = (Apple)apples[i]; apple.IsActive = true; apple.Position = Position + offsetBetweenApples; offsetBetweenApples += new Vector2(apple.Width / 3, apple.Height / 2); apple.OnPlayerPick(); } } } base.OnHit(hitObject); }
private void Bounce(Player player) { if (audioSourceBounce == null) { audioSourceBounce = new AudioSource(); } if (!audioSourceBounce.IsPlaying) { audioSourceBounce.Play(clipBounce); } Animation.Reset(); Animation.NextFrame(); player.Jump(bounceMultiplierY); apples -= NUM_APPLES_AT_BOUNCE; List <Pickable> appleList = ItemPickableManager.GetItems(PickableType.Apple, NUM_APPLES_AT_BOUNCE); Vector2 offset = Vector2.Zero; foreach (Apple apple in appleList) { apple.IsActive = true; apple.Position = Position + offset; apple.OnPlayerPick(); offset += new Vector2((apple.Width * 2) / NUM_APPLES_AT_BOUNCE, (apple.Height * 2) / NUM_APPLES_AT_BOUNCE); } if (apples <= 0) { OnDie(); } }