/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { RenderMan = new RenderMan(this); // provides rendering utils GameWorld = new GameWorld(this); // holds game state InputMan = new InputMan(this, GameWorld); // handles user input // process input events before updating game state Components.Add(InputMan); Components.Add(GameWorld); mHexTileMap = new HexTileMap(this, GameWorld.MapData); mUnitDrawer = new UnitDrawer(this, GameWorld.UnitData); mUserCursor = new UserCursor(this); mUserCursor.DrawUserCursor = DrawUserCursor; mUserCursor.PushBoundaryEvent += new EventHandler(mUserCursor_PushBoundaryEvent); mUserCursor.GamePadEnabled = true; mUserCursor.KeyboardEnabled = true; // order in which components are added determines draw order Components.Add(mHexTileMap); Components.Add(mUnitDrawer); Components.Add(mUserCursor); #if !XBOX // process Lua scripts LuaEngine = new Lua(); LuaEngine.RegisterFunction("MapData", GameWorld.MapData, GameWorld.MapData.GetType().GetMethod("AddData")); LuaEngine.DoFile("scripts/main.lua"); #endif base.Initialize(); }
void DrawUserCursor(UserCursor cursor) { Vector3 pos = Vector3.Transform(mUserCursor.Position, mHexTileMap.ScreenSpaceToMapSpace); HexTilePosition selectedHex = GameWorld.MapData.NearestMapHex(pos); Vector3 selectedHexPos = RenderHex.HexPositionToMapPosition(selectedHex); // render the map highlight underneath the cursor RenderMan.PushWorldMatrix(mHexTileMap.MapSpaceToScreenSpace); GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.SourceBlend = Blend.One; GraphicsDevice.RenderState.DestinationBlend = Blend.DestinationColor; RenderMan.RenderHex.DrawHex(selectedHexPos, Color.Gray); GraphicsDevice.RenderState.AlphaBlendEnable = false; RenderMan.RenderHex.DrawHexBorder(selectedHexPos, Color.Black); RenderMan.PopWorldMatrix(); RenderMan.RenderQuad.DrawQuad(cursor.Position, Color.Magenta); }