diff options
| author | aldrikboy <aldrikboy@gmail.com> | 2017-12-14 23:35:47 +0100 |
|---|---|---|
| committer | aldrikboy <aldrikboy@gmail.com> | 2017-12-14 23:35:47 +0100 |
| commit | a42938d1553565e3d864fa46c04401bbb6f8d13f (patch) | |
| tree | 24a24a3bd7eb01607c30e176ee0fcaf4e912a277 /Penguloon/Projectiles | |
| parent | 98fb0bdcf3fb02f68f07a72cab211debb827e978 (diff) | |
New balloons & sounds. Objects can now shoot projectiles.
Diffstat (limited to 'Penguloon/Projectiles')
| -rw-r--r-- | Penguloon/Projectiles/ProjectileBase.cs | 80 | ||||
| -rw-r--r-- | Penguloon/Projectiles/SnowballProjectile.cs | 23 |
2 files changed, 103 insertions, 0 deletions
diff --git a/Penguloon/Projectiles/ProjectileBase.cs b/Penguloon/Projectiles/ProjectileBase.cs new file mode 100644 index 0000000..4221569 --- /dev/null +++ b/Penguloon/Projectiles/ProjectileBase.cs @@ -0,0 +1,80 @@ +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++) + { + 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; + } + } + } + } + } +}
\ No newline at end of file diff --git a/Penguloon/Projectiles/SnowballProjectile.cs b/Penguloon/Projectiles/SnowballProjectile.cs new file mode 100644 index 0000000..9f72794 --- /dev/null +++ b/Penguloon/Projectiles/SnowballProjectile.cs @@ -0,0 +1,23 @@ +using Microsoft.Xna.Framework; +using Penguloon.Objects; + +namespace Penguloon.Projectiles +{ + public class SnowballProjectile : ProjectileBase + { + public SnowballProjectile(ObjectBase ParentObject, float RotationAngle) : base(ParentObject, RotationAngle) + { + this.Texture = ContentManager.GetTexture("Bullets/penguin-ammo"); + this.Speed = 250f; + this.RotationSpeed = 5f; + this.Size = new Vector2(ParentObject.Map.TileWidth / 2, ParentObject.Map.TileHeight / 2); + this.MaxBalloonPops = 1; + + Rectangle parentRec = new Rectangle(ParentObject.Position.ToPoint(), + new Point(ParentObject.TileSpanX * ParentObject.Map.TileWidth, ParentObject.TileSpanY * ParentObject.Map.TileHeight)); + + this.Position = new Vector2(ParentObject.Position.X + (parentRec.Width / 2) - (Size.X / 2), + ParentObject.Position.Y + (parentRec.Height / 2) - (Size.Y / 2)); + } + } +}
\ No newline at end of file |
