Update() public method

public Update ( ) : void
return void
示例#1
0
        public async Task<IActionResult> UpdatePlatform([FromBody]PlatformEditViewModel model)
        {
            Platform platform = await DataContext.Store.GetOneAsync<Platform>(p => p.Id == model.Id);

            if (platform == null) return NotFound("No platform exists with the given Id");

            platform.Update(Mapper.Map<Platform>(model));

            if (!await DataContext.Store.UpdateOneAsync(platform))
                return BadRequest("An error occured while updating the platform");

            return Ok();
        }
示例#2
0
        public void Update(Graphics g, Rectangle window)
        {
            _graphics = g;
            _window   = window;

            if (_level == null)
            {
                LoadLevel();
            }

            if (_gameIsOver)
            {
                ShowGameOverMessage();
                return;
            }

            if (IsPaused)
            {
                ShowPauseMessage();
                return;
            }

            _ball.Update(g, window);
            _platform.Update(g, window);
            _bricks.ForEach(b =>
            {
                if (!b.IsSmashed)
                {
                    b.Update(g, window);
                }
            });

            _ball.ResolvePlatformCollisions(_platform);
            _ball.ResolveBricksCollisions(_bricks);

            _bricks.RemoveAll(b =>
            {
                _score += b.IsSmashed ? 100 : 0;
                return(b.IsSmashed);
            });

            if (!_bricks.Any())
            {
                LoadLevel();
            }

            ShowInfo();
        }
示例#3
0
        public void Update(float dt)
        {
            for (int i = 0; i < setPieces.Count; i++)
            {
                SetPiece setPiece = setPieces[i];

                if (setPiece.Destroyed)
                {
                    setPieces.RemoveAt(i);
                }
                else
                {
                    setPiece.Update(dt);
                }
            }

            for (int i = 0; i < platforms.Count; i++)
            {
                Platform platform = platforms[i];

                if (platform.Destroyed)
                {
                    platforms.RemoveAt(i);
                }
                else
                {
                    BoundingBox2D boundingBox = platform.BoundingBox;
                    Vector2       bottomLeft  = new Vector2(boundingBox.Left, boundingBox.Bottom);
                    Vector2       bottomRight = new Vector2(boundingBox.Right, boundingBox.Bottom);

                    if (lava.CheckSubmerged(bottomLeft) || lava.CheckSubmerged(bottomRight))
                    {
                        platform.Destroy();
                        platforms.RemoveAt(i);
                    }
                    else
                    {
                        platform.Update(dt);
                    }
                }
            }

            GeneratePlatforms();
        }
示例#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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            keyboardState = Keyboard.GetState();

            //Bill: No, NO! I'm not going down there!
            //Dave: Bill!
            //Jim: Let him be, Dave, this journey isn't for anyone unwilling to lose their sanity.

            //Menu
            if (state == GameState.menu)
            {
                if (keyboardState.IsKeyDown(Keys.Enter) && pressEnter)
                {
                    if (select == 0)
                    {
                        selectSound.Play();
                        state = GameState.level;
                        delay = 1;
                    }
                    if (select == 1)
                    {
                        selectSound.Play();
                        state = GameState.help;
                    }
                    select     = 0;
                    pressEnter = false;
                }

                //Selection
                if (keyboardState.IsKeyDown(Keys.Up) && select > 0 && pressUp)
                {
                    select -= 1;
                    blipSound.Play();
                    pressUp = false;
                }
                else if (keyboardState.IsKeyDown(Keys.Up) && pressUp)
                {
                    select = selectMax;
                    blipSound.Play();
                    pressUp = false;
                }
                if (keyboardState.IsKeyDown(Keys.Down) && select < selectMax && pressDown)
                {
                    select += 1;
                    blipSound.Play();
                    pressDown = false;
                }
                else if (keyboardState.IsKeyDown(Keys.Down) && pressDown)
                {
                    select = 0;
                    blipSound.Play();
                    pressDown = false;
                }

                if (overlayAlpha < 1)
                {
                    overlayAlpha += 0.01f;
                }
            }

            //Game
            if (state == GameState.game)
            {
                if (Menu())
                {
                    MediaPlayer.Stop();
                }

                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                seconds += elapsed;

                player.Update(platform, level);
                platform.Update(player);
                level.Update();
                if (gameLevel == 0)
                {
                    boss1.Update(platform, player);
                }

                if (player.grounded && (player.xVel > 0 || player.xVel < 0))
                {
                    playerWalking.Update();
                }

                //Platform movement
                if (gameLevel != 2)
                {
                    if (gameLevel == 1 || (timer < Boss1.arrivalScore || (timer > Boss1.leavingScore && timer < Boss1.arrivalScore2) || (timer > Boss1.leavingScore2 && timer < Boss1.arrivalScore3) || timer > Boss1.leavingScore3))
                    {
                        if (keyboardState.IsKeyDown(Keys.W))
                        {
                            platform.Move(0, -Platform.speed, player);
                        }
                        if (keyboardState.IsKeyDown(Keys.D))
                        {
                            platform.Move(Platform.speed, 0, player);
                        }
                        if (keyboardState.IsKeyDown(Keys.S))
                        {
                            platform.Move(0, Platform.speed, player);
                        }
                        if (keyboardState.IsKeyDown(Keys.A))
                        {
                            platform.Move(-Platform.speed, 0, player);
                        }
                    }
                }

                //Player movement
                if ((keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space)) && pressSpace)
                {
                    player.Jump();
                    pressSpace = false;
                }
                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    player.Move(player.accel, 0);
                }
                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    player.Move(0, player.accel);
                }
                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    player.Move(-player.accel, 0);
                }

                //Music
                if (gameLevel == 0)
                {
                    if (MediaPlayer.PlayPosition >= gameSong1.Duration - TimeSpan.FromSeconds(9))
                    {
                        FadeMusic();
                    }
                }
                if (gameLevel == 1)
                {
                    if (MediaPlayer.PlayPosition >= gameSong2.Duration - TimeSpan.FromSeconds(9))
                    {
                        FadeMusic();
                    }
                }
                if (gameLevel == 2)
                {
                    if (MediaPlayer.PlayPosition >= gameSong3.Duration)
                    {
                        Player.scoreMult++;
                    }
                }

                //Text
                if (scoreTextSize > scoreTextSizeMin)
                {
                    scoreTextSize -= 0.05f;
                }

                if (overlayAlpha > 0)
                {
                    overlayAlpha -= 0.01f;
                }

                tick--;
                if (tick <= 0)
                {
                    tick = 10;
                }

                if (Player.score > goal && goal > 0)
                {
                    goal           = 0;
                    player.health += 1;
                    healthSound.Play();
                }

                timer++;
            }

            //Lose
            if (state == GameState.lose)
            {
                Menu();

                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    selectSound.Play();
                    state = GameState.game;
                    StartGame();
                }

                if (overlayAlpha < 1)
                {
                    overlayAlpha += 0.01f;
                }
            }

            //Win
            if (state == GameState.win)
            {
                Menu();

                if (keyboardState.IsKeyDown(Keys.Enter))
                {
                    selectSound.Play();
                    state = GameState.game;
                    StartGame();
                }

                if (overlayAlpha < 1)
                {
                    overlayAlpha += 0.01f;
                }
            }

            //Help
            if (state == GameState.help)
            {
                Menu();

                if (overlayAlpha < 1)
                {
                    overlayAlpha += 0.01f;
                }
            }

            //Level select
            if (state == GameState.level)
            {
                Menu();

                if (keyboardState.IsKeyDown(Keys.Enter) && delay == 0 && pressEnter)
                {
                    selectSound.Play();
                    state = GameState.game;

                    if (select2 == 0)
                    {
                        gameLevel = 0;
                    }
                    if (select2 == 1)
                    {
                        gameLevel = 1;
                    }
                    if (select2 == 2)
                    {
                        gameLevel = 2;
                    }

                    StartGame();
                    select     = 0;
                    pressEnter = false;
                }

                //Selection
                if (keyboardState.IsKeyDown(Keys.Up) && select2 > 0 && pressUp)
                {
                    select2 -= 1;
                    blipSound.Play();
                    pressUp = false;
                }
                else if (keyboardState.IsKeyDown(Keys.Up) && pressUp)
                {
                    select2 = selectMax2;
                    blipSound.Play();
                    pressUp = false;
                }
                if (keyboardState.IsKeyDown(Keys.Down) && select2 < selectMax2 && pressDown)
                {
                    select2 += 1;
                    blipSound.Play();
                    pressDown = false;
                }
                else if (keyboardState.IsKeyDown(Keys.Down) && pressDown)
                {
                    select2 = 0;
                    blipSound.Play();
                    pressDown = false;
                }

                if (overlayAlpha < 1)
                {
                    overlayAlpha += 0.01f;
                }
            }

            if (delay > 0)
            {
                delay--;
            }

            //Keys are up?
            if (keyboardState.IsKeyUp(Keys.Up) && keyboardState.IsKeyUp(Keys.Space))
            {
                pressSpace = true;
            }
            if (keyboardState.IsKeyUp(Keys.Up))
            {
                pressUp = true;
            }
            if (keyboardState.IsKeyUp(Keys.Down))
            {
                pressDown = true;
            }
            if (keyboardState.IsKeyUp(Keys.Enter))
            {
                pressEnter = true;
            }

            base.Update(gameTime);

            //Dave: Dear god, I can feel myself slowly slipping...
            //Jim: Hang in their Dave! I'll find help, just rest here!
        }