diff options
Diffstat (limited to 'Penguloon/Objects')
| -rw-r--r-- | Penguloon/Objects/ObjectBase.cs | 78 | ||||
| -rw-r--r-- | Penguloon/Objects/PenguinObject.cs | 16 |
2 files changed, 94 insertions, 0 deletions
diff --git a/Penguloon/Objects/ObjectBase.cs b/Penguloon/Objects/ObjectBase.cs new file mode 100644 index 0000000..9834b39 --- /dev/null +++ b/Penguloon/Objects/ObjectBase.cs @@ -0,0 +1,78 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Penguloon.Levels; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Penguloon.Objects +{ + public abstract class ObjectBase + { + public int AttackSpeedMS { get; set; } + public DateTime LastAttack { get; set; } + + public float Range { get; set; } + + public Texture2D Texture { get; set; } + public float Rotation { get; set; } + + public Vector2 Position { get; set; } + public Vector2 Center { get; set; } + public int TileSpanX { get; set; } + public int TileSpanY { get; set; } + + public Map Map { get; set; } + + public ObjectBase(Vector2 position, Map map) + { + this.Map = map; + this.Position = position; + } + + public void Update(float deltaTime) + { + this.Center = new Vector2(Position.X + ((TileSpanX * Map.TileWidth) / 2), Position.Y + ((TileSpanY * Map.TileHeight) / 2)); + + for (int i = 0; i < Map.Enemies.Count; i++) + { + if (Contains(Map.Enemies[i].Box.Location.ToVector2())) + { + Rotation = (float)GetRotation(Map.Enemies[i].Box.Center.ToVector2()); + return; + } + } + } + + public void Draw(float deltaTime) + { + float rotation = ((Rotation)); + + Rectangle rec = new Rectangle( + (int)Position.X + ((int)(Map.TileWidth * TileSpanX)) / 2, + (int)Position.Y + ((int)(Map.TileHeight * TileSpanY)) / 2, + Map.TileWidth * TileSpanX, + Map.TileHeight * TileSpanY); + + Map.ParentScene.Main.SpriteBatch.Draw(Texture, + destinationRectangle: rec, + rotation: rotation, + origin: new Vector2(Texture.Width / 2, Texture.Height / 2)); + + Map.ParentScene.Main.SpriteBatch.DrawString(ContentManager.GetFont("Fonts/GWENT/24"), Rotation.ToString(), rec.Location.ToVector2(), Color.Red); + } + + private double GetRotation(Vector2 enemyPos) + { + double radians = Math.Atan2(enemyPos.Y - Center.Y, enemyPos.X - Center.X); + + return (radians / MathHelper.PiOver2) * MathHelper.Pi; + } + + // The concise version... + private bool Contains(Vector2 point) + { + return ((point - Center).Length() <= Range); + } + } +}
\ No newline at end of file diff --git a/Penguloon/Objects/PenguinObject.cs b/Penguloon/Objects/PenguinObject.cs new file mode 100644 index 0000000..e035f70 --- /dev/null +++ b/Penguloon/Objects/PenguinObject.cs @@ -0,0 +1,16 @@ +using Microsoft.Xna.Framework; +using Penguloon.Levels; + +namespace Penguloon.Objects +{ + class PenguinObject : ObjectBase + { + public PenguinObject(Vector2 position, Map map) : base(position, map) + { + this.Texture = ContentManager.GetTexture("Objects/penguin1"); + this.TileSpanX = 1; + this.TileSpanY = 1; + this.Range = Map.TileWidth * 2; + } + } +}
\ No newline at end of file |
