added random asteroid sizes and travel dir

main
RedStealthDev 2 years ago
parent 83e40b6f0f
commit c313194009

@ -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);

36
UI.cs

@ -15,12 +15,29 @@ public class Scenes
private List<Button> Buttons;
public bool wait;
private bool mwait;
private RenderTarget2D blackborder;
public Scenes(Game1 Game, SpriteBatch _spriteBatch)
{
GU = GU = new gameui(Game.Content.Load<Texture2D>("background"), Game.PL);
this._spriteBatch = _spriteBatch;
this.Game = Game;
Buttons = new List<Button>();
blackborder = new RenderTarget2D(_spriteBatch.GraphicsDevice, (int)vars.ScreenSize.X, (int)vars.ScreenSize.Y);
Rectangle[] box = new Rectangle[]{
new Rectangle(0, 0, (int)vars.ScreenSize.X, vars.PlayArea.Y),
new Rectangle(0, 0, vars.PlayArea.X, (int)vars.ScreenSize.Y),
new Rectangle(0, vars.PlayArea.Bottom, (int)vars.ScreenSize.X, (int)vars.ScreenSize.Y-vars.PlayArea.Bottom),
new Rectangle(vars.PlayArea.Right, 0, (int)vars.ScreenSize.X-vars.PlayArea.Right, (int)vars.ScreenSize.Y),
};
_spriteBatch.GraphicsDevice.SetRenderTarget(blackborder);
_spriteBatch.GraphicsDevice.Clear(Color.Transparent);
_spriteBatch.Begin();
foreach(var item in box)
{
_spriteBatch.Draw(vars.ThePixel, item, null, Color.Black);
}
_spriteBatch.End();
_spriteBatch.GraphicsDevice.SetRenderTarget(null);
initscenes();
}
public void draw(GameTime gameTime)
@ -111,8 +128,8 @@ public class Scenes
GU.draw(_spriteBatch);
Game.PL.Draw(_spriteBatch, gameTime);
Game.AS.Draw(_spriteBatch, gameTime);
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.X, vars.PlayArea.Bottom, vars.PlayArea.Width, (int)vars.ScreenSize.Y - vars.PlayArea.Bottom), null, Color.Black);
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.X, 0, vars.PlayArea.Width, vars.PlayArea.Y), null, Color.Black);
_spriteBatch.Draw(blackborder, Vector2.Zero, null, Color.White);
GU.draw(_spriteBatch);
_spriteBatch.End();
}
public void U1(GameTime gameTime)
@ -138,8 +155,8 @@ public class Scenes
item.draw(_spriteBatch);
}
}
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.X, vars.PlayArea.Bottom, vars.PlayArea.Width, (int)vars.ScreenSize.Y - vars.PlayArea.Bottom), null, Color.Black);
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.X, 0, vars.PlayArea.Width, vars.PlayArea.Y), null, Color.Black);
_spriteBatch.Draw(blackborder, Vector2.Zero, null, Color.White);
GU.draw(_spriteBatch);
_spriteBatch.End();
}
public void U2()
@ -182,6 +199,7 @@ public class gameui
public Texture2D Background;
private float bgY;
private Player PL;
private int layer;
public gameui(Texture2D bg, Player PL)
{
this.Background = bg;
@ -203,8 +221,13 @@ public class gameui
bgY = vars.PlayArea.Y;
}
//the boxes
_spriteBatch.Draw(Background, new Rectangle(vars.PlayArea.X, (int)bgY, vars.PlayArea.Width, vars.PlayArea.Height), null, Color.White);
_spriteBatch.Draw(Background, new Rectangle(vars.PlayArea.X, (int)bgY - vars.PlayArea.Height, vars.PlayArea.Width, vars.PlayArea.Height), null, Color.White);
if(layer == 0)
{
_spriteBatch.Draw(Background, new Rectangle(vars.PlayArea.X, (int)bgY, vars.PlayArea.Width, vars.PlayArea.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0);
_spriteBatch.Draw(Background, new Rectangle(vars.PlayArea.X, (int)bgY - vars.PlayArea.Height, vars.PlayArea.Width, vars.PlayArea.Height), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0);
layer++;
return;
}
_spriteBatch.Draw(vars.ThePixel, new Rectangle(50, 50, vars.PlayArea.X - 100, (int)vars.ScreenSize.Y - 100), null, new Color(dimnes, dimnes, dimnes));
Rectangle rightbox = new Rectangle(vars.PlayArea.Right + 50, 50, (int)vars.ScreenSize.X - vars.PlayArea.Right - 100, (int)vars.ScreenSize.Y - 100);
_spriteBatch.Draw(vars.ThePixel, rightbox, null, new Color(dimnes, dimnes, dimnes));
@ -247,5 +270,6 @@ public class gameui
_spriteBatch.DrawString(vars.Font, "Current Nr: " + AudioEn.cursong, new Vector2(musice.Center.X - vars.Font.MeasureString("Current Nr: " + AudioEn.cursong).X/2, musice.Center.Y - vars.Font.MeasureString("Current Nr: " + AudioEn.cursong).Y/2), Color.RoyalBlue);
string time = AudioEn.playedtime.ToString().Remove(0, 3).Remove(5) + " / " + AudioEn.songtime.ToString().Remove(0, 3).Remove(5);
_spriteBatch.DrawString(vars.Font, time, new Vector2(musice.Center.X - vars.Font.MeasureString(time).X/2, musice.Bottom-vars.Font.MeasureString(time).Y-25), Color.RoyalBlue);
layer = 0;
}
}

@ -7,4 +7,4 @@ build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = Asteroids
build_property.ProjectDir = e:\Repos\Asteroids\
build_property.ProjectDir = E:\Repos\Asteroids\

Loading…
Cancel
Save