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/Objects/ObjectBase.cs | |
| parent | 98fb0bdcf3fb02f68f07a72cab211debb827e978 (diff) | |
New balloons & sounds. Objects can now shoot projectiles.
Diffstat (limited to 'Penguloon/Objects/ObjectBase.cs')
| -rw-r--r-- | Penguloon/Objects/ObjectBase.cs | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/Penguloon/Objects/ObjectBase.cs b/Penguloon/Objects/ObjectBase.cs index a16f70c..c72788e 100644 --- a/Penguloon/Objects/ObjectBase.cs +++ b/Penguloon/Objects/ObjectBase.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Penguloon.Levels; +using Penguloon.Projectiles; using System; using System.Collections.Generic; using System.Linq; @@ -23,8 +24,12 @@ namespace Penguloon.Objects public int TileSpanX { get; set; } public int TileSpanY { get; set; } + public List<ProjectileBase> Projectiles { get; set; } = new List<ProjectileBase>(); + public Map Map { get; set; } + public Rectangle Box { get; set; } + public ObjectBase(Vector2 position, Map map) { this.Map = map; @@ -41,18 +46,25 @@ namespace Penguloon.Objects if (Contains(Map.Enemies[i].Box.Center.ToVector2())) { Rotation = (float)GetRotation(Map.Enemies[i].Box.Center.ToVector2()); - return; + + if ((DateTime.Now - LastAttack).TotalMilliseconds > AttackSpeedMS) + { + LastAttack = DateTime.Now; + SpawnUnique(); + } + + break; } } - if ((DateTime.Now - LastAttack).TotalMilliseconds > AttackSpeedMS) - { - LastAttack = DateTime.Now; - UpdateUnique(deltaTime); - } + for (int i = 0; i < Projectiles.Count; i++) + Projectiles[i].Update(deltaTime); + + UpdateUnique(deltaTime); } public abstract void UpdateUnique(float deltaTime); + public abstract void SpawnUnique(); public void Draw(float deltaTime) { @@ -67,6 +79,13 @@ namespace Penguloon.Objects Map.TileWidth * TileSpanX, Map.TileHeight * TileSpanY); + // Draw projectiles before drawing the object + for (int i = 0; i < Projectiles.Count; i++) + Projectiles[i].Draw(deltaTime); + + DrawUnique(deltaTime); + + // Draw object Map.ParentScene.Main.SpriteBatch.Draw(Texture, destinationRectangle: rec, rotation: (float)rot, @@ -74,8 +93,6 @@ namespace Penguloon.Objects Map.ParentScene.Main.SpriteBatch.Draw(RangeCircle, destinationRectangle: new Rectangle((int)rec.X - ((int)Range), (int)rec.Y - ((int)Range), (int)Range * 2, (int)Range * 2)); - - DrawUnique(deltaTime); } public abstract void DrawUnique(float deltaTime); |
