Example #1
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch = new SpriteBatch(GraphicsDevice);
     GlobalState.LoadContent(Content);
     HookHomeStateEvents();
 }
Example #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            switch (_currentState)
            {
            case LevelSelectorState levelSelectorState:
                _currentState = new PlayingState(_gameModel, _sunnyLevel);
                _currentState.LoadContent();
                break;

            case CustomiseState customiseState:

                break;

            case PlayingState playingState:

                break;

            default:
                throw new Exception("Unknown state: " + _currentState.ToString());
            }

            _currentState.Update(gameTime);

            base.Update(gameTime);
        }
Example #3
0
        public void Update()
        {
            while (true)
            {
                _stopWatch.Restart();

                // Actual Key
                Key = Input.GetKeyDown();

                if (_nextState != null)
                {
                    _currentState = _nextState;
                    _currentState.LoadContent();

                    _nextState = null;
                    Ticks      = 1;
                }

                _currentState.Update();
                _currentState.PostUpdate();

                Ticks++;
                if (Ticks == int.MaxValue)
                {
                    Ticks = 0;
                }
                // Slow FPS
                int elapsed = (int)_stopWatch.ElapsedMilliseconds;
                elapsed = Utils.Clamp(elapsed, 0, 10);
                Thread.Sleep(10 - elapsed);
            }
        }
Example #4
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     spriteBatch   = new SpriteBatch(GraphicsDevice);
     _currentState = new GameState(this, Content);
     _currentState.LoadContent();
     _nextState = null;
 }
Example #5
0
        private void Initialize()
        {
            Console.OutputEncoding = System.Text.Encoding.Unicode;

            Random = new Random();

            Console.SetWindowSize(ScreenWidth, ScreenHeight);
            Console.SetBufferSize(ScreenWidth, ScreenHeight);

            Console.CursorVisible = false;

            _currentState = new MenuState(this);
            _currentState.LoadContent();

            _nextState = null;

            Ticks = 0;

            Key = SpicyKeys.Nothing;

            Sound      = true;
            Difficulty = 1;

            _stopWatch = new Stopwatch();
        }
Example #6
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch   = new SpriteBatch(GraphicsDevice);
     _currentState = new GameState(this, Content);
     _currentState.LoadContent();
     _nextState = null;
 }
Example #7
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            current = new MenuState(_graphics, _spriteBatch, this, "Main");//new GameState(_graphics, _spriteBatch, this, 1);
            current.LoadContent();
            // TODO: use this.Content to load your game content here
        }
Example #8
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            _currentState = new MenuState(this, Content, _sessionStorageProvider);
            _currentState.LoadContent();
            _nextState = null;
        }
Example #9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            _currentState = new MenuState(this, graphics.GraphicsDevice, Content);
            _currentState.LoadContent();
        }
Example #10
0
 public static void LoadState(State state)
 {
     m_state = state;
     if (m_assetHandler != null)
     {
         m_state.LoadContent(m_assetHandler);
         m_state.Draw(m_target);
     }
 }
        /// LoadContent kallas för att ladda in all grafik och sprites

        protected override void LoadContent()
        {
            // skapar ny spritebatch som skriver ut grafik

            spriteBatch = new SpriteBatch(GraphicsDevice);

            _currentState = new MenuState(this, Content);
            _currentState.LoadContent();
            _nextState = null;
        }
Example #12
0
        void ReplayGameHandler(object sender, EventArgs e)
        {
            UnhookHomeStateEvents();

            GlobalState = new GameState();
            GlobalState.Initialize(null);
            GlobalState.LoadContent(Content);

            HookGameStateEvents();
        }
Example #13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            GameModel = new GameModel(Content, _graphics, _spriteBatch);

            var testTexture = Content.Load <Texture2D>("Enemy");

            _units = new List <Unit>();

            var ar = new AbilityRepository();

            ar.Load();

            var ur = new UnitRepository();

            ur.Load(ar);

            var sr = new SquadRepository();

            sr.Load();

            var startPositions = new List <Point>()
            {
                new Point(1, 2),
                new Point(4, 2),
                new Point(0, 5),
                new Point(2, 3),
                new Point(3, 1),
            };

            var squad = sr.Squads.First();

            foreach (var unitId in squad.UnitIds)
            {
                var index = Random.Next(0, startPositions.Count);

                var startPoint = startPositions[index];
                startPositions.RemoveAt(index);

                var unitModel = ur.GetById(unitId);

                _units.Add(new Unit(testTexture)
                {
                    TilePosition = Map.PointToVector2(startPoint.X, startPoint.Y),
                    UnitModel    = unitModel,
                    Layer        = 0.6f,
                });
            }

            //_state = new BattleState(GameModel, _units);
            _state = new HomeState(GameModel);
            _state.LoadContent();
        }
Example #14
0
        /// <summary>
        /// Remove all existing states and set it to the given new state.
        /// </summary>
        /// <param name="newState">State to set the game to.</param>
        public void ChangeState(State newState)
        {
            State oldState = currentState;

            currentState = newState;

            oldState.UnloadContent();
            oldState = null;

            currentState.Initialize();
            currentState.LoadContent();
        }
Example #15
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (_nextState != null)
            {
                _currentState = _nextState;
                _currentState.LoadContent();
                _nextState = null;
            }
            _currentState.Update(gameTime);
            _currentState.PostUpdate(gameTime);

            base.Update(gameTime);
        }
Example #16
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _defaultTex = new Texture2D(GraphicsDevice, 1, 1);
            _defaultTex.SetData(new Color[1] {
                Color.White
            });

            _currentState = new MenuState(this, Content, _defaultTex);
            _currentState.LoadContent();
            _nextState = null;
        }
Example #17
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //-

            /*if (Keyboard.GetState().IsKeyDown(Keys.Space))
             *  _hasStarted = true;
             *
             * if (!_hasStarted)
             *  return;
             *
             * _timer2 += (float)gameTime.ElapsedGameTime.TotalSeconds;
             *
             * ZomTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
             *
             *
             * foreach (var sprite in _sprites.ToArray())
             * {
             *  sprite.Update(gameTime, _sprites);
             * }
             *
             *
             * foreach (var sprite in ZomList.ToArray())
             * {
             *  sprite.Update(gameTime, ZomList);
             * }
             *
             * foreach(var sprite in _sprites.ToArray())
             * {
             *  sprite.Update(gameTime, ZomList);
             * }*/

            if (_nextState != null)
            {
                _currentState = _nextState;
                _currentState.LoadContent();
                _nextState = null;
            }

            _currentState.Update(gameTime);

            _currentState.PostUpdate(gameTime);

            //PostUpdate();
            //
            //SpawnTarget();



            base.Update(gameTime);
        }
Example #18
0
        protected override void Update(GameTime gameTime)
        {
            if (_nextState != null)
            {
                // If there is a next state, change it to current and load it.
                _currentState = _nextState;
                _currentState.LoadContent();
                _nextState = null;
            }

            _currentState.Update(gameTime);
            _currentState.PostUpdate(gameTime);

            base.Update(gameTime);
        }
Example #19
0
        // Loads up all the graphics and menu states.
        protected override void LoadContent()
        {
            sb = new SpriteBatch(GraphicsDevice);

            _currentState = new MenuState(this, Content);
            _currentState.LoadContent();
            backgroundMusic = Content.Load <Song>("Sound/Deep");
            MediaPlayer.Play(backgroundMusic);
            flameEffect = Content.Load <SoundEffect>("Sound/flame");
            flameEffect.Play();


            _nextState = null;

            // TODO: use this.Content to load your game content here
        }
Example #20
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (_nextState != null)
            {
                _currentState = _nextState;
                _currentState.LoadContent();
                _nextState = null;
            }
            _currentState.Update(gameTime);
            _currentState.PostUpdate(gameTime);


            // TODO: Add your update logic here

            base.Update(gameTime);
        }
 public State GetState(Type type)
 {
     if (_stateCache.ContainsKey(type))
     {
         return(_stateCache[type]);
     }
     else
     {
         //State state = (State) Activator.CreateInstance(type,Game);
         State state = (State)Activator.CreateInstance(type);
         state.Game = Game;
         state.Initialize();
         state.LoadContent();
         _stateCache[type] = state;
         return(state);
     }
 }
Example #22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //------
            //_scoreManager = ScoreManager.Load();
            //-----
            _currentState = new MenuState(this, graphics, Content);
            _currentState.LoadContent();
            _nextState = null;

            /*_targetTexture = Content.Load<Texture2D>("ZombieT1");
             * _font = Content.Load<SpriteFont>("Font");
             *
             *
             * //-
             * Restart();*/
        }
Example #23
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (_nextState != null)
            {
                _currentState = _nextState;
                _currentState.LoadContent();
                _nextState = null;
            }
            _currentState.Update(gameTime);
            _currentState.PostUpdate(gameTime);

            base.Update(gameTime);
        }
Example #24
0
        void CreateGameHandler(object sender, EventArgs e)
        {
            try
            {
                Session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
                HookSessionEvents();
            }
            catch (Exception exception)
            {
            }
        }
Example #25
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            //    Exit();

            if (_nextState != null)
            {
                _currentState.UnloadContent();
                _nextState.LoadContent();
                _currentState = _nextState;
                _nextState    = null;
            }

            // TODO: Add your update logic here
            _currentState.Update(gameTime);

            _currentState.PostUpdate(gameTime);

            base.Update(gameTime);
        }
Example #26
0
        protected override void Update(GameTime gameTime)
        {
            PreviousKey = CurrentKey;
            CurrentKey  = Keyboard.GetState();


            if (_currentState is MenuState)
            {
                if (Graphics.IsFullScreen)
                {
                    Graphics.ToggleFullScreen();
                }
                if (CurrentKey.IsKeyDown(Keys.Escape) && PreviousKey.IsKeyUp(Keys.Escape))
                {
                    Exit();
                }
            }

            if (CurrentKey.IsKeyDown(Keys.F11) && PreviousKey.IsKeyUp(Keys.F11) && !(_currentState is MenuState))
            {
                Graphics.ToggleFullScreen();
            }

            ScreenWidth  = GraphicsDevice.Viewport.Bounds.Width;
            ScreenHeight = GraphicsDevice.Viewport.Bounds.Height;


            if (_nextState != null)
            {
                _currentState = _nextState;
                _currentState.LoadContent();

                _nextState = null;
            }

            _currentState.Update(gameTime);

            _currentState.PostUpdate(gameTime);

            base.Update(gameTime);
        }
Example #27
0
        void JoinGameHandler(object sender, EventArgs e)
        {
            AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 2, null);

            if (sessions.Count < 1)
            {
                return;
            }
            Session = NetworkSession.Join(sessions[0]);
            if (Session != null)
            {
                HookSessionEvents();

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
            }
        }
Example #28
0
 protected override void LoadContent()
 {
     SpriteBatch = new SpriteBatch(GraphicsDevice);
     State.LoadContent(this);
     base.LoadContent();
 }
Example #29
0
 /// <summary>
 /// Adds the new state to the stack. NOTE: the previous, if any, state is still in the stack. If need to remove current state before pushing new on on, refer to PopAndSetState
 /// </summary>
 /// <param name="state"></param>
 public void SetState(State state)
 {
     gameStates.Push(state);
     currentState = (State)gameStates.Peek();
     currentState.LoadContent(_game.Content);
 }
Example #30
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            _gameModel = new GameModel()
            {
                ContentManger         = Content,
                GraphicsDeviceManager = graphics,
                SpriteBatch           = spriteBatch,
            };

            _currentState = new LevelSelectorState(_gameModel);
            _currentState.LoadContent();

            var player = new Player(new Dictionary <string, Animation>()
            {
                { "Running", new Animation(Content.Load <Texture2D>("Player/Running"), 4) },
                { "Jumping", new Animation(Content.Load <Texture2D>("Player/Jumping"), 4) },
                { "Falling", new Animation(Content.Load <Texture2D>("Player/Falling"), 4) },
            })
            {
                BaseAttributes = new Attributes()
                {
                    Speed = 3f,
                },
                Position = new Vector2(50, 300),
                Layer    = 1f,
            };

            _sunnyLevel = new LevelModel(player)
            {
                //Emitter = new SnowEmitter(new Particle(Content.Load<Texture2D>("Particles/Snow"))),
                ScrollingBackgrounds = new List <ScrollingBackground>()
                {
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Trees"), player, 60f)
                    {
                        Layer = 0.99f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Floor"), player, 60f)
                    {
                        Layer = 0.9f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Hills_Front"), player, 40f)
                    {
                        Layer = 0.8f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Hills_Middle"), player, 30f)
                    {
                        Layer = 0.79f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Clouds_Fast"), player, 25f, true)
                    {
                        Layer = 0.78f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Hills_Back"), player, 0f)
                    {
                        Layer = 0.77f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Clouds_Slow"), player, 10f, true)
                    {
                        Layer = 0.7f,
                    },
                    new ScrollingBackground(Content.Load <Texture2D>("Levels/Sunny/Sky"), player, 0f)
                    {
                        Layer = 0.1f,
                    },
                }
            };
        }
Example #31
0
 public void setPrimaryState(State state)
 {
     this.state = state;
     state.LoadContent(content);
 }
Example #32
0
        void CreateGameHandler(object sender, EventArgs e)
        {
            try
            {
                Session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
                HookSessionEvents();
            }
            catch (Exception exception)
            {

            }
        }
Example #33
0
        void JoinGameHandler(object sender, EventArgs e)
        {
            AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 2, null);
            if (sessions.Count < 1)
                return;
            Session = NetworkSession.Join(sessions[0]);
            if (Session != null)
            {
                HookSessionEvents();

                UnhookHomeStateEvents();

                GlobalState = new LobbyState();
                GlobalState.Initialize(null);
                GlobalState.LoadContent(Content);

                HookLobbyStateEvents();
            }
        }
Example #34
0
        void ReplayGameHandler(object sender, EventArgs e)
        {
            UnhookHomeStateEvents();

            GlobalState = new GameState();
            GlobalState.Initialize(null);
            GlobalState.LoadContent(Content);

            HookGameStateEvents();
        }