]> git.r.bdr.sh - rbdr/super-polarity/commitdiff
Chubas's house sprint.
authorBen Beltran <redacted>
Sat, 23 Nov 2013 23:33:38 +0000 (17:33 -0600)
committerBen Beltran <redacted>
Sat, 23 Nov 2013 23:33:38 +0000 (17:33 -0600)
16 files changed:
Super Polarity.suo
Super Polarity/LetterChooseWidget.cs [new file with mode: 0644]
Super Polarity/MenuItem.cs
Super Polarity/MenuWidget.cs
Super Polarity/NameChooserWidget.cs [new file with mode: 0644]
Super Polarity/Player.cs
Super Polarity/ScoreScreen.cs
Super Polarity/Super Polarity.csproj
Super Polarity/SuperPolarity.cs
Super Polarity/Widget.cs
Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe
Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb
Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Super Polarity/obj/x86/Debug/Super Polarity.exe
Super Polarity/obj/x86/Debug/Super Polarity.pdb
Super Polarity/scores.txt [new file with mode: 0644]

index 4872822db81575dd8c8f8c6451990498b52e907d..360a22abd8cddd5d61cdb82075f8f48a3a999ed0 100644 (file)
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 (file)
index 0000000..e52733f
--- /dev/null
@@ -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<SpriteFont>("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);
+        }
+    }
+}
index 77561a9613db6ce0148a7fbda19af5d5735b2e8c..8e24c972f030b487f0efd4a12dbc4b8d744d0014 100644 (file)
@@ -5,7 +5,7 @@ using System.Text;
 
 namespace SuperPolarity
 {
 
 namespace SuperPolarity
 {
-    class MenuItem : Widget
+    class MenuItem
     {
     }
 }
     {
     }
 }
index 8131e50503623535615578d5cd0781bb44b1278a..992ef43e87ebf4cf1c8f5398895e2053943c406e 100644 (file)
@@ -5,7 +5,7 @@ using System.Text;
 
 namespace SuperPolarity
 {
 
 namespace SuperPolarity
 {
-    class MenuWidget : Widget
+    class MenuWidget
     {
     }
 }
     {
     }
 }
diff --git a/Super Polarity/NameChooserWidget.cs b/Super Polarity/NameChooserWidget.cs
new file mode 100644 (file)
index 0000000..ce7c149
--- /dev/null
@@ -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);
+            }
+        }
+    }
+}
index 2680a1ce4397cc83053335897662d2f45f6ba149..184abdd5ae3c5c598283cdee38520e6bb2c00faf 100644 (file)
@@ -48,10 +48,10 @@ namespace SuperPolarity
         {
             var UiColor = new Color(0, 0, 0, 200);
             var lightColor = new Color(0, 0, 0, 128);
         {
             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);
             if (Lives > 4)
             {
                 spriteBatch.Draw(LifeSprite, lifePosition, null, UiColor, (float)(Math.PI / 2), Vector2.Zero, 0.5f, SpriteEffects.None, 0f);
index b96ae9bdfc50409bb361de2fffbc39b22455089b..bf432752b1eed1563ed3027e2fde76cb21e19ce3 100644 (file)
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 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
     {
 
 namespace SuperPolarity
 {
     class ScoreScreen : Screen
     {
-        public ScoreScreen(SuperPolarity newGame) : base(newGame) {}
+        protected SpriteFont Font;
+        protected NameChooserWidget nameChooser;
+        protected Dictionary<string, int> Scores;
+
+        public ScoreScreen(SuperPolarity newGame) : base(newGame) { }
 
         public override void Initialize()
         {
 
         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<string, int>();
+            ReadScore();
+        }
+
+        public override void LoadContent()
+        {
+            base.LoadContent();
+            Font = Game.Content.Load<SpriteFont>("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<string, int> 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));
+            }
+
         }
     }
 }
         }
     }
 }
index 32e8d631f81dddf11662c8c31d4eca0dc9903a91..24cea5c3daf86706475d742fd779b5a9b71b0be9 100644 (file)
     <Compile Include="GameScreen.cs" />
     <Compile Include="InputController.cs" />
     <Compile Include="Actors\MainShip.cs" />
     <Compile Include="GameScreen.cs" />
     <Compile Include="InputController.cs" />
     <Compile Include="Actors\MainShip.cs" />
+    <Compile Include="LetterChooseWidget.cs" />
     <Compile Include="MenuItem.cs" />
     <Compile Include="MenuWidget.cs" />
     <Compile Include="MenuItem.cs" />
     <Compile Include="MenuWidget.cs" />
+    <Compile Include="NameChooserWidget.cs" />
     <Compile Include="Particle.cs" />
     <Compile Include="ParticleEffectFactory.cs" />
     <Compile Include="ParticleEngine.cs" />
     <Compile Include="Particle.cs" />
     <Compile Include="ParticleEffectFactory.cs" />
     <Compile Include="ParticleEngine.cs" />
index 8125f8cdcea147b608d2f4b5c074bd577201cee3..9311d5311c59c371127f151afdf51821761f9b60 100644 (file)
@@ -36,6 +36,8 @@ namespace SuperPolarity
             : base()
         {
             graphics = new GraphicsDeviceManager(this);
             : base()
         {
             graphics = new GraphicsDeviceManager(this);
+            Components.Add(new GamerServicesComponent(this));
+
             graphics.PreferMultiSampling = true;
             graphics.PreferredBackBufferWidth = 1280;
             graphics.PreferredBackBufferHeight = 720;
             graphics.PreferMultiSampling = true;
             graphics.PreferredBackBufferWidth = 1280;
             graphics.PreferredBackBufferHeight = 720;
@@ -147,9 +149,13 @@ namespace SuperPolarity
 
         public void GameOver()
         {
 
         public void GameOver()
         {
+            var scoreScreen = new ScoreScreen(this);
+            scoreScreen.Initialize();
+
             MediaPlayer.Stop();
             GameOverSound.Play();
             ScreenManager.Pop();
             MediaPlayer.Stop();
             GameOverSound.Play();
             ScreenManager.Pop();
+            ScreenManager.Push(scoreScreen);
         }
     }
 }
         }
     }
 }
index 65c3fd23d4f36bb01caabe5a264c71de78b4337c..ea92cfd7565fc148ad410643297b3534c72c7ae4 100644 (file)
@@ -2,14 +2,40 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
 
 namespace SuperPolarity
 {
     class Widget
     {
 
 namespace SuperPolarity
 {
     class Widget
     {
-        public IList<Widget> Children;
+        public List<Widget> Children;
         public Dictionary<string, List<Action<float>>> Listeners;
 
         public Dictionary<string, List<Action<float>>> 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<Widget>();
+            Listeners = new Dictionary<string, List<Action<float>>>();
+        }
+
+        public void Activate()
+        {
+            Active = true;
+        }
+
+        public void Deactivate()
+        {
+            Active = false;
+        }
+
         public virtual void AppendChild(Widget widget)
         {
             Children.Add(widget);
         public virtual void AppendChild(Widget widget)
         {
             Children.Add(widget);
@@ -54,5 +80,13 @@ namespace SuperPolarity
                 method(value);
             }
         }
                 method(value);
             }
         }
+
+        public virtual void Update(GameTime gameTime)
+        {
+        }
+
+        public virtual void Draw(SpriteBatch spriteBatch)
+        {
+        }
     }
 }
     }
 }
index 2e1de3b2aad87b8c9be8fbb5c1e7067daa4eefd4..746c670d212dd743e8e75933bb75b8c15c5ebe81 100644 (file)
Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.exe differ
index 5e7a3033dc3c542a10c97f0473bc3d73ce0a704f..fea49a11535fb995ba2f98ea99be1341b300099f 100644 (file)
Binary files a/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb and b/Super Polarity/bin/WindowsGL/Debug/Super Polarity.pdb differ
index b8a1d5fe0a5049e71256b7bd88d5992577dd790e..ef9920b9a6d488eac2f2efb8f4ac5a2ba940f17e 100644 (file)
Binary files a/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/Super Polarity/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ
index 2e1de3b2aad87b8c9be8fbb5c1e7067daa4eefd4..746c670d212dd743e8e75933bb75b8c15c5ebe81 100644 (file)
Binary files a/Super Polarity/obj/x86/Debug/Super Polarity.exe and b/Super Polarity/obj/x86/Debug/Super Polarity.exe differ
index 5e7a3033dc3c542a10c97f0473bc3d73ce0a704f..fea49a11535fb995ba2f98ea99be1341b300099f 100644 (file)
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 (file)
index 0000000..e69de29