• On the road to the Marketplace (Part 1)

    by  • October 9, 2011 • .Net, Journal, Programming • 0 Comments

    Ever since Apple introduced the App Store there have been a flock of people wanting to cash in on the opportunity. The App Store itself is now saturated with Games, Apps and silly utilities. With the recent launch of Windows Phone 7 with its own Marketplace, I now have a chance to cash in this time round.

    Usually the only thing holding most people back is an idea; though looking through the Marketplace this doesn’t seem to hold some people back. And so while sitting with Coffee & Cake I had an idea for a game.

    Herbert & The H Language

    While entering the 2008 AI Challenge of the Imagine Cup I had great fun completing ‘AI’ puzzles based on a language called H using a simulation tool.

    My idea is to make a game based on a cut down version of this, where points can be scored on the size of the algorithm and the amount of points collected in a certain amount of time.

    To make things more interesting I wanted to chart my progression and coding from the initial idea to submission to the Marketplace and hopefully making a few pennies.

    In this post I lay the foundation and start coding some of the groundwork for the follow on blog posts where I go on to continue develop.

    Getting the Tools

    First things first, I went to my App Hub Developer account and downloaded all the necessary tools (which are kindly all bundled together for developing the latest Mango Apps)

    App Type

    Once everything installed, I fired up Visual Studio 2010 and began coding, first off I had to choose the application type. Pure Silverlight, Silverlight & XNA or Pure XNA. As I am creating a game choosing pure XNA makes things simpler.

    Laying the Framework

    When developing a game, the content is split up across various screens, with only one being visible at any one time, when the screen is topmost and visible, updating and rendering control shall be passed to the GameScreen.

    namespace RoboMind
    {
        using Microsoft.Xna.Framework;
    
        ///
    <summary> /// Enum describes the screen transition state.
     /// </summary>
        public enum ScreenState
        {
            TransitionOn,
            Active,
            TransitionOff,
            Hidden,
        }
    
        public abstract class GameScreen
        {
            ///
    <summary> /// Unload content for the screen. Called when the screen is removed from the screen manager.
     /// </summary>
            public virtual void Unload() { }
    
            public virtual void Draw(GameTime gameTime) { }
    
            public virtual void Update(GameTime gameTime) { }
        }
    }
     

    To accomplish this we need to split content into GameScreen’s which is managed by a controlling class, the controlling class shall have a stack of GameScreen’s and Draw operations shall be passed to the topmost screen.

    using System;
    using System.Collections.Generic;
    
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Input.Touch;
    
    namespace RoboMind
    {
        public class ScreenManager : DrawableGameComponent
        {
            ///
    <summary> /// Store all the GameScreens currently in use by the application.
     /// </summary>
            private Stack screenStack = new Stack();
    
            ///
    <summary> /// Constructs a new screen manager component.
     /// </summary>
            public ScreenManager(Game game)
                : base(game)
            {
                // we must set EnabledGestures before we can query for them, but
                // we don't assume the game wants to read them.
                TouchPanel.EnabledGestures = GestureType.None;
            }
    
            public GameScreen CreateScreen(Type screenType)
            {
                // All of our screens have empty constructors so we can just use Activator
                return Activator.CreateInstance(screenType) as GameScreen;
            }
    
            public override void Update(GameTime gameTime)
            {
                // Call the topmost GameScreen and update
                if (screenStack.Count > 0)
                {
                    screenStack.Peek().Update(gameTime);
                }
            }
    
            public override void Draw(GameTime gameTime)
            {
                // Call the topmost GameScreen and draw
                if (screenStack.Count > 0)
                {
                    screenStack.Peek().Draw(gameTime);
                }
            }
        }
    }
    

    So now we have a basic mechanism to render screens, though we shall add transition animations to them eventually.

    About

    Software engineer. Tea drinker

    http://MrPfister.com

    Leave a Reply

    Your email address will not be published. Required fields are marked *