using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Penguloon.Objects; using System; namespace Penguloon.Projectiles { public abstract class ProjectileBase { public Vector2 Position { get; set; } public Vector2 Size { get; set; } public float RotationAngle { get; set; } public float RotationSpeed { get; set; } public float Rotation { get; set; } public float Speed { get; set; } public int MaxBalloonPops { get; set; } public int BaloonsPopped { get; set; } = 0; public Texture2D Texture { get; set; } public ObjectBase ParentObject { get; set; } public ProjectileBase(ObjectBase ParentObject, float RotationAngle) { this.ParentObject = ParentObject; this.RotationAngle = RotationAngle; } public void Draw(float deltaTime) { Rectangle rec = new Rectangle(new Point((int)Position.X + (int)Size.X / 2, (int)Position.Y + (int)Size.Y / 2), Size.ToPoint()); if(Texture != null) ParentObject.Map.Level.ParentScene.Main.SpriteBatch.Draw(Texture, destinationRectangle: rec, rotation: Rotation, origin: new Vector2(Texture.Width / 2, Texture.Height / 2)); } public void Update(float deltaTime) { Rotation += RotationSpeed * deltaTime; Vector2 direction = new Vector2((float)Math.Cos(RotationAngle), (float)Math.Sin(RotationAngle)); direction.Normalize(); Position += direction * Speed * deltaTime; CheckForCollion(); } private void CheckForCollion() { Rectangle projectileRec = new Rectangle(Position.ToPoint(), Size.ToPoint()); for(int i = 0; i < ParentObject.Map.Enemies.Count; i++) { try { if (ParentObject.Map.Enemies[i] != null) if (ParentObject.Map.Enemies[i].Dead) continue; if (projectileRec.Intersects(ParentObject.Map.Enemies[i].Box)) { ParentObject.Map.Enemies[i].GetHit(); this.BaloonsPopped++; // Remove object if it has hit maximum amount of targets if (BaloonsPopped >= MaxBalloonPops) { ParentObject.Projectiles.Remove(this); return; } } } catch { } } } } }