Skip to content

Commit

Permalink
update before public
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Jesper Krægpøth Ryder committed May 4, 2019
1 parent 8e364ca commit 0956798
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 164 deletions.
Binary file modified .vs/Uranus/v16/Server/sqlite3/storage.ide
Binary file not shown.
Binary file added .vs/Uranus/v16/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file added .vs/Uranus/v16/Server/sqlite3/storage.ide-wal
Binary file not shown.
6 changes: 0 additions & 6 deletions Content/Content.mgcb
Expand Up @@ -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
Expand Down
Binary file removed Content/InfectedMushroomGuitarmass.mp3
Binary file not shown.
10 changes: 4 additions & 6 deletions Managers/MusicManager.cs
Expand Up @@ -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<SoundEffect>("To_the_Next_Destination");
MenuMusic = content.Load<SoundEffect>("InfectedMushroomGuitarmass");
}

public void PlayMenuMusic()
{
currentVolume = maxVolume;

instance = MenuMusic.CreateInstance();
instance = GameMusic.CreateInstance();
instance.Volume = currentVolume;
instance.Play();
}
Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions Sprites/Astroid.cs
Expand Up @@ -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;

Expand Down
22 changes: 0 additions & 22 deletions Sprites/Bullet.cs
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions Sprites/Enemy.cs
Expand Up @@ -17,11 +17,9 @@ public Enemy(Texture2D texture)
{
Speed = 2f;
}

public override void Update(GameTime gameTime)
{


if (gameTime.TotalGameTime.TotalMilliseconds >= ShootingTimer)
{
Shoot(-10f);
Expand Down
10 changes: 2 additions & 8 deletions Sprites/Player.cs
Expand Up @@ -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;
}

Expand Down
50 changes: 4 additions & 46 deletions Sprites/TrackingEnemy.cs
Expand Up @@ -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++;
}
}
}*/
}
}
80 changes: 28 additions & 52 deletions States/GameState.cs
Expand Up @@ -14,28 +14,28 @@ public class GameState : State
{
private EnemyManager _enemyManager;
private PlayerManger _playerManger;

private SpriteFont _font;

private List<Player> _players;

private ScoreManager _scoreManager;

private List<Sprite> _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<Texture2D>("Bullet");

_font = _content.Load<SpriteFont>("Font");
Expand All @@ -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);
Expand All @@ -81,26 +78,21 @@ 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)
{
_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)
Expand All @@ -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);
}
}

Expand All @@ -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<Sprite>();
}
Expand All @@ -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++;
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -234,6 +209,7 @@ public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)

x += 150;
}

spriteBatch.End();
}
}
Expand Down

0 comments on commit 0956798

Please sign in to comment.