//------------------------------------------------------------------------------
        // Constructor: GameObject2DManager
        // Author: Neil Holmes & Andrew Green
        // Summary: main constructor for the 2D game object manager - creates the manager
        //          and prepares it for adding and processing 2D game objects
        //------------------------------------------------------------------------------
        public GameObject2DManager(Game game, ContentManager content)
        {
            // store a reference to the parent game
            this.game = game;

            // get a handle to the display manager service
            displayManager = (DisplayManager)game.Services.GetService(typeof(DisplayManager));

            // create LinkedList object to store the game objects
            gameObjects = new LinkedList<GameObject2D>();

            // create list of objects to be removed
            objectsToBeRemoved = new LinkedList<GameObject2D>();
        }
        //------------------------------------------------------------------------------
        // Function: GameStateManager
        // Author: Neil Holmes & Andrew Green
        // Summary: constructor for the game state manager
        //-----------------------------------------------------------------------------
        public GameStateManager(Game game)
        {
            // store the game system that owns this game state manager
            this.game = game;

            // get a handle to the display manager service
            displayManager = (DisplayManager)game.Services.GetService(typeof(DisplayManager));

            // create the list of game states and the list of game states to be updated
            gameStates = new List<GameState>();
            gameStatesToUpdate = new List<GameState>();

            // load the blank texture we use for dawing the safe zones and darkening the screen
            blankTexture = game.Content.Load<Texture2D>(@"System\Blank");
        }
        //------------------------------------------------------------------------------
        // Constructor: Enemy
        // Author: Neil Holmes & Andrew Green
        // Summary: Constructor - prepares the player for use
        //------------------------------------------------------------------------------
        public Enemy(Game game, GameObject2DManager gameObjectManager, DisplayManager displayManager, Vector2 position, ShadowSystem shadowSystem, Random random)
            : base(game, gameObjectManager, displayManager, position, properties)
        {
            // store a reference to the shadow system
            this.shadowSystem = shadowSystem;

            // create a random number generator
            this.random = random;

            // create the player's state manager
            stateManager = new GameObjectStateManager(game);

            // set direction to right
            Velocity = new Vector2(4, 0);
        }
        //------------------------------------------------------------------------------
        // Function: GameState
        // Author: Neil Holmes & Andrew Green
        // Summary: main constructor
        //------------------------------------------------------------------------------
        public GameState(Game game, PlayerIndex? controllingPlayer)
        {
            // store a reference to the game that owns this game state
            this.game = game;

            // get the display manager service
            displayManager = (DisplayManager)game.Services.GetService(typeof(DisplayManager));

            // get the game state manager service
            gameStateManager = (GameStateManager)game.Services.GetService(typeof(GameStateManager));

            // get the game timer system service
            timerSystem = (TimerSystem)game.Services.GetService(typeof(TimerSystem));

            // get the game input manager service
            inputManager = (InputManager)game.Services.GetService(typeof(InputManager));

            // store the player that has control of this game state
            this.controllingPlayer = controllingPlayer;

            // set the default sub-state of the state to be transitioning on
            subState = SubState.TransitionOn;

            // by default, transition has not finished
            transitionAmount = 1.0f;

            // by default, we are not exiting ;)
            isExiting = false;
        }
        //------------------------------------------------------------------------------
        // Function: MenuItem
        // Author: nholmes
        // Summary: item constructor, stores the menu the item belongs to
        //------------------------------------------------------------------------------
        public MenuItem(Menu menu, Game game, int textOffset)
        {
            // store the menu that owns this item
            this.menu = menu;

            // store the game system reference
            this.game = game;

            // store the text offset
            this.textOffset = textOffset;

            // get the display manager service
            displayManager = (DisplayManager)game.Services.GetService(typeof(DisplayManager));

            // get the timer system service
            timerSystem = (TimerSystem)game.Services.GetService(typeof(TimerSystem));
        }
 //------------------------------------------------------------------------------
 // Constructor: GreenBug
 // Author: Neil Holmes & Andrew Green
 // Summary: Constructor - prepares the player for use
 //------------------------------------------------------------------------------
 public GreenBug(Game game, GameObject2DManager gameObjectManager, DisplayManager displayManager, Vector2 position, ShadowSystem shadowSystem, Random random)
     : base(game, gameObjectManager, displayManager, position, shadowSystem, random)
 {
     // nothing special to do here :)
 }
        //------------------------------------------------------------------------------
        // Constructor: GameObject2D
        // Author: Neil Holmes & Andrew Green
        // Summary: default constructor - initialises a 2D game object ready for use
        //------------------------------------------------------------------------------
        public GameObject2D(Game game, GameObject2DManager gameObjectManager, DisplayManager displayManager, Vector2 position, GameObject2DProperties properties)
        {
            // Store reference to parent game system object
            this.game = game;

            // Store reference to owning gameObjectManager
            this.gameObjectManager = gameObjectManager;

            // store reference to the display manager
            this.displayManager = displayManager;

            // get the game input manager service
            inputManager = (InputManager)game.Services.GetService(typeof(InputManager));

            // get the game input manager service
            timerSystem = (TimerSystem)game.Services.GetService(typeof(TimerSystem));

            // set the type of this game object
            type = properties.type;

            // store whether the object should always be updated
            alwaysUpdate = properties.alwaysUpdate;

            // store the update range for this object
            updateRange = properties.updateRange;

            // store the position
            this.position = position;

            // set initial velocity to zero
            velocity = new Vector2(0, 0);

            // create the master list for the animation frames
            animationFrames = new List<List<Texture2D>>();

            // set some default values for current animation frame and animation speed
            defaultAnimationSpeed = 10;
            animationSpeed = 0;

            // default to showing no animation at all
            currentAnimation = -1;

            // set the current animation frame index to zero
            currentAnimFrame = 0;

            // set the texture frame flip X and & to false by default
            textureFrameFlipX = false;
            textureFrameFlipY = false;

            // set the texture frame rotation to zero by defaul
            textureFrameRotation = 0;

            // store the display offset and size
            displayOffset = properties.displayOffset;
            displaySize = properties.displaySize;

            // set the rotation offset based on the display size
            rotationOffset = displaySize * 0.5f;

            // store the collision offset and size
            collisionOffset = properties.collisionOffset;
            collisionSize = properties.collisionSize;
        }
        //------------------------------------------------------------------------------
        // Method: Initialize
        // Author: Neil Holmes & Andrew Green
        // Summary: overrides base initialize so we can perform our own class
        //          initialisations called after the XNA devices have been initialised
        //------------------------------------------------------------------------------
        protected override void Initialize()
        {
            // *** IndieCity Setup ***

            // initialise the message pop up display class and register it as a service
            messagePopUp = new ICMessagePopUp(this, graphicsDeviceManager, ICMessagePosition.bottomRight, ICMessageScale.normal);
            base.Services.AddService(typeof(ICMessagePopUp), messagePopUp);

            // create bridge
            ICEBridgeLib.CoBridge bridge = new ICEBridgeLib.CoBridge();
            if (bridge != null)
            {
                // setup the game id and game secret
                ICECoreLib.GameId myGameId = StringToGameId("540a5e40-669c-4782-8424-fd688e720573");
                string mySecret = "248f9aa3-624b-4e2d-b286-8d6de3781896";

                // initialise the bridge
                bridge.Initialise(myGameId, mySecret);

                //get some user info
                int userId = bridge.DefaultUserId;
                ICECoreLib.CoUserStore storeClass = bridge.UserStore;
                ICECoreLib.CoUserInfo userClass = storeClass.GetUserFromId(userId);
                string name = userClass.Name;

                //Create a game session
                try
                {
                    indieCitySession = bridge.CreateDefaultGameSession();
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    // session creation failed - report the error and tell the game to bail out
                    messagePopUp.AddMessage("Session Creation Error", "Valid tokens for " + name +" could not be found.\nThis means a IndieCity session could not be created.", ICMessagePriority.urgent);
                    gameStatus = GameStatus.exiting;
                }

                // only do the following if the session was succesfully created
                if (indieCitySession != null)
                {
                    indieCitySession.RequestStartSession();

                    // create the achievement manager and initialise it
                    indieCityAchievementManager = new ICELandaLib.CoAchievementManager();
                    indieCityAchievementManager.SetGameSession(indieCitySession);
                    indieCityAchievementManager.InitialiseAchievements(null);

                    // retrieve the achievement group from the achievement manager
                    indieCityAchievementGroup = indieCityAchievementManager.AchievementGroup;

                    // initialise the achievement list and pop up display classes and register them as services
                    achievementPopUp = new ICAchievementPopUp(this, graphicsDeviceManager, ICAchievementPosition.topRight, ICAchievementScale.normal);
                    achievementList = new ICAchievementList(this, graphicsDeviceManager, indieCityAchievementGroup, ICAchievementScale.normal);
                    base.Services.AddService(typeof(ICAchievementPopUp), achievementPopUp);
                    base.Services.AddService(typeof(ICAchievementList), achievementList);

                    // get the current user's list of unlocked achievements
                    indieCityUserList = indieCityAchievementManager.GetUserAchievementList(indieCitySession.UserId);

                    // register the pop up achievement class with the achievement manager to handle events
                    ICELandaLib.IAchievementService iService = (ICELandaLib.IAchievementService)indieCityAchievementManager;
                    m_cookie = iService.RegisterAchievementEventHandler(achievementPopUp);

                    // create the leaderboard manager
                    indieCityLeaderboardManager = new ICELandaLib.CoLeaderboardManager();
                    indieCityLeaderboardManager.SetGameSession(indieCitySession);
                    indieCityLeaderboardManager.InitialiseLeaderboards(null);

                    // we need to create a list of the leaderboard UIDs so that the game knows the order in which to display the leaderboards
                    // this list will be custom for your game and will depend on the IDs that exist for your games leaderboards and the order
                    // in which you wish to display them!
                    int[] leaderboardUIDlist = {54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,120,74,75,76};

                    // for sanity, check that the number of IDs we have specified is the same as the number of leaderboards before proceeding ;)
                    if (leaderboardUIDlist.Length == indieCityLeaderboardManager.GetNumberLeaderboards())
                    {
                        // initlaise the leaderboard browser class and register it as a service
                        leaderboardBrowser = new ICLeaderboardsBrowser(this, graphicsDeviceManager, indieCityLeaderboardManager, ICLeaderboardScale.normal, leaderboardUIDlist);
                        base.Services.AddService(typeof(ICLeaderboardsBrowser), leaderboardBrowser);
                    }
                }
            }

            // *** optional initialisations ***

            // create the display manager and register it as a service
            displayManager = new DisplayManager(this, Window, graphicsDeviceManager, 1280, 720, ScreenMode.Windowed, 1);
            base.Services.AddService(typeof(DisplayManager), displayManager);

            // create the timer system and add it as a service
            timerSystem = new TimerSystem(this);
            base.Services.AddService(typeof(TimerSystem), timerSystem);

            // create the input manager for a single player game and add it as a service
            inputManager = new InputManager(NumPlayers.one);
            base.Services.AddService(typeof(InputManager), inputManager);

            // create the save game manager and add it as a service
            saveGameManager = new SaveGameManager(this);
            base.Services.AddService(typeof(SaveGameManager), saveGameManager);

            // initialise the mouse pointer system and add it as a service
            mousePointer = new Pointer(this, PointerType.mouse, true);
            base.Services.AddService(typeof(Pointer), mousePointer);

            // create the game state manager and register it as a service
            gameStateManager = new GameStateManager(this);
            base.Services.AddService(typeof(GameStateManager), gameStateManager);

            // activate the initial example game states - in this example we are adding two :)
            gameStateManager.AddGameState(new Background(this, null));
            gameStateManager.AddGameState(new TitleScreen(this, null));

            // propogate initialise call to base class
            base.Initialize();
        }
        //------------------------------------------------------------------------------
        // Function: TileLayer
        // Author: nholmes
        // Summary: constructor to use to create a blank tile layer
        //------------------------------------------------------------------------------
        public TileLayer(Game game, string layerName)
        {
            // get a handle to the display manager service
            displayManager = (DisplayManager)game.Services.GetService(typeof(DisplayManager));

            // store the layer's name
            name = layerName;

            // store the name of the tile set and a reference to them
            tileSetName = "";
            tileSet = null;

            // store the name of the tile map and a reference to them
            tileMapName = "";
            tileMap = null;

            // store the layer mode
            mode = TileLayerMode.Follow;

            // set the target layer to be undefined
            target = null;

            // default tint color is white
            tintColor = new Color(255, 255, 255, 255);

            // clear the updated status
            updated = false;

            // store the scale
            displayScale = 1.0f;

            // store the position scale (this will be ignored if position mode is anything other than 'Scaled'
            positionScale = new Vector2(1.0f, 1.0f);

            // store the position offset (used by all targeted layer modes)
            positionOffset = new Vector2(0.0f, 0.0f);
        }