diff options
| author | Ben Beltran <ben@nsovocal.com> | 2013-11-23 13:54:16 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2013-11-23 13:54:16 -0600 |
| commit | b587e9d8e0cc5eb1edf972fd3b644704441e5289 (patch) | |
| tree | 7ad7c006afa1d7101111d8b2418c8a96a824eafc | |
| parent | 097781e6ad3f7bb1c13c16ff7b6bb7219764fb29 (diff) | |
Protoshow sprint.
40 files changed, 564 insertions, 81 deletions
diff --git a/Super Polarity Content/Super Polarity ContentContent/Fonts/bigfont.png b/Super Polarity Content/Super Polarity ContentContent/Fonts/bigfont.png Binary files differnew file mode 100644 index 0000000..67307dd --- /dev/null +++ b/Super Polarity Content/Super Polarity ContentContent/Fonts/bigfont.png diff --git a/Super Polarity Content/Super Polarity ContentContent/Fonts/smallfont.png b/Super Polarity Content/Super Polarity ContentContent/Fonts/smallfont.png Binary files differnew file mode 100644 index 0000000..51a2c14 --- /dev/null +++ b/Super Polarity Content/Super Polarity ContentContent/Fonts/smallfont.png diff --git a/Super Polarity Content/Super Polarity ContentContent/Graphics/pause-screen.png b/Super Polarity Content/Super Polarity ContentContent/Graphics/pause-screen.png Binary files differnew file mode 100644 index 0000000..0d6db73 --- /dev/null +++ b/Super Polarity Content/Super Polarity ContentContent/Graphics/pause-screen.png diff --git a/Super Polarity Content/Super Polarity ContentContent/Graphics/polaritydemotitle.png b/Super Polarity Content/Super Polarity ContentContent/Graphics/polaritydemotitle.png Binary files differnew file mode 100644 index 0000000..10a9b92 --- /dev/null +++ b/Super Polarity Content/Super Polarity ContentContent/Graphics/polaritydemotitle.png diff --git a/Super Polarity Content/Super Polarity ContentContent/Sound/polaritytheme.wav b/Super Polarity Content/Super Polarity ContentContent/Sound/polaritytheme.wav Binary files differnew file mode 100644 index 0000000..28a6bce --- /dev/null +++ b/Super Polarity Content/Super Polarity ContentContent/Sound/polaritytheme.wav diff --git a/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj b/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj index 2b327e7..12417a2 100644 --- a/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj +++ b/Super Polarity Content/Super Polarity ContentContent/Super Polarity ContentContent.contentproj @@ -110,7 +110,11 @@ </Compile> </ItemGroup> <ItemGroup> - <Folder Include="Sound\" /> + <Compile Include="Graphics\pause-screen.png"> + <Name>pause-screen</Name> + <Importer>TextureImporter</Importer> + <Processor>TextureProcessor</Processor> + </Compile> </ItemGroup> <ItemGroup> <Compile Include="Graphics\circle.png"> @@ -150,6 +154,32 @@ <Processor>FontDescriptionProcessor</Processor> </Compile> </ItemGroup> + <ItemGroup> + <Compile Include="Sound\polaritytheme.wav"> + <Name>polaritytheme</Name> + <Importer>WavImporter</Importer> + <Processor>SongProcessor</Processor> + </Compile> + </ItemGroup> + <ItemGroup> + <Compile Include="Graphics\polaritydemotitle.png"> + <Name>polaritydemotitle</Name> + <Importer>TextureImporter</Importer> + <Processor>TextureProcessor</Processor> + </Compile> + </ItemGroup> + <ItemGroup> + <Compile Include="Fonts\bigfont.png"> + <Name>bigfont</Name> + <Importer>TextureImporter</Importer> + <Processor>FontTextureProcessor</Processor> + </Compile> + <Compile Include="Fonts\smallfont.png"> + <Name>smallfont</Name> + <Importer>TextureImporter</Importer> + <Processor>FontTextureProcessor</Processor> + </Compile> + </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. diff --git a/Super Polarity.suo b/Super Polarity.suo Binary files differindex 4f5c9c9..ae197e2 100644 --- a/Super Polarity.suo +++ b/Super Polarity.suo diff --git a/Super Polarity/ActorFactory.cs b/Super Polarity/ActorFactory.cs index 9995707..f9c7697 100644 --- a/Super Polarity/ActorFactory.cs +++ b/Super Polarity/ActorFactory.cs @@ -18,7 +18,6 @@ namespace SuperPolarity mainShip.Initialize(Game.Content.Load<Texture2D>("Graphics\\main-ship"), position); ActorManager.CheckIn(mainShip); - Renderer.CheckIn(mainShip); return mainShip; } @@ -45,7 +44,6 @@ namespace SuperPolarity ship.SetPolarity(polarity); ActorManager.CheckIn(ship); - Renderer.CheckIn(ship); return ship; } @@ -64,7 +62,6 @@ namespace SuperPolarity bullet.Angle = angle; ActorManager.CheckIn(bullet); - Renderer.CheckIn(bullet); return bullet; } @@ -93,7 +90,7 @@ namespace SuperPolarity ship.BoxDimensions.Z = 10; ship.Initialize(texture, position); - ship.MaxVelocity = 5.5f; + ship.MaxVelocity = 5.2f; ship.FleeVelocity = 6.5f; ship.ChargeVelocity = 5.5f; ship.Value = 3; @@ -102,7 +99,6 @@ namespace SuperPolarity ship.SetPolarity(polarity); ActorManager.CheckIn(ship); - Renderer.CheckIn(ship); return ship; } @@ -131,15 +127,16 @@ namespace SuperPolarity ship.BoxDimensions.Z = 40; ship.Initialize(texture, position); + ship.MagneticRadius = 1000; + ship.RepelRadius = 200; ship.MaxVelocity = 0.5f; ship.FleeVelocity = 5; ship.ChargeVelocity = 1; ship.Value = 10; - ship.HP = 9; + ship.HP = 29; ship.SetPolarity(polarity); ActorManager.CheckIn(ship); - Renderer.CheckIn(ship); return ship; } diff --git a/Super Polarity/ActorManager.cs b/Super Polarity/ActorManager.cs index 8cd265a..f5587b9 100644 --- a/Super Polarity/ActorManager.cs +++ b/Super Polarity/ActorManager.cs @@ -27,7 +27,9 @@ namespace SuperPolarity static public void CheckOut(Actor actor) { + actor.CleanUp(); Actors.Remove(actor); + actor = null; } static public void Update(GameTime gameTime) @@ -55,6 +57,12 @@ namespace SuperPolarity if (i >= Actors.Count) { i = Actors.Count - 1; } + + if (Actors.Count == 0) + { + return; + } + Actor actor = Actors[i]; for (var j = i - 1; j >= 0; j--) { @@ -110,13 +118,43 @@ namespace SuperPolarity actor.Position.Y > Game.GraphicsDevice.Viewport.Height + OutlierBounds) { CheckOut(actor); + if (actor.Parent != null) + { + actor.Parent.Children.Remove(actor); + } } } } + static public void Empty() + { + foreach (Actor actor in Actors) { + actor.CleanUp(); + } + Actors.Clear(); + } + internal static void SetGame(SuperPolarity game) { Game = game; } + + public static void Bomb() + { + for (var i = Actors.Count - 1; i >= 0; i--) + { + var actor = Actors[i]; + if (actor.GetType() == typeof(StandardShip)) + { + CheckOut(actor); + Renderer.CheckOut(actor); + } + } + } + + public static int CountBaddies() + { + return Actors.Where(a => a.GetType() == typeof(StandardShip)).Count(); + } } } diff --git a/Super Polarity/Actors/Actor.cs b/Super Polarity/Actors/Actor.cs index c317796..3bb06be 100644 --- a/Super Polarity/Actors/Actor.cs +++ b/Super Polarity/Actors/Actor.cs @@ -204,13 +204,21 @@ namespace SuperPolarity public virtual void Draw(SpriteBatch spriteBatch) { - foreach (Actor child in Children) + Actor child = null; + + // TODO: Check what's up with the null children. + if (Children == null) { + return; + } + for (var i = Children.Count - 1; i >= 0; i--) + { + child = Children[i]; child.Draw(spriteBatch); } spriteBatch.Draw(Texture, Position, null, Color, Angle, Origin, 1f, SpriteEffects.None, 0f); - spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25)); + //spriteBatch.Draw(BoxTexture, Box, new Color(255, 0, 255, 25)); } void CheckOutliers() @@ -247,5 +255,13 @@ namespace SuperPolarity { Dying = true; } + + public virtual void CleanUp() + { + Texture = null; + BoxTexture = null; + Children = null; + Texture = null; + } } } diff --git a/Super Polarity/Actors/Bullet.cs b/Super Polarity/Actors/Bullet.cs index 6b797c2..d20289c 100644 --- a/Super Polarity/Actors/Bullet.cs +++ b/Super Polarity/Actors/Bullet.cs @@ -70,5 +70,11 @@ namespace SuperPolarity Renderer.CheckOut(this); Parent.Children.Remove(this); } + + public override void CleanUp() + { + base.CleanUp(); + this.particleEngine = null; + } } } diff --git a/Super Polarity/Actors/MainShip.cs b/Super Polarity/Actors/MainShip.cs index 616f16e..9f28c80 100644 --- a/Super Polarity/Actors/MainShip.cs +++ b/Super Polarity/Actors/MainShip.cs @@ -6,6 +6,7 @@ using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Audio; namespace SuperPolarity { @@ -24,6 +25,10 @@ namespace SuperPolarity protected float MaxImmortalTime; protected bool Flashing; + protected SoundEffect PolarityChange; + protected SoundEffect ShootSound; + protected SoundEffect Hit; + public MainShip(SuperPolarity newGame) : base(newGame) {} ~MainShip() @@ -35,12 +40,18 @@ namespace SuperPolarity { base.Initialize(texture, position); - MainShip.BlueColor = new Color(230, 244, 249); - MainShip.RedColor = new Color(255, 234, 241); + MainShip.BlueColor = new Color(0, 184, 229); + MainShip.RedColor = new Color(201, 0, 68); + + PolarityChange = game.Content.Load<SoundEffect>("Sound\\polaritychange"); + ShootSound = game.Content.Load<SoundEffect>("Sound\\bullet"); + Hit = game.Content.Load<SoundEffect>("Sound\\hit"); InitParticleEngine(); SetPolarity(Polarity.Positive); + ActVelocity = 2.5f; + ShotCooldown = 50; MaxImmortalTime = 1500; @@ -68,19 +79,28 @@ namespace SuperPolarity protected void HandleShot(float value) { + + Shooting = true; + Timer t = new Timer(new TimerCallback(UnlockShot)); + t.Change(ShotCooldown, Timeout.Infinite); + + if (Children.Count > 10) + { + return; + } + var bullet = ActorFactory.CreateBullet(Position, Angle); Children.Add(bullet); bullet.Parent = this; - Shooting = true; - Timer t = new Timer(new TimerCallback(UnlockShot)); - t.Change(ShotCooldown, Timeout.Infinite); + ShootSound.Play(); } protected void UnlockShot(object state) { InputController.Unlock("shoot"); + Shooting = false; } protected void HandleChangePolarity(float value) @@ -90,28 +110,29 @@ namespace SuperPolarity public void HandleHorizontalMovement(float value) { - Acceleration.X = value * AccelerationRate; - - if (value > 0.1 && Velocity.X < 0 || value < 0.1 && Velocity.X > 0) + if (value >= -0.5 && value <= 0.5) { - Acceleration.X *= 2; + value = 0; } - if (value > 0.1 && Velocity.Y < 0 || value < 0.1 && Velocity.Y > 0) - { - Acceleration.Y *= 2; - } + Velocity.X = value * MaxVelocity; } public void HandleVerticalMovement(float value) { - Acceleration.Y = value * AccelerationRate; + if (value >= -0.5 && value <= 0.5) + { + value = 0; + } + + Velocity.Y = value * MaxVelocity; } public override void SwitchPolarity() { base.SwitchPolarity(); SwitchParticleEngine(CurrentPolarity); + PolarityChange.Play(); game.Player.ResetMultiplier(); } @@ -144,7 +165,6 @@ namespace SuperPolarity particleEngine.Update(); ConstrainToEdges(); UpdateImmortality(gameTime); - Shooting = false; } public void UpdateImmortality(GameTime gameTime) @@ -174,30 +194,36 @@ namespace SuperPolarity public override void Move(GameTime gameTime) { - base.Move(gameTime); + var VelocityLimit = MaxVelocity; + var SavedVelocity = new Vector2(Velocity.X, Velocity.Y); if (Shooting) { - if (Velocity.X > ActVelocity) - { - Velocity.X = ActVelocity; - } + VelocityLimit = ActVelocity; + } - if (Velocity.X < -ActVelocity) - { - Velocity.X = -ActVelocity; - } + if (SavedVelocity.X > VelocityLimit) + { + SavedVelocity.X = VelocityLimit; + } - if (Velocity.Y > ActVelocity) - { - Velocity.Y = ActVelocity; - } + if (SavedVelocity.X < -VelocityLimit) + { + SavedVelocity.X = -VelocityLimit; + } - if (Velocity.Y < -ActVelocity) - { - Velocity.Y = -ActVelocity; - } + if (SavedVelocity.Y > VelocityLimit) + { + SavedVelocity.Y = VelocityLimit; + } + + if (SavedVelocity.Y < -VelocityLimit) + { + SavedVelocity.Y = -VelocityLimit; } + + Position.X = Position.X + SavedVelocity.X; + Position.Y = Position.Y + SavedVelocity.Y; } public override void Magnetize(Ship ship, float distance, float angle) @@ -266,11 +292,23 @@ namespace SuperPolarity if (game.Player.Lives < 0) { Dying = true; + game.GameOver(); } else { + Hit.Play(); Immortal = true; CurrentImmortalTime = 0; } } + + public override void CleanUp() + { + base.CleanUp(); + particleEngine = null; + InputController.Unbind("moveX", HandleHorizontalMovement); + InputController.Unbind("moveY", HandleVerticalMovement); + InputController.Unbind("changePolarity", HandleChangePolarity); + InputController.Unbind("shoot", HandleShot); + } } } diff --git a/Super Polarity/Actors/Ship.cs b/Super Polarity/Actors/Ship.cs index 49d0b14..229f639 100644 --- a/Super Polarity/Actors/Ship.cs +++ b/Super Polarity/Actors/Ship.cs @@ -17,7 +17,7 @@ namespace SuperPolarity public float FleeVelocity; public float ActVelocity; public float ChargeVelocity; - protected int RepelRadius; + public int RepelRadius; protected bool Magnetizing; diff --git a/Super Polarity/BasicGenerator.cs b/Super Polarity/BasicGenerator.cs index 7cc4544..ba51742 100644 --- a/Super Polarity/BasicGenerator.cs +++ b/Super Polarity/BasicGenerator.cs @@ -26,11 +26,17 @@ namespace SuperPolarity Rate = rate; Randomizer = new Random(); Position = position; + CurrentTime = rate; } public void Update(GameTime gameTime) { - if (Game.Player.Score > ScoreThreshold) + if (ActorManager.CountBaddies() > 50) + { + return; + } + + if (Game.Player.Score >= ScoreThreshold) { CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; @@ -53,17 +59,17 @@ namespace SuperPolarity if (ShipType == Ships.Ship) { - ActorFactory.CreateShip(polarity, Position); + Renderer.CheckIn(ActorFactory.CreateShip(polarity, Position)); } if (ShipType == Ships.Scout) { - ActorFactory.CreateScout(polarity, Position); + Renderer.CheckIn(ActorFactory.CreateScout(polarity, Position)); } if (ShipType == Ships.Battlecruiser) { - ActorFactory.CreateCruiser(polarity, Position); + Renderer.CheckIn(ActorFactory.CreateCruiser(polarity, Position)); } } diff --git a/Super Polarity/Content/Fonts/bigfont.xnb b/Super Polarity/Content/Fonts/bigfont.xnb Binary files differnew file mode 100644 index 0000000..c1d876c --- /dev/null +++ b/Super Polarity/Content/Fonts/bigfont.xnb diff --git a/Super Polarity/Content/Fonts/smallfont.xnb b/Super Polarity/Content/Fonts/smallfont.xnb Binary files differnew file mode 100644 index 0000000..a87e66a --- /dev/null +++ b/Super Polarity/Content/Fonts/smallfont.xnb diff --git a/Super Polarity/Content/Graphics/pause-screen.xnb b/Super Polarity/Content/Graphics/pause-screen.xnb Binary files differnew file mode 100644 index 0000000..2307009 --- /dev/null +++ b/Super Polarity/Content/Graphics/pause-screen.xnb diff --git a/Super Polarity/Content/Graphics/polaritydemotitle.xnb b/Super Polarity/Content/Graphics/polaritydemotitle.xnb Binary files differnew file mode 100644 index 0000000..2fa9cf3 --- /dev/null +++ b/Super Polarity/Content/Graphics/polaritydemotitle.xnb diff --git a/Super Polarity/Content/Sound/bomb.wav b/Super Polarity/Content/Sound/bomb.wav Binary files differnew file mode 100644 index 0000000..5af439b --- /dev/null +++ b/Super Polarity/Content/Sound/bomb.wav diff --git a/Super Polarity/Content/Sound/bullet.wav b/Super Polarity/Content/Sound/bullet.wav Binary files differnew file mode 100644 index 0000000..6586489 --- /dev/null +++ b/Super Polarity/Content/Sound/bullet.wav diff --git a/Super Polarity/Content/Sound/gameover.wav b/Super Polarity/Content/Sound/gameover.wav Binary files differnew file mode 100644 index 0000000..cac9d23 --- /dev/null +++ b/Super Polarity/Content/Sound/gameover.wav diff --git a/Super Polarity/Content/Sound/hit.wav b/Super Polarity/Content/Sound/hit.wav Binary files differnew file mode 100644 index 0000000..43433cd --- /dev/null +++ b/Super Polarity/Content/Sound/hit.wav diff --git a/Super Polarity/Content/Sound/life.wav b/Super Polarity/Content/Sound/life.wav Binary files differnew file mode 100644 index 0000000..a1d0436 --- /dev/null +++ b/Super Polarity/Content/Sound/life.wav diff --git a/Super Polarity/Content/Sound/polaritychange.wav b/Super Polarity/Content/Sound/polaritychange.wav Binary files differnew file mode 100644 index 0000000..25b59a4 --- /dev/null +++ b/Super Polarity/Content/Sound/polaritychange.wav diff --git a/Super Polarity/Content/Sound/polaritytheme.wav b/Super Polarity/Content/Sound/polaritytheme.wav Binary files differnew file mode 100644 index 0000000..28a6bce --- /dev/null +++ b/Super Polarity/Content/Sound/polaritytheme.wav diff --git a/Super Polarity/GameScreen.cs b/Super Polarity/GameScreen.cs index 28fd7b7..783e3c1 100644 --- a/Super Polarity/GameScreen.cs +++ b/Super Polarity/GameScreen.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Input; namespace SuperPolarity @@ -12,42 +14,196 @@ namespace SuperPolarity { public GameScreen(SuperPolarity newGame) : base(newGame) {} - private BasicGenerator generatorTest; + protected List<BasicGenerator> Generators; + + protected int LivesRate; + protected int CurrentLivesRate; + protected int BombRate; + protected int CurrentBombRate; + protected SoundEffect BombSound; + protected SoundEffect LifeSound; + + protected bool Flashing; + + protected bool IsPaused; + protected Texture2D PauseScreen; public override void Initialize() { + Generators = new List<BasicGenerator>(); + + CurrentBombRate = 1; + BombRate = 6000; + + LivesRate = 10000; + CurrentLivesRate = 1; + InputController.RegisterEventForButton("changePolarity", Buttons.A); InputController.RegisterEventForKey("changePolarity", Keys.Z); InputController.RegisterEventForButton("shoot", Buttons.X); InputController.RegisterEventForKey("shoot", Keys.X); + + InputController.Bind("pause", HandlePause); + + PauseScreen = Game.Content.Load<Texture2D>("Graphics\\pause-screen"); + } + + protected void HandlePause(float value) + { + Console.WriteLine("Paused"); + IsPaused = !IsPaused; + + if (IsPaused) + { + MediaPlayer.Volume = 0.05f; + } + else + { + MediaPlayer.Volume = 1; + } } public override void LoadContent() { + CreateGenerators(); + + Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X + Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2); - generatorTest = new BasicGenerator(); - generatorTest.Initialize(Game, new Vector2(100, 600), BasicGenerator.Ships.Scout, 3000, 10); + BombSound = Game.Content.Load<SoundEffect>("Sound\\bomb"); + LifeSound = Game.Content.Load<SoundEffect>("Sound\\life"); - Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2); + Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition)); - ActorFactory.CreateMainShip(playerPosition); - ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200)); - ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200)); - ActorFactory.CreateScout(Ship.Polarity.Negative, new Vector2(500, 500)); - ActorFactory.CreateCruiser(Ship.Polarity.Positive, new Vector2(40, 40)); + Game.PlaySong("game"); + } + + protected void CalculateBomb() + { + if (Game.Player.Score >= BombRate * CurrentBombRate) + { + ActorManager.Bomb(); + Flashing = true; + BombSound.Play(); + CurrentBombRate = CurrentBombRate + 1; + } + } + + protected void CalculateLife() + { + if (Game.Player.Score >= LivesRate * CurrentLivesRate) + { + Game.Player.Lives = Game.Player.Lives + 1; + LifeSound.Play(); + CurrentLivesRate = CurrentLivesRate + 1; + } } public override void Update(GameTime gameTime) { - InputController.UpdateInput(); + CalculateBomb(); + CalculateLife(); + InputController.UpdateInput(IsPaused); + if (IsPaused) + { + return; + } ActorManager.Update(gameTime); - generatorTest.Update(gameTime); + + foreach (BasicGenerator generator in Generators) + { + generator.Update(gameTime); + } } public override void Draw(SpriteBatch spriteBatch) { Renderer.Draw(spriteBatch); + Game.Player.Draw(spriteBatch); + + if (IsPaused) + { + spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White); + } + + if (Flashing) + { + Game.GraphicsDevice.Clear(Color.Black); + Flashing = false; + } + } + + protected void CreateGenerators() + { + // The basic ship generators. + var gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + // After 1.5k liberate some sporadic Scouts, and add two more ship generators. + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500); + Generators.Add(gen); + + + // After 3k add more scouts. + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000); + Generators.Add(gen); + + // After 5k release more ships and a cruiser. + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000); + Generators.Add(gen); + } + + public override void CleanUp() + { + base.CleanUp(); + Generators.Clear(); + InputController.Unbind("pause", HandlePause); + Renderer.Empty(); + ActorManager.Empty(); } } } diff --git a/Super Polarity/InputController.cs b/Super Polarity/InputController.cs index 79bd039..c92bb9c 100644 --- a/Super Polarity/InputController.cs +++ b/Super Polarity/InputController.cs @@ -37,11 +37,42 @@ namespace SuperPolarity public static void UpdateInput() { - Poll(); DispatchMoveEvents(); DispatchRegisteredEvents(); } + public static void UpdateInput(bool highPriorityOnly) + { + Poll(); + DispatchPauseEvent(); + if (!highPriorityOnly) + { + UpdateInput(); + } + } + + public static void DispatchPauseEvent() + { + // OK THIS IS ALL KINDS OF WRONG. THIS IS A PLACEHOLDER BECAUSE DEMO! + var keyPressed = false; + if ((InputKeyboardState.IsKeyDown(Keys.Enter) || InputGamePadState.IsButtonDown(Buttons.Start))) { + keyPressed = true; + if(!BlockedButtons.Contains("pause") && !BlockedKeys.Contains("pause")) + { + BlockedButtons.Add("pause"); + BlockedKeys.Add("pause"); + Console.WriteLine("Dispatch"); + Dispatch("pause", 0); + } + } + + if (!keyPressed) + { + BlockedButtons.Remove("pause"); + BlockedKeys.Remove("pause"); + } + } + private static void Poll() { InputGamePadState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One); @@ -175,6 +206,21 @@ namespace SuperPolarity listenerList.Add(listener); } + public static void Unbind(string eventName, Action<float> listener) + { + List<Action<float>> listenerList; + bool foundListeners; + + if (!Listeners.ContainsKey(eventName)) + { + return; + } + + foundListeners = Listeners.TryGetValue(eventName, out listenerList); + + listenerList.Remove(listener); + } + public static void Dispatch(string eventName, float value) { List<Action<float>> listenerList; @@ -187,9 +233,9 @@ namespace SuperPolarity return; } - foreach (Action<float> method in listenerList) + for (var i = listenerList.Count - 1; i >= 0; i--) { - method(value); + listenerList[i](value); } } diff --git a/Super Polarity/Player.cs b/Super Polarity/Player.cs index 25e66da..2680a1c 100644 --- a/Super Polarity/Player.cs +++ b/Super Polarity/Player.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace SuperPolarity { @@ -11,11 +13,20 @@ namespace SuperPolarity public int Multiplier; public int Lives; - public Player() + + SpriteFont DebugFont; + SuperPolarity Game; + + Texture2D LifeSprite; + + public Player(SuperPolarity game) { Score = 0; Multiplier = 1; Lives = 3; + Game = game; + DebugFont = Game.Content.Load<SpriteFont>("Fonts\\bigfont"); + LifeSprite = Game.Content.Load<Texture2D>("Graphics\\neutral-ship"); } public void AddScore(int value) @@ -33,14 +44,38 @@ namespace SuperPolarity Multiplier = 1; } - public void Draw() + public void Draw(SpriteBatch spriteBatch) { + var UiColor = new Color(0, 0, 0, 200); + var lightColor = new Color(0, 0, 0, 128); + spriteBatch.DrawString(DebugFont, Score.ToString(), new Vector2(10, 10), UiColor); + spriteBatch.DrawString(DebugFont, "x" + Multiplier.ToString(), new Vector2(10, 30), lightColor); + var lifePosition = new Vector2(Game.GraphicsDevice.Viewport.Width - 120, 10); + if (Lives > 4) + { + spriteBatch.Draw(LifeSprite, lifePosition, null, UiColor, (float)(Math.PI / 2), Vector2.Zero, 0.5f, SpriteEffects.None, 0f); + spriteBatch.DrawString(DebugFont, "x " + Lives.ToString(), new Vector2(lifePosition.X + 8, lifePosition.Y + 5), UiColor); + } + else + { + for (var i = 0; i < Lives; i++) + { + spriteBatch.Draw(LifeSprite, new Vector2(lifePosition.X + (i * 28), lifePosition.Y), null, UiColor, (float)(Math.PI / 2), Vector2.Zero, 0.5f, SpriteEffects.None, 0f); + } + } } public void Update() { } + + public void Reset() + { + Score = 0; + Multiplier = 1; + Lives = 3; + } } } diff --git a/Super Polarity/Renderer.cs b/Super Polarity/Renderer.cs index 2f5c5aa..7ca8158 100644 --- a/Super Polarity/Renderer.cs +++ b/Super Polarity/Renderer.cs @@ -33,5 +33,10 @@ namespace SuperPolarity actor.Draw(spriteBatch); } } + + static public void Empty() + { + Actors.Clear(); + } } } diff --git a/Super Polarity/Screen.cs b/Super Polarity/Screen.cs index 8cea5c9..006b047 100644 --- a/Super Polarity/Screen.cs +++ b/Super Polarity/Screen.cs @@ -10,8 +10,10 @@ namespace SuperPolarity class Screen { protected SuperPolarity Game; + public bool Active; public Screen(SuperPolarity game) { + Active = false; Game = game; } diff --git a/Super Polarity/ScreenManager.cs b/Super Polarity/ScreenManager.cs index 04c10a4..b88741b 100644 --- a/Super Polarity/ScreenManager.cs +++ b/Super Polarity/ScreenManager.cs @@ -19,12 +19,22 @@ namespace SuperPolarity static public void Push(Screen screen) { + if (Screens.Count > 0) + { + Screens.Peek().Active = false; + } + + screen.LoadContent(); + screen.Active = true; Screens.Push(screen); } static public void Pop() { - Screens.Pop(); + var screen = Screens.Pop(); + screen.Active = false; + screen.CleanUp(); + Screens.Peek().Active = true; } static public void Update(GameTime gameTime) @@ -34,10 +44,7 @@ namespace SuperPolarity static public void Draw(SpriteBatch spriteBatch) { - foreach (Screen screen in Screens) - { - screen.Draw(spriteBatch); - } + Screens.Peek().Draw(spriteBatch); } internal static void SetGame(SuperPolarity game) diff --git a/Super Polarity/Super Polarity.csproj b/Super Polarity/Super Polarity.csproj index 27ea7c5..32e8d63 100644 --- a/Super Polarity/Super Polarity.csproj +++ b/Super Polarity/Super Polarity.csproj @@ -82,15 +82,40 @@ <Link>SDL.dll</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> + <Content Include="Content\Sound\bomb.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="Content\Sound\bullet.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="Content\Sound\gameover.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="Content\Sound\hit.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="Content\Sound\life.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="Content\Sound\polaritychange.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="Content\Sound\polaritytheme.wav"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> <Content Include="Icon.ico" /> </ItemGroup> + <ItemGroup /> <ItemGroup> - <Folder Include="Content\Sound\" /> - </ItemGroup> - <ItemGroup> + <None Include="Content\Fonts\bigfont.xnb"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> <None Include="Content\Fonts\SegoeUIMono14.xnb"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> + <None Include="Content\Fonts\smallfont.xnb"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> <None Include="Content\Graphics\circle.xnb"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> @@ -127,6 +152,12 @@ <None Include="Content\Graphics\neutral-ship.xnb"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> + <None Include="Content\Graphics\pause-screen.xnb"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> + <None Include="Content\Graphics\polaritydemotitle.xnb"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> <None Include="neutral-supercruiser.xnb"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> diff --git a/Super Polarity/SuperPolarity.cs b/Super Polarity/SuperPolarity.cs index 6689167..8125f8c 100644 --- a/Super Polarity/SuperPolarity.cs +++ b/Super Polarity/SuperPolarity.cs @@ -7,6 +7,8 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using Microsoft.Xna.Framework.GamerServices; +using Microsoft.Xna.Framework.Media; +using Microsoft.Xna.Framework.Audio; using SuperPolarity; #endregion @@ -26,7 +28,9 @@ namespace SuperPolarity Screen EntryScreen; - SpriteFont DebugFont; + protected Song TitleSong; + protected Song GameSong; + protected SoundEffect GameOverSound; public SuperPolarity() : base() @@ -43,7 +47,7 @@ namespace SuperPolarity ActorManager.SetGame(this); ScreenManager.SetGame(this); - EntryScreen = (Screen)new GameScreen(this); + EntryScreen = (Screen)new TitleScreen(this); } /// <summary> @@ -60,7 +64,6 @@ namespace SuperPolarity InputController.Bind("fullScreenToggle", HandleFullScreenToggle); EntryScreen.Initialize(); - ScreenManager.Push(EntryScreen); OutlierBounds = 100; } @@ -77,13 +80,17 @@ namespace SuperPolarity /// </summary> protected override void LoadContent() { + + MediaPlayer.IsRepeating = true; + GameSong = Content.Load<Song>("Sound\\polaritytheme.wav"); + GameOverSound = Content.Load<SoundEffect>("Sound\\gameover"); + // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); - EntryScreen.LoadContent(); + ScreenManager.Push(EntryScreen); - Player = new Player(); - DebugFont = Content.Load<SpriteFont>("Fonts\\SegoeUIMono14"); + Player = new Player(this); } /// <summary> @@ -107,6 +114,8 @@ namespace SuperPolarity ScreenManager.Update(gameTime); + Player.Update(); + base.Update(gameTime); } @@ -122,13 +131,25 @@ namespace SuperPolarity ScreenManager.Draw(spriteBatch); - spriteBatch.DrawString(DebugFont, "Score: " + Player.Score.ToString(), new Vector2(10, 10), Color.LightGray); - spriteBatch.DrawString(DebugFont, "Multiplier: " + Player.Multiplier.ToString(), new Vector2(10, 30), Color.LightGray); - spriteBatch.DrawString(DebugFont, "Lives: " + Player.Lives.ToString(), new Vector2(10, 50), Color.LightGray); - spriteBatch.End(); base.Draw(gameTime); } + + public void PlaySong(string songName) + { + // temp stuff before media manager is in + if (songName == "game") + { + MediaPlayer.Play(GameSong); + } + } + + public void GameOver() + { + MediaPlayer.Stop(); + GameOverSound.Play(); + ScreenManager.Pop(); + } } } diff --git a/Super Polarity/TitleScreen.cs b/Super Polarity/TitleScreen.cs index 5b33218..a953f27 100644 --- a/Super Polarity/TitleScreen.cs +++ b/Super Polarity/TitleScreen.cs @@ -2,11 +2,49 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace SuperPolarity { class TitleScreen : Screen { + protected Texture2D TitleImage; + public TitleScreen(SuperPolarity newGame) : base(newGame) {} + + public override void LoadContent() + { + base.LoadContent(); + TitleImage = Game.Content.Load<Texture2D>("Graphics\\polaritydemotitle"); + InputController.Bind("pause", HandleStart); + } + + public void HandleStart(float value) + { + if (!Active) { return; } + Game.Player.Reset(); + var gameScreen = new GameScreen(Game); + gameScreen.Initialize(); + ScreenManager.Push(gameScreen); + } + + public override void CleanUp() + { + base.CleanUp(); + TitleImage = null; + } + + public override void Draw(SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + spriteBatch.Draw(TitleImage, new Vector2(0, 0), Color.White); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + InputController.UpdateInput(false); + } } } diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe Binary files differindex 0740117..15c20d0 100644 --- a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe +++ b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb Binary files differindex b09aea1..6c1adfe 100644 --- a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb +++ b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb diff --git a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache Binary files differindex bb51f56..b8a1d5f 100644 --- a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache +++ b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt b/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt index e25ddab..cabc9d2 100644 --- a/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt +++ b/Super Polarity/obj/x86/Debug/Super Polarity.csproj.FileListAbsolute.txt @@ -29,3 +29,14 @@ C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarit C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\square.xnb C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Fonts\SegoeUIMono14.xnb C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\neutral-supercruiser.xnb +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\polaritytheme.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\bullet.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\polaritychange.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\pause-screen.xnb +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Graphics\polaritydemotitle.xnb +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\gameover.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\bomb.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\hit.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Sound\life.wav +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Fonts\bigfont.xnb +C:\Users\Miau\documents\visual studio 2010\Projects\Super Polarity\Super Polarity\bin\WindowsGL\Debug\Content\Fonts\smallfont.xnb diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.exe b/Super Polarity/obj/x86/Debug/Super Polarity.exe Binary files differindex 0740117..15c20d0 100644 --- a/Super Polarity/obj/x86/Debug/Super Polarity.exe +++ b/Super Polarity/obj/x86/Debug/Super Polarity.exe diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.pdb b/Super Polarity/obj/x86/Debug/Super Polarity.pdb Binary files differindex b09aea1..6c1adfe 100644 --- a/Super Polarity/obj/x86/Debug/Super Polarity.pdb +++ b/Super Polarity/obj/x86/Debug/Super Polarity.pdb |