void EntitiesUpdate(double elapsedTime) { //血掉光后死亡 if (hp <= 0 && living) { living = false; disabled = true; //死亡时掉落道具 Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Datas.CurrentItemAdd.Add(new PowerPoint(texturemanager, Position.X, Position.Y)); Bullets.Clear(); //清空子弹列表 } double dx = elapsedTime * Direction.X * speed; double dy = elapsedTime * Direction.Y * speed; double tx = Position.X + dx; double ty = Position.Y + dy; Position.X = tx; Position.Y = ty; }
// when the player dies internal void Reset() { Player1 = new Player(); Bullets.Clear(); Enemies.Clear(); resetTimer = RESET_TIMER; }
public void Reset() { shotIterator.Reset(); Bullets.Clear(); ActiveStreams.Clear(); Score = 0; TotalExited = 0; }
public void ResetBeforeNextLevel() { foreach (Bullet bullet in Bullets) { SpaceShipManager.Remove(bullet); bullet.Dispose(); } Bullets.Clear(); Position = InitPosition; ScoreAsText.Text = string.Format("Player {0} Score : {1}", PlayerNumber.ToString(), Score.ToString()); }
public void Update() { if (Bullets.Count == 0) { return; } for (var i = 0; i < Bullets.Count; i++) { Bullets[i].UpdateNotImportant(); } var exists = Bullets.Where(e => e.Exists).ToArray(); Bullets.Clear(); Bullets.AddRange(exists); }
protected override void BeforeShoot() { for (int i = 0; i < BulletsCount; ++i) { var bullet = Instantiate <GameObject>(BulletPrefab); bullet.GetComponent <ShotgunBullet>().Setup(this, Damage, MoveSpeed); var bulletTr = bullet.transform; bulletTr.SetParent(ThisTransform); bulletTr.localPosition = new Vector2((i - BulletsCount / 2) * 0.2f, 0f); float angle = Angle * (BulletsCount / 2 - i); bulletTr.Rotate(0f, 0f, angle, Space.World); Bullets.Clear(); Bullets.Add(bullet); } }
/// <summary> /// Se llama en cada frame. /// Se debe escribir toda la lógica de computo del modelo, así como también verificar entradas del usuario y reacciones /// ante ellas. /// </summary> /// <param name="gameTime">The gameTime<see cref="GameTime"/>.</param> protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { // Exit game Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.P)) { // Pause/Start game GamePause = !GamePause; } Spawner.Update(this); // If GamePause is false i can move and play if (!GamePause) { Camera.Update(gameTime); Player.SetPosition(Camera.Position); // Creates new bullets when left click var mouse = Mouse.GetState(); if (mouse.LeftButton == ButtonState.Pressed && !ClickPressed && Bullets.Count < 15 && Recoil == 0) { Bullet singleBullet = new Bullet(); singleBullet.SetPosition(Camera.Position + Camera.FrontDirection * 25f); singleBullet.SetDirection(Camera.FrontDirection); singleBullet.SetUp(Camera.UpDirection); Bullets.Add(singleBullet); ClickPressed = true; } if (mouse.RightButton == ButtonState.Pressed && !ClickPressed && Bullets.Count < 15 && Recoil == 0) { Bullet Bullet1 = new Bullet(); Bullet1.SetPosition(Camera.Position + Camera.FrontDirection * 50f); Bullet1.SetDirection(Camera.FrontDirection); Bullet1.SetUp(Camera.UpDirection); Bullets.Add(Bullet1); Bullet Bullet2 = new Bullet(); Bullet2.SetPosition(Camera.Position + Vector3.Up * 5 + Camera.FrontDirection * 25f); Bullet2.SetDirection(Camera.FrontDirection); Bullet2.SetUp(Camera.UpDirection); Bullets.Add(Bullet2); ClickPressed = true; } if (mouse.LeftButton == ButtonState.Released && mouse.RightButton == ButtonState.Released && ClickPressed) { ClickPressed = false; } if (Bullets.Count >= 15) { Bullets.Clear(); } float totalGameTime = (float)gameTime.TotalGameTime.TotalSeconds; SpawnerModel.Update(totalGameTime, Spawner); RedIlluminationEffect.Parameters["lightPosition"].SetValue(Camera.Position); RedIlluminationEffect.Parameters["eyePosition"].SetValue(Camera.Position); foreach (Enemy enemy in Enemies) { Vector3 enemyPos = enemy.GetPosition(); enemy.SetUp(Camera.UpDirection); enemy.SetDirection(Vector3.Normalize(new Vector3(enemyPos.X - Camera.Position.X, 0, enemyPos.Z - Camera.Position.Z))); enemy.Update(Camera.Position, Enemies, Camera.Position); foreach (Bullet bullet in Bullets) { bullet.Update(); if (Vector3.Distance(bullet.GetPosition(), enemy.GetPosition()) < 50 && !bullet.GetDidDamage()) { enemy.TakeDamage(bullet.GetDamage()); bullet.DoDamage(); } } } Player.SetPosition(Camera.Position); } base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (Sprites[0].kill > 0) { score = 0; Sprites.Clear(); Bullets.Clear(); LoadContent(); return; } if (Sprites.Count == 1) { for (int i = 1; i < r.Next(8, 25); i++) { Sprites.Add(new Sprite() { attackSpeed = System.Math.Max(r.Next(3, 20) * r.NextDouble(), 2), attacktime = System.Math.Max(r.Next(1, 10) * r.NextDouble(), 1), speed = r.Next(40, 128), index = r.Next(1, 3), changeDir = 1, Pos = new Vector2(r.Next(0, 480 - 32), r.Next(0, 16) * 32), Direction = new Vector2(r.Next(0, 2) == 1 ? 1 : -1, 0) }); } } oldKs = ks; ks = Keyboard.GetState(); bool left = ks.IsKeyDown(Keys.Left), right = ks.IsKeyDown(Keys.Right), shoot = ks.IsKeyUp(Keys.Space) && oldKs.IsKeyDown(Keys.Space) && Sprites[0].attacktime <= 0; Sprites[0].Direction.X = left && right ? 0 : left ? -1 : right ? 1 : 0; for (int i = Sprites.Count - 1; i >= 0; i--) { Sprites[i].Update(gameTime); if (Sprites[i].shoot > 0) { Bullets.Add(new Sprite() { index = 4, Direction = new Vector2(0, 1), Pos = new Vector2(Sprites[i].Pos.X, Sprites[i].Pos.Y - 32), speed = 164, frameSpeed = .20 }); Sprites[i].attacktime = Sprites[i].attackSpeed; Sprites[i].shoot = 0; } if (Sprites[i].kill > 0) { Sprites.RemoveAt(i); } } if (shoot) { Sprites[0].attacktime = Sprites[0].attackSpeed; Sprites[0].frame = 2; Bullets.Add(new Sprite() { index = 3, Direction = new Vector2(0, -1), Pos = new Vector2(Sprites[0].Pos.X, Sprites[0].Pos.Y - 32), speed = 164, frameSpeed = .20 }); } for (int i = Bullets.Count - 1; i >= 0; i--) { for (int j = Sprites.Count - 1; j >= 0; j--) { if (Bullets[i].Direction.Y > 0 && j != 0) { continue; } else if (Bullets[i].Direction.Y < 0 && j == 0) { continue; } else if (new Rectangle((int)Bullets[i].Pos.X + 4, (int)Bullets[i].Pos.Y + 4, 24, 24).Intersects(new Rectangle((int)Sprites[j].Pos.X, (int)Sprites[j].Pos.Y, 32, 32))) { Bullets[i].kill = 1; Sprites[j].kill = 1; score += Bullets[i].Direction.Y > 0 ? 0 : 5; continue; } } Bullets[i].Update(gameTime); if (Bullets[i].kill > 0) { Bullets.RemoveAt(i); } } base.Update(gameTime); }