public void update(BulletCollection bullets, Vector3 position, Vector3 direction, bool canShoot) { if (ammo < maxAmmo + mod_acp && recharge <= 0) { ammo++; recharge = maxRechrg - mod_rcg; } if (cooldown <= 0 && ammo > 0 && (Keyboard.GetState().IsKeyDown(Keys.Space) || Mouse.GetState().LeftButton == ButtonState.Pressed) && canShoot && Mouse.GetState().RightButton == ButtonState.Released) { cooldown = maxCooldn - mod_cdn; bullets.generate(true, position + direction * .5f, direction, 1 + mod_spd, 20, 20 + mod_str, (byte)mod_elm, (byte)mod_typ); ammo--; audio.playShoot(true); } cooldown = Math.Max(cooldown - 1, 0); recharge = Math.Max(recharge - 1, 0); }
public bool update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m) { #region npc death //die and grant xp if (health <= 0 && !isDead) { int exp = (int)(XP * (float)level / (float)p.level); exp = Math.Min(exp, (int)(XP * 1.5f)); exp = Math.Max(exp, 1); if (p.lv == 50) { exp = 0; } else { p.getEXP(exp); } m.update(kind, exp); isDead = true; isHit = false; hitTimer = 0; explosion.Position = Position + new Vector3(0, 0.5f, 0); explosion.Initialize(camera); } //Explosion Update if NPC is down if (isDead && active) { hitTimer++; explosion.Update(gameTime, camera); if (hitTimer > 25) { active = false; isDead = false; this.explosion.Clear(); dmgNumbers.Clear(); return(false); } } #endregion #region shoot //shoot if player is within shooting distance and not on cooldown if (playerDistance <= world.shootDistance && cooldown == 0) { cooldown = maxCooldn; Vector3 dir = (p.position - position); dir.Normalize(); bullets.generate(false, position + dir, dir, 1, world.shootDistance * 2, strength, element); audio.playShoot(false); } if (cooldown > 0) { cooldown--; } #endregion #region move //if (moving) //move(); //else if (!moving || !move()) { { pathFinder.setup(new Point((int)Math.Round((-1 * position.X + world.size - 1)), (int)Math.Round((-1 * position.Z + world.size - 1))), p); target = pathFinder.findPath(kind == Constants.NPC_BOSS); newTarget = true; direction = target - position; if (direction.Length() != 0) { direction.Normalize(); } moving = true; //move(); } } #endregion #region get hit billboard/dmg number //Hit Notification if (isHit) { hitTimer++; billboardEngine.AddBillboard(this.position + new Vector3(0, 2, 0), Color.Red, 1.5f); if (hitTimer == 70) { isHit = false; hitTimer = 0; } } #endregion //Rotate Model double rotationAngle = Math.Acos((Vector3.Dot(direction, -1 * Vector3.UnitX)) / (direction.Length())); rotationAngle = (p.Position.Z < this.Position.Z) ? rotationAngle * -1.0f : rotationAngle; rotationAngle += (this.kind == Constants.NPC_BOSS) ? Math.PI / 2 : -Math.PI / 2; model.Rotation = new Vector3(0, (float)(rotationAngle), 0); //Update PlayerDistance playerDistance = (p.Position - this.Position).Length(); if (playerDistance < 4) { target = position; direction = p.Position - this.Position; } return(true); }