コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: Title.cs プロジェクト: groundh0g/camp2018
        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);
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: MoreOnCode/MonoGameBookCode
        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);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: groundh0g/camp2018
        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);
        }