summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraldrikboy <aldrikboy@gmail.com>2018-01-17 21:11:18 +0100
committeraldrikboy <aldrikboy@gmail.com>2018-01-17 21:11:18 +0100
commitaa6972a5d052d1f57dfda3dadb79fcd5d8ded30b (patch)
tree551c536bcce4bbee415fe20c48a911e152019983
parent2185c2d45506c8b0d4e95000b82bc50859c663b7 (diff)
optimization
-rw-r--r--Penguloon/Content/Content.mgcb12
-rw-r--r--Penguloon/Content/UI/circle.pngbin0 -> 7667 bytes
-rw-r--r--Penguloon/Levels/LevelBase.cs41
-rw-r--r--Penguloon/Levels/Map.cs11
-rw-r--r--Penguloon/Objects/ObjectBase.cs37
5 files changed, 34 insertions, 67 deletions
diff --git a/Penguloon/Content/Content.mgcb b/Penguloon/Content/Content.mgcb
index ceea1e6..36eaa5e 100644
--- a/Penguloon/Content/Content.mgcb
+++ b/Penguloon/Content/Content.mgcb
@@ -1015,3 +1015,15 @@
/processorParam:TextureFormat=Color
/build:SplashArt/5.png
+#begin UI/circle.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:MakeSquare=False
+/processorParam:TextureFormat=Color
+/build:UI/circle.png
+
diff --git a/Penguloon/Content/UI/circle.png b/Penguloon/Content/UI/circle.png
new file mode 100644
index 0000000..db22208
--- /dev/null
+++ b/Penguloon/Content/UI/circle.png
Binary files differ
diff --git a/Penguloon/Levels/LevelBase.cs b/Penguloon/Levels/LevelBase.cs
index a9340b2..f2d8234 100644
--- a/Penguloon/Levels/LevelBase.cs
+++ b/Penguloon/Levels/LevelBase.cs
@@ -121,7 +121,7 @@ namespace Penguloon.Levels
Rectangle rangeCircleRec = new Rectangle(tilePos.X - ((rangeWidth - objWidth) / 2), tilePos.Y - ((rangeHeight - objHeight) / 2), rangeWidth, rangeHeight);
if (obj.RangeCircle == null)
- obj.RangeCircle = obj.CreateCircle((int)obj.Range * 2);
+ obj.RangeCircle = ContentManager.GetTexture("UI/circle");
if (obj.RangeCircle != null)
Map.ParentScene.Main.SpriteBatch.Draw(obj.RangeCircle,
@@ -228,45 +228,28 @@ namespace Penguloon.Levels
int tileX = (int)touchLocations[i].Position.X / Map.TileWidth;
int tileY = (int)touchLocations[i].Position.Y / Map.TileHeight;
- if (Map.TileMap[tileY, tileX].Direction != Direction.None)
- {
- ParentScene.ObjectSeletor.State = Controls.State.Idle;
- ParentScene.ObjectSeletor.SelectedObjectIndex = -1;
- return;
- }
-
int posToSpawnX = tileX * Map.TileWidth;
int posToSpawnY = tileY * Map.TileHeight;
- List<Vector2> spawnPosToCheck = new List<Vector2>();
- for(int x = 0; x < ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1.TileSpanX; x++)
- {
- for (int y = 0; y < ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1.TileSpanY; y++)
- {
- spawnPosToCheck.Add(new Vector2(posToSpawnX + (Map.TileWidth * x), posToSpawnY + (Map.TileHeight * y)));
- }
- }
+ Rectangle objectToPlaceRect = new Rectangle(posToSpawnX, posToSpawnY,
+ ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1.TileSpanX * Map.TileWidth,
+ ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1.TileSpanY * Map.TileHeight);
// check if there isnt an object already
for (int x = 0; x < Map.Objects.Count; x++)
{
- for (int px = 0; px < Map.Objects[x].TileSpanX; px++)
+ Rectangle objRec = new Rectangle((int)Map.Objects[x].Position.X, (int)Map.Objects[x].Position.Y,
+ Map.Objects[x].TileSpanX * Map.TileWidth, Map.Objects[x].TileSpanY * Map.TileHeight);
+
+ if (objRec.Intersects(objectToPlaceRect))
{
- for (int py = 0; py < Map.Objects[x].TileSpanY; py++)
- {
- Vector2 posToCheck = Map.Objects[x].Position + new Vector2(px * Map.TileWidth, py * Map.TileHeight);
-
- for (int t = 0; t < spawnPosToCheck.Count; t++)
- if (posToCheck == spawnPosToCheck[t])
- {
- ParentScene.ObjectSeletor.State = Controls.State.Idle;
- ParentScene.ObjectSeletor.SelectedObjectIndex = -1;
- return;
- }
- }
+ ParentScene.ObjectSeletor.State = Controls.State.Idle;
+ ParentScene.ObjectSeletor.SelectedObjectIndex = -1;
+ return;
}
}
+
// check if it isnt touching any walkable tiles
for (int px = 0; px < ParentScene.ObjectSeletor.Objects[ParentScene.ObjectSeletor.SelectedObjectIndex].Item1.TileSpanX; px++)
{
diff --git a/Penguloon/Levels/Map.cs b/Penguloon/Levels/Map.cs
index 362b1ba..43a701e 100644
--- a/Penguloon/Levels/Map.cs
+++ b/Penguloon/Levels/Map.cs
@@ -7,6 +7,7 @@ using System;
using Penguloon.Objects;
using Penguloon.Controls;
using System.Linq;
+using System.Threading;
namespace Penguloon.Levels
{
@@ -157,18 +158,16 @@ namespace Penguloon.Levels
{
for (int i = 0; i < Enemies.Count; i++)
{
- try
- {
- if (Enemies[i] != null)
- Enemies[i].Update(deltaTime);
- }
- catch { }
+
+ if (Enemies[i] != null)
+ Enemies[i].Update(deltaTime);
}
if (ParentScene.Level.Finished) return;
for (int i = 0; i < Objects.Count; i++)
{
+ if (Objects[i] != null)
Objects[i].Update(deltaTime);
}
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);