public void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (AIDude e in Enemies.Where(en => (gameHero.Position - en.Position).Length() < 2000f)) { e.DrawShadows(sb, lightingEngine); } }
public void Draw(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Item i in Items.Where(it => (gameHero.Position - it.Position).Length() < 2000f)) { sb.Draw(SpriteSheet, i.Position, rectDict[i.Type], lightingEngine.CurrentSunColor, i.Rotation, new Vector2(25, 25), 1f, SpriteEffects.None, 1); } }
public void DrawLightBlock(SpriteBatch sb, HeroDude gameHero) { foreach (AIDude e in Enemies.Where(en => (gameHero.Position - en.Position).Length() < 2000f)) { e.DrawLightBlock(sb); } }
public void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f)) { if (v is Chopper && ((Chopper)v).Height > 0f) continue; v.DrawShadows(sb, lightingEngine); } }
public void DrawLightBlock(SpriteBatch sb, HeroDude gameHero) { foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f)) { if (v is Chopper && ((Chopper)v).Height > 0f) continue; v.DrawLightBlock(sb); } }
public void DrawShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Item i in Items.Where(it => (gameHero.Position - it.Position).Length() < 2000f)) { for (int s = 1; s < 20; s += 2) { Vector2 pos = i.Position + new Vector2(lightingEngine.CurrentShadowVect.X * s, lightingEngine.CurrentShadowVect.Y * s); sb.Draw(SpriteSheet, pos, rectDict[i.Type], Color.Black * 0.03f, i.Rotation, new Vector2(25, 25), 1f, SpriteEffects.None, 1); } } }
/// <summary> /// Constructor. /// </summary> public MapScreen(Map map, bool[,] fog, HeroDude hero, Texture2D icons) { TransitionOnTime = TimeSpan.FromSeconds(0.5); TransitionOffTime = TimeSpan.FromSeconds(0.5); gameMap = map; mapFog = fog; mapIcons = icons; gameHero = hero; IsPopup = true; }
public void Draw(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f && !(veh is Chopper))) { v.Draw(sb, lightingEngine); } // Draw helis on top of other vehicles because of rotor blades foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f && veh is Chopper)) { if (((Chopper)v).Height > 0f) continue; v.Draw(sb, lightingEngine); } }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, bool[,] mapFog) { int count = 0; foreach (Item i in Items.Where(it => (gameHero.Position - it.Position).Length() < 4000f)) { count++; i.Update(gameTime); if ((gameHero.Position - i.Position).Length() < 50f && gameHero.drivingVehicle==null) { Pickup(i, gameHero, gameMap, mapFog); } } Items.RemoveAll(it => !it.Active); }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, bool[,] mapFog, Camera gameCamera) { int count = 0; foreach (AIDude e in Enemies.Where(en => (gameHero.Position - en.Position).Length() < 4000f)) { count++; if ((gameHero.Position - e.Position).Length() < 2000f) { e.Update(gameTime, gameMap, gameHero, mapFog, gameCamera); bool alerted = false; if (gameHero.HuntedLevel.Level > 0f) { if (!alerted && Helper.Random.Next(11000 - (int)(gameHero.HuntedLevel.Level * 100)) == 1 && e.State == AIState.Patrolling && (gameHero.Position - e.Position).Length() < 2000f) { //e.InvestigatePosition(); alerted = true; } } } } // Spawn some new enemies if (count < 10 + (int)(gameHero.HuntedLevel.Level / 10)) { Vector2 pos = Helper.RandomPointInCircle(gameHero.Position, 2000f, 4000f); if (!gameMap.CheckTileCollision(pos) && pos.X > 0 && pos.X < (gameMap.Width * gameMap.TileWidth) && pos.Y > 0 && pos.Y < (gameMap.Height * gameMap.TileHeight) && !VehicleController.Instance.CheckVehicleCollision(pos)) { AIDude newDude = new AIDude(pos); newDude.LoadContent(SpriteSheet, graphicsDevice, lightingEngine, gameHero); newDude.Health = 10 + Helper.Random.Next(30); Enemies.Add(newDude); } } Enemies.RemoveAll(e => !e.Active); }
public void Update(GameTime gameTime, HeroDude gameHero, DateTime timeofday, int gameDay) { vehicle = (gameHero.drivingVehicle != null); heroHealthTarget = (gameHero.drivingVehicle==null?gameHero.Health:gameHero.drivingVehicle.Health); if (heroHealthTarget > 99f && heroHealthTarget < 100f) heroHealthTarget = 100f; huntedLevelTarget = gameHero.HuntedLevel.Level; huntedLevel = MathHelper.Lerp(huntedLevel, huntedLevelTarget, 0.1f); heroHealth = MathHelper.Lerp(heroHealth, heroHealthTarget, 0.1f); showAmmo = gameHero.SelectedWeapon > 0; // ammo = gameHero.Weapons[gameHero.SelectedWeapon].clipAmmo; ammo = gameHero.Ammo; weapon = gameHero.Weapons[gameHero.SelectedWeapon].sortOrder; timeOfDay = timeofday; day = gameDay; Ticker.Update(gameTime); }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero) { foreach (Projectile p in Projectiles.Where(part => part.Active)) { p.Life -= gameTime.ElapsedGameTime.TotalMilliseconds; p.Position += p.Velocity; //p.Rotation += p.RotationSpeed; if (p.CanCollide && gameMap.CheckCollision(p.Position,false) == true) { p.Velocity = Vector2.Zero; p.RotationSpeed = 0f; } foreach (Vehicle v in VehicleController.Instance.Vehicles) { if (Helper.IsPointInShape(p.Position, v.CollisionVerts)) { v.HitByProjectile(p); p.Active = false; } } if (!p.Active) continue; if (p.Owner.GetType() == typeof(HeroDude)) { foreach (AIDude d in EnemyController.Instance.Enemies.Where(dude => dude.Active && !dude.Dead)) { if ((d.Position - p.Position).Length() < 60f) { d.HitByProjectile(p); p.Active = false; } } } if (!p.Active) continue; if (p.Owner.GetType() == typeof(AIDude)) { if ((gameHero.Position - p.Position).Length() < 60f) { gameHero.HitByProjectile(p); } } if (p.Life <= 0) { p.Active = false; } } Projectiles.RemoveAll(part => !part.Active); }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, Camera gameCamera) { int count = 0; foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 4000f)) { count++; v.Update(gameTime, gameMap, gameHero, gameCamera); if ((gameHero.Position - v.Position).Length() < 50f) { } } Vehicles.RemoveAll(it => !it.Active); }
internal void HeroFiredShot(HeroDude gameHero) { int numAlerted = 0; foreach (Dude d in Enemies.Where(e => (gameHero.Position - e.Position).Length() < 1200f).OrderBy(e => (gameHero.Position - e.Position).Length()).ToList()) { if (numAlerted < 1 + (int)(gameHero.HuntedLevel.Level / 10)) { numAlerted++; gameHero.HuntedLevel.Heard(gameHero.Position, true); ((AIDude)d).InvestigatePosition(); } } }
public virtual void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, Camera gameCamera) { DoCollisions(gameMap); Position += Speed; Position.X = MathHelper.Clamp(Position.X, 50, (gameMap.Width * gameMap.TileWidth) -50); Position.Y = MathHelper.Clamp(Position.Y, 50, (gameMap.Height * gameMap.TileHeight) -50); Health = MathHelper.Clamp(Health, 0f, 100f); if (gameHero.drivingVehicle == this) { foreach (LightSource l in Lights) l.Active = true; } else { foreach (LightSource l in Lights) l.Active = false; } if (Health < 30f) { if(Helper.Random.Next(((int)Health/15))==0) { Vector2 smokePos = Helper.RandomPointInCircle(Position, 0f, 300f); if (Helper.IsPointInShape(smokePos, CollisionVerts)) ParticleController.Instance.AddSmoke(smokePos); } } if (Health <= 0f) { if ((gameHero.Position - Position).Length() > 3000f) { for (int l=0;l<Lights.Count;l++) { LightingEngine.Instance.LightSources.Remove(Lights[l]); Lights[l].Active = false; Lights[l] = null; } Active = false; } } }
private void SpawnDrops(Map gameMap, HeroDude gameHero) { bool hasweapon = false; foreach(Weapon w in gameHero.Weapons) if(w.GetType()==Weapons[SelectedWeapon].GetType()) hasweapon = true; if (hasweapon) { int drop = Helper.Random.Next(65); if (drop < 5) return; if (drop >= 5 && drop < 35) { if (Helper.Random.Next(2) == 0) { List<Compound> c = gameMap.FindNearestCompounds(Position); if (c[0].Discovered == false) ItemController.Instance.Spawn(ItemType.CompoundMap, Position); else if (BelongsToCompound) { bool found = false; for (int i = 1; i <= 2; i++) { if (c[i].Discovered == false) { ItemController.Instance.Spawn(ItemType.CompoundMap, Position); found = true; break; } } if (!found) ItemController.Instance.Spawn(ItemType.Ammo, Position); } else ItemController.Instance.Spawn(ItemType.Health, Position); } else ItemController.Instance.Spawn(ItemType.Health, Position); } if (drop >= 35 && drop < 58) { if (Helper.Random.Next(2) == 0) { List<Compound> c = gameMap.FindNearestCompounds(Position); if (c[0].Discovered == false) ItemController.Instance.Spawn(ItemType.CompoundMap, Position); else if (BelongsToCompound) { bool found = false; for (int i = 1; i <= 2; i++) { if (c[i].Discovered == false) { ItemController.Instance.Spawn(ItemType.CompoundMap, Position); found = true; break; } } if (!found) ItemController.Instance.Spawn(ItemType.Ammo, Position); } else ItemController.Instance.Spawn(ItemType.Ammo, Position); } else ItemController.Instance.Spawn(ItemType.Ammo, Position); } if (drop >= 58 && BelongsToCompound) { foreach (AIDude e in EnemyController.Instance.Enemies.Where(en => en.IsGeneral).OrderBy(en => (en.Position - Position).Length())) { if (!e.Discovered && (e.Position - Position).Length() < 20000) { ItemController.Instance.Spawn(ItemType.GeneralMap, Position); break; } else break; } } } else { if (Weapons[SelectedWeapon] is Pistol) ItemController.Instance.Spawn(ItemType.Pistol, Position); if (Weapons[SelectedWeapon] is Shotgun) ItemController.Instance.Spawn(ItemType.Shotgun, Position); if (Weapons[SelectedWeapon] is SMG) ItemController.Instance.Spawn(ItemType.SMG, Position); if (Weapons[SelectedWeapon] is Rifle) ItemController.Instance.Spawn(ItemType.Rifle, Position); } }
public void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, bool[,] mapFog, Camera gameCamera) { checkLOSTime += gameTime.ElapsedGameTime.TotalMilliseconds; genPathTime += gameTime.ElapsedGameTime.TotalMilliseconds; checkTorchTime += gameTime.ElapsedGameTime.TotalMilliseconds; // Moving if ((Position - Target).Length() > 10f) { Vector2 dir = Target - Position; Move(dir); //if(State==AIState.Patrolling) if(State!=AIState.Attacking) LookAt(Target); } else { Target = Position; // Reached target switch (State) { case AIState.Patrolling: if (Helper.Random.Next(500) == 1) { Vector2 potentialTarget = Helper.RandomPointInCircle(Position, 100, 500); if (!gameMap.CheckCollision(potentialTarget)) Target = potentialTarget; } break; } } switch (State) { case AIState.Patrolling: // Chase player if in LOS if (CheckLineOfSight(gameHero.Position, gameMap)) { gameHero.HuntedLevel.Seen(gameHero.Position); Target = Position; // Stop dead in tracks if (gameHero.drivingVehicle == null) State = AIState.Chasing; // Begin chasing player else { if (Weapons[SelectedWeapon].GetType() != typeof(Knife)) State = AIState.Attacking; } } // Allow the enemy to "hear" the player if player moves close to enemy if ((gameHero.Speed.Length() > 0f && (gameHero.Position - Position).Length() < 250f) || (gameHero.drivingVehicle != null && (gameHero.Position - Position).Length() < 800f)) { gameHero.HuntedLevel.Heard(gameHero.Position, false); LookAt(gameHero.Position); } if ((gameHero.Position - Position).Length() < 800f && insideBuilding == null && gameHero.drivingVehicle is Chopper && ((Chopper)gameHero.drivingVehicle).Height >0f && !(Weapons[SelectedWeapon] is Knife)) State = AIState.Attacking; break; case AIState.Chasing: Target = gameHero.Position; LookAt(gameHero.Position); if(gameHero.drivingVehicle is Chopper) State = AIState.Patrolling; if (((gameHero.Position - Position).Length() < 450f && CheckLineOfSight(gameHero.Position, gameMap)) || ((gameHero.Position - Position).Length() < 800f && gameHero.drivingVehicle is Chopper)) { Target = Position; State = AIState.Attacking; } break; case AIState.FollowingPath: if (Target == Position) { if (chasePath == null || regeneratePath) { if (genPathTime > 1000) { genPathTime = 0; regeneratePath = false; chasePath = PathFinder.FindPath(gameMap.AStarWorld, new Point3D((int)(Position.X / gameMap.TileWidth), (int)(Position.Y / gameMap.TileHeight), 0), new Point3D((int)(gameHero.Position.X / gameMap.TileWidth), (int)(gameHero.Position.Y / gameMap.TileHeight), 0)); if (chasePath != null) Target = new Vector2((chasePath.position.X * gameMap.TileWidth) + (gameMap.TileWidth / 2), (chasePath.position.Y * gameMap.TileHeight) + (gameMap.TileHeight / 2)); else State = AIState.Patrolling; } } else { chasePath = chasePath.next; if (chasePath != null) Target = new Vector2((chasePath.position.X * gameMap.TileWidth) + (gameMap.TileWidth / 2), (chasePath.position.Y * gameMap.TileHeight) + (gameMap.TileHeight / 2)); else State = AIState.Chasing; } } if (CheckLineOfSight(gameHero.Position, gameMap)) { Target = Position; // Stop dead in tracks State = AIState.Chasing; // Begin chasing player } break; case AIState.Attacking: if (gameHero.drivingVehicle is Chopper && insideBuilding != null) { State = AIState.Patrolling; break; } LookAt(gameHero.Position); bool shootUp = (gameHero.drivingVehicle != null && gameHero.drivingVehicle is Chopper && ((Chopper)gameHero.drivingVehicle).Height >0f); Attack(gameTime, gameHero.Position, true, gameCamera, !shootUp); if (Weapons[SelectedWeapon].GetType() != typeof(Knife)) { if ((gameHero.Position - Position).Length() > 450f) { if (gameHero.drivingVehicle == null) { Target = gameHero.Position; State = AIState.Chasing; } else State = AIState.Patrolling; } if (Helper.Random.Next(100) == 1) { Vector2 potentialTarget = Helper.RandomPointInCircle(Position, 100, 500); if (!gameMap.CheckCollision(potentialTarget)) Target = potentialTarget; } } else { if (gameHero.drivingVehicle == null) { Target = gameHero.Position; if ((gameHero.Position - Position).Length() < 100f) Target = Position; } else State = AIState.Patrolling; } break; case AIState.Investigating: if (Target == Position) { if (chasePath == null || regeneratePath) { if (genPathTime > 1000) { genPathTime = 0; regeneratePath = false; chasePath = PathFinder.FindPath(gameMap.AStarWorld, new Point3D((int)(Position.X / gameMap.TileWidth), (int)(Position.Y / gameMap.TileHeight), 0), new Point3D((int)(gameHero.HuntedLevel.LastKnownPosition.X / gameMap.TileWidth), (int)(gameHero.HuntedLevel.LastKnownPosition.Y / gameMap.TileHeight), 0)); if (chasePath != null) Target = new Vector2((chasePath.position.X * gameMap.TileWidth) + (gameMap.TileWidth / 2), (chasePath.position.Y * gameMap.TileHeight) + (gameMap.TileHeight / 2)); else State = AIState.Patrolling; } } else { chasePath = chasePath.next; if (chasePath != null) Target = new Vector2((chasePath.position.X * gameMap.TileWidth) + (gameMap.TileWidth / 2), (chasePath.position.Y * gameMap.TileHeight) + (gameMap.TileHeight / 2)); else State = AIState.Patrolling; } } if ((Position - gameHero.HuntedLevel.LastKnownPosition).Length() < 200f) State = AIState.Patrolling; if (CheckLineOfSight(gameHero.Position, gameMap)) { Target = Position; // Stop dead in tracks State = AIState.Chasing; // Begin chasing player } break; } if (gameHero.Dead) State = AIState.Patrolling; if (Health <= 0 && !Dead) { deadTime = 5000; deadAlpha = 1f; Dead = true; SpawnDrops(gameMap, gameHero); LightingEngine.Instance.RemoveSource(HeadTorch); ParticleController.Instance.AddBloodPool(Position); if (IsGeneral) { Hud.Instance.Ticker.AddLine("> You have eliminated a General! " + (3 - (3-EnemyController.Instance.Enemies.Count(e => e.IsGeneral && !e.Dead))) + "/" + (3)); } } if (IsGeneral) { if ((gameHero.Position - Position).Length() < 720f && !Discovered && gameHero.drivingVehicle==null && !LineCollision(gameHero.Position, gameMap, true)) { Discovered = true; Hud.Instance.Ticker.AddLine("> You have found a General!"); } } HeadTorch.Position = Helper.PointOnCircle(ref Position, 32, Rotation - MathHelper.PiOver2); HeadTorch.Rotation = Rotation - MathHelper.PiOver2; if (checkTorchTime > 250) { checkTorchTime = 0; if ((Position.X < gameCamera.Position.X - ((gameCamera.Width / gameCamera.Zoom) / 2) || Position.X > gameCamera.Position.X + ((gameCamera.Width / gameCamera.Zoom) / 2) || Position.Y < gameCamera.Position.Y - ((gameCamera.Height / gameCamera.Zoom) / 2) || Position.Y > gameCamera.Position.Y + ((gameCamera.Height / gameCamera.Zoom) / 2)) && LineCollision(gameHero.Position, gameMap, false)) { HeadTorch.Active = false; } } else if (!Dead) HeadTorch.Active = true; if (IsGeneral) Animations["head"].XOffset = 4; else Animations["head"].XOffset = 2; if (Dead) { if (deadTime <= 0) { deadAlpha -= 0.01f; } } if (Dead && deadTime <= 0 && deadAlpha <= 0f) { Active = false; } base.Update(gameTime, gameMap, mapFog, gameHero); }
void DoCollisions(Map gameMap, HeroDude gameHero) { bool LCollision = false; bool RCollision = false; bool UCollision = false; bool DCollision = false; if (Speed.X > 0f) { if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, 0f))) RCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, -0.4f))) RCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, 0.4f))) RCollision = true; for (int i = 0; i < VehicleController.Instance.Vehicles.Count; i++) { if (Vector2.Distance(VehicleController.Instance.Vehicles[i].Position, Position) > 500f) continue; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, 0f), VehicleController.Instance.Vehicles[i].CollisionVerts)) RCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, -0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) RCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) RCollision = true; } for(int d=0;d<EnemyController.Instance.Enemies.Count;d++) { if (Vector2.Distance(EnemyController.Instance.Enemies[d].Position, Position) > 500f) continue; if (EnemyController.Instance.Enemies[d].Dead || EnemyController.Instance.Enemies[d] == this) continue; if ((Helper.PointOnCircle(ref Position, 50, 0f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) RCollision = true; if ((Helper.PointOnCircle(ref Position, 50, -0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) RCollision = true; if ((Helper.PointOnCircle(ref Position, 50, 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) RCollision = true; } if (this is AIDude) { if ((Helper.PointOnCircle(ref Position, 50, 0f) - gameHero.Position).Length() < 40f) RCollision = true; if ((Helper.PointOnCircle(ref Position, 50, -0.4f) - gameHero.Position).Length() < 40f) RCollision = true; if ((Helper.PointOnCircle(ref Position, 50, 0.4f) - gameHero.Position).Length() < 40f) RCollision = true; } } if (Speed.X < 0f) { if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, MathHelper.Pi))) LCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, MathHelper.Pi - 0.4f))) LCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, MathHelper.Pi + 0.4f))) LCollision = true; for (int i = 0; i < VehicleController.Instance.Vehicles.Count; i++) { if (Vector2.Distance(VehicleController.Instance.Vehicles[i].Position, Position) > 500f) continue; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, MathHelper.Pi), VehicleController.Instance.Vehicles[i].CollisionVerts)) LCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, MathHelper.Pi - 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) LCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, MathHelper.Pi + 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) LCollision = true; } for (int d = 0; d < EnemyController.Instance.Enemies.Count; d++) { if (Vector2.Distance(EnemyController.Instance.Enemies[d].Position, Position) > 500f) continue; if (EnemyController.Instance.Enemies[d].Dead || EnemyController.Instance.Enemies[d] == this) continue; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.Pi) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) LCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.Pi - 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) LCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.Pi + 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) LCollision = true; } if (this is AIDude) { if ((Helper.PointOnCircle(ref Position, 50, MathHelper.Pi) - gameHero.Position).Length() < 40f) LCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.Pi - 0.4f) - gameHero.Position).Length() < 40f) LCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.Pi + 0.4f) - gameHero.Position).Length() < 40f) LCollision = true; } } if (Speed.Y < 0f) { if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi)))) UCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) - 0.4f))) UCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) + 0.4f))) UCollision = true; for (int i = 0; i < VehicleController.Instance.Vehicles.Count; i++) { if (Vector2.Distance(VehicleController.Instance.Vehicles[i].Position, Position) > 500f) continue; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi)), VehicleController.Instance.Vehicles[i].CollisionVerts)) UCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) - 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) UCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) + 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) UCollision = true; } for (int d = 0; d < EnemyController.Instance.Enemies.Count; d++) { if (Vector2.Distance(EnemyController.Instance.Enemies[d].Position, Position) > 500f) continue; if (EnemyController.Instance.Enemies[d].Dead || EnemyController.Instance.Enemies[d] == this) continue; if ((Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi)) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) UCollision = true; if ((Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) - 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) UCollision = true; if ((Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) + 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) UCollision = true; } if (this is AIDude) { if ((Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi)) - gameHero.Position).Length() < 40f) UCollision = true; if ((Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) - 0.4f) - gameHero.Position).Length() < 40f) UCollision = true; if ((Helper.PointOnCircle(ref Position, 50, (MathHelper.PiOver2 + MathHelper.Pi) + 0.4f) - gameHero.Position).Length() < 40f) UCollision = true; } } if (Speed.Y > 0f) { if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2))) DCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 - 0.4f))) DCollision = true; if (gameMap.CheckCollision(Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 + 0.4f))) DCollision = true; for (int i = 0; i < VehicleController.Instance.Vehicles.Count; i++) { if (Vector2.Distance(VehicleController.Instance.Vehicles[i].Position, Position) > 500f) continue; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2), VehicleController.Instance.Vehicles[i].CollisionVerts)) DCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 - 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) DCollision = true; if (Helper.IsPointInShape(Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 + 0.4f), VehicleController.Instance.Vehicles[i].CollisionVerts)) DCollision = true; } for(int d=0;d<EnemyController.Instance.Enemies.Count;d++) { if (Vector2.Distance(EnemyController.Instance.Enemies[d].Position, Position) > 500f) continue; if (EnemyController.Instance.Enemies[d].Dead || EnemyController.Instance.Enemies[d] == this) continue; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) DCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 - 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) DCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 + 0.4f) - EnemyController.Instance.Enemies[d].Position).Length() < 40f) DCollision = true; } if (this is AIDude) { if ((Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2) - gameHero.Position).Length() < 40f) DCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 - 0.4f) - gameHero.Position).Length() < 40f) DCollision = true; if ((Helper.PointOnCircle(ref Position, 50, MathHelper.PiOver2 + 0.4f) - gameHero.Position).Length() < 40f) DCollision = true; } } if (Speed.X > 0f && RCollision) Speed.X = 0f; if (Speed.X < 0f && LCollision) Speed.X = 0f; if (Speed.Y > 0f && DCollision) Speed.Y = 0f; if (Speed.Y < 0f && UCollision) Speed.Y = 0f; if (UCollision || DCollision || LCollision || RCollision) Collided(); }
void Pickup(Item i, HeroDude gameHero, Map gameMap, bool[,] mapFog) { switch (i.Type) { case ItemType.Health: AudioController.PlaySFX("medkit", 0.5f, -0.4f, -0.4f, i.Position); gameHero.Health += 25f + (float)Helper.Random.Next(25); break; case ItemType.Ammo: AudioController.PlaySFX("ammo", 1f, 0f, 0f, i.Position); gameHero.Ammo += 10 + Helper.Random.Next(15); break; case ItemType.CompoundMap: List<Compound> c = gameMap.FindNearestCompounds(gameHero.Position); if (c[0].Discovered == false) { gameMap.DiscoverCompound(c[0], mapFog); if(!c[0].Bounds.Contains(Helper.VtoP(i.Position/100))) Hud.Instance.Ticker.AddLine("> An enemy compound has been revealed! (Tab/Back for map)"); else Hud.Instance.Ticker.AddLine("> This compound has been revealed!"); } else { foreach (Compound nc in c) { if (nc.Discovered == false) { gameMap.DiscoverCompound(nc, mapFog); if (!nc.Bounds.Contains(Helper.VtoP(i.Position / 100))) Hud.Instance.Ticker.AddLine("> An enemy compound has been revealed! (Tab/Back for map)"); else Hud.Instance.Ticker.AddLine("> This compound has been revealed!"); break; } } } break; case ItemType.GeneralMap: EnemyController.Instance.DiscoverGeneral(i.Position); break; case ItemType.Pistol: case ItemType.Shotgun: case ItemType.SMG: case ItemType.Rifle: gameHero.Ammo += 10 + Helper.Random.Next(15); gameHero.GiveWeapon(i.Type); break; } i.Active = false; }
public override void Update(GameTime gameTime, Map gameMap, bool[,] mapFog, HeroDude gameHero) { base.Update(gameTime, gameMap, mapFog, gameHero); HuntedLevel.Update(gameTime); HeadTorch.Position = Helper.PointOnCircle(ref Position, 32, Rotation - MathHelper.PiOver2); HeadTorch.Rotation = Rotation - MathHelper.PiOver2; foreach (Compound c in gameMap.Compounds) { if (!c.Discovered && (c.Position-Position).Length()<1000f) { gameMap.DiscoverCompound(c, mapFog); Hud.Instance.Ticker.AddLine("> This compound has been revealed!"); } } if (drivingVehicle!=null) { HeadTorch.Active = false; Position = drivingVehicle.Position; Rotation = drivingVehicle.Rotation + MathHelper.PiOver2; } else if(!Dead) HeadTorch.Active = true; if (Health < 30f) { if(Helper.Random.Next((int)Health*10)==1) ParticleController.Instance.AddBlood(Position); if(Health<10f) if (Helper.Random.Next((int)Health * 100) == 1) ParticleController.Instance.AddBloodPool(Position); } if (Health <= 0 && !Dead) { deadTime = 5000; deadAlpha = 1f; Dead = true; HeadTorch.Active = false; ParticleController.Instance.AddBloodPool(Position); } if (Dead) { if (deadTime < 3000) { deadAlpha -= 0.01f; } if (deadTime < 1000) { Position = gameMap.HeroSpawn; Camera.Instance.Position = Position; Camera.Instance.Target = Position; Health = 100f; HeadTorch.Active = true; Dead = false; Weapons.Clear(); Weapons.Add(new Knife(this)); SelectedWeapon = 0; HuntedLevel.Level = 0f; EnemyController.Instance.ClearSpawn(gameMap.HeroSpawn); VehicleController.Instance.ClearSpawn(gameMap.HeroSpawn); VehicleController.Instance.SpawnNearestVehicles(gameMap.HeroSpawn, gameMap); Ammo = 0; } } if (!(drivingVehicle is Chopper)) { foreach (Compound c in gameMap.Compounds) foreach (Building b in c.Buildings) if (b.Type == BuildingType.Building) { Point pos = Helper.VtoP(Position / 100); if (b.Rect.Contains(pos) && b.RoofFade > 0.1f) b.RoofFade -= 0.01f; else if (b.RoofFade < 1f) b.RoofFade += 0.01f; } } if (!Dead && deadAlpha < 1f) deadAlpha += 0.01f; }
/// <summary> /// Load graphics content for the game. /// </summary> public override void LoadContent() { if (content == null) content = new ContentManager(ScreenManager.Game.Services, "Content"); AudioController.LoadContent(content); //gameFont = content.Load<SpriteFont>("menufont"); lightingEngine.LoadContent(content, ScreenManager.GraphicsDevice, ScreenManager.SpriteBatch); enemyController = new EnemyController(); enemyController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); particleController = new ParticleController(); particleController.LoadContent(content); projectileController = new ProjectileController(); projectileController.LoadContent(content); itemController = new ItemController(); itemController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); vehicleController = new VehicleController(); vehicleController.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); gameMap = content.Load<Map>("map/map"); gameHud = new Hud(); gameHud.LoadContent(content); mapFog = new bool[gameMap.Width, gameMap.Height]; ThreadPool.QueueUserWorkItem(new WaitCallback(GenerateTerrainAsync)); gameHero = new HeroDude(gameMap.HeroSpawn); gameHero.LoadContent(content, ScreenManager.GraphicsDevice, lightingEngine); gameCamera = new Camera(ScreenManager.GraphicsDevice.Viewport, gameMap); gameCamera.ClampRect = new Rectangle(0, 0, gameMap.Width * gameMap.TileWidth, gameMap.Height * gameMap.TileHeight); gameCamera.ZoomTarget = 1f; //gameCamera.Position = gameHero.Position - (new Vector2(ScreenManager.GraphicsDevice.Viewport.Width, ScreenManager.GraphicsDevice.Viewport.Height) / 2); gameCamera.Position = gameHero.Position; gameCamera.Target = gameCamera.Position; gameCamera.Update(ScreenManager.GraphicsDevice.Viewport.Bounds); //cameraLightSource.Type = LightSourceType.Spot; //lightingEngine.LightSources.Add(cameraLightSource); minimapRT = new RenderTarget2D(ScreenManager.GraphicsDevice, 200, 200); crosshairTex = content.Load<Texture2D>("crosshair"); mapIcons = content.Load<Texture2D>("mapicons"); //lightSource1 = new LightSource(ScreenManager.GraphicsDevice, 600, LightAreaQuality.Low, new Color(1f, 1f, 1f), BeamStencilType.Wide, SpotStencilType.None); //lightingEngine.LightSources.Add(lightSource1); ScreenManager.Game.ResetElapsedTime(); }
public override void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, Camera gameCamera) { CollisionVerts.Clear(); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 100, -0.44f + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 100, 0.44f + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 200, MathHelper.Pi + (Rotation))); //CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, 0.44f + MathHelper.Pi + (Rotation))); base.Update(gameTime, gameMap, gameHero, gameCamera); //HeadTorch.Position = Helper.PointOnCircle(ref Position, 30, Rotation - MathHelper.PiOver2); //HeadTorch.Rotation = Rotation - MathHelper.PiOver2; //Lights[0].Position = Helper.PointOnCircle(ref Position, 137, (Rotation) - 0.2f); //Lights[1].Position = Helper.PointOnCircle(ref Position, 137, (Rotation) + 0.2f); //Lights[0].Rotation = Rotation; //Lights[1].Rotation = Rotation; if (linearSpeed > 0f) linearSpeed -= decelerate; if (linearSpeed < 0f) linearSpeed += decelerate; linearSpeed = MathHelper.Clamp(linearSpeed, -maxSpeed, maxSpeed); Vector2 moveVect = Helper.AngleToVector(Rotation, 100f); moveVect.Normalize(); if (!turning) { turnAmount = MathHelper.Lerp(turnAmount, 0f, 0.1f); } if ((turnAmount > 0f && turnAmount < 0.001f) || (turnAmount < 0f && turnAmount > -0.001f)) turnAmount = 0f; Rotation += MathHelper.Clamp(turnAmount * 0.05f, -0.025f, 0.025f); Speed = moveVect * linearSpeed; if (takingOff && bladesSpeed>0.4f) { linearSpeed = 0f; Speed = Vector2.Zero; Height = MathHelper.Lerp(Height, 1f, 0.02f); if (Height > 0.99f) { Height = 1f; takingOff = false; } } if (landing) { linearSpeed = 0f; Speed = Vector2.Zero; Height = MathHelper.Lerp(Height, 0f, 0.02f); if (Height < 0.01f) { Height = 0f; landing = false; } } turning = false; if (gameHero.drivingVehicle == this && Health>0f) bladesSpeed = MathHelper.Lerp(bladesSpeed, 0.5f, 0.01f); if (gameHero.drivingVehicle == null) bladesSpeed = MathHelper.Lerp(bladesSpeed, 0f, 0.01f); bladesRot += bladesSpeed; if (gameHero.drivingVehicle == this) { engineSound.Play(); gameCamera.ZoomTarget = 1f - ((maxCameraScale / 1f) * Height); engineSound.Volume = ((1f / 0.5f) * (float)Math.Abs(bladesSpeed)); } else { engineSound.Stop(); } if (Health <= 0f) { Land(gameMap); if (Height <= 0f) bladesSpeed = MathHelper.Lerp(bladesSpeed, 0f, 0.01f); } }
public virtual void Update(GameTime gameTime, Map gameMap, bool[,] mapFog, HeroDude gameHero) { if (!Dead) { checkColTime += gameTime.ElapsedGameTime.TotalMilliseconds; DoCollisions(gameMap, gameHero); Position += Speed; Position.X = MathHelper.Clamp(Position.X, 50, (gameMap.Width * gameMap.TileWidth) - 50); Position.Y = MathHelper.Clamp(Position.Y, 50, (gameMap.Height * gameMap.TileHeight) - 50); if (Speed.Length() > 0f) { Animations["feet"].Update(gameTime); Animations["arms"].Update(gameTime); Animations["head"].Update(gameTime); if ((Animations["feet"].CurrentFrame == 0 || Animations["feet"].CurrentFrame == 3) && (Position - gameHero.Position).Length() < 700f && Animations["feet"].CurrentFrameTime==0) { // Footsteps Tile t = ((TileLayer)gameMap.GetLayer("Terrain")).Tiles[(int)(Position.X / gameMap.TileWidth), (int)(Position.Y / gameMap.TileWidth)]; if (t.Properties.Contains("fstep")) { footSteps[t.Properties["fstep"]].Volume = 0.2f; footSteps[t.Properties["fstep"]].Pitch = -0.3f + ((float)Helper.Random.NextDouble() * (0.6f)); footSteps[t.Properties["fstep"]].Pan = MathHelper.Clamp((Vector2.Transform(Position, Camera.Instance.CameraMatrix).X - (Camera.Instance.Width / 2)) / (Camera.Instance.Width / 2), -1f, 1f); #if(OPENGL) if (t.Properties.Contains("fstep")) { footSteps[t.Properties["fstep"]].Stop(); footSteps[t.Properties["fstep"]].Play(); } #else AudioController.PlaySFX("fstep-" + t.Properties["fstep"], 0.2f, -0.3f, 0.3f, Position); #endif } } } else { Animations["feet"].Reset(); Animations["arms"].Reset(); Animations["head"].Reset(); } Animations["hands"].CellRect.X = 100 * Animations["hands"].CurrentFrame; Animations["gun"].CellRect.X = 100 * Animations["gun"].CurrentFrame; Speed = Vector2.Zero; foreach (Weapon w in Weapons) w.Update(gameTime); if (Weapons[SelectedWeapon] is Knife) { if (Weapons[SelectedWeapon].coolDown > 0 && Weapons[SelectedWeapon].coolDown < 100) Animations["hands"].CurrentFrame = 1; else if (Weapons[SelectedWeapon].coolDown >= 100 && Weapons[SelectedWeapon].coolDown < 200) Animations["hands"].CurrentFrame = 2; else if (Weapons[SelectedWeapon].coolDown >= 200 && Weapons[SelectedWeapon].coolDown < 300) Animations["hands"].CurrentFrame = 3; else Animations["hands"].CurrentFrame = 0; Animations["gun"].CurrentFrame = 0; } else { Animations["hands"].CurrentFrame = 3; Animations["gun"].CurrentFrame = Weapons[SelectedWeapon].sortOrder; } } Health = MathHelper.Clamp(Health, 0f, 100f); Ammo = (int)MathHelper.Clamp(Ammo, 0, 100); if (Dead) { deadTime -= gameTime.ElapsedGameTime.TotalMilliseconds; } insideBuilding = null; foreach (Compound c in gameMap.Compounds) foreach (Building b in c.Buildings) if (b.Type == BuildingType.Building) { Point pos = Helper.VtoP(Position / 100); if (b.Rect.Contains(pos)) insideBuilding = b; } }
public void LoadContent(Texture2D sheet, GraphicsDevice gd, LightingEngine le, HeroDude gameHero) { spriteSheet = sheet; Initialize(gd, le); Weapons.Add(new Knife(this)); if (Helper.Random.Next(gameHero.Weapons.Count>1?2:10) == 1) { Weapons.Add(new Pistol(this)); } if (IsGeneral) { Weapons.Add(new Rifle(this)); } else { if (BelongsToCompound) { switch (Helper.Random.Next(20)) { case 1: Weapons.Add(new Shotgun(this)); break; case 2: Weapons.Add(new SMG(this)); break; case 3: Weapons.Add(new Rifle(this)); break; } } else { switch (Helper.Random.Next(gameHero.Weapons.Count > 1 ? (gameHero.Weapons.Count > 2 ? 30 : 50) : 100)) { case 1: Weapons.Add(new Shotgun(this)); break; case 2: Weapons.Add(new SMG(this)); break; case 3: Weapons.Add(new Rifle(this)); break; } } } SelectedWeapon = Weapons.Count - 1; }
public override void Update(GameTime gameTime, Map gameMap, HeroDude gameHero, Camera gameCamera) { CollisionVerts.Clear(); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, -0.44f + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, 0.44f + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, -0.44f + MathHelper.Pi + (Rotation))); CollisionVerts.Add(Helper.PointOnCircle(ref Position, 150, 0.44f + MathHelper.Pi + (Rotation))); base.Update(gameTime, gameMap, gameHero, gameCamera); if (linearSpeed > 0f) linearSpeed -= decelerate; if (linearSpeed < 0f) linearSpeed += decelerate; linearSpeed = MathHelper.Clamp(linearSpeed, -(limitedSpeed / 2), limitedSpeed); Vector2 moveVect = Helper.AngleToVector(Rotation, 100f); moveVect.Normalize(); if (!turning) { turnAmount = MathHelper.Lerp(turnAmount, 0f, 0.05f); } if ((turnAmount > 0f && turnAmount < 0.001f) || (turnAmount < 0f && turnAmount > -0.001f)) turnAmount = 0f; if (linearSpeed >= 0.1f || linearSpeed <= -0.1f) Rotation += MathHelper.Clamp((linearSpeed / 100f) * turnAmount, -0.025f, 0.025f); Speed = moveVect * linearSpeed; turning = false; foreach (Dude d in EnemyController.Instance.Enemies) { if (Helper.IsPointInShape(d.Position, this.CollisionVerts) && d.Health >= 0f) { Health -= 0.5f; d.HitByVehicle(this); } } if (Health < 50f) { limitedSpeed = 10f; } if (Health < 20f) { limitedSpeed = 5f; } if (Health <= 0f) { limitedSpeed = 2f; } //HeadTorch.Position = Helper.PointOnCircle(ref Position, 30, Rotation - MathHelper.PiOver2); //HeadTorch.Rotation = Rotation - MathHelper.PiOver2; Lights[0].Position = Helper.PointOnCircle(ref Position, 145, (Rotation)); //Lights[1].Position = Helper.PointOnCircle(ref Position, 137, (Rotation) + 0.2f); Lights[0].Rotation = Rotation; //Lights[1].Rotation = Rotation; if (gameHero.drivingVehicle == this) { engineSound.Play(); if (maxSpeed > 0f) gameCamera.ZoomTarget = 1f - ((0.5f / maxSpeed) * (float)Math.Abs(linearSpeed)); else gameCamera.ZoomTarget = 1f; if (Health > 0f) { engineSound.Volume = MathHelper.Clamp(0.2f + ((1f / 18f) * (float)Math.Abs(linearSpeed)), 0f, 1f); engineSound.Pitch = -0.3f + (((0.6f / 18f) * (float)Math.Abs(linearSpeed))); } else { engineSound.Volume = 0f; } } else { engineSound.Stop(); } }
internal void DrawHeliShadows(SpriteBatch sb, LightingEngine lightingEngine, HeroDude gameHero) { foreach (Vehicle v in Vehicles.Where(veh => (gameHero.Position - veh.Position).Length() < 2000f)) { if (v is Chopper && ((Chopper)v).Height > 0f) { ((Chopper)v).DrawShadowsInAir(sb, lightingEngine); } } }