You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
251 lines
11 KiB
251 lines
11 KiB
2 years ago
|
using Microsoft.Xna.Framework;
|
||
|
using Microsoft.Xna.Framework.Graphics;
|
||
|
using Microsoft.Xna.Framework.Input;
|
||
|
using System.Collections.Generic;
|
||
|
using System;
|
||
|
|
||
|
namespace Asteroids;
|
||
|
|
||
|
public class Scenes
|
||
|
{
|
||
|
public int Scene;
|
||
|
private gameui GU;
|
||
|
private SpriteBatch _spriteBatch;
|
||
|
private Game1 Game;
|
||
|
private List<Button> Buttons;
|
||
|
public bool wait;
|
||
|
private bool mwait;
|
||
|
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>();
|
||
|
initscenes();
|
||
|
}
|
||
|
public void draw(GameTime gameTime)
|
||
|
{
|
||
|
switch (Scene)
|
||
|
{
|
||
|
case 0:
|
||
|
U0();
|
||
|
S0();
|
||
|
break;
|
||
|
case 1:
|
||
|
U1(gameTime);
|
||
|
S1(gameTime);
|
||
|
break;
|
||
|
case 2:
|
||
|
U2();
|
||
|
S2();
|
||
|
break;
|
||
|
default:
|
||
|
Scene = 0;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
public void initscenes()
|
||
|
{
|
||
|
//S0
|
||
|
Buttons.Add(new Button(0, new Rectangle((int)vars.ScreenSize.X / 2 - 250, 200, 500, 150), Color.Gray, Color.DarkGray, 0, "Start"));
|
||
|
Buttons.Add(new Button(0, new Rectangle((int)vars.ScreenSize.X / 2 - 250, 400, 500, 150), Color.Gray, Color.DarkGray, 1, "Options"));
|
||
|
Buttons.Add(new Button(0, new Rectangle((int)vars.ScreenSize.X / 2 - 250, 600, 500, 150), Color.Gray, Color.DarkGray, 2, "Exit"));
|
||
|
//S2
|
||
|
Buttons.Add(new Button(2, new Rectangle((int)vars.PlayArea.X + 20, vars.PlayArea.Y + 100, vars.PlayArea.Width - 40, 150), Color.Gray, Color.DarkGray, 3, "Continue"));
|
||
|
Buttons.Add(new Button(2, new Rectangle((int)vars.PlayArea.X + 20, vars.PlayArea.Y + 300, vars.PlayArea.Width - 40, 150), Color.Gray, Color.DarkGray, 4, "Options"));
|
||
|
Buttons.Add(new Button(2, new Rectangle((int)vars.PlayArea.X + 20, vars.PlayArea.Y + 500, vars.PlayArea.Width - 40, 150), Color.Gray, Color.DarkGray, 5, "Exit to menu"));
|
||
|
}
|
||
|
public void S0()
|
||
|
{
|
||
|
Game.GraphicsDevice.Clear(Color.Black);
|
||
|
_spriteBatch.Begin();
|
||
|
_spriteBatch.DrawString(vars.Font, "Asteroids", new Vector2(vars.ScreenSize.X / 2 - vars.Font.MeasureString("Asteroids").X / 2, 40), Color.White);
|
||
|
foreach (var item in Buttons)
|
||
|
{
|
||
|
if (item.Key == 0)
|
||
|
{
|
||
|
item.draw(_spriteBatch);
|
||
|
}
|
||
|
}
|
||
|
_spriteBatch.End();
|
||
|
}
|
||
|
public void U0()
|
||
|
{
|
||
|
if(Mouse.GetState().LeftButton == ButtonState.Released)
|
||
|
{
|
||
|
mwait = false;
|
||
|
}
|
||
|
if(mwait)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
foreach (var item in Buttons)
|
||
|
{
|
||
|
if (item.Key == 0)
|
||
|
{
|
||
|
item.Update();
|
||
|
if (item.clicked)
|
||
|
{
|
||
|
switch (item.id)
|
||
|
{
|
||
|
case 0:
|
||
|
Scene = 1;
|
||
|
break;
|
||
|
case 1:
|
||
|
Scene = 4;
|
||
|
break;
|
||
|
case 2:
|
||
|
Game.Exit();
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public void S1(GameTime gameTime)
|
||
|
{
|
||
|
Game.GraphicsDevice.Clear(Color.Black);
|
||
|
_spriteBatch.Begin();
|
||
|
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.End();
|
||
|
}
|
||
|
public void U1(GameTime gameTime)
|
||
|
{
|
||
|
Game.PL.input(gameTime);
|
||
|
Rectangle[] boxes = new Rectangle[]{
|
||
|
vars.PlayArea,
|
||
|
};
|
||
|
Game.PL.Collision(boxes);
|
||
|
Game.AS.Update(_spriteBatch);
|
||
|
}
|
||
|
public void S2()
|
||
|
{
|
||
|
Game.GraphicsDevice.Clear(Color.Black);
|
||
|
_spriteBatch.Begin();
|
||
|
GU.draw(_spriteBatch);
|
||
|
_spriteBatch.Draw(vars.ThePixel, vars.PlayArea, null, new Color(20, 20, 20));
|
||
|
_spriteBatch.DrawString(vars.Font, "Pause", new Vector2(vars.PlayArea.X + vars.PlayArea.Width / 2 - vars.Font.MeasureString("Pause").X / 2, vars.PlayArea.Y + 20), Color.White);
|
||
|
foreach (var item in Buttons)
|
||
|
{
|
||
|
if (item.Key == 2)
|
||
|
{
|
||
|
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.End();
|
||
|
}
|
||
|
public void U2()
|
||
|
{
|
||
|
if(Keyboard.GetState().IsKeyDown(Keys.Escape) && wait)
|
||
|
{
|
||
|
vars.Scens.Scene = 1;
|
||
|
Game.PL.waitb = false;
|
||
|
}
|
||
|
if(Keyboard.GetState().IsKeyUp(Keys.Escape)){wait = true;}
|
||
|
foreach (var item in Buttons)
|
||
|
{
|
||
|
if (item.Key == 2)
|
||
|
{
|
||
|
item.Update();
|
||
|
if (item.clicked)
|
||
|
{
|
||
|
switch (item.id)
|
||
|
{
|
||
|
case 3:
|
||
|
Scene = 1;
|
||
|
break;
|
||
|
case 4:
|
||
|
Scene = 3;
|
||
|
break;
|
||
|
case 5:
|
||
|
Scene = 0;
|
||
|
mwait = true;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public class gameui
|
||
|
{
|
||
|
public Texture2D Background;
|
||
|
private float bgY;
|
||
|
private Player PL;
|
||
|
public gameui(Texture2D bg, Player PL)
|
||
|
{
|
||
|
this.Background = bg;
|
||
|
this.PL = PL;
|
||
|
bgY = vars.PlayArea.Y;
|
||
|
}
|
||
|
public void draw(SpriteBatch _spriteBatch)
|
||
|
{
|
||
|
//Neaded variables
|
||
|
int dimnes = 30;
|
||
|
string[] pows = new string[PL.Ups.Count];
|
||
|
for (int i = 0; i < pows.Length; i++)
|
||
|
{
|
||
|
pows[i] = PL.Ups[i].TimeLeft.ToString();
|
||
|
}
|
||
|
bgY++;
|
||
|
if (bgY >= vars.PlayArea.Bottom)
|
||
|
{
|
||
|
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);
|
||
|
_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));
|
||
|
//all the powerup things
|
||
|
_spriteBatch.DrawString(vars.Font, "Power Up Times", new Vector2(100, 60), Color.RoyalBlue, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
|
||
|
for (int i = 0; i < pows.Length; i++)
|
||
|
{
|
||
|
_spriteBatch.DrawString(vars.Font, pows[i], new Vector2(120, 130 + 50 * i), Color.RoyalBlue, 0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
|
||
|
}
|
||
|
//Points text
|
||
|
_spriteBatch.DrawString(vars.Font, "Points", new Vector2(vars.PlayArea.Right + 100, 60), Color.RoyalBlue);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 100, 130, (int)vars.ScreenSize.X - vars.PlayArea.Right - 200, 70), null, Color.Black);
|
||
|
_spriteBatch.DrawString(vars.Font, vars.Points.ToString(), new Vector2(vars.PlayArea.Right + 110, 130), Color.RoyalBlue);
|
||
|
//health Bar
|
||
|
int wid = (int)vars.ScreenSize.X - vars.PlayArea.Right - 220;
|
||
|
int inp = (int)(((float)PL.Health / (float)PL.maxHP) * wid);
|
||
|
_spriteBatch.DrawString(vars.Font, "Health: " + PL.Health, new Vector2(vars.PlayArea.Right + 100, 250), Color.RoyalBlue);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 100, 320, (int)vars.ScreenSize.X - vars.PlayArea.Right - 200, 100), null, Color.Black);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 110, 330, wid, 80), null, Color.Red);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 110, 330, inp, 80), null, Color.Green);
|
||
|
//boost bar
|
||
|
inp = (int)(((float)PL.boost / (float)PL.maxboost) * wid);
|
||
|
_spriteBatch.DrawString(vars.Font, "Boost: " + MathF.Round(PL.boost), new Vector2(vars.PlayArea.Right + 100, 460), Color.RoyalBlue);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 100, 530, (int)vars.ScreenSize.X - vars.PlayArea.Right - 200, 100), null, Color.Black);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 110, 540, wid, 80), null, new Color(60, 60, 60));
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(vars.PlayArea.Right + 110, 540, inp, 80), null, Color.SkyBlue);
|
||
|
//music backboard
|
||
|
Rectangle musice = new Rectangle(rightbox.X+25, 655, rightbox.Width-50, rightbox.Bottom-680);
|
||
|
_spriteBatch.Draw(vars.ThePixel, musice, null , new Color(dimnes + 30, dimnes + 30, dimnes + 30));
|
||
|
|
||
|
//musicbar
|
||
|
int max = musice.Width-40;
|
||
|
int widt = (int)((AudioEn.playedtime.TotalSeconds/AudioEn.songtime.TotalSeconds)*max);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(musice.X+10, musice.Bottom-120, musice.Width-20, 110), null, Color.Black);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(musice.X+20, musice.Bottom-110, musice.Width-40, 90), null, Color.DarkGray);
|
||
|
_spriteBatch.Draw(vars.ThePixel, new Rectangle(musice.X+20, musice.Bottom-110, widt, 90), null, Color.Green);
|
||
|
|
||
|
//music text
|
||
|
_spriteBatch.DrawString(vars.Font, "Music", new Vector2(musice.X + musice.Width/2 - vars.Font.MeasureString("Music").X/2, musice.Y+25), Color.RoyalBlue);
|
||
|
_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);
|
||
|
}
|
||
|
}
|