Update() public method

public Update ( ) : void
return void
Esempio n. 1
0
 /// <summary>
 /// Fires the current weapon
 /// </summary>
 public void Fire()
 {
     // If the weapon has not been fired yet
     if (!CurrentWeapon.Fired)
     {
         CurrentWeapon.FireWeapon();
         Shot.Update(position, 1280, Assets.MapData.TileMap, Assets.MapData.MapArea, rotation);
         Vector2 direction = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation));
         //debrisEmitter.Launch(Shot.CollisionPos, rotation);
     }
 }
        public void RemovesEntityOutOfBounds()
        {
            // Set the entity's position out of bounds
            _             = new Game();
            Game.gameSize = new Viewport(0, 0, 800, 480);
            Vector2 position = new Vector2(900, 500);
            Vector2 velocity = new Vector2(150, 150);
            Shot    bullet   = new Shot(position, velocity);

            // Update the position of the entity
            bullet.Update();

            // Assert
            Assert.IsTrue(bullet.shouldRemove);
        }
        public void ProperEntityMovement()
        {
            // Arrange
            _             = new Game();
            Game.gameSize = new Viewport(0, 0, 800, 480);
            Vector2 position = new Vector2(414, 215);
            Vector2 velocity = new Vector2(-10, 3);
            Vector2 expected = position + velocity;
            Shot    bullet   = new Shot(position, velocity);

            // Update the position of the entity
            bullet.Update();

            // Assert
            Assert.IsTrue(bullet.Position.X == expected.X);
            Assert.IsTrue(bullet.Position.Y == expected.Y);
        }
Esempio n. 4
0
        } // UnloadContent

        #endregion

        #region Update
        /// <summary>
        /// Updates all objects in the scene
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="otherScreenHasFocus"></param>
        /// <param name="coveredByOtherScreen"></param>
        /// <returns></returns>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // Update GameTime
            GameTime = gameTime;


            // Move parallax layers and don't do shit if there's no cam movement!
            camPosLastFrame = camPos;
            camPos          = Camera.Position;
            float difference = camPos.X - camPosLastFrame.X; // Suckx for negative X-CamPosition (Screenspace)!

            if (difference <= 0)
            {
                difference *= -1;                                                            //= 0;
            }
            _background.Move(ConvertUnits.ToDisplayUnits(new Vector2(difference / 200, 0))); // _background.Move(ConvertUnits.ToDisplayUnits(Vector2.UnitX / 30));
            _clouds.Move(ConvertUnits.ToDisplayUnits(new Vector2(difference / 100, 0)));     // _clouds.Move(ConvertUnits.ToDisplayUnits(Vector2.UnitX / 20));

            // Update Towers
            for (int i = 0; i < physicBreakables.Count; i++)
            {
                physicBreakables[i].Update(gameTime);
            }

            // Update Shots
            if (ScreenManager.Input.IsNewMouseButtonPress(MouseButtons.LeftButton))
            {
                // Create new Shot if Left Mouse is pressed
                Shots.Add(new Shot(false));
                Vector2 particlePos = GameDemo1.vehicle.cannon.Body.Position;
                particlePos.X += 0.3f;
                particleManager.AddCannonSmoke(particlePos);


                if (Shots.Count > 10)           // if we have reached more than 10 shots, remove the oldest shot
                {
                    Shots[0].shotBody.Dispose();
                    Shots.RemoveAt(0);
                }
                // And play some Cannon sound
                Sound.Play(Sound.Sounds.CannonShot);
            }

            for (int i = 0; i < Shots.Count; i++)
            {
                Shot shot = Shots[i];
                shot.Update();
                shot.shotBody.IgnoreCollisionWith(vehicle.Body);
                shot.shotBody.IgnoreCollisionWith(vehicle.WheelBackBody);
                shot.shotBody.IgnoreCollisionWith(vehicle.WheelFrontBody);
                shot.shotBody.IgnoreCollisionWith(vehicle.cannon.Body);
                if (Shots[i].shouldbedisposed == true)
                {
                    Shots[i].shotBody.Dispose();
                    Shots.RemoveAt(i);
                }
            }

            // Update Actors
            level.Update();

            // Update Triggers!
            for (int i = 0; i < Trigger.Triggers.Count; i++)
            {
                Trigger trigger = Trigger.Triggers[i];
                trigger.Update();
            }

            // Update Eyes
            foreach (Eye eye in Eye.Eyes)
            {
                eye.Update();
            }

            // Update Bridges
            bridge1.Update();

            // Update traps and Stuff
            trap.Update();

            // Update f*****g particles!!!
            particleManager.Update();


            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }