From: Ben Beltran Date: Sat, 23 Nov 2013 23:33:38 +0000 (-0600) Subject: Chubas's house sprint. X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/commitdiff_plain/bca44639c27169b0643de1b56361e6c2958d1d4a?ds=inline Chubas's house sprint. --- diff --git a/Super Polarity.suo b/Super Polarity.suo index 4872822..360a22a 100644 Binary files a/Super Polarity.suo and b/Super Polarity.suo differ diff --git a/Super Polarity/LetterChooseWidget.cs b/Super Polarity/LetterChooseWidget.cs new file mode 100644 index 0000000..e52733f --- /dev/null +++ b/Super Polarity/LetterChooseWidget.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class LetterChooseWidget : Widget + { + int CurrentChar; + bool Locked; + int LockRate; + int CurrentTime; + + SpriteFont Font; + + public LetterChooseWidget(SuperPolarity game, Vector2 position) : base(game, position) + { + Active = false; + CurrentChar = 65; + Font = game.Content.Load("Fonts\\bigfont"); + LockRate = 300; + CurrentTime = 0; + + InputController.Bind("moveY", HandleMovement); + } + + public void HandleMovement(float value) + { + if (!Active) { return; } + + if (value > 0.8 && !Locked) { + CurrentChar = CurrentChar + 1; + + if (CurrentChar > 90) + { + CurrentChar = 32; + } + + Locked = true; + } + + if (value < -0.8 && !Locked) { + CurrentChar = CurrentChar - 1; + + if (CurrentChar < 32) + { + CurrentChar = 90; + } + + Locked = true; + } + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; + if (CurrentTime > LockRate) + { + CurrentTime = 0; + Locked = false; + } + } + + public string Value() + { + return char.ConvertFromUtf32(CurrentChar); + } + + public override void Draw(SpriteBatch spriteBatch) + { + var color = new Color(0, 0, 0, 128); + if (Active) + { + color = new Color(201, 0, 68, 255); + } + spriteBatch.DrawString(Font, Value(), Position, color); + } + } +} diff --git a/Super Polarity/MenuItem.cs b/Super Polarity/MenuItem.cs index 77561a9..8e24c97 100644 --- a/Super Polarity/MenuItem.cs +++ b/Super Polarity/MenuItem.cs @@ -5,7 +5,7 @@ using System.Text; namespace SuperPolarity { - class MenuItem : Widget + class MenuItem { } } diff --git a/Super Polarity/MenuWidget.cs b/Super Polarity/MenuWidget.cs index 8131e50..992ef43 100644 --- a/Super Polarity/MenuWidget.cs +++ b/Super Polarity/MenuWidget.cs @@ -5,7 +5,7 @@ using System.Text; namespace SuperPolarity { - class MenuWidget : Widget + class MenuWidget { } } diff --git a/Super Polarity/NameChooserWidget.cs b/Super Polarity/NameChooserWidget.cs new file mode 100644 index 0000000..ce7c149 --- /dev/null +++ b/Super Polarity/NameChooserWidget.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class NameChooserWidget : Widget + { + int CurrentIndex; + bool Lock; + int LockRate; + int CurrentTime; + + public NameChooserWidget(SuperPolarity game, Vector2 position) + : base(game, position) + { + AppendChild(new LetterChooseWidget(game, new Vector2(position.X, position.Y))); + AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 32, position.Y))); + AppendChild(new LetterChooseWidget(game, new Vector2(position.X + 64, position.Y))); + CurrentIndex = 0; + Children[CurrentIndex].Activate(); + LockRate = 300; + CurrentTime = 0; + + InputController.Bind("moveX", HandleMovement); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + + CurrentTime = CurrentTime + gameTime.ElapsedGameTime.Milliseconds; + if (CurrentTime > LockRate) + { + CurrentTime = 0; + Lock = false; + } + + foreach (LetterChooseWidget widget in Children) + { + widget.Update(gameTime); + } + } + + public void HandleMovement(float value) + { + if (value > 0.8 && !Lock) + { + Children[CurrentIndex].Deactivate(); + CurrentIndex = CurrentIndex + 1; + + if (CurrentIndex > Children.Count - 1) + { + CurrentIndex = 0; + } + + Lock = true; + } + + if (value < -0.8 && !Lock) + { + Children[CurrentIndex].Deactivate(); + CurrentIndex = CurrentIndex - 1; + + if (CurrentIndex < 0) + { + CurrentIndex = Children.Count - 1; + } + + Lock = true; + } + + Children[CurrentIndex].Activate(); + } + + public string Value() + { + var name = ""; + + foreach (LetterChooseWidget letter in Children) + { + name = name + letter.Value(); + } + + return name; + } + + public override void Draw(SpriteBatch spriteBatch) + { + foreach (LetterChooseWidget widget in Children) + { + widget.Draw(spriteBatch); + } + } + } +} diff --git a/Super Polarity/Player.cs b/Super Polarity/Player.cs index 2680a1c..184abdd 100644 --- a/Super Polarity/Player.cs +++ b/Super Polarity/Player.cs @@ -48,10 +48,10 @@ namespace SuperPolarity { 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); + spriteBatch.DrawString(DebugFont, Score.ToString(), new Vector2(40, 30), UiColor); + spriteBatch.DrawString(DebugFont, "x" + Multiplier.ToString(), new Vector2(40, 50), lightColor); - var lifePosition = new Vector2(Game.GraphicsDevice.Viewport.Width - 120, 10); + var lifePosition = new Vector2(Game.GraphicsDevice.Viewport.Width - 140, 30); if (Lives > 4) { spriteBatch.Draw(LifeSprite, lifePosition, null, UiColor, (float)(Math.PI / 2), Vector2.Zero, 0.5f, SpriteEffects.None, 0f); diff --git a/Super Polarity/ScoreScreen.cs b/Super Polarity/ScoreScreen.cs index b96ae9b..bf43275 100644 --- a/Super Polarity/ScoreScreen.cs +++ b/Super Polarity/ScoreScreen.cs @@ -2,15 +2,107 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.IO; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; namespace SuperPolarity { class ScoreScreen : Screen { - public ScoreScreen(SuperPolarity newGame) : base(newGame) {} + protected SpriteFont Font; + protected NameChooserWidget nameChooser; + protected Dictionary Scores; + + public ScoreScreen(SuperPolarity newGame) : base(newGame) { } public override void Initialize() { + base.Initialize(); + nameChooser = new NameChooserWidget(Game, new Vector2(40, Game.GraphicsDevice.Viewport.Height / 4)); + InputController.RegisterEventForButton("OK", Buttons.A); + InputController.RegisterEventForKey("OK", Keys.Z); + Scores = new Dictionary(); + ReadScore(); + } + + public override void LoadContent() + { + base.LoadContent(); + Font = Game.Content.Load("Fonts\\bigfont"); + InputController.Bind("OK", HandleNext); + } + + public void HandleNext(float value) + { + if (!Active) { return; } + WriteScore(); + ScreenManager.Pop(); + } + + public void WriteScore() + { + using (StreamWriter swriter = new StreamWriter("scores.txt", true)) + { + swriter.WriteLine(nameChooser.Value() + "," + Game.Player.Score.ToString()); + } + } + + public void ReadScore() + { + try + { + using (StreamReader sreader = new StreamReader("scores.txt")) + { + string line = null; + while ((line = sreader.ReadLine()) != null) + { + string[] parts = line.Split(','); + Scores.Add(parts[0], int.Parse(parts[1])); + } + } + } + catch (FileNotFoundException) + { + } + } + + public override void CleanUp() + { + base.CleanUp(); + Font = null; + } + + public override void Draw(SpriteBatch spriteBatch) + { + base.Draw(spriteBatch); + spriteBatch.DrawString(Font, "YOUR SCORE WAS: " + Game.Player.Score.ToString(), new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2), Color.Black); + spriteBatch.DrawString(Font, "Use Left Stick or Arrows to Choose Name Press A when done", new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2 + 40), new Color(0, 0, 0, 128)); + nameChooser.Draw(spriteBatch); + DrawScores(spriteBatch); + } + + public override void Update(GameTime gameTime) + { + base.Update(gameTime); + InputController.UpdateInput(false); + nameChooser.Update(gameTime); + } + + protected void DrawScores(SpriteBatch spriteBatch) + { + var sortedDict = (from entry in Scores orderby entry.Value descending select entry) + .Take(5) + .ToDictionary(pair => pair.Key, pair => pair.Value); + + var i = 0; + + foreach (KeyValuePair entry in sortedDict) { + i++; + spriteBatch.DrawString(Font, entry.Key + " " + entry.Value, new Vector2(40, Game.GraphicsDevice.Viewport.Height / 2 + 100 + (32 * i)), new Color(0, 0, 0, 64)); + } + } } } diff --git a/Super Polarity/Super Polarity.csproj b/Super Polarity/Super Polarity.csproj index 32e8d63..24cea5c 100644 --- a/Super Polarity/Super Polarity.csproj +++ b/Super Polarity/Super Polarity.csproj @@ -43,8 +43,10 @@ + + diff --git a/Super Polarity/SuperPolarity.cs b/Super Polarity/SuperPolarity.cs index 8125f8c..9311d53 100644 --- a/Super Polarity/SuperPolarity.cs +++ b/Super Polarity/SuperPolarity.cs @@ -36,6 +36,8 @@ namespace SuperPolarity : base() { graphics = new GraphicsDeviceManager(this); + Components.Add(new GamerServicesComponent(this)); + graphics.PreferMultiSampling = true; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; @@ -147,9 +149,13 @@ namespace SuperPolarity public void GameOver() { + var scoreScreen = new ScoreScreen(this); + scoreScreen.Initialize(); + MediaPlayer.Stop(); GameOverSound.Play(); ScreenManager.Pop(); + ScreenManager.Push(scoreScreen); } } } diff --git a/Super Polarity/Widget.cs b/Super Polarity/Widget.cs index 65c3fd2..ea92cfd 100644 --- a/Super Polarity/Widget.cs +++ b/Super Polarity/Widget.cs @@ -2,14 +2,40 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; namespace SuperPolarity { class Widget { - public IList Children; + public List Children; public Dictionary>> Listeners; + public Vector2 Position; + public SuperPolarity Game; + + protected bool Active; + + public Widget(SuperPolarity game, Vector2 position) + { + Game = game; + Position = position; + Active = false; + Children = new List(); + Listeners = new Dictionary>>(); + } + + public void Activate() + { + Active = true; + } + + public void Deactivate() + { + Active = false; + } + public virtual void AppendChild(Widget widget) { Children.Add(widget); @@ -54,5 +80,13 @@ namespace SuperPolarity method(value); } } + + public virtual void Update(GameTime gameTime) + { + } + + public virtual void Draw(SpriteBatch spriteBatch) + { + } } } diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe index 2e1de3b..746c670 100644 Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe differ diff --git a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb index 5e7a303..fea49a1 100644 Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb differ diff --git a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache index b8a1d5f..ef9920b 100644 Binary files a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.exe b/Super Polarity/obj/x86/Debug/Super Polarity.exe index 2e1de3b..746c670 100644 Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.exe and b/Super Polarity/obj/x86/Debug/Super Polarity.exe differ diff --git a/Super Polarity/obj/x86/Debug/Super Polarity.pdb b/Super Polarity/obj/x86/Debug/Super Polarity.pdb index 5e7a303..fea49a1 100644 Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.pdb and b/Super Polarity/obj/x86/Debug/Super Polarity.pdb differ diff --git a/Super Polarity/scores.txt b/Super Polarity/scores.txt new file mode 100644 index 0000000..e69de29