diff options
Diffstat (limited to 'Penguloon/Objects')
| -rw-r--r-- | Penguloon/Objects/ObjectBase.cs | 33 | ||||
| -rw-r--r-- | Penguloon/Objects/PenguinObject.cs | 12 |
2 files changed, 35 insertions, 10 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); diff --git a/Penguloon/Objects/PenguinObject.cs b/Penguloon/Objects/PenguinObject.cs index 14ad30a..adbdc7e 100644 --- a/Penguloon/Objects/PenguinObject.cs +++ b/Penguloon/Objects/PenguinObject.cs @@ -1,5 +1,7 @@ using Microsoft.Xna.Framework; using Penguloon.Levels; +using Penguloon.Projectiles; +using System.Collections.Generic; namespace Penguloon.Objects { @@ -11,16 +13,22 @@ namespace Penguloon.Objects this.TileSpanX = 1; this.TileSpanY = 1; this.Range = Map.TileWidth * 2; + this.AttackSpeedMS = 1000; } public override void DrawUnique(float deltaTime) { - + } public override void UpdateUnique(float deltaTime) { - + + } + + public override void SpawnUnique() + { + Projectiles.Add(new SnowballProjectile(this, this.Rotation)); } } }
\ No newline at end of file |
