summaryrefslogtreecommitdiff
path: root/Penguloon/Objects/ObjectBase.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Penguloon/Objects/ObjectBase.cs')
-rw-r--r--Penguloon/Objects/ObjectBase.cs60
1 files changed, 53 insertions, 7 deletions
diff --git a/Penguloon/Objects/ObjectBase.cs b/Penguloon/Objects/ObjectBase.cs
index 9834b39..a16f70c 100644
--- a/Penguloon/Objects/ObjectBase.cs
+++ b/Penguloon/Objects/ObjectBase.cs
@@ -15,6 +15,7 @@ namespace Penguloon.Objects
public float Range { get; set; }
public Texture2D Texture { get; set; }
+ public Texture2D RangeCircle { get; set; }
public float Rotation { get; set; }
public Vector2 Position { get; set; }
@@ -34,19 +35,31 @@ namespace Penguloon.Objects
{
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++)
+ // loop from back of list to front so we always focus the balloons in front
+ for (int i = Map.Enemies.Count - 1; i >= 0; i--)
{
- if (Contains(Map.Enemies[i].Box.Location.ToVector2()))
+ 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;
+ UpdateUnique(deltaTime);
+ }
}
+ public abstract void UpdateUnique(float deltaTime);
+
public void Draw(float deltaTime)
{
- float rotation = ((Rotation));
+ if(RangeCircle == null)
+ RangeCircle = CreateCircle((int)Range * 2);
+
+ float rot = (float)Rotation + (float)MathHelper.PiOver2;
Rectangle rec = new Rectangle(
(int)Position.X + ((int)(Map.TileWidth * TileSpanX)) / 2,
@@ -56,20 +69,53 @@ namespace Penguloon.Objects
Map.ParentScene.Main.SpriteBatch.Draw(Texture,
destinationRectangle: rec,
- rotation: rotation,
+ rotation: (float)rot,
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);
+ 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);
+
+ private Texture2D CreateCircle(int radius)
+ {
+ Texture2D texture = new Texture2D(Map.ParentScene.Main.GraphicsDevice, radius, radius);
+ Color[] colorData = new Color[radius * radius];
+
+ float diam = radius / 2f;
+ float diamsq = diam * diam;
+
+ for (int x = 0; x < radius; x++)
+ {
+ for (int y = 0; y < radius; y++)
+ {
+ int index = x * radius + y;
+ Vector2 pos = new Vector2(x - diam, y - diam);
+ if (pos.LengthSquared() <= diamsq)
+ {
+ colorData[index] = Color.FromNonPremultiplied(200, 0, 0, 50);
+ }
+ else
+ {
+ colorData[index] = Color.Transparent;
+ }
+ }
+ }
+
+ texture.SetData(colorData);
+ return texture;
}
private double GetRotation(Vector2 enemyPos)
{
double radians = Math.Atan2(enemyPos.Y - Center.Y, enemyPos.X - Center.X);
- return (radians / MathHelper.PiOver2) * MathHelper.Pi;
+ return (radians);
}
- // The concise version...
private bool Contains(Vector2 point)
{
return ((point - Center).Length() <= Range);