From aa6972a5d052d1f57dfda3dadb79fcd5d8ded30b Mon Sep 17 00:00:00 2001 From: aldrikboy Date: Wed, 17 Jan 2018 21:11:18 +0100 Subject: optimization --- Penguloon/Objects/ObjectBase.cs | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) (limited to 'Penguloon/Objects/ObjectBase.cs') diff --git a/Penguloon/Objects/ObjectBase.cs b/Penguloon/Objects/ObjectBase.cs index d1ed0d4..19a222c 100644 --- a/Penguloon/Objects/ObjectBase.cs +++ b/Penguloon/Objects/ObjectBase.cs @@ -56,11 +56,15 @@ namespace Penguloon.Objects this.Position = position; CreateUpgrades(); + + RangeCircle = ContentManager.GetTexture("UI/circle"); } public ObjectBase(Map map) { this.Map = map; + + RangeCircle = ContentManager.GetTexture("UI/circle"); } public virtual void CreateUpgrades() @@ -151,9 +155,6 @@ namespace Penguloon.Objects public void Draw(float deltaTime) { - if(RangeCircle == null) - RangeCircle = CreateCircle((int)Range * 2); - float rot = (float)Rotation + (float)MathHelper.PiOver2; if (!ShouldRotate) @@ -199,35 +200,7 @@ namespace Penguloon.Objects public abstract void DrawUnique(float deltaTime); - public 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); -- cgit v1.2.3-70-g09d2