Commits

Carolyn Van Slyck committed 28b95b3

* Switching the main character from a monkey to a pony
* Random cleanup

Comments (0)

Files changed (23)

OMG/GameController/GameControllerState.cs

 {
     public class GameControllerState
     {
-        public GameControllerAction Actions { get; private set; }
+        private GameControllerAction Actions { get; set; }
         public Vector2 GameCursorLocation;
 
-        public static bool KeyboardActivated;
-        public static bool MouseActivated;
-        public static bool GamePadActivated;
+        private static bool KeyboardActivated;
+        private static bool MouseActivated;
+        private static bool GamePadActivated;
 
         public static GameControllerState GetState(GameTime gameTime)
         {
 
             if (GamePadActivated)
             {
-                XboxControllerAction xboxActions = XboxController.ProcessGamePad(gamePad.Value, state);
+// ReSharper disable PossibleInvalidOperationException
+                XboxControllerAction xboxActions = XboxController.ProcessGamePad(gamePad.Value);
+// ReSharper restore PossibleInvalidOperationException
                 state.Actions |= xboxActions.Actions;
                 GameCursor.UpdateLocation(xboxActions.RightThumbStickDirection, gameTime);
             }
             if (KeyboardActivated)
             {
-                state.Actions |= KeyboardController.ProcessKeyboard(state);
+                state.Actions |= KeyboardController.ProcessKeyboard();
             }
             if (MouseActivated)
             {
-                MouseAction mouseActions = MouseController.ProcessMouse(state);
+                MouseAction mouseActions = MouseController.ProcessMouse();
                 state.Actions |= mouseActions.Actions;
                 GameCursor.Location = mouseActions.Location;
             }

OMG/GameController/KeyboardController.cs

 {
     public static class KeyboardController
     {
-        private static readonly Dictionary<Keys, GameControllerAction> _keysMapping = new Dictionary<Keys, GameControllerAction>
+        private static readonly Dictionary<Keys, GameControllerAction> KeysMapping = new Dictionary<Keys, GameControllerAction>
                                                                              {
                                                                                {Keys.Up, GameControllerAction.Up},
                                                                                {Keys.Down, GameControllerAction.Down},
                                                                                {Keys.Right, GameControllerAction.Right}
                                                                              };
 
-        public static GameControllerAction ProcessKeyboard(GameControllerState state)
+        public static GameControllerAction ProcessKeyboard()
         {
-            GameControllerAction actions = GameControllerAction.None;
+            var actions = GameControllerAction.None;
 
             var keyboardState = Keyboard.GetState();
             var keysPressed = keyboardState.GetPressedKeys().AsEnumerable();
             {
                 foreach (var keyPressed in keysPressed)
                 {
-                    if (!_keysMapping.ContainsKey(keyPressed))
+                    if (!KeysMapping.ContainsKey(keyPressed))
                         continue;
-                    actions |= _keysMapping[keyPressed];
+                    actions |= KeysMapping[keyPressed];
                 }
             }
 

OMG/GameController/MouseController.cs

 
 namespace OMG.GameController
 {
-    public class MouseController
+    public static class MouseController
     {
-        public static MouseAction ProcessMouse(GameControllerState state)
+        public static MouseAction ProcessMouse()
         {
             var action = new MouseAction();
 

OMG/GameController/XboxController.cs

 
 namespace OMG.GameController
 {
-    public class XboxController
+    public static class XboxController
     {
-        public static XboxControllerAction ProcessGamePad(GamePadState gamePad, GameControllerState state)
+        public static XboxControllerAction ProcessGamePad(GamePadState gamePad)
         {
             var action = new XboxControllerAction();
 

OMG/GameCursor.cs

             }
         }
 
-        public static int Speed { get; set; }
+        private static int Speed { get; set; }
 
         public static void UpdateLocation(Vector2 direction, GameTime gameTime)
         {

OMG/GameScreen.cs

     public static class GameScreen
     {
         public static Rectangle SafeArea { get; set; }
+
+        public static Vector2 GetCenterScreenVector()
+        {
+            var x = (float)SafeArea.Width / 2;
+            var y = (float)SafeArea.Height / 2;
+            return new Vector2(x, y);
+        }
     }
 }

OMG/MiniGame/AgilityCourse/AgilityCourseGame.cs

 {
     public class AgilityCourseGame : MiniGameBase
     {
-        private Monkey _monkey;
+        private Character _character;
         private ScrollingBackground _scrollingBackground;
         private Cursor _cursor;
 
         protected override void InitializeSprites()
         {
             _cursor = new Cursor {DrawOrder = 2};
-            _monkey = new Monkey {DrawOrder = 1};
+            _character = new Pony {DrawOrder = 1};
             _scrollingBackground = new ScrollingBackground();
 
-            Sprites.Add(_monkey);
+            Sprites.Add(_character);
             Sprites.Add(_scrollingBackground);
             Sprites.Add(_cursor);
-        } 
+        }
     }
 }

OMG/MiniGame/IMiniGame.cs

         void Initialize(GraphicsDeviceManager graphics, ContentManager content);
         void LoadContent();
         void Update(GameControllerState gameControllerState, GameTime gameTime);
-        void Draw(GameTime gameTime);
+        void Draw();
     }
 
     public delegate void GameComplete(GameCompleteEventArguments e);

OMG/MiniGame/MiniGameBase.cs

 {
     public abstract class MiniGameBase : IMiniGame
     {
-        protected GraphicsDeviceManager Graphics;
-        protected ContentManager Content;
-        protected SpriteManager Sprites { get; set; }
+        private GraphicsDeviceManager _graphics;
+        private ContentManager _content;
+        protected SpriteManager Sprites { get; private set; }
 
         /// <summary>
         /// Allows the game to perform any initialization it needs to before starting to run.
         /// </summary>
         public void Initialize(GraphicsDeviceManager graphics, ContentManager content)
         {
-            Graphics = graphics;
-            Content = content;
+            _graphics = graphics;
+            _content = content;
 
-            GameScreen.SafeArea = Graphics.GraphicsDevice.Viewport.TitleSafeArea;
-            GameCursor.Location = new Vector2(GameScreen.SafeArea.X / 2, GameScreen.SafeArea.Y / 2);
+            GameScreen.SafeArea = _graphics.GraphicsDevice.Viewport.TitleSafeArea;
+            GameCursor.Location = GameScreen.GetCenterScreenVector();
 
-            Sprites = new SpriteManager(Graphics.GraphicsDevice);
+            Sprites = new SpriteManager(_graphics.GraphicsDevice);
             InitializeSprites();
         }
 
         /// </summary>
         public virtual void LoadContent()
         {
-            Sprites.LoadContent(Content);
+            Sprites.LoadContent(_content);
         }
 
         /// <summary>
         /// <summary>
         /// This is called when the game should draw itself.
         /// </summary>
-        /// <param name="gameTime">Provides a snapshot of timing values.</param>
-        public void Draw(GameTime gameTime)
+        public void Draw()
         {
-            Graphics.GraphicsDevice.Clear(Color.Black);
+            _graphics.GraphicsDevice.Clear(Color.Black);
             Sprites.Draw();
         }
 

OMG/MiniGame/MiniGameManager.cs

 
         protected override void Draw(GameTime gameTime)
         {
-            CurrentGame.Draw(gameTime);
+            CurrentGame.Draw();
 
             base.Draw(gameTime);
         }

OMG/OMG.Windows.csproj

     <Compile Include="MiniGame\MiniGameManager.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Program.cs" />
+    <Compile Include="Sprite\Background.cs" />
+    <Compile Include="Sprite\Character.cs" />
     <Compile Include="Sprite\Cursor.cs" />
     <Compile Include="Sprite\DialogOption.cs" />
     <Compile Include="Sprite\ISprite.cs" />
     <Compile Include="Sprite\Monkey.cs" />
+    <Compile Include="Sprite\Pony.cs" />
     <Compile Include="Sprite\ScrollingBackground.cs" />
     <Compile Include="Sprite\Sprite.cs" />
     <Compile Include="Sprite\SpriteManager.cs" />

OMG/OMG.Xbox.csproj

     <Compile Include="MiniGame\MiniGameManager.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Program.cs" />
+    <Compile Include="Sprite\Background.cs" />
+    <Compile Include="Sprite\Character.cs" />
     <Compile Include="Sprite\Cursor.cs" />
     <Compile Include="Sprite\DialogOption.cs" />
     <Compile Include="Sprite\ISprite.cs" />
     <Compile Include="Sprite\Monkey.cs" />
+    <Compile Include="Sprite\Pony.cs" />
     <Compile Include="Sprite\ScrollingBackground.cs" />
     <Compile Include="Sprite\Sprite.cs" />
     <Compile Include="Sprite\SpriteManager.cs" />
 using OMG.MiniGame;
-using OMG.MiniGame.AgilityCourse;
 
 namespace OMG
 {

OMG/Sprite/Background.cs

+namespace OMG.Sprite
+{
+    public class Background : Sprite
+    {
+        private readonly string _backaroundImageName;
+
+        public Background(string backaroundImageName)
+        {
+            _backaroundImageName = backaroundImageName;
+        }
+
+        protected override string ImageName
+        {
+            get { return _backaroundImageName; }
+        }
+    }
+}

OMG/Sprite/Character.cs

+using System;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
+using OMG.GameController;
+
+namespace OMG.Sprite
+{
+    public abstract class Character : Sprite
+    {
+        private Vector2 _currentDirection = Vector2.Zero;
+        private Vector2 _currentSpeed = Vector2.Zero;
+        private Rectangle? _targetPosition;
+
+        private const int WalkingSpeed = 160;
+        private const int RunningSpeed = WalkingSpeed*4;
+        private const int MoveUp = -1;
+        private const int MoveDown = 1;
+        private const int MoveLeft = -1;
+        private const int MoveRight = 1;
+
+        public override void LoadContent(ContentManager contentManager)
+        {
+            base.LoadContent(contentManager);
+
+            Position = GameScreen.GetCenterScreenVector();
+        }
+
+        public override void Update(GameTime gameTime, GameControllerState gameControllerState)
+        {
+            UpdateMovement(gameControllerState);
+            Move(gameTime, _currentSpeed, _currentDirection);
+        }
+
+        private void UpdateMovement(GameControllerState gameControllerState)
+        {
+            if (_targetPosition == null || _targetPosition.Value.Contains(new Point((int)Position.X, (int)Position.Y)))
+            {
+                _currentDirection = new Vector2(0, 0);
+            }
+
+            if (gameControllerState.HasAction(GameControllerAction.Select))
+            {
+                _targetPosition = new Rectangle((int)GameCursor.Location.X - Size.Width / 2, (int)GameCursor.Location.Y - Size.Height / 2, Size.Width, Size.Height);
+
+                Vector2 distance = GameCursor.Location - Position;
+                distance.Normalize();
+
+                _currentDirection = distance;
+
+                _currentSpeed.X = RunningSpeed;
+                _currentSpeed.Y = RunningSpeed;
+            }
+
+            if (gameControllerState.HasAction(GameControllerAction.Left))
+            {
+                _targetPosition = null;
+                _currentSpeed.X = WalkingSpeed;
+                _currentSpeed.Y = 0;
+                _currentDirection.X = MoveLeft;
+                _currentDirection.Y = 0;
+            }
+            else if (gameControllerState.HasAction(GameControllerAction.Right))
+            {
+                _targetPosition = null;
+                _currentSpeed.X = WalkingSpeed;
+                _currentSpeed.Y = 0;
+                _currentDirection.X = MoveRight;
+                _currentDirection.Y = 0;
+            }
+            else if (gameControllerState.HasAction(GameControllerAction.Up))
+            {
+                _targetPosition = null;
+                _currentSpeed.Y = WalkingSpeed;
+                _currentSpeed.X = 0;
+                _currentDirection.Y = MoveUp;
+                _currentDirection.X = 0;
+            }
+            else if (gameControllerState.HasAction(GameControllerAction.Down))
+            {
+                _targetPosition = null;
+                _currentSpeed.Y = WalkingSpeed;
+                _currentSpeed.X = 0;
+                _currentDirection.Y = MoveDown;
+                _currentDirection.X = 0;
+            }
+        }
+
+        private void Move(GameTime gameTime, Vector2 speed, Vector2 direction)
+        {
+            Position += direction * speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
+        }
+    }
+}

OMG/Sprite/Cursor.cs

-using System.Collections.Generic;
-using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework;
 using OMG.GameController;
 
 namespace OMG.Sprite
 {
     public class Cursor : Sprite
     {
-        public const string AssetName = "cursor";
-
-        protected List<ISprite> CollidedSprites = new List<ISprite>();
-
-        public Cursor() : base(AssetName)
+        public Cursor()
         {
             DrawOrder = int.MaxValue;
         }
 
-        protected bool Selected;
+        protected override string ImageName
+        {
+            get { return "cursor"; }
+        }
 
         private Color? _lastTint;
         public override void Update(GameTime gameTime, GameControllerState gameControllerState)

OMG/Sprite/Monkey.cs

-using Microsoft.Xna.Framework;
-using Microsoft.Xna.Framework.Content;
-using OMG.GameController;
-
-namespace OMG.Sprite
+namespace OMG.Sprite
 {
-    public class Monkey : Sprite
+    public class Monkey : Character
     {
-        private const string AssetName = "face-monkey";
-
-        private const int WalkingSpeed = 160;
-        private const int RunningSpeed = WalkingSpeed*4;
-
-        private const int MoveUp = -1;
-        private const int MoveDown = 1;
-        private const int MoveLeft = -1;
-        private const int MoveRight = 1;
-
-        Vector2 _currentDirection = Vector2.Zero;
-        Vector2 _currentSpeed = Vector2.Zero;
-
-        private Rectangle? _targetPosition;
-
-        public Monkey() : base(AssetName)
+        protected override string ImageName
         {
-        }
-
-        public override void LoadContent(ContentManager contentManager)
-        {
-            base.LoadContent(contentManager);
-            Position = new Vector2(GameScreen.SafeArea.Width / 2, GameScreen.SafeArea.Height / 2);
-        }
-
-        public override void Update(GameTime gameTime, GameControllerState gameControllerState)
-        {
-            UpdateMovement(gameControllerState);
-            Move(gameTime, _currentSpeed, _currentDirection);
-        }
-
-        private void UpdateMovement(GameControllerState gameControllerState)
-        {
-            if (_targetPosition == null || _targetPosition.Value.Contains(new Point((int)Position.X, (int)Position.Y)))
-            {
-                _currentDirection = new Vector2(0, 0);
-            }
-
-            if (gameControllerState.HasAction(GameControllerAction.Select))
-            {
-                _targetPosition = new Rectangle((int)GameCursor.Location.X - Size.Width / 2, (int)GameCursor.Location.Y - Size.Height / 2, Size.Width, Size.Height);
-
-                Vector2 distance = GameCursor.Location - Position;
-                distance.Normalize();
-
-                _currentDirection = distance;
-
-                _currentSpeed.X = RunningSpeed;
-                _currentSpeed.Y = RunningSpeed;
-            }
-
-            if (gameControllerState.HasAction(GameControllerAction.Left))
-            {
-                _targetPosition = null;
-                _currentSpeed.X = WalkingSpeed;
-                _currentSpeed.Y = 0;
-                _currentDirection.X = MoveLeft;
-                _currentDirection.Y = 0;
-            }
-            else if (gameControllerState.HasAction(GameControllerAction.Right))
-            {
-                _targetPosition = null;
-                _currentSpeed.X = WalkingSpeed;
-                _currentSpeed.Y = 0;
-                _currentDirection.X = MoveRight;
-                _currentDirection.Y = 0;
-            }
-            else if (gameControllerState.HasAction(GameControllerAction.Up))
-            {
-                _targetPosition = null;
-                _currentSpeed.Y = WalkingSpeed;
-                _currentSpeed.X = 0;
-                _currentDirection.Y = MoveUp;
-                _currentDirection.X = 0;
-            }
-            else if (gameControllerState.HasAction(GameControllerAction.Down))
-            {
-                _targetPosition = null;
-                _currentSpeed.Y = WalkingSpeed;
-                _currentSpeed.X = 0;
-                _currentDirection.Y = MoveDown;
-                _currentDirection.X = 0;
-            }
-        }
-
-        private void Move(GameTime gameTime, Vector2 speed, Vector2 direction)
-        {
-            Position += direction * speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
+            get { return "face-monkey"; }
         }
     }
 }

OMG/Sprite/Pony.cs

+namespace OMG.Sprite
+{
+    public class Pony : Character
+    {
+        protected override string ImageName
+        {
+            get { return "Pony-Appaloosa"; }
+        }
+    }
+}

OMG/Sprite/ScrollingBackground.cs

-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
             _backgrounds = new List<ISprite>();
             for (int i = 0; i < NumberOfBackgrounds; i++)
             {
-                _backgrounds.Add(new Sprite(BackgroundAssetName + (i + 1)));
+                _backgrounds.Add(new Background(BackgroundAssetName + (i + 1)));
             }
         }
 
             
         }
 
-        public Rectangle Size { get; set; }
+        public Rectangle Size { get; private set; }
 
         public Rectangle Border
         {
                 background.Scale = 2.0f;
                 background.LoadContent(contentManager);
 
+                Size = new Rectangle(0, 0, background.Size.Width, background.Size.Height);
+
                 if (i > 0)
                 {
                     var previousBkg = _backgrounds[i - 1];

OMG/Sprite/Sprite.cs

-using System;
-using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
 using OMG.GameController;
 
 namespace OMG.Sprite
 {
-    public class Sprite : ISprite
+    public abstract class Sprite : ISprite
     {
-        private readonly string _assetName;
-
-        public Sprite(string assetName)
+        protected Sprite()
         {
-            _assetName = assetName;
             Position = new Vector2(0, 0);
             Scale = 1.0f;
             Tint = NoTint;
         }
 
+        protected abstract string ImageName { get; }
         protected static readonly Color NoTint = Color.White;
-
         protected Color Tint { get; set; }
 
         private Vector2 _position;
 
         public virtual void LoadContent(ContentManager contentManager)
         {
-            _spriteTexture = contentManager.Load<Texture2D>(_assetName);
+            _spriteTexture = contentManager.Load<Texture2D>(ImageName);
             UpdateSize();
         }
 

OMG/Sprite/TextSprite.cs

 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
-using OMG.GameController;
 
 namespace OMG.Sprite
 {
         private readonly GameFont _font;
         private SpriteFont _spriteFont;
 
-        public TextSprite(string text) 
-            : base(GameFont.Standard.Location())
+        private TextSprite(string text)
         {
             _font = GameFont.Standard;
             Text = text;
             DrawOrder = int.MaxValue-1;
         }
 
-        public TextSprite(GameFont font)
+        protected TextSprite(GameFont font)
             : this(string.Empty)
         {
             _font = font;
             _font = font;
         }
 
-        public string Text;
+        protected override string ImageName
+        {
+            get { return GameFont.Standard.Location(); }
+        }
+
+        protected string Text;
         public Color TextColor = Color.White;
 
         public override void LoadContent(ContentManager contentManager)

OMG/StartScreen.cs

-using Microsoft.Xna.Framework;
-using OMG.MiniGame;
+using OMG.MiniGame;
 using OMG.MiniGame.AgilityCourse;
 using OMG.Sprite;
 
         {
             base.LoadContent();
 
-            _startGameOption.Position = new Vector2(GameScreen.SafeArea.Width / 2, GameScreen.SafeArea.Height / 2);
+            _startGameOption.Position = GameScreen.GetCenterScreenVector();
         }
 
         private void StartGame()
+Requirements
+Visual Studio 2010
+XNA Game Studio 4.0 (http://www.microsoft.com/download/en/details.aspx?id=23714)
+
+1. Open OMG.sln
+2. Start OMG.Windows.csproj
+
+Visit http://cvanslyck.com/projects for more!