コード例 #1
0
ファイル: Game1.cs プロジェクト: cchawley/platformer-example
        /// <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();
            }

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

            ghost.Update(gameTime);
            // Check for platform collisions
            var platformQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);

            player.CheckForPlatformCollision(platformQuery);



            DoorParticles.Update(gameTime);
            Rain.Update(gameTime);
            GhostParticles.Update(gameTime);

            if (ghost.Bounds.CollidesWith(player.Bounds)) // check for collisions with the player
            {
                player.gameState = 2;

                /*
                 * if (player.Bounds.Y + player.Bounds.Height <= Bounds.Y)
                 * {
                 *  //logic player bouncing off head, but ghost wont be dying, can bounce off ghost heads
                 *  player.Position.Y -= 1;
                 *  player.playerBounce = 1;
                 * }
                 * else if (player.Bounds.X >= Bounds.X + Bounds.Width) //&& player.Bounds.Y > Bounds.Y
                 * {
                 *  //logic for player death
                 *  player.gameState = 2;
                 * }
                 * else if (player.Bounds.X + player.Bounds.Width <= Bounds.X) //&& player.Bounds.Y > Bounds.Y - 18
                 * {
                 *  //logic for player death
                 *  player.gameState = 2;
                 * }
                 */
            }
            base.Update(gameTime);
        }
コード例 #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

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

            // Check for platform collisions
            var platformQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);

            player.CheckForPlatformCollision(platformQuery);

            base.Update(gameTime);
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: GavinMNeises/GameProject5
        /// <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 (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                if (state == GameState.End)
                {
                    player.Reset();
                    tokens.ForEach(token =>
                    {
                        token.Reset();
                    });
                    score = 0;
                }
                state = GameState.Playing;
            }

            if (state == GameState.Playing)
            {
                // TODO: Add your update logic here
                player.Update(gameTime);
                if (player.Dead)
                {
                    state = GameState.End;
                    playerDeathParticles.SystemLife = 0.5f;
                }

                // Check for platform collisions
                var platformQuery = platformAxis.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);
                player.CheckForPlatformCollision(platformQuery);

                var tokenQuery = tokenAxis.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);
                score += player.CheckForTokenCollision(tokenQuery);
            }

            playerDeathParticles.Update(gameTime);

            base.Update(gameTime);
        }
コード例 #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

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

            // Check for platform collisions
            var platformQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);

            player.CheckForPlatformCollision(platformQuery);
            foreach (Tile tile in tilemap.Tiles)
            {
                if (tile.Collision != Rectangle.Empty)
                {
                    Debug.WriteLine("We found one boys");
                }
            }
            base.Update(gameTime);
        }
コード例 #5
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();
            }

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

            // Check for platform collisions
            var platformQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);

            player.CheckForPlatformCollision(platformQuery);
            // Check for collision with flag
            if (player.Bounds.CollidesWith(recFlag))
            {
                flagReached = true;
            }
            textPostion.X = player.Bounds.X - 100;
            textPostion.Y = player.Bounds.Y - 200;
            base.Update(gameTime);
        }
コード例 #6
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();
            }

            // TODO: Add your update logic here
            player.Update(gameTime);
            if (player.Position.Y > deathY)
            {
                view = ViewState.DEAD;
            }

            // Check for platform collisions
            var platformQuery = world.QueryRange(player.Bounds.X, player.Bounds.X + player.Bounds.Width);

            player.CheckForPlatformCollision(platforms);
            foreach (Platform p in platforms)
            {
                p.Update(gameTime);
                if (player.Position.Y + 100 < p.Position.Y && player.verticalState == VerticalMovementState.OnGround)
                {
                    PlatformShift(p, gameTime);
                    return;
                }
                Debug.WriteLine($"{p.Position}\t{p.Velocity}");
            }
            curPlatform          = platforms[0];
            curPlatform.Velocity = Vector2.Zero;

            if (gameTime.TotalGameTime.TotalMilliseconds - curPlatformTimer > 2000)
            {
                platform_warning = true;
            }
            if (gameTime.TotalGameTime.TotalMilliseconds - curPlatformTimer > 3000)
            {
                platform_gone = true;
            }
            base.Update(gameTime);
        }