Update() public method

public Update ( ) : void
return void
示例#1
0
    /// <summary>
    /// this subprogram updates the bomb that belongs to the player
    /// by calling the bomb update subprogrogram, alos determines if
    /// the bomb is still active
    /// </summary>
    private void UpdateBomb()
    {
        //update the bomb
        playerBomb.Update();

        //checking to see if the bomb has exploded or not
        isBombActive = playerBomb.ReturnIsActive();

        //getting the bombs coordinates
        bombCoordinates = playerBomb.ReturnBombCoordinate();

        //if the bomb has exploded
        if (!isBombActive)
        {
            //going through each of the surrounding blocks of the bomb
            //going through each column around the bomb
            for (int column = (int)bombCoordinates.x - 1; column < (int)bombCoordinates.x + 2; column++)
            {
                //going through each row around the bomb
                for (int row = (int)bombCoordinates.y - 1; row < (int)bombCoordinates.y + 2; row++)
                {
                    //if the player is within the bomb blast radius
                    if (playerCoordinate == new Vector2(column, row))
                    {
                        //the player has died and can no lonhger play
                        IsPlayerActive = false;


                        //calling the animation for the death of the player
                        anim.Play("Dying", -1, 0f);
                    }
                }
            }
        }
    }
示例#2
0
        public void BombRemovalTest()
        {
            World     world  = new World(new Vector2(0.0f, 0.0f), false);
            Rectangle rect   = new Rectangle(1, 1, 32, 32);
            Bomb      target = new Bomb(world, null, rect, null, 1000, 4);

            target.TriggerBomb(0);

            target.Update(2000.0f);

            Assert.IsTrue(target.HaveExploded());
        }
        /// <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))
            //    Paused = !Paused;
            if (currentLevelPoints >= pointsToWin || Enemies.Count <= 0)
            {
                SwitchLevel();
            }

            if (!Paused)
            {
                Input.CheckKeyboardInput(menu);
                if (!isGameOver)
                {
                    ScreenWidth  = GraphicsDevice.Viewport.Width;
                    ScreenHeight = GraphicsDevice.Viewport.Height;

                    link.Update(gameTime);
                    foreach (Bouncerang b in bouncerangs)
                    {
                        b.Update(gameTime);
                        b.CheckState(link);
                    }
                    for (int x = 0; x < Projectiles.Count; x++)
                    {
                        if (Projectiles[x] is Arrow)
                        {
                            Arrow a = (Arrow)Projectiles[x];
                            a.Update(gameTime);
                        }
                        else if (Projectiles[x] is Bomb)
                        {
                            Bomb a = (Bomb)Projectiles[x];
                            a.Update(gameTime);
                        }
                        else if (Projectiles[x] is Potion)
                        {
                            Potion a = (Potion)Projectiles[x];
                            a.Update(gameTime);
                            a.CheckState(link);
                        }
                    }
                }

                base.Update(gameTime);
            }
            else
            {
                Input.MenuInput(menu);
            }
        }
示例#4
0
 public static void Update(float timeDelta)
 {
     Controller.Update();
     hero.Update(timeDelta, enemies);
     UpdateEnemies(timeDelta);
     UpdateEnemyProjectiles(timeDelta);
     UpdateHeroProjectiles(timeDelta);
     Stars.Update(timeDelta);
     Bomb.Update(timeDelta);
     SoundManager.Update();
     //Update particles
     system.Update(Time.FromSeconds(timeDelta));
     StringTable.GetInstance().Update();
     UpdateText();
 }
示例#5
0
        public void BombBlockCheckTest()
        {
            World     world  = new World(new Vector2(0.0f, 0.0f), false);
            Rectangle rect   = new Rectangle(1, 1, 32, 32);
            Block     b      = new Block(world, null, new Rectangle(1, 2, 32, 32), 1, 'D');
            Bomb      target = new Bomb(world, null, rect, null, 1000, 4);
            double    time1  = 2F;

            target.TriggerBomb(0);

            target.Update(time1);
            List <Body> listOfBodies = target.GetExplosionResult();

            Assert.IsTrue(b.GetBody() == listOfBodies[0]);
        }
示例#6
0
        //////////////////////////////////////////////////////////////////////////////

        #region IUpdatable

        public override void Update(float delta)
        {
            base.Update(delta);

            if (IsAlive)
            {
                UpdateInput(delta);

                if (m_bombInHands != null)
                {
                    m_bombInHands.Update(delta);
                }

                m_diseases.Update(delta);
            }

            UpdateAnimation(delta);

            for (int bombIndex = 0; bombIndex < m_thrownBombs.Count; ++bombIndex)
            {
                m_thrownBombs[bombIndex].Update(delta);
            }
        }
        /// <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();
            }

            Time.Update(gameTime);
            InputManager.Update();
            player.Update();
            bomb.Update();

            int count = 0;

            for (int i = 0; i < 3; i++)
            {
                agents[i].Update();

                Vector3 distance = player.Transform.LocalPosition - agents[i].Transform.LocalPosition;
                if (distance.Length() < 2)
                {
                    alienCaught = true;
                    count       = i;
                    break;
                }
            }

            if (alienCaught)
            {
                player.aliensCaught++;
                agents.Remove(agents[count]);
                agents.Add(new Agent(terrain, Content, cameras[0], GraphicsDevice, light));
                agents[2].Add <Rigidbody>();
                Renderer agentRenderer = new Renderer(sphere, agents[2].Rigidbody.Transform,
                                                      cameras[0], Content, GraphicsDevice, light, 1, "SimpleShading", 20f, texture);
                agents[2].Add <Renderer>(agentRenderer);
                alienCaught = false;
            }

            Vector3 distance2 = player.Transform.LocalPosition - bomb.Transform.LocalPosition;

            if (distance2.Length() < 5)
            {
                player = null;
                bomb   = null;
                player = new Player(terrain, Content, cameras[0], GraphicsDevice, light);
                player.Add <BoxCollider>();
                Renderer playerRenderer = new Renderer(cube, player.Rigidbody.Transform, cameras[0],
                                                       Content, GraphicsDevice, light, 1, "SimpleShading", 20f, texture);
                player.Add <Renderer>(playerRenderer);
                bomb = new Bomb(terrain, Content, cameras[0], graphics.GraphicsDevice, light, player);
                bomb.Add <Rigidbody>();
                Renderer bombRenderer = new Renderer(cube, bomb.Rigidbody.Transform, cameras[0],
                                                     Content, graphics.GraphicsDevice, light, 1, "SimpleShading", 20f, texture);
                bomb.Add <Renderer>(bombRenderer);
                while (!(bomb.search.Start = bomb.search.Nodes[random.Next(bomb.search.Cols),
                                                               random.Next(bomb.search.Rows)]).Passable)
                {
                    ;
                }
            }

            base.Update(gameTime);
        }
示例#8
0
        public void Update()
        {
            if (!init)
            {
                Lists.playerList.Add(new Player.Player(new Vector2(GetCenterX + PlayScreenMinX, 440)));
                playerSpawnFrame = 0;
                init             = true;
            }
            playerSpawnFrame--;
            stage.Update();

            if (playerSpawnFrame == 0)
            {
                Lists.playerList.Add(new Player.Player(new Vector2(GetCenterX + PlayScreenMinX, 440)));
            }
            if (playerSpawnFrame < 0)
            {
                Lists.playerList[0].Update();
                GameStats.UpdatePlayerPosition();
                if (Lists.playerList[0].IsDead())
                {
                    Lists.playerList.Clear();
                    playerSpawnFrame = 60;
                }
            }

            for (int i = Lists.itemList.Count - 1; i >= 0; i--)
            {
                ItemPrime item = Lists.itemList[i];
                item.Update();

                if (!item.GetAlive())
                {
                    Lists.itemList.Remove(item);
                }
            }

            for (int i = Lists.enemyList.Count - 1; i >= 0; i--)
            {
                EnemyPrime enemy = Lists.enemyList[i];
                enemy.Update();

                if (!enemy.GetAlive())
                {
                    Lists.enemyList.Remove(enemy);
                }
            }
            for (int i = 0; i <= Lists.bomb.Count - 1; i++)
            {
                Bomb bomb = Lists.bomb[i];
                bomb.Update();
                if (bomb.GetOver())
                {
                    Lists.bomb.Clear();
                }
            }
            for (int i = Lists.bulletList.Count - 1; i >= 0; i--)
            {
                Bullet bullet = Lists.bulletList[i];
                bullet.Update();

                if (!bullet.IsAlive())
                {
                    Lists.bulletList.Remove(bullet);
                }
            }
            for (int i = Lists.FXList.Count - 1; i >= 0; i--)
            {
                FX fx = Lists.FXList[i];
                fx.Update();

                if (!fx.IsAlive())
                {
                    Lists.FXList.Remove(fx);
                }
            }
            for (int i = 0; i <= Lists.playerBulletList.Count - 1; i++)
            {
                PlayerBulletPrime playerbullet = Lists.playerBulletList[i];
                playerbullet.Update();

                if (!playerbullet.GetAlive())
                {
                    Lists.playerBulletList.Remove(playerbullet);
                }
            }
        }
示例#9
0
    public void CheckCollisions()
    {
        //To Do enviromental collisions

        if (character.CollidesWith(level.Walls))
        {
            character.X = oldX;
            character.Y = oldY;
            level.XMap  = oldXMap;
            level.YMap  = oldYMap;
        }

        if (character.CollidesWith(level.SideWall))
        {
            character.X = oldX;
            character.Y = oldY;
            level.XMap  = oldXMap;
            level.YMap  = oldYMap;
        }

        /*if (character.CollidesWith(level.floorTiles))
         * {
         *  character.X = oldX;
         *  character.Y = oldY;
         *  level.XMap = oldXMap;
         *  level.YMap = oldYMap;
         * }*/

        //Heart pickup

        /*if (Heart.PickUp(character.X, character.Y))
         *  character.hearts++;*/

        //key pickup

        if ((character.X >= k.X - 30 && character.X <= k.X + 30) &&
            (character.Y >= k.Y - 30 && character.Y <= k.Y + 30))
        {
            character.hasKey = true;
        }

        //Damage collisions

        if ((character.X >= enemy.X - 30 && character.X <= enemy.X + 30) &&
            (character.Y >= enemy.Y - 30 && character.Y <= enemy.Y + 30))
        {
            if (character.isAttacking)
            {
                switch (character.direction)
                {
                case 0:    //up
                    if (enemy.Y >= character.Y && enemy.Y <= character.Y + 20)
                    {
                        Console.WriteLine("Hit!");
                        enemy.hearts--;
                    }
                    break;

                case 1:    //down
                    if (enemy.Y <= character.Y && enemy.Y <= character.Y - 20)
                    {
                        Console.WriteLine("Hit!");
                        enemy.hearts--;
                    }
                    break;

                case 2:    //left
                    if (enemy.X <= character.X && enemy.X >= character.X - 20)
                    {
                        Console.WriteLine("Hit!");
                        enemy.hearts--;
                    }
                    break;

                case 3:    //right
                    if (enemy.X >= character.X && enemy.X <= character.X + 20)
                    {
                        Console.WriteLine("Hit!");
                        enemy.hearts--;
                    }
                    break;
                }
            }
        }
        if (character.cooldown >= 0)
        {
            character.cooldown--;
        }

        if (character.bombCooldown >= 0)
        {
            character.bombCooldown--;
            if (character.bombCooldown % 100 == 0)
            {
                Console.WriteLine(character.bombCooldown);
            }
        }

        if (b != null)
        {
            b.Update(character, enemy);
        }
    }