using System; using System.Collections.Generic; using System.Linq; using System.Text; using IceCream.Components; using IceCream.Attributes; using Microsoft.Xna.Framework; using IceCream; using Microsoft.Xna.Framework.Graphics; using IceCream.SceneItems; using IceCream.SceneItems.AnimationClasses; using IceCream1945.Global; namespace IceCream1945.Components { [IceComponentAttribute("BulletComponent")] public class BulletComponent : IceComponent { [IceComponentProperty("Can Damage Player")] public bool CanDamagePlayer { get; set; } [IceComponentProperty("Can Damange Enemies")] public bool CanDamageEnemy { get; set; } public BulletComponent() { } public override void CopyValuesTo(object target) { base.CopyValuesTo(target); if (target is BulletComponent) { BulletComponent targetCom = target as BulletComponent; targetCom.CanDamagePlayer = this.CanDamagePlayer; targetCom.CanDamageEnemy = this.CanDamageEnemy; } } public override void OnRegister() { Enabled = true; } public override void Update(float elapsedTime) { //We get all scene items ( not recommended in bigger games, at least not every frame) for (int i=0; i < GlobalGameData.ActiveSceneItems.Count; ++i) { SceneItem si = GlobalGameData.ActiveSceneItems[i]; if (si != Owner && (si.GetType() == typeof(Sprite) || si.GetType() == typeof(AnimatedSprite)) && !Owner.MarkForDelete) { if (CanDamageEnemy) { if (si.CheckType(2) && Owner.BoundingRect.Intersects(si.BoundingRect)) { si.MarkForDelete = true; Owner.MarkForDelete = true; GlobalGameData.ActiveSceneItems.Remove(si); GlobalGameData.ActiveSceneItems.Remove(Owner); --i; AnimatedSprite explosion = Owner.SceneParent.CreateCopy<AnimatedSprite>("BigExplosion"); explosion.Visible = true; explosion.Position = si.Position; explosion.PositionX += si.BoundingRectSize.X / 2; explosion.PositionY += si.BoundingRectSize.Y / 2; explosion.CurrentAnimation.LoopMax = 1; explosion.CurrentAnimation.HideWhenStopped = true; Owner.SceneParent.RegisterSceneItem(explosion); GlobalGameData.PlayerOnePointTracking.AddScore(50); Sound.Play(Sound.ExplosionHit); } } if (CanDamagePlayer) { if (Owner.BoundingRect.Intersects(GlobalGameData.PlayerAnimatedSprite.BoundingRect)) { --GlobalGameData.PlayerHealth; Owner.MarkForDelete = true; GlobalGameData.ScreenDamageEffect.Reset();//if the player is getting bombarded, we want many flashes GlobalGameData.ScreenDamageEffect.Play(); Sound.Play(Sound.Quick_Hit); } } } } } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)