Initial main menu impl

This commit is contained in:
2021-04-23 15:07:50 +02:00
parent 05657b14dd
commit 44f0f9e399
10 changed files with 91 additions and 38 deletions
Binary file not shown.
Binary file not shown.
+3 -3
View File
@@ -32,13 +32,13 @@
</ItemGroup>
<ItemGroup>
<Reference Include="CppSharp.Runtime">
<HintPath>..\..\Synthizer\Synthy\bin\Debug\netstandard2.1\CppSharp.Runtime.dll</HintPath>
<HintPath>..\..\synthy\Synthy\bin\Debug\netstandard2.1\CppSharp.Runtime.dll</HintPath>
</Reference>
<Reference Include="Synthizer.Net">
<HintPath>..\..\Synthizer\Synthy\bin\Debug\netstandard2.1\Synthizer.Net.dll</HintPath>
<HintPath>..\..\synthy\Synthy\bin\Debug\netstandard2.1\Synthizer.Net.dll</HintPath>
</Reference>
<Reference Include="Synthy">
<HintPath>..\..\Synthizer\Synthy\bin\Debug\netstandard2.1\Synthy.dll</HintPath>
<HintPath>..\..\synthy\Synthy\bin\Debug\netstandard2.1\Synthy.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
+2 -1
View File
@@ -23,7 +23,8 @@ namespace EvilSatellites
protected override void Initialize()
{
// TODO: Add your initialization logic here
_manager.AddScreen(new EvilSatellites.Screens.GameScreen());
// _manager.AddScreen(new EvilSatellites.Screens.GameScreen());
_manager.AddScreen(new EvilSatellites.Screens.MainMenuScreen());
base.Initialize();
}
+2 -2
View File
@@ -50,14 +50,14 @@ namespace EvilSatellites.Objects
{
Move(new Vector3(0, 0, -0.05f));
Sound.Position = new System.Numerics.Vector3(Position.X+Dimensions.X/2, Position.Y+Dimensions.Y/2, Position.Z+Dimensions.Z/2);
if (rnd.Next(512) == 250)
if (rnd.Next(1024) == 512)
{
var scr = (GameScreen)Screen;
var player = scr.GetPlayer();
var orient = Matrix.Invert(Matrix.CreateTranslation(Position) * Matrix.CreateLookAt(Position, scr.GetPlayer().Position, Rotation.Up));
var dir = Position - player.Position;
dir.Normalize();
Screen.Manager.Sound.PlayOneshot(@"sfx/weapons/LaserCannon/fire/" + (rnd.Next(2) + 1).ToString() + ".wav", new System.Numerics.Vector3(Position.X + Dimensions.X / 2, Position.Y + Dimensions.Y / 2, Position.Z / Dimensions.Z / 2), Screen.Manager.EnvironmentEffect);
var proj = new Projectile(Screen, Position, orient, this);
// proj.Direction = dir;
scr.AddObject(proj);
+25 -6
View File
@@ -4,7 +4,6 @@ using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using SynthySound;
using Synthizer;
using Microsoft.Xna.Framework.Audio;
using EvilSatellites.Screens;
@@ -14,6 +13,8 @@ namespace EvilSatellites
public class ScreenManager : DrawableGameComponent
{
private List<IScreen> _Screens;
private List<IScreen> _ToRemove;
private List<IScreen> _ToAdd;
private IScreen _CurrentScreen;
private Game _Game;
private bool _Running = false;
@@ -29,9 +30,11 @@ namespace EvilSatellites
EnvironmentEffect.T60 = 1;
EnvironmentEffect.Defusion = 1f;
EnvironmentEffect.FreePath = 0.02;
Sound.SetMaxDistance(150);
_Game = instance;
_Screens = new List<IScreen>();
_ToRemove = new List<IScreen>();
_ToAdd = new List<IScreen>();
_CurrentScreen = null;
}
@@ -48,8 +51,7 @@ namespace EvilSatellites
public void AddScreen(IScreen screen)
{
screen.Manager = this;
if (_Running) screen.Activate();
_Screens.Add(screen);
_ToAdd.Add(screen);
}
public void RemoveScreen(IScreen screen)
{
@@ -57,12 +59,29 @@ namespace EvilSatellites
{
throw new Exception("Cannot remove a screen that isn't added to manager");
}
screen.Deactivate();
_Screens.Remove(screen);
_ToRemove.Add(screen);
}
public void Update(GameTime gameTime)
{
if (_ToAdd.Count > 0)
{
foreach (var screen in _ToAdd)
{
screen.Activate();
_Screens.Add(screen);
}
_ToAdd.Clear();
}
if (_ToRemove.Count > 0)
{
foreach (var screen in _ToRemove)
{
screen.Deactivate();
_Screens.Remove(screen);
}
_ToRemove.Clear();
}
Sound.Update();
var input = Keyboard.GetState();
foreach (var screen in _Screens)
-2
View File
@@ -30,8 +30,6 @@ namespace EvilSatellites.Screens
Player player = new Player(this);
Objects.Add(player);
_player = player;
// Satellite prop = new Satellite(this, new Vector3(5000, 5000, 5000));
// Objects.Add(prop);
ObjectRadar = new Radar(_player, this);
Spawner = new SatelliteSpawner(this);
Spawner.Spawn();
+34
View File
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EvilSatellites.Menu;
using EvilSatellites.Screens;
namespace EvilSatellites.Screens
{
public class MainMenuScreen : MenuScreen
{
public override void Activate()
{
MenuOptions = new MenuContainer("Main Menu", "Navigate with up and down arrows,, and enter to select.");
MenuOptions.Add(new MenuEntry("Start", "Start the game"))
.Add(new MenuEntry("Exit", "Exit the game"))
.Add(new MenuEntry("Something Else", "Do something else"));
base.Activate();
}
public override void SelectItem()
{
Manager.Sound.PlayOneshot(@"sfx/ui/menuChoose.wav");
if (CursorPosition == 0)
{
Manager.AddScreen(new GameScreen());
Manager.RemoveScreen(this);
Manager.Game.ResetElapsedTime();
}
}
}
}
+18 -17
View File
@@ -17,36 +17,33 @@ namespace EvilSatellites.Screens
public ScreenManager _Manager;
public ScreenState _State;
public InputManager Inputs = new InputManager();
public MenuScreen(ScreenManager manager, MenuContainer options)
{
_Manager = manager;
MenuOptions = options;
}
ScreenManager IScreen.Manager { get => _Manager; set => _Manager = value; }
ScreenState IScreen.State { get => _State; set => _State = value; }
void IScreen.Activate()
public ScreenManager Manager { get => _Manager; set => _Manager = value; }
public ScreenState State { get => _State; set => _State = value; }
public virtual void Activate()
{
CursorPosition = 0;
Tolk.Output(MenuOptions.Title, true);
Tolk.Output(MenuOptions.Description, false);
Tolk.Output(MenuOptions.Entries[CursorPosition].Name);
Manager.Sound.PlayOneshot(@"sfx/ui/menuOpen.wav");
}
void IScreen.Deactivate()
public virtual void Deactivate()
{
return;
}
void IScreen.HandleInput(GameTime gameTime, KeyboardState inputs)
public void HandleInput(GameTime gameTime, KeyboardState inputs)
{
Inputs.Update();
if (Inputs.IsJustPressed(Keys.Down))
{
NextItem();
}
if (Inputs.IsJustPressed(Keys.Down))
if (Inputs.IsJustPressed(Keys.Up))
{
PreviousItem();
}
@@ -56,21 +53,22 @@ namespace EvilSatellites.Screens
}
}
void IScreen.Update(GameTime gameTime)
public virtual void Update(GameTime gameTime)
{
return;
Manager.Sound.Update();
}
public void PreviousItem()
{
CursorPosition--;
CursorPosition -= 1;
CheckMenuBounds();
ReadMenuItem();
}
public void NextItem()
{
CursorPosition++;
CursorPosition += 1;
CheckMenuBounds();
ReadMenuItem();
}
@@ -80,19 +78,22 @@ namespace EvilSatellites.Screens
if (CursorPosition > MenuOptions.Entries.Count-1)
{
CursorPosition = 0;
Manager.Sound.PlayOneshot(@"sfx/ui/menuBoundary.wav");
}
if (CursorPosition < 0)
{
CursorPosition = MenuOptions.Entries.Count - 1;
CursorPosition = MenuOptions.Entries.Count-1;
Manager.Sound.PlayOneshot(@"sfx/ui/menuBoundary.wav");
}
}
public void ReadMenuItem()
{
Manager.Sound.PlayOneshot(@"sfx/ui/menuMove.wav");
Tolk.Output(MenuOptions.Entries[CursorPosition].Name, true);
}
public void SelectItem()
public virtual void SelectItem()
{
return;
}
+7 -7
View File
@@ -56,7 +56,7 @@ namespace EvilSatellites.Weapons
State = WeaponState.Starting;
sfxSpinup.Reset();
sfxSpinup.Play();
TimerStart = time.TotalGameTime.TotalMilliseconds;
TimerStart = 0;
}
public override void Stop()
@@ -73,19 +73,19 @@ namespace EvilSatellites.Weapons
public override void Update(GameTime time)
{
TimerEnd += time.ElapsedGameTime.TotalMilliseconds;
TimerStart += time.ElapsedGameTime.TotalMilliseconds;
if (State == WeaponState.Starting)
{
if (TimerEnd - TimerStart > 800)
if (TimerStart > 800)
{
State = WeaponState.Firing;
sfxSpinning.Play();
TimerStart = TimerEnd;
TimerStart = 0;
}
}
if (State == WeaponState.Firing)
{
if (TimerEnd - TimerStart > FireRate)
if (TimerStart > FireRate)
{
if (RemainingAmmo > 0)
{
@@ -104,10 +104,10 @@ namespace EvilSatellites.Weapons
}
if (State == WeaponState.Stopping)
{
if (TimerEnd - TimerStart > 500)
if (TimerStart > 500)
{
State = WeaponState.Stopped;
TimerStart = TimerEnd;
TimerStart = 0;
}
}
base.Update(time);