Example #1
0
        protected Game2D(int defaultScreenWidth = 800, int defaultScreenHeight = 600, bool fullscreen = false, bool useGamePad = false, DepthFormat depthFormat = DepthFormat.None, string configFileName = null)
        {
            _configFileName = string.IsNullOrEmpty(configFileName) ? DefaultConfigFileName : configFileName;
            LoadGameProperties();

            var width  = GetScreenSizeComponent(defaultScreenWidth, GameProperty.GameResolutionXProperty, 800);
            var height = GetScreenSizeComponent(defaultScreenHeight, GameProperty.GameResolutionYProperty, 600);

            GraphicsDeviceManager = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth    = width,
                PreferredBackBufferHeight   = height,
                PreferredDepthStencilFormat = depthFormat,
                IsFullScreen = fullscreen
            };
            Content.RootDirectory = "Content";

            Keyboard      = new KeyboardEx();
            Mouse         = new MouseEx();
            GuiSystem     = new GuiSystem(this);
            DepthRenderer = new DepthRenderer();
            Cursor        = new Cursor(this);
            if (useGamePad)
            {
                GamePad = new GamePadEx();
            }

            _clearOptions = ClearOptions.Target;
            if (depthFormat != DepthFormat.None)
            {
                _clearOptions |= ClearOptions.DepthBuffer;
            }

            _registeredGlobals = new Dictionary <string, GameObject>();
        }
Example #2
0
 /// <summary>
 /// This is called when the game should draw itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Draw(GameTime gameTime)
 {
     //TODO: Add your drawing code here
     GamePadEx.Update(gameTime);
     TouchPanelEx.Update(gameTime);
     ScreenUtil.Draw(gameTime, spriteBatch);
 }
Example #3
0
        protected Game2D(int screenWidth, int screenHeight, bool fullscreen, bool useGamePad = false, DepthFormat depthFormat = DepthFormat.None)
        {
            GraphicsDeviceManager = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth    = screenWidth,
                PreferredBackBufferHeight   = screenHeight,
                PreferredDepthStencilFormat = depthFormat,
                IsFullScreen = fullscreen
            };
            Content.RootDirectory = "Content";

            Keyboard      = new KeyboardEx();
            Mouse         = new MouseEx();
            DepthRenderer = new DepthRenderer();
            ScriptRunner  = new ScriptRunner(this);
            if (useGamePad)
            {
                GamePad = new GamePadEx();
            }

            _clearOptions = ClearOptions.Target;
            if (depthFormat != DepthFormat.None)
            {
                _clearOptions |= ClearOptions.DepthBuffer;
            }

            _registeredGlobals = new Dictionary <string, GameObject>();
        }
Example #4
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)
 {
     // TODO: Add your update logic here
     base.Update(gameTime);
     GamePadEx.Update(gameTime);
     TouchPanelEx.Update(gameTime);
     ScreenUtil.Update(gameTime);
 }
Example #5
0
 public virtual void Update(GameTime gameTime)
 {
     // For Mobile devices, this logic will close the Game when the Back button is pressed
     if (ExitOnBack && GamePadEx.WasJustPressed(PlayerIndex.One, Buttons.Back))
     {
         Exit();
     }
 }
Example #6
0
        public static void Update(GameTime gameTime)
        {
            GamePadEx.Update(gameTime);
            KeyboardEx.Update(gameTime);
            TouchPanelEx.Update(gameTime);

            if (CurrentScreen != null)
            {
                CurrentScreen.Update(gameTime);
            }
        }
        public static void Update(GameTime gameTime)
        {
            GamePad1 = GamePadEx.GetState(PlayerIndex.One);
            GamePad2 = GamePadEx.GetState(PlayerIndex.Two);
            GamePad3 = GamePadEx.GetState(PlayerIndex.Three);
            GamePad4 = GamePadEx.GetState(PlayerIndex.Four);

            if (CurrentScreen != null)
            {
                CurrentScreen.Update(gameTime);
            }
        }
Example #8
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            var nextScreen =
                GamePadEx.WasJustPressed(PlayerIndex.One, Buttons.A) ||
                GamePadEx.WasJustPressed(PlayerIndex.One, Buttons.Start) ||
                TouchPanelEx.WasJustPressed();

            if (nextScreen)
            {
                ScreenUtil.Show(new TitleScreen(Parent));
            }
        }
Example #9
0
        public override void Update(GameTime gameTime)
        {
            gamepad = GamePadEx.GetState(PlayerIndex.One);

            if (GamePadEx.WasJustPressed(PlayerIndex.One, Buttons.A))
            {
                ScreenUtil.Show(new Main(this.Parent));
            }
            else if (GamePadEx.WasJustPressed(PlayerIndex.One, Buttons.Back))
            {
                ScreenUtil.Show(new Splash(this.Parent));
            }

            base.Update(gameTime);
        }
Example #10
0
 public static void Show(GameScreen screen)
 {
     GamePadEx.ResetWasPressed();
     if (CurrentScreen != screen)
     {
         if (CurrentScreen != null)
         {
             CurrentScreen.Hiding();
         }
         CurrentScreen = screen;
     }
     if (CurrentScreen != null)
     {
         CurrentScreen.Showing();
     }
 }
Example #11
0
        public override void Update(GameTime gameTime)
        {
            elapsed += gameTime.ElapsedGameTime.TotalSeconds;

            gamepad = GamePadEx.GetState(PlayerIndex.One);

            var buttonWasPressed = GamePadEx.WasJustPressed(PlayerIndex.One, Buttons.A);

            if (elapsed >= 3.0)
            {
                buttonWasPressed = true;
            }

            if (buttonWasPressed)
            {
                ScreenUtil.Show(new Title(this.Parent));
            }

            base.Update(gameTime);
        }
Example #12
0
        protected override void Update(GameTime gameTime)
        {
            var gamepad1 = GamePadEx.GetState(PlayerIndex.One);

            if (gamepad1.IsButtonDown(Buttons.Back))
            {
                this.Exit();
            }
            else
            {
                // move the ship
                var elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                var dX      =
                    gamepad1.ThumbSticks.Left.X +
                    gamepad1.ThumbSticks.Right.X;
                var dY =
                    gamepad1.ThumbSticks.Left.Y +
                    gamepad1.ThumbSticks.Right.Y;
                locShip.X += dX * SPEED_SHIP * elapsed;
                locShip.Y -= dY * SPEED_SHIP * elapsed;

                // keep ship in bounds (Horizontal)
                var maxX = rectPlayerBounds.Right - texShip.Bounds.Width;
                if (locShip.X < rectPlayerBounds.X)
                {
                    locShip.X = rectPlayerBounds.X;
                }
                else if (locShip.X > maxX)
                {
                    locShip.X = maxX;
                }

                // keep ship in bounds (Vertical)
                var maxY = rectPlayerBounds.Bottom - texShip.Bounds.Height;
                if (locShip.Y < rectPlayerBounds.Y)
                {
                    locShip.Y = rectPlayerBounds.Y;
                }
                else if (locShip.Y > maxY)
                {
                    locShip.Y = maxY;
                }

                // move the stars
                locStars.Y += SPEED_STARS * elapsed;
                if (locStars.Y >= 0.0f)
                {
                    locStars.Y = -texStars.Bounds.Height;
                }

                // add a new enemy?
                enemyElapsed += elapsed;
                if (enemyElapsed >= ENEMY_DELAY)
                {
                    var locEnemy = new Vector3(locStartEnemyLeft, 0.0f);
                    if (!isEnemyLeft)
                    {
                        locEnemy = new Vector3(locStartEnemyRight, 0.0f);
                    }
                    locEnemyShips.Add(locEnemy);
                    enemyElapsed = 0.0f;
                    isEnemyLeft  = !isEnemyLeft;
                }

                // update existing enemies
                for (int i = 0; i < locEnemyShips.Count; i++)
                {
                    var loc = locEnemyShips [i];
                    if (loc.Y == locStartEnemyLeft.Y)
                    {
                        loc.X += elapsed * SPEED_SHIP;
                    }
                    else
                    {
                        loc.X -= elapsed * SPEED_SHIP;
                    }
                    locEnemyShips [i] = loc;
                }

                // add a new meteor?
                meteorElapsed += elapsed;
                if (meteorElapsed >= METEOR_DELAY)
                {
                    var iMeteor      = rand.Next(texMeteors.Count);
                    var meteorWidth  = texMeteors [iMeteor].Bounds.Width;
                    var meteorHeight = texMeteors [iMeteor].Bounds.Height;
                    var randX        = rand.Next(rectPlayerBounds.Width - meteorWidth);
                    var loc          =
                        new Vector3(
                            rectPlayerBounds.Left + randX,
                            1 - meteorHeight,
                            iMeteor);
                    locMeteors.Add(loc);
                    meteorElapsed = 0.0f;
                }

                // update existing meteors
                for (int i = 0; i < locMeteors.Count; i++)
                {
                    var loc = locMeteors [i];
                    loc.Y         += elapsed * SPEED_METEOR;
                    locMeteors [i] = loc;
                }

                // add a new laser?
                laserElapsed += elapsed;
                if (gamepad1.IsButtonDown(Buttons.A))
                {
                    if (laserElapsed >= laserDelay)
                    {
                        var loc =
                            new Vector2(
                                locShip.X + texShip.Width / 2 - texLaser.Width / 2,
                                locShip.Y);
                        locLasers.Add(loc);
                        laserElapsed = 0.0f;
                    }
                }

                // update existing lasers
                for (int i = 0; i < locLasers.Count; i++)
                {
                    var loc = locLasers [i];
                    loc.Y        -= elapsed * SPEED_LASER;
                    locLasers [i] = loc;
                }

                // add a new enemy laser?
                for (int i = 0; i < locEnemyShips.Count; i++)
                {
                    var loc = locEnemyShips [i];
                    loc.Z += elapsed;
                    if (loc.Z >= INIT_ENEMY_LASER_DELAY)
                    {
                        var locLaser =
                            new Vector2(
                                loc.X + texEnemyShip.Width / 2 - texEnemyLaser.Width / 2,
                                loc.Y + texEnemyShip.Height);
                        locEnemyLasers.Add(locLaser);
                        loc.Z = 0.0f;
                    }
                    locEnemyShips [i] = loc;
                }

                // update existing enemy lasers
                for (int i = 0; i < locEnemyLasers.Count; i++)
                {
                    var loc = locEnemyLasers [i];
                    loc.Y += elapsed * SPEED_LASER;
                    locEnemyLasers [i] = loc;
                }

                // check for collisions
                CheckForCollisions();
                DoHousekeeping();
            }
            base.Update(gameTime);
        }
Example #13
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            var gamepad1 = GamePadEx.GetState(PlayerIndex.One);

            if (gamepad1.Buttons.Back == ButtonState.Pressed)
            {
                ScreenUtil.Show(new TitleScreen(Parent));
            }

            // === TouchPanel or Mouse ===
            var touchState = TouchPanelEx.GetState();

            if (touchState.Count > 0)
            {
                emitter.Active =
                    touchState [0].State == TouchLocationState.Pressed ||
                    touchState [0].State == TouchLocationState.Moved;
                emitter.EmitterRect = new Rectangle(
                    (int)Math.Round(touchState [0].Position.X),
                    (int)Math.Round(touchState [0].Position.Y),
                    emitter.EmitterRect.Width,
                    emitter.EmitterRect.Height
                    );
            }
            else
            {
                emitter.Active = false;
            }
            // ===

            // === Controller or Keyboard ===
            if (gamepad1.IsButtonDown(Buttons.A))
            {
                emitter.Active = true;
            }

            if (gamepad1.DPad.Up == ButtonState.Pressed)
            {
                emitter.EmitterRect = new Rectangle(
                    emitter.EmitterRect.X,
                    emitter.EmitterRect.Y - 5,
                    emitter.EmitterRect.Width,
                    emitter.EmitterRect.Height);
            }
            else if (gamepad1.DPad.Down == ButtonState.Pressed)
            {
                emitter.EmitterRect = new Rectangle(
                    emitter.EmitterRect.X,
                    emitter.EmitterRect.Y + 5,
                    emitter.EmitterRect.Width,
                    emitter.EmitterRect.Height);
            }

            if (gamepad1.DPad.Left == ButtonState.Pressed)
            {
                emitter.EmitterRect = new Rectangle(
                    emitter.EmitterRect.X - 5,
                    emitter.EmitterRect.Y,
                    emitter.EmitterRect.Width,
                    emitter.EmitterRect.Height);
            }
            else if (gamepad1.DPad.Right == ButtonState.Pressed)
            {
                emitter.EmitterRect = new Rectangle(
                    emitter.EmitterRect.X + 5,
                    emitter.EmitterRect.Y,
                    emitter.EmitterRect.Width,
                    emitter.EmitterRect.Height);
            }
            // ===

            emitter.Update(gameTime.ElapsedGameTime.TotalSeconds);
        }
Example #14
0
        public override void Update(GameTime gameTime)
        {
            // TODO: Fix, the add 2nd controller
            gamepad = GamePadEx.GetState(Board.Player);

            if (State == GameState.SelectingFromQueue)
            {
                if (GamePadEx.WasJustPressed(Board.Player, Buttons.DPadUp))
                {
                    SelectedQueueIndex = Math.Max(0, SelectedQueueIndex - 1);
                }
                else if (GamePadEx.WasJustPressed(Board.Player, Buttons.DPadDown))
                {
                    SelectedQueueIndex = Math.Min(3, SelectedQueueIndex + 1);
                }

                if (GamePadEx.WasJustPressed(Board.Player, Buttons.A))
                {
                    //ScreenUtil.Show(new Credits(this.Parent));
                    // TODO: move selected piece to top for drop
                    StagedPiece = Board.Player == PlayerIndex.One ?
                                  Board.BlueQueue[SelectedQueueIndex] :
                                  Board.RedQueue[SelectedQueueIndex];
                    (Board.Player == PlayerIndex.One ? Board.BlueQueue : Board.RedQueue)[SelectedQueueIndex]
                        = Piece.Empty;
                    StagedPieceColumn = 3;
                    State             = GameState.SelectingColumn;

                    //Board.ClearPieceFlags();
                }
            }
            else if (State == GameState.SelectingColumn)
            {
                if (GamePadEx.WasJustPressed(Board.Player, Buttons.DPadLeft))
                {
                    StagedPieceColumn = Math.Max(0, StagedPieceColumn - 1);
                }
                else if (GamePadEx.WasJustPressed(Board.Player, Buttons.DPadRight))
                {
                    StagedPieceColumn = Math.Min(7, StagedPieceColumn + 1);
                }

                if (GamePadEx.WasJustPressed(Board.Player, Buttons.A))
                {
                    if (Board.Pieces[StagedPieceColumn, 0].PieceType == PieceTypes.Empty)
                    {
                        Board.Pieces[StagedPieceColumn, 0] = StagedPiece;

                        switch (Board.Player)
                        {
                        case PlayerIndex.One:
                            Board.FillQueue(Board.BlueQueue, PieceTypes.NormalBlue);
                            break;

                        case PlayerIndex.Two:
                            Board.FillQueue(Board.RedQueue, PieceTypes.NormalRed);
                            break;
                        }

                        //Board.ClearPieceFlags();

                        State       = GameState.SelectingFromQueue;
                        StagedPiece = Piece.Empty;
                        Board.TogglePlayer();
                    }
                }
            }



            if (GamePadEx.WasJustPressed(Board.Player, Buttons.Back))
            {
                ScreenUtil.Show(new Title(this.Parent));
            }
            else
            {
                var isAnimating = false;
                if (Board.Animations != null && Board.Animations.Count > 0)
                {
                    foreach (var animation in Board.Animations)
                    {
                        if (animation.IsDone == false)
                        {
                            isAnimating = true;
                            break;
                        }
                    }
                }

                if (isAnimating)
                {
                    // DO NOTHING!
                }
                else if (Board.DoGravity((float)gameTime.ElapsedGameTime.TotalSeconds))
                {
                    // DO NOTHING!
                }
                else
                {
                    if (Board.ScanForPowerUps())
                    {
                    }
                    else
                    {
                        var matchRed  = Board.ScanForMatches(Board.MatchOnRed);
                        var matchBlue = Board.ScanForMatches(Board.MatchOnBlue);

                        if (matchRed == PieceTypes.NormalRed && matchBlue == PieceTypes.NormalBlue)
                        {
                            // TIE GAME :/
                        }
                        else if (matchBlue == PieceTypes.NormalBlue)
                        {
                            // BLUE WINS!
                        }
                        else if (matchRed == PieceTypes.NormalRed)
                        {
                            // RED WINS!
                        }
                        else if (Board.IsFull)
                        {
                            // TIE GAME :/
                        }
                    }
                }
            }

            if (Board.Animations != null && Board.Animations.Count > 0)
            {
                foreach (var animation in Board.Animations)
                {
                    animation.Update(gameTime);
                }
            }
            base.Update(gameTime);
        }