public override void Update(GameTime gameTime) { //Must be called before Movement.Update() UpdateFlipbookRotation(); SyncPosition = Position; Movement.Update(); if (IsPlayable && IsAbleToShoot) { Shoot(gameTime); } else { SyncShootHandler(); } if (IsAlive) { if (Crosshair != null) { Crosshair.Update(gameTime); } smokeParticleEmitter?.Update(gameTime); } ProjectileList.ForEach((x) => x.Update()); UnusedProjectile.ForEach((x) => ProjectileList.Remove(x)); UnusedProjectile.Clear(); LastCreatedProjectileList.ForEach((x) => ProjectileList.Add(x)); LastCreatedProjectileList.Clear(); CollisionBox.Update(); SendRequestToServer(); Rider?.Update(); #if DEBUG //Debug debugCrosshair.Update(Position); debugCrosshair2.Update(MobileFlipbook.Position); #endif }
/// <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(); } MouseState mouse = Mouse.GetState(); // Keep track of delay between balls ballTimer += gameTime.ElapsedGameTime.TotalMilliseconds; // Create new balls if the delay is correct if (mouse.LeftButton == ButtonState.Pressed && ballTimer > 400) { ballTimer = 0; createBall(); } crosshair.Update(new Vector2(mouse.Position.X, mouse.Position.Y)); // Update all the balls foreach (var b in balls) { /*if (b.Position.Y >= screenHeight - 60) * { * b.AddForce(new Vector2(2, -10)); * }*/ b.Update(screenHeight); checkBallCollisions(); } fpsCounter = fps.CurrentFramesPerSecond; ballCounter = balls.Count; base.Update(gameTime); }