public void update(NPCCollection npcs, Player p, Mission m, bool isMainMission = false) { foreach (NPCSpawner spawner in spawners) { spawner.update(npcs, p, m, isMainMission); } }
public void update(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m) { if (!active) { return; } waveTime += gameTime.ElapsedGameTime; float dx = (float)Math.Sin(waveTime.Milliseconds); float dz = (float)Math.Cos(waveTime.Milliseconds); int factor = (int)Math.Ceiling(speed); float remainingSpeed = speed; float spd = speed / (float)factor; for (int i = 0; i < factor; i++) { spd = Math.Min(spd, remainingSpeed); bool u = updateCycle(gameTime, camera, world, npcs, p, m, factor, spd, dx, dz); remainingSpeed -= spd; if (!u || remainingSpeed == 0) { break; } } return; }
public void update(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m) { for (int i = 0; i < Constants.CAP_BULLETS; i++) { _content[i].update(gameTime, camera, world, npcs, p, m); } }
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 AStar(World w, Player p, Point o, NPCCollection col) { world = w; npcs = col; origin = o; list = new List <Vector3>(); isBoss = false; PathNoteEqualityComparer comparer = new PathNoteEqualityComparer(); openList = new SortedList <ulong, PathNode>(); closedList = new HashSet <PathNode>(comparer); setup(origin, p); }
//bullet - npc collision private bool collision(NPCCollection npcs, Mission m) { byte tile = npcs.npcMoveData[xTile][zTile]; if (tile != 0 && tile != 255) { if (fromPlayer) { npcs[tile - 1].getHit(this, m); } return(true); } return(false); }
public MissionCollection(World w, NPCCollection n) : base(4) { world = w; npcs = n; level = 1; Random ran = new Random(); for (int i = 0; i < 4; ++i) { _content.Add(new Type1Mission()); } activeMission = this[0]; mainMission = this[3]; nextModLevel = 6; isNew = new bool[4]; }
public void update(NPCCollection npcs, Player p, Mission m, bool isMainMission = false) { if (!active) { return; } if (cooldown == 0) { Vector3 pos = new Vector3(Constants.MAP_SIZE - 2 * x - 1, 0, Constants.MAP_SIZE - 2 * z - 1); Vector3 dir = p.Position - pos; dir.Normalize(); if (isMainMission && kind != Constants.NPC_BOSS) { npcs.generate(kind, pos, dir, m.level - 10); } else { npcs.generate(kind, pos, dir, m.level); } if (rate == Constants.SPAWN_ONCE) { active = false; } else { cooldown = new Random().Next((int)(maxCooldown * 0.6f), (int)(maxCooldown * 1.0f)); } } else { cooldown = Math.Max(cooldown - 1, 0); } }
private bool updateCycle(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m, int factor, float spd, float dx, float dz) { position += spd * direction; if (type == Constants.TYP_WAV) { Vector3 cross = Vector3.Cross(direction, Vector3.Up); if (mirror) { position -= 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds * 200); } else { position += 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds * 200); } //position += 0.5f * Vector3.Up * (float)Math.Cos(waveTime.Milliseconds); //position.X += dx / factor; //position.Z += dz / factor; } distance += spd; bulletOb.Position = position; particleEffect.Update((float)gameTime.ElapsedGameTime.TotalSeconds, camera.ViewMatrix, position, direction); xTile = (byte)Math.Round(-1 * (position.X) + (Constants.MAP_SIZE - 1)); zTile = (byte)Math.Round(-1 * (position.Z) + (Constants.MAP_SIZE - 1)); if (collision(world) || collision(npcs, m) || collision(p, m) || distance > maxDist) { active = false; particleEffect.Clear(); return(false); } return(true); }
public override string getShortLabel(NPCCollection npcs) { string l = actCount + " / " + tarCount + " " + npcs.Labels[target] + " down"; return(l); }
/// <summary> /// assigns NPC attributes and ModelObject and activates the NPC /// </summary> /// <param name="k">NPC kind/species</param> /// <param name="m">ModelObject</param> /// <param name="p">starting position</param> /// <param name="d">starting direction</param> /// <param name="l">level</param> /// <param name="pl">Player</param> /// <param name="npcs">parent NPCCollection (should always be "this")</param> public void setup(byte k, ModelObject m, Vector3 p, Vector3 d, int l, Player pl, NPCCollection npcs, byte elem = Constants.ELM_NIL) { kind = k; model = m; position = p; direction = d; level = l; if (kind == Constants.NPC_BOSS) { level = Math.Min(60, Math.Max(1, level)); } else { level = Math.Min(50, Math.Max(1, level)); } playerDistance = (pl.Position - this.Position).Length(); #region kind specific stats switch (kind) { case Constants.NPC_NONE: speed = 0.03f; maxHealth = (int)(50 * Math.Pow(1.05f, level - 1)); XP = 2; maxCooldn = 70; model.Scaling = new Vector3(0.75f, 0.75f, 0.75f); element = Constants.ELM_NIL; strength = (byte)(10 * Math.Pow(1.045f, level - 1)); break; case Constants.NPC_PLAS: speed = 0.035f; maxHealth = (int)(50 * Math.Pow(1.045f, level - 1)); XP = 3; maxCooldn = 80; model.Scaling = new Vector3(0.75f, 0.75f, 0.75f); element = Constants.ELM_PLA; strength = (byte)(10 * Math.Pow(1.05f, level - 1)); break; case Constants.NPC_HEAT: speed = 0.04f; maxHealth = (int)(50 * Math.Pow(1.04f, level - 1)); XP = 3; maxCooldn = 75; model.Scaling = new Vector3(0.5f, 0.5f, 0.5f); element = Constants.ELM_HEA; strength = (byte)(10 * Math.Pow(1.055f, level - 1)); break; case Constants.NPC_ICE: speed = 0.03f; maxHealth = (int)(50 * Math.Pow(1.055f, level - 1)); XP = 3; maxCooldn = 90; model.Scaling = new Vector3(0.75f, 0.75f, 0.75f); element = Constants.ELM_ICE; strength = (byte)(10 * Math.Pow(1.04f, level - 1)); break; case Constants.NPC_BOSS: speed = 0.02f; maxHealth = (int)(200 * Math.Pow(1.07f, level - 1)); XP = 70; maxCooldn = 50; model.Scaling = new Vector3(0.75f, 0.75f, 0.75f); element = elem; strength = (byte)Math.Min((10 * Math.Pow(1.06f, level - 1)), 255); break; default: speed = 0.001f; maxHealth = 1; XP = 0; maxCooldn = 1000; break; } #endregion health = maxHealth; active = true; model.Position = this.position; moving = false; newTarget = false; isHit = false; hitTimer = 0; isDead = false; pathFinder = npcs.PathFinder; target = new Vector3(position.X, position.Y, position.Z); }
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); }
//public void moveAndCollide1(NPCCollection npcs) //{ // this.position += speed * direction; // int x1 = (int)Math.Round(-1 * this.position.X + Constants.MAP_SIZE - 1) / 2; // int x2 = (int)Math.Round(-1 * this.position.X + Constants.MAP_SIZE) / 2; // int z1 = (int)Math.Round(-1 * this.position.Z + Constants.MAP_SIZE - 1) / 2; // int z2 = (int)Math.Round(-1 * this.position.Z + Constants.MAP_SIZE) / 2; // if ((world.MoveData[x1][z1] == 1) || (world.MoveData[x2][z2] == 1) || (world.MoveData[x2][z1] == 1) || (world.MoveData[x1][z2] == 1)) // this.position = this.model.Position; // else model.Position = this.position; // byte tile = npcs.npcMoveData[xTile][zTile]; // if (tile != 0 && tile != 255 && invincibleTimer == 0) // { // getHit(npcs[tile - 1]); // npcs[tile - 1].getHit(this); // } //} public void moveAndCollide(NPCCollection npcs) { //calculate tiles before movement int oldx1 = (int)Math.Round(-1 * this.position.X + Constants.MAP_SIZE - 1) / 2; int oldx2 = (int)Math.Round(-1 * this.position.X + Constants.MAP_SIZE) / 2; int oldz1 = (int)Math.Round(-1 * this.position.Z + Constants.MAP_SIZE - 1) / 2; int oldz2 = (int)Math.Round(-1 * this.position.Z + Constants.MAP_SIZE) / 2; //apply speed and direction to move character this.position += speed * direction; //calculate tiles after movement int x1 = (int)Math.Round(-1 * this.position.X + Constants.MAP_SIZE - 1) / 2; int x2 = (int)Math.Round(-1 * this.position.X + Constants.MAP_SIZE) / 2; int z1 = (int)Math.Round(-1 * this.position.Z + Constants.MAP_SIZE - 1) / 2; int z2 = (int)Math.Round(-1 * this.position.Z + Constants.MAP_SIZE) / 2; //determine Movement bools for tiles; true means not passable bool moveDataX1Z1 = world.MoveData[x1][z1] == 1; bool moveDataX1Z2 = world.MoveData[x1][z2] == 1; bool moveDataX2Z2 = world.MoveData[x2][z2] == 1; bool moveDataX2Z1 = world.MoveData[x2][z1] == 1; if (moveDataX1Z1 || moveDataX2Z2 || moveDataX2Z1 || moveDataX1Z2) { #region check for single Collisions //Bottom Right if (moveDataX1Z1 && !moveDataX2Z2 && !moveDataX2Z1 && !moveDataX1Z2) { if (oldz1 - 1 == z1) { this.position = this.model.Position; this.position += speed * new Vector3(direction.X, direction.Y, 0); } else if (oldx1 - 1 == x1) { this.position = this.model.Position; this.position += speed * new Vector3(0, direction.Y, direction.Z); } } //Top Left else if (!moveDataX1Z1 && moveDataX2Z2 && !moveDataX2Z1 && !moveDataX1Z2) { if (oldz2 + 1 == z2) { this.position = this.model.Position; this.position += speed * new Vector3(direction.X, direction.Y, 0); } else if (oldx2 + 1 == x2) { this.position = this.model.Position; this.position += speed * new Vector3(0, direction.Y, direction.Z); } } //Top Right else if (!moveDataX1Z1 && !moveDataX2Z2 && !moveDataX2Z1 && moveDataX1Z2) { if (oldz2 + 1 == z2) { this.position = this.model.Position; this.position += speed * new Vector3(direction.X, direction.Y, 0); } else if (oldx1 - 1 == x1) { this.position = this.model.Position; this.position += speed * new Vector3(0, direction.Y, direction.Z); } } //Bottom Left else if (!moveDataX1Z1 && !moveDataX2Z2 && moveDataX2Z1 && !moveDataX1Z2) { if (oldz1 - 1 == z1) { this.position = this.model.Position; this.position += speed * new Vector3(direction.X, direction.Y, 0); } else if (oldx2 + 1 == x2) { this.position = this.model.Position; this.position += speed * new Vector3(0, direction.Y, direction.Z); } } #endregion #region check for collision on one whole side //Bottom else if (moveDataX1Z1 && !moveDataX2Z2 && moveDataX2Z1 && !moveDataX1Z2) { this.position = this.model.Position; this.position += speed * new Vector3(direction.X, direction.Y, 0); } //Right else if (moveDataX1Z1 && !moveDataX2Z2 && !moveDataX2Z1 && moveDataX1Z2) { this.position = this.model.Position; this.position += speed * new Vector3(0, direction.Y, direction.Z); } //Top else if (!moveDataX1Z1 && moveDataX2Z2 && moveDataX2Z1 && !moveDataX1Z2) { this.position = this.model.Position; this.position += speed * new Vector3(0, direction.Y, direction.Z); } //Left else if (!moveDataX1Z1 && moveDataX2Z2 && !moveDataX2Z1 && moveDataX1Z2) { this.position = this.model.Position; this.position += speed * new Vector3(direction.X, direction.Y, 0); } #endregion // corner, nowhere to slide to else { this.position = this.model.Position; } } //Set Model Position at last this.model.Position = this.position; //check for player - npc collision byte tile = npcs.npcMoveData[xTile][zTile]; if (tile != 0 && tile != 255 && invincibleTimer == 0) { getHit(npcs[tile - 1]); npcs[tile - 1].getHit(this); } }
public override string getShortLabel(NPCCollection npcs) { throw new NotImplementedException(); }
public abstract string getShortLabel(NPCCollection npcs);