diff --git a/.vs/Uranus/v16/Server/sqlite3/storage.ide b/.vs/Uranus/v16/Server/sqlite3/storage.ide index dbd3ca9..76cb1af 100644 Binary files a/.vs/Uranus/v16/Server/sqlite3/storage.ide and b/.vs/Uranus/v16/Server/sqlite3/storage.ide differ diff --git a/.vs/Uranus/v16/Server/sqlite3/storage.ide-shm b/.vs/Uranus/v16/Server/sqlite3/storage.ide-shm new file mode 100644 index 0000000..435c9b9 Binary files /dev/null and b/.vs/Uranus/v16/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/Uranus/v16/Server/sqlite3/storage.ide-wal b/.vs/Uranus/v16/Server/sqlite3/storage.ide-wal new file mode 100644 index 0000000..e48ceb7 Binary files /dev/null and b/.vs/Uranus/v16/Server/sqlite3/storage.ide-wal differ diff --git a/Content/Content.mgcb b/Content/Content.mgcb index e4c6a1a..652e345 100644 --- a/Content/Content.mgcb +++ b/Content/Content.mgcb @@ -140,12 +140,6 @@ /processorParam:TextureFormat=Color /build:Background/StarsSmall1.png -#begin InfectedMushroomGuitarmass.mp3 -/importer:Mp3Importer -/processor:SoundEffectProcessor -/processorParam:Quality=Best -/build:InfectedMushroomGuitarmass.mp3 - #begin To_the_Next_Destination.mp3 /importer:Mp3Importer /processor:SoundEffectProcessor diff --git a/Content/InfectedMushroomGuitarmass.mp3 b/Content/InfectedMushroomGuitarmass.mp3 deleted file mode 100644 index e836aaa..0000000 Binary files a/Content/InfectedMushroomGuitarmass.mp3 and /dev/null differ diff --git a/Managers/MusicManager.cs b/Managers/MusicManager.cs index 84822d9..9e78d8b 100644 --- a/Managers/MusicManager.cs +++ b/Managers/MusicManager.cs @@ -6,21 +6,20 @@ namespace Uranus.Managers { public class MusicManager { - public float maxVolume = 0.5f; + public float maxVolume = 0.25f; public float currentVolume = 0.0001F; private SoundEffectInstance instance; public MusicManager(ContentManager content) { GameMusic = content.Load("To_the_Next_Destination"); - MenuMusic = content.Load("InfectedMushroomGuitarmass"); } public void PlayMenuMusic() { currentVolume = maxVolume; - instance = MenuMusic.CreateInstance(); + instance = GameMusic.CreateInstance(); instance.Volume = currentVolume; instance.Play(); } @@ -39,13 +38,12 @@ public void Stop() instance.Stop(); } - - public SoundEffect MenuMusic { get; set; } - public SoundEffect GameMusic { get; set; } public void UpdateGame(GameTime gameTime) { + if(instance.State == SoundState.Stopped) + instance.Play(); if (currentVolume < maxVolume) { currentVolume += 0.0005F; diff --git a/Sprites/Astroid.cs b/Sprites/Astroid.cs index 3674e4b..9407508 100644 --- a/Sprites/Astroid.cs +++ b/Sprites/Astroid.cs @@ -36,14 +36,12 @@ public override void Update(GameTime gameTime) { Rotation+=0.25f; _timeToRotate = gameTime.TotalGameTime.TotalMilliseconds + 45; - // Add random rotation direction and random speed. } } public void OnCollide(Sprite sprite, GameTime gameTime) { - // Can't hit a player if they're dead if (sprite is Player && ((Player)sprite).IsDead) return; diff --git a/Sprites/Bullet.cs b/Sprites/Bullet.cs index ff02363..457480b 100644 --- a/Sprites/Bullet.cs +++ b/Sprites/Bullet.cs @@ -34,37 +34,15 @@ public override void Update(GameTime gameTime) public void OnCollide(Sprite sprite, GameTime gameTime) { - //switch (sprite) - //{ - // case Bullet b: - // return; - // case Enemy e1 when e1.Parent is Enemy: - - // if (e1.Parent is Enemy) - // return; - - // if() - - // return; - // case Enemy e2 when - - // case Player p when (p.IsDead || p.Parent is Player): - // return; - //} - - // Bullets don't collide with eachother if (sprite is Bullet) return; - // Enemies can't shoot eachother if (sprite is Enemy && this.Parent is Enemy) return; - // Players can't shoot eachother if (sprite is Player && this.Parent is Player) return; - // Can't hit a player if they're dead if (sprite is Player && ((Player)sprite).IsDead) return; diff --git a/Sprites/Enemy.cs b/Sprites/Enemy.cs index 903d583..98617b4 100644 --- a/Sprites/Enemy.cs +++ b/Sprites/Enemy.cs @@ -17,11 +17,9 @@ public Enemy(Texture2D texture) { Speed = 2f; } - + public override void Update(GameTime gameTime) { - - if (gameTime.TotalGameTime.TotalMilliseconds >= ShootingTimer) { Shoot(-10f); diff --git a/Sprites/Player.cs b/Sprites/Player.cs index d565892..38d13fc 100644 --- a/Sprites/Player.cs +++ b/Sprites/Player.cs @@ -75,17 +75,11 @@ public override void Update(GameTime gameTime) if (_currentKey.IsKeyDown(Input.Shoot) && _shootTimer > 0.25f) { - //Shoot(10f, -6f); - // Shoot(10f, -4f); - - // Shoot(10f, -2f); + //Shoot(10f, -2f); Shoot left Shoot(10f); - // Shoot(10f, 2f); - - // Shoot(10f, 4f); + //Shoot(10f, 2f); shoot right - // Shoot(10f, 6f); _shootTimer = 0f; } diff --git a/Sprites/TrackingEnemy.cs b/Sprites/TrackingEnemy.cs index 0bb4c4a..6d501cc 100644 --- a/Sprites/TrackingEnemy.cs +++ b/Sprites/TrackingEnemy.cs @@ -49,68 +49,26 @@ public override void Update(GameTime gameTime) } } - - - float yMaxSpeed = 1f; + float yMaxSpeed = 0.35f*Speed; if (nearestPlayer == new Vector2()) { yMaxSpeed = 0f; } - else if (nearestPlayer.Y - Position.Y > yMaxSpeed) + else if ((nearestPlayer.Y - Position.Y) > (yMaxSpeed)) { - yMaxSpeed = Speed; + yMaxSpeed = yMaxSpeed; } else if (nearestPlayer.Y - Position.Y < -yMaxSpeed) { - yMaxSpeed = -Speed; - } - else if (nearestPlayer.Y < Position.Y) - { - yMaxSpeed = nearestPlayer.Y - Position.Y; - } - else if (nearestPlayer.Y > Position.Y) - { - yMaxSpeed = nearestPlayer.Y - Position.Y; + yMaxSpeed = yMaxSpeed * -1; } Position += new Vector2(-Speed, yMaxSpeed); - if (yMaxSpeed > 2) - _texture = _left; - else if (yMaxSpeed < -2) - _texture = _right; - else - _texture = _center; - // if the enemy is off the left side of the screen if (Position.X < -_texture.Width) IsRemoved = true; } - - /* - public override void OnCollide(Sprite sprite, GameTime gameTime) - { - // If we crash into a player that is still alive - if (sprite is Player && !((Player)sprite).IsDead) - { - ((Player)sprite).Score.Value++; - - // We want to remove the ship completely - IsRemoved = true; - } - - // If we hit a bullet that belongs to a player - if (sprite is Bullet && ((Bullet)sprite).Parent is Player) - { - Health--; - - if (Health <= 0) - { - IsRemoved = true; - ((Player)sprite.Parent).Score.Value++; - } - } - }*/ } } diff --git a/States/GameState.cs b/States/GameState.cs index c54463a..a83d680 100644 --- a/States/GameState.cs +++ b/States/GameState.cs @@ -14,28 +14,28 @@ public class GameState : State { private EnemyManager _enemyManager; private PlayerManger _playerManger; - private SpriteFont _font; - private List _players; - private ScoreManager _scoreManager; - private List _sprites; - public int PlayerCount; private BackgroundManager _backgroundManager; private MusicManager _musicManager; private BulletManager _bulletManager; + static float shakeRadius = 10f; + static bool shakeScreen = false; + static Vector2 shakeOffset = new Vector2(15, 15); + static int shakeCount = 0; + static int maxShakes = 20; + static int shakeStartAngle = 15; + private AstroidManager _astroidManager; - public GameState(Game1 game, ContentManager content) - : base(game, content) + public GameState(Game1 game, ContentManager content) : base(game, content) { } public override void LoadContent() { - var bulletTexture = _content.Load("Bullet"); _font = _content.Load("Font"); @@ -59,12 +59,9 @@ public override void LoadContent() _sprites.Add(_playerManger.GetPlayer(PlayerColour.Green, PlayerControls.Arrow, "Player 2")); } - _players = _sprites.Where(c => c is Player).Select(c => (Player)c).ToList(); + _players = _sprites.Where(c => c is Player).Select(c => (Player) c).ToList(); - _enemyManager = new EnemyManager(_content) - { - Bullet = _bulletManager.GetBullet(BulletType.Proton), - }; + _enemyManager = new EnemyManager(_content) {Bullet = _bulletManager.GetBullet(BulletType.Proton),}; _backgroundManager = new BackgroundManager(_content); _musicManager = new MusicManager(_content); @@ -81,11 +78,9 @@ public override void Update(GameTime gameTime) { _musicManager.Stop(); _game.ChangeState(new MenuState(_game, _content)); - } - foreach (var sprite in _sprites) - sprite.Update(gameTime); + foreach (var sprite in _sprites) sprite.Update(gameTime); _enemyManager.Update(gameTime); if (_enemyManager.CanAdd && _sprites.Where(c => c is Enemy).Count() < _enemyManager.MaxEnemies) @@ -93,14 +88,11 @@ public override void Update(GameTime gameTime) _sprites.Add(_enemyManager.GetEnemy()); } - _astroidManager.Update(gameTime); if (_astroidManager.CanAdd && _sprites.Where(c => c is Astroid).Count() < _astroidManager.MaxAstroids) { _sprites.Add(_astroidManager.GetAstroid()); } - - } public override void PostUpdate(GameTime gameTime) @@ -112,29 +104,21 @@ public override void PostUpdate(GameTime gameTime) foreach (var spriteB in collidableSprites) { // Don't do anything if they're the same sprite! - if (spriteA == spriteB) - continue; + if (spriteA == spriteB) continue; - if (spriteA is Bullet && spriteB is Bullet) - continue; + if (spriteA is Bullet && spriteB is Bullet) continue; - if (spriteA is Bullet && spriteB is Player && ((Bullet)spriteA).Parent is Player) - continue; + if (spriteA is Bullet && spriteB is Player && ((Bullet) spriteA).Parent is Player) continue; - if (spriteB is Bullet && spriteA is Player && ((Bullet)spriteB).Parent is Player) - continue; + if (spriteB is Bullet && spriteA is Player && ((Bullet) spriteB).Parent is Player) continue; - if (spriteA is Bullet && spriteB is Enemy && ((Bullet)spriteA).Parent is Enemy) - continue; + if (spriteA is Bullet && spriteB is Enemy && ((Bullet) spriteA).Parent is Enemy) continue; - if (spriteB is Bullet && spriteA is Enemy && ((Bullet)spriteB).Parent is Enemy) - continue; + if (spriteB is Bullet && spriteA is Enemy && ((Bullet) spriteB).Parent is Enemy) continue; - if (!spriteA.CollisionArea.Intersects(spriteB.CollisionArea)) - continue; + if (!spriteA.CollisionArea.Intersects(spriteB.CollisionArea)) continue; - if (spriteA.Intersects(spriteB)) - ((ICollidable)spriteA).OnCollide(spriteB, gameTime); + if (spriteA.Intersects(spriteB)) ((ICollidable) spriteA).OnCollide(spriteB, gameTime); } } @@ -143,8 +127,7 @@ public override void PostUpdate(GameTime gameTime) for (int i = 0; i < spriteCount; i++) { var sprite = _sprites[i]; - foreach (var child in sprite.Children) - _sprites.Add(child); + foreach (var child in sprite.Children) _sprites.Add(child); sprite.Children = new List(); } @@ -170,7 +153,9 @@ public override void PostUpdate(GameTime gameTime) //shakeOffset *= -1; //float shakeRadius = 10f; - shakeOffset = new Vector2((float)(Math.Sin(shakeStartAngle) * shakeRadius), (float)(Math.Cos(shakeStartAngle) * shakeRadius)); ; + shakeOffset = new Vector2((float) (Math.Sin(shakeStartAngle) * shakeRadius), + (float) (Math.Cos(shakeStartAngle) * shakeRadius)); + ; shakeRadius -= 0.25f; shakeStartAngle += (150 + Game1.Random.Next(60)); shakeCount++; @@ -184,8 +169,7 @@ public override void PostUpdate(GameTime gameTime) // If all the players are dead, we save the scores, and return to the highscore state if (_players.All(c => c.IsDead)) { - foreach (var player in _players) - _scoreManager.Add(player.Score); + foreach (var player in _players) _scoreManager.Add(player.Score); ScoreManager.Save(_scoreManager); _musicManager.Stop(); @@ -201,25 +185,16 @@ public static void ShakeScreen() shakeCount = 0; } - // - static float shakeRadius = 10f; - static bool shakeScreen = false; - static Vector2 shakeOffset = new Vector2(15, 15); - static int shakeCount = 0; - static int maxShakes = 20; - static int shakeStartAngle = 15; - private AstroidManager _astroidManager; - public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { if (shakeScreen) - spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Matrix.CreateTranslation(shakeOffset.X, shakeOffset.Y, 0)); + spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, + Matrix.CreateTranslation(shakeOffset.X, shakeOffset.Y, 0)); else spriteBatch.Begin(SpriteSortMode.FrontToBack); _backgroundManager.Draw(spriteBatch); - foreach (var sprite in _sprites) - sprite.Draw(gameTime, spriteBatch); + foreach (var sprite in _sprites) sprite.Draw(gameTime, spriteBatch); spriteBatch.End(); @@ -234,6 +209,7 @@ public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) x += 150; } + spriteBatch.End(); } } diff --git a/States/HighscoresState.cs b/States/HighscoresState.cs index 2e36856..07488d7 100644 --- a/States/HighscoresState.cs +++ b/States/HighscoresState.cs @@ -18,8 +18,7 @@ public class HighscoresState : State private ScoreManager _scoreManager; - public HighscoresState(Game1 game, ContentManager content) - : base(game, content) + public HighscoresState(Game1 game, ContentManager content) : base(game, content) { } @@ -33,15 +32,15 @@ public override void LoadContent() var buttonFont = _content.Load("Font"); _components = new List() - { - new Button(buttonTexture, buttonFont) - { - Text = "Main Menu", - Position = new Vector2(Game1.ScreenWidth / 2, 560), - Click = new EventHandler(Button_MainMenu_Clicked), - Layer = 0.1f - }, - }; + { + new Button(buttonTexture, buttonFont) + { + Text = "Main Menu", + Position = new Vector2(Game1.ScreenWidth / 2, 560), + Click = new EventHandler(Button_MainMenu_Clicked), + Layer = 0.1f + } + }; } private void Button_MainMenu_Clicked(object sender, EventArgs args) @@ -51,30 +50,29 @@ private void Button_MainMenu_Clicked(object sender, EventArgs args) public override void Update(GameTime gameTime) { - if (Keyboard.GetState().IsKeyDown(Keys.Escape)) - Button_MainMenu_Clicked(this, new EventArgs()); + if (Keyboard.GetState().IsKeyDown(Keys.Escape)) Button_MainMenu_Clicked(this, new EventArgs()); - foreach (var component in _components) - component.Update(gameTime); + foreach (var component in _components) component.Update(gameTime); } public override void PostUpdate(GameTime gameTime) { - } public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { spriteBatch.Begin(SpriteSortMode.FrontToBack); - foreach (var component in _components) - component.Draw(gameTime, spriteBatch); + foreach (var component in _components) component.Draw(gameTime, spriteBatch); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.FrontToBack); - spriteBatch.DrawString(_font, "Highscores:\n" + string.Join("\n", _scoreManager.HighScores.Select(c => c.PlayerName + ": " + c.Value)), new Vector2(400, 100), Color.Red); + spriteBatch.DrawString(_font, + "Highscores:\n" + + string.Join("\n", _scoreManager.HighScores.Select(c => c.PlayerName + ": " + c.Value)), + new Vector2(400, 100), Color.Red); spriteBatch.End(); } diff --git a/States/MenuState.cs b/States/MenuState.cs index 32e70b0..b6d612f 100644 --- a/States/MenuState.cs +++ b/States/MenuState.cs @@ -95,6 +95,7 @@ private void Button_Quit_Clicked(object sender, EventArgs args) public override void Update(GameTime gameTime) { + _musicManager.UpdateGame(gameTime); foreach (var component in _components) component.Update(gameTime); }