public GameData(ContentManager Content, GraphicsDevice device, AudioManager audio, World world) { player = new Player(world, Content, audio, device); mods = new ModCollection(); npcs = new NPCCollection(world, Content, player, device, audio); bullets = new BulletCollection(Content, device); missions = new MissionCollection(world, npcs); this.world = world; this.audio = audio; }
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 void update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m) { //TODO clearMoveData(); //Initialize BillboardEngine billboardEngine.Begin(camera.ViewMatrix); billboardEngine.AddBillboard(new Vector3(0.0f, 1.0f, 0.0f), Color.Transparent, 0.01f); for (int i = 0; i < Constants.CAP_NPCS; ++i) { NPC n = _content[i]; if (!n.active) { continue; } try { bool k = n.update(gameTime, bullets, camera, p, m); if (k) { float nx = n.position.X; float nz = n.position.Z; float tx = n.target.X; float tz = n.target.Z; int TX = (int)Math.Round((-1 * tx + world.size - 1)); int TZ = (int)Math.Round((-1 * tz + world.size - 1)); moveData[TX][TZ] = 255; int X = (int)Math.Round((-1 * nx + world.size - 1)); int Z = (int)Math.Round((-1 * nz + world.size - 1)); if (n.kind == Constants.NPC_BOSS) { moveData[X][Z] = (byte)(i + 1); for (int j = -1; j < 2; ++j) { for (int l = -1; l < 2; ++l) { if (moveData[X + j][Z + l] == 0) { moveData[X + j][Z + l] = (byte)(i + 1); } } } } else { moveData[X][Z] = (byte)(i + 1); } } } catch (IndexOutOfRangeException) { n.active = false; } } }
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); }
public bool update(GameTime gameTime, NPCCollection npcs, BulletCollection bullets, Camera camera, bool canShoot) { if (Mouse.GetState().RightButton == ButtonState.Released && rightButton) { charge.Clear(); } rightButton = (Mouse.GetState().RightButton == ButtonState.Pressed); if (lastMapID != world.mapID) { reset(); return(true); } if (health <= 0) { return(false); } restore = (byte)Math.Max(restore - 1, 0); hitDelay = (byte)Math.Max(hitDelay - 1, 0); if (health < maxHealth && hitDelay == 0 && Mouse.GetState().RightButton == ButtonState.Pressed) { charging = true; charge.Update(gameTime, camera, this.Position); if (restore <= 0) { int h = Math.Max((int)(maxHealth * .01f), 1); health = Math.Min(health + h, maxHealth); restore = maxRest; } } else { charging = false; } /*if (Mouse.GetState().RightButton == ButtonState.Pressed) * { * charging = true; * charge.Update(gameTime, camera, this.Position); * }*/ model.Rotation = new Vector3(0, -camera.Phi, 0); Vector3 front = new Vector3(camera.Direction.X, 0, camera.Direction.Z); front.Normalize(); float forward = (Keyboard.GetState().IsKeyDown(Keys.W) ? 1.0f : 0.0f) - (Keyboard.GetState().IsKeyDown(Keys.S) ? 1.0f : 0.0f); Vector3 sideVec = Vector3.Cross(front, new Vector3(0, 1, 0)); float side = (Keyboard.GetState().IsKeyDown(Keys.D) ? 1.0f : 0.0f) - (Keyboard.GetState().IsKeyDown(Keys.A) ? 1.0f : 0.0f); this.direction = front * forward + sideVec * side; if (this.direction != Vector3.Zero) { this.direction.Normalize(); } moveAndCollide(npcs); if (invincibleTimer > 0) { invincibleTimer--; } if (world.mapID != 0) { weapon.update(bullets, position, front, canShoot); } return(true); }