--- /dev/null
+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);
+ }
+ }
+}
namespace SuperPolarity
{
- class MenuItem : Widget
+ class MenuItem
{
}
}
namespace SuperPolarity
{
- class MenuWidget : Widget
+ class MenuWidget
{
}
}
--- /dev/null
+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);
+ }
+ }
+ }
+}
{
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);
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<string, int> 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<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));
+ }
+
}
}
}
<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="NameChooserWidget.cs" />
<Compile Include="Particle.cs" />
<Compile Include="ParticleEffectFactory.cs" />
<Compile Include="ParticleEngine.cs" />
: base()
{
graphics = new GraphicsDeviceManager(this);
+ Components.Add(new GamerServicesComponent(this));
+
graphics.PreferMultiSampling = true;
graphics.PreferredBackBufferWidth = 1280;
graphics.PreferredBackBufferHeight = 720;
public void GameOver()
{
+ var scoreScreen = new ScoreScreen(this);
+ scoreScreen.Initialize();
+
MediaPlayer.Stop();
GameOverSound.Play();
ScreenManager.Pop();
+ ScreenManager.Push(scoreScreen);
}
}
}
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<Widget> Children;
+ public List<Widget> Children;
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);
method(value);
}
}
+
+ public virtual void Update(GameTime gameTime)
+ {
+ }
+
+ public virtual void Draw(SpriteBatch spriteBatch)
+ {
+ }
}
}