示例#1
0
        /// <summary>
        /// Constructs a new settler at the specified position.
        /// </summary>
        /// <param name="position">Where the unit should be spawned.</param>
        /// <param name="camera">Game camera being used.</param>
        /// <param name="director">Reference to the game director.</param>
        /// <param name="gameScreen">Gamescreen of the game so that the settler can build platforms.</param>
        /// <param name="ui">UI of the game so the settler can edit the UI.</param>
        public Settler(Vector2 position, Camera camera, ref Director director, GameScreen gameScreen, UserInterfaceScreen ui)
            : base(position, camera, ref director)
        {
            Speed  = 4;
            Health = 10;

            AbsoluteSize = new Vector2(20, 20);

            RevelationRadius = (int)AbsoluteSize.X * 6;

            mDirector.GetInputManager.FlagForAddition(this);

            mNeverMoved = true;

            mUi = ui;

            /* too inefficient
             * ColliderGrid = new[,]
             * {
             *  {true, true},
             *  {true, true}
             * };
             */

            SetAbsBounds();
        }
示例#2
0
        private void StandardInitialization(ContentManager content)
        {
            //Load stuff
            var platformConeTexture  = content.Load <Texture2D>("Cones");
            var platformCylTexture   = content.Load <Texture2D>("Cylinders");
            var platformBlankTexture = content.Load <Texture2D>("PlatformBasic");
            var platformDomeTexture  = content.Load <Texture2D>("Dome");
            var mapBackground        = content.Load <Texture2D>("backgroundGrid");
            var libSans12            = content.Load <SpriteFont>("LibSans12");

            PlatformFactory.Init(platformConeTexture, platformCylTexture, platformDomeTexture, platformBlankTexture, libSans12);
            StructureLayoutHolder.Initialize(ref mDirector);

            //Map related stuff
            Camera = new Camera(mGraphics.GraphicsDevice, ref mDirector);
            mFow   = new FogOfWar(Camera, mGraphics.GraphicsDevice);

            var map = new Map.Map(mapBackground, 60, 60, mFow, Camera, ref mDirector);

            Map = map;
            var milUnitSheet  = content.Load <Texture2D>("UnitSpriteSheet");
            var milGlowSheet  = content.Load <Texture2D>("UnitGlowSprite");
            var genUnitSprite = content.Load <Texture2D>("GenUnit");

            MilitaryUnit.mMilSheet      = milUnitSheet;
            MilitaryUnit.mGlowTexture   = milGlowSheet;
            GeneralUnit.mGenUnitTexture = genUnitSprite;

            mDirector.GetMilitaryManager.SetMap(ref map);

            //INITIALIZE SCREENS
            GameScreen = new GameScreen(mGraphics.GraphicsDevice, ref mDirector, Map, Camera, mFow);
            Ui         = new UserInterfaceScreen(ref mDirector, Map, Camera, mScreenManager);
            mDirector.GetUserInterfaceController.ControlledUserInterface = Ui; // the UI needs to be added to the controller

            // the input manager keeps this from not getting collected by the GC
            mDebugscreen = new DebugScreen((StackScreenManager)mScreenManager, Camera, Map, ref mDirector);

            mDirector.GetInputManager.FlagForAddition(this);

            if (Ai != null)
            {
                GameScreen.AddObject(Ai);
            }
        }
示例#3
0
        public void ReloadContent(ContentManager content, GraphicsDeviceManager graphics, ref Director director, IScreenManager screenmanager)
        {
            mScreenManager = screenmanager;
            mGraphics      = graphics;
            //Load stuff
            var platformConeTexture  = content.Load <Texture2D>("Cones");
            var platformCylTexture   = content.Load <Texture2D>("Cylinders");
            var platformBlankTexture = content.Load <Texture2D>("PlatformBasic");
            var platformDomeTexture  = content.Load <Texture2D>("Dome");

            MilitaryUnit.mMilSheet    = content.Load <Texture2D>("UnitSpriteSheet");
            MilitaryUnit.mGlowTexture = content.Load <Texture2D>("UnitGlowSprite");
            var mapBackground = content.Load <Texture2D>("backgroundGrid");
            var libSans12     = content.Load <SpriteFont>("LibSans12");

            PlatformFactory.Init(platformConeTexture, platformCylTexture, platformDomeTexture, platformBlankTexture, libSans12);
            PlatformBlank.mLibSans12 = libSans12;
            director.ReloadContent(mDirector, Map.GetMeasurements(), content, mGraphics);
            mDirector = director;

            //Map related stuff
            Camera.ReloadContent(mGraphics, ref mDirector);
            mFow.ReloadContent(mGraphics, Camera);
            Ui = new UserInterfaceScreen(ref mDirector, Map, Camera, mScreenManager);
            Ui.LoadContent(content);
            Ui.Loaded = true;
            //This has to be after ui creation, because the ui graphid dictionary is updated in the structuremap.reloadcontent method
            Map.ReloadContent(mapBackground, Camera, mFow, ref mDirector, content, Ui);
            GameScreen.ReloadContent(content, graphics, Map, mFow, Camera, ref mDirector, Ui);
            mDirector.GetUserInterfaceController.ReloadContent(ref mDirector);
            mDirector.GetUserInterfaceController.ControlledUserInterface = Ui; // the UI needs to be added to the controller

            // Reload map for the military manager
            var map = Map;

            director.GetMilitaryManager.ReloadSetMap(ref map);
            // the input manager keeps this from not getting collected by the GC
            mDebugscreen = new DebugScreen((StackScreenManager)mScreenManager, Camera, Map, ref mDirector);
            mDirector.GetInputManager.FlagForAddition(this);

            //AI Stuff
            Ai?.ReloadContent(ref mDirector);
            StructureLayoutHolder.Initialize(ref mDirector);
        }
示例#4
0
 public void ReloadContent(ref Director director, Camera camera, ref Map.Map map, GameScreen gamescreen, UserInterfaceScreen ui)
 {
     ReloadContent(ref director, camera);
     mUi = ui;
     mDirector.GetInputManager.FlagForAddition(this);
 }
示例#5
0
        public void ReloadContent(ContentManager content, FogOfWar fow, ref Director dir, Camera camera, Map map, UserInterfaceScreen ui)
        {
            mFow      = fow;
            mDirector = dir;
            dir.GetInputManager.AddMousePositionListener(this);
            foreach (var placement in mStructuresToPlace)
            {
                placement.ReloadContent(camera, ref dir, map);
            }

            foreach (var platform in mPlatforms)
            {
                platform.ReloadContent(content, ref dir);
            }
            //Update uis graphid dictionary
            ui.GraphIdToGraphStructureDict = mGraphIdToGraph;

            foreach (var roads in mRoads)
            {
                roads.ReloadContent(ref dir);
            }
        }
示例#6
0
        public void ReloadContent(ContentManager content, GraphicsDeviceManager graphics, Map.Map map, FogOfWar fow, Camera camera, ref Director director, UserInterfaceScreen ui)
        {
            mMap      = map;
            mFow      = fow;
            mCamera   = camera;
            mDirector = director;
            mDirector.GetSoundManager.SetLevelThemeMusic("Tutorial");
            mDirector.GetSoundManager.SetSoundPhase(SoundPhase.Build);
            mSelBox = new SelectionBox(Color.White, mCamera, ref mDirector);
            AddObject(mSelBox);
            //All collider items have to be readded to the ColliderMap
            var colliderlist = new List <ICollider>();

            foreach (var spatial in mSpatialObjects)
            {
                var collider = spatial as ICollider;
                if (collider != null && !colliderlist.Contains(collider))
                {
                    mMap.UpdateCollider(collider);
                    colliderlist.Add(collider);
                }
            }

            //Reload the content for all ingame objects like Platforms etc.
            foreach (var drawable in mDrawables)
            {
                //TODO: Add terrain when its in master
                var possibleMilitaryUnit = drawable as MilitaryUnit;
                var possibleEnemy        = drawable as EnemyUnit;
                var possibleSettler      = drawable as Settler;
                var possiblegenunit      = drawable as GeneralUnit;
                var possiblerock         = drawable as Rock;
                var possiblepuddle       = drawable as Puddle;
                var conUnit = drawable as FreeMovingUnit;
                if (conUnit != null)
                {
                    mSelBox.SelectingBox += conUnit.BoxSelected;
                }
                possibleEnemy?.ReloadContent(content, ref mDirector, camera, ref mMap);
                possiblepuddle?.ReloadContent(ref mDirector);
                possiblerock?.ReloadContent(ref mDirector);
                //This should also affect enemy units, since they are military units
                possibleMilitaryUnit?.ReloadContent(content, ref mDirector, camera, ref map);
                possibleSettler?.ReloadContent(ref mDirector, mCamera, ref map, this, ui);
                if (possibleSettler != null)
                {
                    possibleSettler.BuildCommandCenter += SettlerBuild;
                }
                possiblegenunit?.ReloadContent(ref mDirector, content);
            }

            //Reload the content for all ingame objects like Platforms etc.
            foreach (var updateable in mUpdateables)
            {
                //TODO: Add terrain when its in master
                var possibleMilitaryUnit = updateable as MilitaryUnit;
                var possibleEnemy        = updateable as EnemyUnit;
                var possibleSettler      = updateable as Settler;
                var possiblegenunit      = updateable as GeneralUnit;
                var possiblerock         = updateable as Rock;
                var possiblepuddle       = updateable as Puddle;

                var freeMovingUnit = updateable as FreeMovingUnit;
                if (freeMovingUnit != null && freeMovingUnit.Friendly)
                {
                    mSelBox.SelectingBox += freeMovingUnit.BoxSelected;
                }
                possibleEnemy?.ReloadContent(content, ref mDirector, camera, ref mMap);
                possiblepuddle?.ReloadContent(ref mDirector);
                possiblerock?.ReloadContent(ref mDirector);
                //This should also affect enemy units, since they are military units
                possibleMilitaryUnit?.ReloadContent(content, ref mDirector, camera, ref map);
                possibleSettler?.ReloadContent(ref mDirector, mCamera, ref map, this, ui);
                if (possibleSettler != null)
                {
                    possibleSettler.BuildCommandCenter += SettlerBuild;
                }
                possiblegenunit?.ReloadContent(ref mDirector, content);
            }

            //Reload the content for all ingame objects like Platforms etc.
            foreach (var spatial in mSpatialObjects)
            {
                //TODO: Add terrain when its in master
                var possibleMilitaryUnit = spatial as MilitaryUnit;
                var possibleEnemy        = spatial as EnemyUnit;
                var possibleSettler      = spatial as Settler;
                var possiblegenunit      = spatial as GeneralUnit;
                var possiblerock         = spatial as Rock;
                var possiblepuddle       = spatial as Puddle;
                var freeMovingUnit       = spatial as FreeMovingUnit;
                var possibleplatform     = spatial as PlatformBlank;
                var possibleroad         = spatial as Road;
                if (freeMovingUnit != null && freeMovingUnit.Friendly)
                {
                    mSelBox.SelectingBox += freeMovingUnit.BoxSelected;
                }

                possibleroad?.ReloadContent(ref mDirector);
                possibleEnemy?.ReloadContent(content, ref mDirector, camera, ref mMap);
                possibleplatform?.ReloadContent(content, ref mDirector);
                possiblepuddle?.ReloadContent(ref mDirector);
                possiblerock?.ReloadContent(ref mDirector);
                //This should also affect enemy units, since they are military units
                possibleMilitaryUnit?.ReloadContent(content, ref mDirector, camera, ref map);
                possibleSettler?.ReloadContent(ref mDirector, mCamera, ref map, this, ui);

                if (possibleSettler != null)
                {
                    possibleSettler.BuildCommandCenter += SettlerBuild;
                }
                possiblegenunit?.ReloadContent(ref mDirector, content);
            }

            if (mUistarted)
            {
                ui.Activate();
            }
        }
        /// <summary>
        /// Updates the state of the LoadGameManager and changes to the game if the conditions are met.
        /// by the stack screen manager
        /// </summary>
        /// <param name="gametime"></param>
        public void Update(GameTime gametime)
        {
            if (mGameLoaded)
            {
                mGameLoaded = false;
            }

            if (sResolutionChanged)
            {
                sResolutionChanged = false;
            }

            switch (sPressed)
            {
            case "None":
                return;

            case "Skirmish":
                mLevel      = new Skirmish(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Skirmish);
                mGameScreen = mLevel.GameScreen;
                mUi         = mLevel.Ui;
                mNewGame    = true;
                break;

            case "TechDemo":
                mLevel      = new TechDemo(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Techdemo);
                mGameScreen = mLevel.GameScreen;
                mUi         = mLevel.Ui;
                mNewGame    = true;
                break;

            case "Tutorial":
                mLevel      = new Tutorial(mGraphics, ref mDirector, mContent, mScreenManager, LevelType.Tutorial);
                mGameScreen = mLevel.GameScreen;
                mUi         = mLevel.Ui;
                mNewGame    = true;
                break;

            case "Save1":
                mName = XSerializer.GetSaveNames()[0];
                break;

            case "Save2":
                mName = XSerializer.GetSaveNames()[1];
                break;

            case "Save3":
                mName = XSerializer.GetSaveNames()[2];
                break;

            case "Save4":
                mName = XSerializer.GetSaveNames()[3];
                break;

            case "Save5":
                mName = XSerializer.GetSaveNames()[4];
                break;

            case "ReturnToMainMenu":
                int width;
                int height;
                if (GlobalVariables.IsFullScreen)
                {
                    width  = mGame.mGraphicsAdapter.CurrentDisplayMode.Width;
                    height = mGame.mGraphicsAdapter.CurrentDisplayMode.Height;
                }
                else
                {
                    width  = GlobalVariables.ResolutionList[GlobalVariables.ChosenResolution].Item1;
                    height = GlobalVariables.ResolutionList[GlobalVariables.ChosenResolution].Item2;
                }

                mScreenManager.AddScreen(new MainMenuManagerScreen(screenResolution: new Vector2(width, height),
                                                                   screenManager: mScreenManager,
                                                                   director: ref mDirector,
                                                                   showSplash: false,
                                                                   game: mGame));
                break;

            default:
                throw new InvalidGenericArgumentException(
                          "Somehow the LoadGameManagerScreen was assigned to a button that he should not have been assigned to. Cannot handle" +
                          "this State");
            }

            //This means a save has to be loaded
            if (mName != "")
            {
                var levelToBe = XSerializer.Load(mName, false);
                if (levelToBe.IsPresent())
                {
                    mLevel = (ILevel)levelToBe.Get();
                    mLevel.ReloadContent(mContent, mGraphics, ref mDirector, mScreenManager);
                    mGameScreen = mLevel.GameScreen;
                    mUi         = mLevel.Ui;
                    //Remove all screens above this screen, of course this only works if this screen is really on the bottom of the stack
                    for (var i = mScreenManager.GetScreenCount() - 1; i > 1; i--)
                    {
                        mScreenManager.RemoveScreen();
                    }
                    mScreenManager.AddScreen(mGameScreen);
                    mScreenManager.AddScreen(mUi);
                    mDirector.GetStoryManager.SetScreenManager(mScreenManager);
                    mGameLoaded = true;
                    mName       = "";
                    GlobalVariables.mGameIsPaused = false;
                }
            }

            else if (mNewGame)
            {
                //Remove all screens above this screen, of course this only works if this screen is really on the bottom of the stack
                for (var i = mScreenManager.GetScreenCount() - 1; i > 0; i--)
                {
                    mScreenManager.RemoveScreen();
                }
                mScreenManager.AddScreen(mGameScreen);
                mScreenManager.AddScreen(mUi);

                mGameLoaded = true;
                mNewGame    = false;
                GlobalVariables.mGameIsPaused = false;
            }

            sPressed = "None";
        }
示例#8
0
 public void ReloadContent(Texture2D background, Camera camera, FogOfWar fow, ref Director dir, ContentManager content, UserInterfaceScreen ui)
 {
     mBackgroundTexture = background;
     mCamera            = camera;
     mFow = fow;
     //ADD ALL THE THINGS TO THE CAMERA AND THE FOW
     mStructureMap.ReloadContent(content, mFow, ref dir, mCamera, this, ui);
     mCollisionMap.ReloadContent();
     mResourceMap.ReloadContent(ref dir);
 }