From c313194009af372caad1d7c0c53331d1961b71ce Mon Sep 17 00:00:00 2001 From: RedStealthDev Date: Tue, 6 Dec 2022 12:55:24 +0100 Subject: [PATCH] added random asteroid sizes and travel dir --- Asteroids.cs | 20 +++++++---- UI.cs | 36 +++++++++++++++---- ....GeneratedMSBuildEditorConfig.editorconfig | 2 +- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/Asteroids.cs b/Asteroids.cs index ef2c6d2..846f614 100644 --- a/Asteroids.cs +++ b/Asteroids.cs @@ -49,7 +49,7 @@ public class AllAst if (wait <= 0) { Random r = new Random(); - float maxpoints = 10000f; + float maxpoints = 1000f; float t = ((float)vars.Points/maxpoints); wait = r.Next((int)MathHelper.Lerp(120, 10, t), (int)MathHelper.Lerp(300, 60, t)); As.Add(new asteroid(asTextures[r.Next(asTextures.Length)], _spriteBatch)); @@ -68,13 +68,14 @@ public class AllAst EX.Add(new Explosion(ase.Rect)); return true; } - if (ase.Rect.Intersects(PL.Rect)) + Rectangle cent = new Rectangle(ase.Rect.X - ase.Rect.Width / 2, ase.Rect.Y -ase.Rect.Height / 2, ase.Rect.Width, ase.Rect.Height); + if (cent.Intersects(PL.Rect)) { PL.Health--; EX.Add(new Explosion(ase.Rect)); return true; } - if (ase.Rect.Top >= vars.PlayArea.Bottom) + if (!cent.Intersects(vars.PlayArea)) { return true; } @@ -128,24 +129,29 @@ public class asteroid public float rots; public int Health; public hpbar bar; + private float size; + private int flydir; public asteroid(Texture2D Texture, SpriteBatch _spriteBatch) { this.Texture = Texture; Random r = new Random(); speed = (float)((float)r.Next(5, 30) / 10f); rots = (float)((float)r.Next(5, 30) / 10f); + flydir = r.Next(-25, 25); pos = new Vector2(r.Next(vars.PlayArea.X, vars.PlayArea.Right-Texture.Width), 100); Health = r.Next(5, 15); - Rect = new Rectangle((int)pos.X, (int)pos.Y, Texture.Width, Texture.Height); + size = (float)((float)r.Next(50, 300)/100f); + Rect = new Rectangle((int)pos.X, (int)pos.Y, (int)(Texture.Width*size), (int)(Texture.Height*size)); bar = new hpbar(Health, _spriteBatch.GraphicsDevice); } public void Draw(SpriteBatch _spriteBatch) { + Vector2 e = new Vector2(MathF.Cos(MathHelper.ToRadians(flydir)+1.5707963268f) * speed, MathF.Sin(MathHelper.ToRadians(flydir)+1.5707963268f) * speed); rot += rots; - pos.Y += speed; + pos += e; bar.pos = new Vector2(Rect.Center.X, Rect.Center.Y); - Rect = new Rectangle((int)pos.X, (int)pos.Y, Texture.Width, Texture.Height); - _spriteBatch.Draw(Texture, Rect.Center.ToVector2(), null, Color.White, MathHelper.ToRadians(rot), new Vector2(Rect.Width / 2, Rect.Height / 2), Vector2.One, SpriteEffects.None, 0f); + Rect = new Rectangle((int)pos.X, (int)pos.Y, Rect.Width, Rect.Height); + _spriteBatch.Draw(Texture, Rect.Center.ToVector2(), null, Color.White, MathHelper.ToRadians(rot), new Vector2(Texture.Width / 2, Texture.Height / 2), new Vector2(size, size), SpriteEffects.None, 0f); if(bar.max != Health) { bar.Draw(_spriteBatch, Health); diff --git a/UI.cs b/UI.cs index 577966b..c1e940f 100644 --- a/UI.cs +++ b/UI.cs @@ -15,12 +15,29 @@ public class Scenes private List