protected override void NewPath(ManagerHelper mH) { //Do nothing }
public LightningTrail(ManagerHelper mH) : base("Abilities/yellow_test", Vector2.Zero, Vector2.Zero) { managers = mH; }
public void FindEscapePath(Vector2 pA, Vector2 pGTFA, float mD, ManagerHelper mH, float aw, Path path) { //Add blockers for enemies foreach (NPC n in mH.GetNPCManager().GetAllies(NPC.AffliationTypes.black)) { if (NPCManager.IsNPCInRadius(n, pA, aw)) { int x = -1; int y = -1; for (int adjX = -32; adjX < 32; adjX += 32) { for (int adjY = -32; adjY < 32; adjY += 32) { x = (int)(n.GetOriginPosition().X / nodeSize.X) + adjX; y = (int)(n.GetOriginPosition().Y / nodeSize.Y); if ((y > 0 && y < mH.GetLevel().GetSizeOfLevel().Y) && (x > 0 && y < mH.GetLevel().GetSizeOfLevel().X)) { field[x, y].SetBlocker(true); } } } } } float farthest = 0; float convenience = mD * mD; //forces dot to go to furtherest location that is easiest to get to Vector2 pointB = pA; int nodeX, nodeY; //Find best end point for (int x = (int)(pA.X - mD) / 32; x < (pA.X + mD); x += 32) { if (x > 32 && x < mH.GetLevel().GetSizeOfLevel().X) { for (var y = (int)(pA.Y - mD); y < (pA.Y + mD); y += 32) { if (y > 0 && y < mH.GetLevel().GetSizeOfLevel().Y - 32) { nodeX = x / 32; nodeY = y / 32; if (!field[nodeX, nodeY].GetBlocker()) { var currentPoint = new Vector2(x, y); float dist = DistanceSquared(pGTFA, currentPoint); float tempCon = DistanceSquared(pA, currentPoint); if (convenience > tempCon && dist > farthest) { farthest = dist; convenience = tempCon; pointB = currentPoint; } } } } } } FindClearPath(pA, pointB, mH, path); }
public override void Set(string a, Vector2 p, NPC n, Vector2 v, int d, bool iE, bool collide, float dT, ManagerHelper mH) { base.Set(a, p, n, v, d, iE, collide, dT, mH); pulseTime = dT * .5; frameTimer = 0.0; pulseTimer = 0.0; drag = 0.03f; }
public override void Update(ManagerHelper mH) { ProjectileCheck(mH); base.Update(mH); }
public static bool IsNPCInDirection(NPC agent, Vector2 pos, float dir, float cone, ManagerHelper mH) { if (!mH.GetPathHelper().IsVectorObstructed(pos, agent.GetOriginPosition())) { float dirToAgent = PathHelper.Direction(pos, agent.GetOriginPosition()); return(MathHelper.Distance(dirToAgent, dir) < cone); } else { return(false); } }
public override void Update(ManagerHelper mH) { if (frameIndex < totalFrames) { frameIndex = (int)((float)frameCounter / drawFrames * totalFrames); //Spawn fire if (mH.GetRandom().NextDouble() < 0.3) { mH.GetParticleManager() .AddFire(GetOriginPosition(), PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 100, 1, 0.05f, 1, 0.1f); } if (mH.GetGametype() is Survival) { foreach (NPC a in mH.GetNPCManager().GetAllies(NPC.AffliationTypes.black)) { if (NPCManager.IsNPCInRadius(a, GetOriginPosition(), 64) && !doomedDots.Contains(a)) { doomedDots.Add(a); if (!a.GetFireStatus()) { a.ChangeFireStatus(); dotsSetOnFire.Add(a); } a.ChangeHealth(-30, mH.GetNPCManager().GetCommander(NPC.AffliationTypes.red)); } } } else { foreach (NPC a in mH.GetNPCManager().GetNPCs()) { if (a.GetAffiliation() != affiliation && NPCManager.IsNPCInRadius(a, GetOriginPosition(), 64) && !doomedDots.Contains(a)) { doomedDots.Add(a); if (!a.GetFireStatus()) { a.ChangeFireStatus(); dotsSetOnFire.Add(a); } a.ChangeHealth(-70, mH.GetNPCManager().GetCommander(NPC.AffliationTypes.red)); } } } } //Deal Damage for (int i = 0; i < doomedDots.Count; i++) { NPC a = doomedDots[i]; if (!mH.GetNPCManager().GetNPCs().Contains(a)) { doomedDots.Remove(a); i--; continue; } //Spawn fire if (mH.GetRandom().NextDouble() < 0.1f) { mH.GetParticleManager() .AddFire(a.GetOriginPosition(), PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 30, 1, 0.05f, 1, 0.1f); } if (frameCounter % burnFrames == 0) { a.ChangeHealth(-2, mH.GetNPCManager().GetCommander(NPC.AffliationTypes.red)); } } frameCounter++; this.scale = scale * modifer; base.Update(mH); }
public void AddSpawnpoint(Vector2 v, ManagerHelper mH) { spawns.Add(new SpawnPoint(v, NPC.AffliationTypes.black, mH)); }
public override void Update(ManagerHelper mH) { List <NPC.AffliationTypes> currentContestors = Controllers(mH); //Remove old suitors for (int i = 0; i < conquestCounters.Count; i++) { if (!currentContestors.Contains(conquestCounters.Keys.ElementAt(i))) { conquestCounters.Remove(conquestCounters.Keys.ElementAt(i)); i--; } } foreach (SpawnPoint sP in spawns) { if (affiliation != NPC.AffliationTypes.grey) { sP.affilation = affiliation; } else { sP.affilation = NPC.AffliationTypes.black; } } //Add new suitors foreach (NPC.AffliationTypes t in currentContestors) { if (!conquestCounters.ContainsKey(t)) { conquestCounters.Add(t, 0); } } if (conquestCounters.Count == 1) { if (!conquestCounters.Keys.Contains(affiliation)) { if (conquestCounters.Values.ElementAt(0) > conquestTime) { if (affiliation == NPC.AffliationTypes.grey) { affiliation = conquestCounters.Keys.First(); string smokeAsset = ""; //Set up image switch (affiliation) { case NPC.AffliationTypes.red: frameIndex = 1; smokeAsset = "Effects/smoke_red"; break; case NPC.AffliationTypes.blue: frameIndex = 2; smokeAsset = "Effects/smoke_blue"; break; case NPC.AffliationTypes.green: frameIndex = 3; smokeAsset = "Effects/smoke_green"; break; case NPC.AffliationTypes.yellow: frameIndex = 4; smokeAsset = "Effects/smoke_yellow"; break; } //Spawn Explosion mH.GetParticleManager().AddExplosion(GetOriginPosition(), affiliation, 0); for (int i = 0; i < NUM_SMOKES; i++) { mH.GetParticleManager().AddParticle(smokeAsset, GetOriginPosition(), PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 50, 1, 0.01f, 1, 0.05f); } } else { affiliation = NPC.AffliationTypes.grey; frameIndex = 0; conquestCounters.Clear(); //Spawn Explosion mH.GetParticleManager().AddExplosion(GetOriginPosition(), affiliation, 0); } } else { NPC.AffliationTypes tempConquestor = conquestCounters.Keys.ElementAt(0); Double tempTimer = conquestCounters.Values.ElementAt(0); conquestCounters.Remove(tempConquestor); conquestCounters.Add(tempConquestor, tempTimer + mH.GetGameTime().ElapsedGameTime.TotalSeconds); if (mH.GetRandom().NextDouble() < (tempTimer / conquestTime * 0.2f)) { mH.GetParticleManager() .AddFire(GetOriginPosition(), PathHelper.Direction((float)(mH.GetRandom().NextDouble() * Math.PI * 2)) * 50, 1, 0.01f, 1, 0.1f); } } } } base.Update(mH); }
protected void Set(string a, Vector2 p, Vector2 v, float dT, float d, float t, float rA, ManagerHelper mH) { Set(a, 0, 0, p, v, dT, d, t, rA, mH); }
public virtual void DeathCode(ManagerHelper mH) { //nothing }
public BluePlayerCommander(Vector2 p, ManagerHelper mH) : this(p, AffliationTypes.blue, mH) { //Nothing else }
protected override void GrenadeSound(ManagerHelper mH) { mH.GetAudioManager().Play(AudioManager.COMMANDER_GRENADE, 0.90f, AudioManager.RandomPitch(mH), 0, false); }
protected override void ShootSound(ManagerHelper mH) { mH.GetAudioManager().Play(AudioManager.COMMANDER_SHOOT, 0.90f, (float)(mH.GetRandom().NextDouble() * -0.25), 0, false); }
public void DrawScores(SpriteBatch sB, ManagerHelper mH) { //Draw time left int timeLeft = (int)(mH.GetGametype().GetGameEndTimer()) + 1, mins = timeLeft / 60, secs = timeLeft % 60; if (mins != lastMinute) { lastMinute = mins; gameTime = mins + ":" + ((secs < 10) ? "0" : "") + secs; } if (secs != lastSecond) { lastSecond = secs; gameTime = mins + ":" + ((secs < 10) ? "0" : "") + secs; } timer.Draw(sB, Vector2.Zero, mH); mH.GetTextureManager().DrawString(sB, gameTime, timer.GetOriginPosition(), Color.White, TextureManager.FontSizes.small, true); scoreboard.Draw(sB, Vector2.Zero, mH); for (int x = 0; x < mH.GetGametype().GetTeams().Count; x++) { Color teamColor = Color.White; switch (mH.GetGametype().GetTeams()[x]) { case NPC.AffliationTypes.red: teamColor = Color.Red; break; case NPC.AffliationTypes.blue: teamColor = Color.Blue; break; case NPC.AffliationTypes.green: teamColor = Color.Green; break; case NPC.AffliationTypes.yellow: teamColor = Color.Yellow; break; } if (mH.GetGametype().GetTeams()[x] != NPC.AffliationTypes.black) { if (lastScores[x] != mH.GetGametype().GetScores()[x]) { lastScores[x] = mH.GetGametype().GetScores()[x]; lastScoreStrings[x] = lastScores[x] + ""; } mH.GetTextureManager().DrawString(sB, lastScoreStrings[x], rightPos - new Vector2((4 - x) * 82 - 24, -10), teamColor, TextureManager.FontSizes.small, true); } } }
private void Explode(ManagerHelper mH, NPC a) { mH.GetParticleManager().AddExplosion(GetOriginPosition(), a, 125); mH.GetNPCManager().Remove(this); }
public void Update(ManagerHelper mH, int widthVal) { frame.Width = widthVal; base.Update(mH); }
public GreenPlayerCommander(Vector2 p, ManagerHelper mH) : this(p, AffliationTypes.green, mH) { rockCounter = 0; }
public virtual void Initialize() //actually setting up needed materials { //Initialize Managers (the thing that will hold all textures used) textures = new TextureManager(); agents = new NPCManager(); projectiles = new ProjectileManager(1000, 100, 100); objects = new EnvironmentManager(); backgrounds = new BackgroundManager(); spawnplaces = new List <SpawnPoint>(); paths = new PathHelper(); sounds = new AudioManager(); spawns = new SpawnHelper(spawnplaces); particles = new ParticleManager(2000, 200, 200, 50); abilities = new AbilityManager(10, 100, 10, 20, managers); statistics = new StatisticsManager(typeOfGame.GetTeams()); //NOTE: Upper level creates gametype & cameraManager //Once all the managers and helpers are done, initalize ManagerHelper managers = new ManagerHelper(textures, agents, projectiles, objects, cameras, typeOfGame, this, paths, sounds, particles, spawns, abilities, statistics); //Pass the new ManagerHelper to all the other Managers agents.Initialize(managers); projectiles.Initialize(managers); objects.Initialize(managers); typeOfGame.Initialize(managers); paths.Initialize(managers, 10); particles.Initialize(managers); abilities.Initialize(managers); backgrounds.Initialize(managers); statistics.Intitialize(); #region Default Textures textures.Add("Dots/Red/grunt_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/bombardier_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/specialist_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/juggernaut_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/sniper_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/medic_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/gunner_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/commander_red", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/grunt_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/bombardier_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/specialist_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/juggernaut_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/sniper_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/medic_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/gunner_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Blue/commander_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/grunt_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/bombardier_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/specialist_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/juggernaut_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/sniper_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/medic_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/gunner_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Green/commander_green", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/grunt_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/bombardier_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/specialist_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/juggernaut_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/sniper_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/medic_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/gunner_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Yellow/commander_yellow", new Rectangle(0, 0, 32, 32)); textures.Add("Dots/Red/bomber_red", new Rectangle(0, 0, 96, 64)); textures.Add("Dots/Blue/bomber_blue", new Rectangle(0, 0, 96, 64)); textures.Add("Dots/Green/bomber_green", new Rectangle(0, 0, 96, 64)); textures.Add("Dots/Yellow/bomber_yellow", new Rectangle(0, 0, 96, 64)); textures.Add("Projectiles/bullet_standard", new Rectangle(0, 0, 6, 7)); textures.Add("Projectiles/bullet_sniper", new Rectangle(0, 0, 6, 7)); textures.Add("Projectiles/bullet_rocket", new Rectangle(0, 0, 6, 7)); textures.Add("Projectiles/bullet_shotgun", new Rectangle(0, 0, 6, 7)); textures.Add("Projectiles/grenade", new Rectangle(0, 0, 15, 15)); textures.Add("Projectiles/bullet_bombs", new Rectangle(0, 0, 14, 5)); textures.Add("Effects/particle_smoke", new Rectangle(0, 0, 8, 8)); textures.Add("Effects/smoke_red", new Rectangle(0, 0, 9, 9)); textures.Add("Effects/smoke_blue", new Rectangle(0, 0, 9, 9)); textures.Add("Effects/smoke_green", new Rectangle(0, 0, 9, 9)); textures.Add("Effects/smoke_yellow", new Rectangle(0, 0, 9, 9)); textures.Add("Effects/smoke_standard", new Rectangle(0, 0, 30, 30)); textures.Add("Effects/spark_red", new Rectangle(0, 0, 5, 5)); textures.Add("Effects/spark_blue", new Rectangle(0, 0, 5, 5)); textures.Add("Effects/spark_green", new Rectangle(0, 0, 5, 5)); textures.Add("Effects/spark_yellow", new Rectangle(0, 0, 5, 5)); textures.Add("Effects/particle_blood_red", new Rectangle(0, 0, 8, 8)); textures.Add("Effects/particle_blood_blue", new Rectangle(0, 0, 8, 8)); textures.Add("Effects/particle_blood_green", new Rectangle(0, 0, 8, 8)); textures.Add("Effects/particle_blood_yellow", new Rectangle(0, 0, 8, 8)); textures.Add("Effects/particle_fire", new Rectangle(0, 0, 14, 14)); textures.Add("Effects/particle_heal", new Rectangle(0, 0, 16, 16)); textures.Add("Effects/PI_redCommander", new Rectangle(0, 0, 64, 64)); textures.Add("Effects/PI_blueCommander", new Rectangle(0, 0, 64, 64)); textures.Add("Effects/PI_greenCommander", new Rectangle(0, 0, 64, 64)); textures.Add("Effects/PI_yellowCommander", new Rectangle(0, 0, 64, 64)); textures.Add("Dots/Grey/grey_claimable", new Rectangle(0, 0, 36, 36)); textures.Add("Dots/Grey/grey_suicide", new Rectangle(0, 0, 32, 32)); textures.Add("health_station", new Rectangle(0, 0, 64, 64)); textures.Add("Projectiles/flare_red", new Rectangle(0, 0, 15, 15)); textures.Add("Projectiles/flare_blue", new Rectangle(0, 0, 15, 15)); textures.Add("Projectiles/flare_green", new Rectangle(0, 0, 15, 15)); textures.Add("Projectiles/flare_yellow", new Rectangle(0, 0, 15, 15)); textures.Add("Effects/explodeTop", new Rectangle(0, 0, 128, 128)); textures.Add("bases", new Rectangle(0, 0, 64, 64)); textures.Add("Objectives/flag_red", new Rectangle(0, 0, 32, 32)); textures.Add("Objectives/flag_blue", new Rectangle(0, 0, 32, 32)); textures.Add("Objectives/flag_green", new Rectangle(0, 0, 32, 32)); textures.Add("Objectives/flag_yellow", new Rectangle(0, 0, 32, 32)); //HUD elements textures.Add("HUD/bar_health", new Rectangle(0, 0, 127, 14)); textures.Add("HUD/bar_special", new Rectangle(0, 0, 84, 14)); textures.Add("HUD/hud_background", new Rectangle(0, 0, 240, 60)); textures.Add("HUD/hud_blue", new Rectangle(0, 0, 240, 60)); textures.Add("HUD/hud_green", new Rectangle(0, 0, 240, 60)); textures.Add("HUD/hud_gun", new Rectangle(0, 0, 55, 38)); textures.Add("HUD/hud_red", new Rectangle(0, 0, 240, 60)); textures.Add("HUD/hud_toss", new Rectangle(0, 0, 20, 20)); textures.Add("HUD/hud_yellow", new Rectangle(0, 0, 240, 60)); //Guts textures.Add("Effects/Guts/Red/deadGruntRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadGunnerRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadJuggRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadBombRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadSniperRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadMedicRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadSpecialistRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Red/deadCommanderRed", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadGruntBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadGunnerBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadJuggBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadBombBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadSniperBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadMedicBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadSpecialistBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Blue/deadCommanderBlue", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadGruntGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadGunnerGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadJuggGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadBombGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadSniperGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadMedicGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadSpecialistGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Green/deadCommanderGreen", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadGruntYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadGunnerYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadJuggYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadBombYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadSniperYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadMedicYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadSpecialistYellow", new Rectangle(0, 0, 32, 32)); textures.Add("Effects/Guts/Yellow/deadCommanderYellow", new Rectangle(0, 0, 32, 32)); //Abilities textures.Add("Abilities/ability_red", new Rectangle(0, 0, 64, 64)); textures.Add("Abilities/ability_green", new Rectangle(0, 0, 64, 64)); textures.Add("Abilities/ability_blue_splash", new Rectangle(0, 0, 64, 64)); textures.Add("Abilities/ability_blue_spread2", new Rectangle(0, 0, 64, 64)); textures.Add("Abilities/yellow_test", new Rectangle(0, 0, 32, 16)); textures.Add("square", new Rectangle(0, 0, 32, 32)); #endregion #region Default Audio //Shooting sounds sounds.Add("Guns/standardShoot"); sounds.Add("Guns/sniperShoot"); sounds.Add("Guns/shotgunShoot"); sounds.Add("Guns/staticCall"); sounds.Add("Guns/machineShoot"); sounds.Add("Other/planeFly"); sounds.Add("Other/explosion"); sounds.Add("Guns/rocketShoot"); sounds.Add("Guns/flareShoot"); sounds.Add("Guns/grenadeShoot"); sounds.Add("Guns/healShoot"); sounds.Add("Abilities/fireballSound"); sounds.Add("Abilities/waterSound"); sounds.Add("Abilities/rockSound"); sounds.Add("Abilities/sparkSound"); sounds.Add("Explosion1"); #endregion }
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch sB, Vector2 displacement, ManagerHelper mH) { if (drawTarget) { targetSprite.Draw(sB, displacement, mH); } base.Draw(sB, displacement, mH); }
public void Initialize(ManagerHelper mH) { managers = mH; }
protected override void NewPath(ManagerHelper mH) { path.Add(targetPosition, mH); }
public override void Update(ManagerHelper mH) { elapsedTime = mH.GetGameTime().ElapsedGameTime.TotalSeconds; if (isExplosive && drawTime <= 0) { mH.GetParticleManager().AddExplosion(GetOriginPosition(), creator, damage); isExplosive = false; } if (drawTime > 0) { drawTime -= mH.GetGameTime().ElapsedGameTime.TotalSeconds; pulseTimer += elapsedTime; frameTimer += elapsedTime; #region Tossable Update #region Keep it in the level //Update position Vector2 tempPos = position + velocity * mH.GetDeltaSeconds(); //Check for collisions with environment foreach (Environment e in mH.GetEnvironmentManager().GetStaticBlockers()) { int tempCollide = CollisionHelper.IntersectPixelsDirectionalRaw(this, tempPos, e); if (tempCollide != -1) { velocity = CollisionHelper.CollideDirectional(velocity, tempCollide); } } tempPos = position + velocity * mH.GetDeltaSeconds(); if ((tempPos.X < 0 || tempPos.X > mH.GetLevelSize().X - frame.Width - 0 || tempPos.Y < 0 || tempPos.Y > mH.GetLevelSize().Y - frame.Height - 0)) { if (tempPos.X <= 0) { velocity = new Vector2(velocity.X * -1, velocity.Y); tempPos.X = 0; } else if (tempPos.X > mH.GetLevelSize().X - frame.Width - 0) { velocity = new Vector2(velocity.X * -1, velocity.Y); tempPos.X = mH.GetLevelSize().X - frame.Width - 0; } if (tempPos.Y <= 0) { velocity = new Vector2(velocity.X, velocity.Y * -1); tempPos.Y = 0; } else if (tempPos.Y > mH.GetLevelSize().Y - frame.Height - 0) { velocity = new Vector2(velocity.X, velocity.Y * -1); tempPos.Y = mH.GetLevelSize().Y - frame.Height - 0; } } position = tempPos; //Update frames frame.X = frameIndex * frame.Width; frame.Y = modeIndex * frame.Height; #endregion #region Finalize Direction foreach (Vector2 a in accelerations) { if (!float.IsNaN(a.X) && !float.IsNaN(a.Y)) { acceleration += a * mH.GetDeltaSeconds(); } } velocity += thrust * acceleration - drag * velocity; accelerations.Clear(); acceleration = Vector2.Zero; #endregion //Update position originPosition = position + origin; //Update frame if (frameIndex < 1) { frameIndex = 0; frameDirection = 1; } else if (frameIndex == totalFrames - 1) { frameIndex = totalFrames - 1; frameDirection = -1; } if (pulseTimer > pulseTime) { pulseTime /= 2; pulseTimer = 0; } if (frameTimer > pulseTime / (totalFrames * 2)) { frameTimer = 0; frameIndex += frameDirection; } if (modeIndex < 0) { modeIndex = 0; } else if (modeIndex >= totalModes) { modeIndex = totalModes; } frame.X = frameIndex * frame.Width; frame.Y = modeIndex * frame.Height; #endregion //Spawn cool things to make it look better EffectSpawnCode(mH); } existenceTime -= mH.GetGameTime().ElapsedGameTime.TotalSeconds; }
public override bool ShouldUsePower(ManagerHelper mH) { if (CurrentPower() < .5 * MaxPower()) { return(false); } if (mH.GetGametype() is Assault) { var temp = (Assault)mH.GetGametype(); Flag f = temp.GetAllyBase(temp.GetDefender()).GetMyFlag(); if (temp.GetAttacker() == affiliation) { if (f.status != Flag.FlagStatus.taken) { return(PathHelper.DistanceSquared(GetOriginPosition(), f.GetOriginPosition()) < 300 * 300); } else { return(f.GetCaptor() is YellowCommander); } } else { return(f.status != Flag.FlagStatus.home); } } else if (mH.GetGametype() is CaptureTheFlag) { var temp = (CaptureTheFlag)mH.GetGametype(); Flag eF = temp.GetEnemyBase(affiliation).GetMyFlag(); if (eF.status != Flag.FlagStatus.taken) { return(PathHelper.DistanceSquared(GetOriginPosition(), eF.GetOriginPosition()) < 240 * 240); } else if (eF.GetCaptor() != null) { return(eF.GetCaptor() is YellowCommander); } } else if (mH.GetGametype() is Survival) { return((target != null) && (PathHelper.DistanceSquared(GetOriginPosition(), target.GetOriginPosition()) < 200 * 200)); } else { int enemyCount = 0; foreach (var agent in mH.GetNPCManager().GetNPCs()) { if (agent.GetAffiliation() != affiliation && NPCManager.IsNPCInRadius(agent, GetOriginPosition(), 120)) { enemyCount++; } } return(enemyCount > 1); } return(false); }
public override void Draw(SpriteBatch sB, Vector2 d, ManagerHelper mH) { base.Draw(sB, d, mH); }
public override void Draw(SpriteBatch sB, Vector2 displacement, ManagerHelper mH) { }
public void FindClearPath(Vector2 pA, Vector2 pB, ManagerHelper mH, Path path) { counter = 0; open.Clear(); closed.Clear(); //Prevent excecution if current position or end position is bad if (pA.X < 0 || pA.X > mH.GetLevelSize().X || pA.Y < 0 || pA.Y > mH.GetLevelSize().Y || pB.X < 0 || pB.X > mH.GetLevelSize().X || pB.Y < 0 || pB.Y > mH.GetLevelSize().Y) { return; } Vector2 end = new Vector2((int)(pB.X / nodeSize.X), (int)(pB.Y / nodeSize.Y)), beginning = new Vector2((int)(pA.X / nodeSize.X), (int)(pA.Y / nodeSize.Y)); if (end == beginning) { return; } if (field[(int)end.X, (int)end.Y].GetBlocker()) { end = FindOpenNodePoint(end, mH); } //Set up parent according to A* Node parent = field[(int)beginning.X, (int)beginning.Y]; parent.SetFScore((int)(MathHelper.Distance(end.X, beginning.X) + MathHelper.Distance(end.Y, beginning.Y))); open.Add(parent); //Makes the end not a blocker field[(int)end.X, (int)end.Y].SetBlocker(false); #region Loop through array until end is found while (counter < 100 && !(parent.GetPosition() == end)) { //Checks for instance of no solution if (open.Count == 0) { break; } #region Find best new parent Node lowest = open.First(); //Goes through each node on the open list and compares its score to the current low foreach (Node x in open) { if (x.GetFScore() < lowest.GetFScore()) { lowest = x; } } //Once the lowest is found, switch it from the open to the closed list parent = lowest; open.Remove(lowest); closed.Add(lowest); #endregion #region Calculate F scores of adjacent nodes for (int i = (int)parent.GetPosition().X - 1; i <= (int)parent.GetPosition().X + 1; i++) { for (int j = (int)parent.GetPosition().Y - 1; j <= (int)parent.GetPosition().Y + 1; j++) { //If node is invalid if (i < 0 || j < 0 || i >= length || j >= width || field[i, j].GetBlocker() || closed.Contains(field[i, j])) { continue; } //Current node Node current = field[i, j]; #region Calculate cell's info current.SetParent(parent); current.SetGScore(parent.GetGScore() + mH.GetRandom().Next(0, randomness)); //Calculate other scores current.SetHScore((int)(MathHelper.Distance(current.GetPosition().X, end.X) + MathHelper.Distance(current.GetPosition().Y, end.Y)) * 10); current.SetFScore(current.GetGScore() + current.GetHScore()); #endregion //If the cell is already on the open list and has a better if (open.Contains(current) && current.GetGScore() > parent.GetGScore()) { current.SetFScore(current.GetGScore() + current.GetHScore()); current.SetParent(parent); } else { open.Add(current); } } } #endregion counter++; } #endregion #region Create Path //Once end is found, compile path together path.Clear(); Node point = parent; while (!(point.GetPosition() == beginning)) { if (!point.GetBlocker()) { path.Add(point.GetPosition() * nodeSize + new Vector2(16), mH); } point = point.GetParent(); } #endregion }
public override void Update(ManagerHelper mH) { if (timer > endTimer) { timer = 0; on = !on; if (on) { for (int i = 0; i < beamOn.Length; i++) { if (mH.GetRandom().NextDouble() > 0.5f) { beamOn[i] = true; mH.GetEnvironmentManager().GetImpathables().Add(beams[i]); } } } else { //blockers.Clear(); for (int i = 0; i < beamOn.Length; i++) { if (beamOn[i]) { beamOn[i] = false; mH.GetEnvironmentManager().RemoveImpathable(beams[i]); } } } } else { timer += mH.GetGameTime().ElapsedGameTime.TotalSeconds; } if (on) { for (int i = 0; i < beams.Length; i++) { if (beamOn[i]) { foreach (NPC a in mH.GetNPCManager().GetNPCs()) { if (!(a is Bomber)) { if (CollisionHelper.IntersectPixelsDirectional(a, beams[i]) != -1) { a.ChangeHealth(-3, a.GetLastDamager()); } } } } beams[i].SetFrameIndex(mH.GetRandom().Next(beams[i].totalFrames)); } } base.Update(mH); }
//This method will be used to dictate the AI's behavior in this public class public override void Update(ManagerHelper mH) { base.Update(mH); }
public override void Update(ManagerHelper mH) { //Check health if (ProjectileCheck(mH)) { Explode(mH); return; } #if WINDOWS KeyboardState keyState = mH.GetCurrentState(); MouseState mouseState = Mouse.GetState(); #elif XBOX GamePadState theState = mH.GetCameraManager().GetCameras()[mH.GetCameraManager().GetPlayerInt(this.GetType())].GetState(); GamePadState oldState = mH.GetCameraManager().GetCameras()[mH.GetCameraManager().GetPlayerInt(this.GetType())].GetOldState(); #endif #region Shooting #if WINDOWS if (mouseState.LeftButton == ButtonState.Pressed /* true*/) { if (weaponType == 0 && shootingCounter > shootingSpeed /* true*/) { shootingCounter = 0; Shoot(mH); } else if (weaponType == 1 && shootingCounter > shotgunShootingSpeed) { shootingCounter = 0; ShootShotgun(mH); } } else if (mouseState.RightButton == ButtonState.Pressed && grenadeCounter > grenadeSpeed) { if (grenadeType == 0) { grenadeCounter = 0; TossGrenade(mH); } else if (grenadeType == 1) { grenadeCounter = 0; LayMine(mH); } } //Switch weapons if (keyState.IsKeyDown(Keys.E) && !oldState.IsKeyDown(Keys.E)) { weaponType = (weaponType == 0) ? 1 : 0; modeIndex = weaponType; } else if (keyState.IsKeyDown(Keys.R) && !oldState.IsKeyDown(Keys.R)) { grenadeType = (grenadeType == 0) ? 1 : 0; } #elif XBOX if (theState.IsButtonDown(Buttons.RightTrigger)) { if (weaponType == 0 && shootingCounter > shootingSpeed) { shootingCounter = 0; Shoot(mH); } else if (weaponType == 1 && shootingCounter > shotgunShootingSpeed) { shootingCounter = 0; ShootShotgun(mH); } } else if (theState.IsButtonDown(Buttons.LeftTrigger) && grenadeCounter > grenadeSpeed) { if (grenadeType == 0) { grenadeCounter = 0; TossGrenade(mH); } else if (grenadeType == 1) { grenadeCounter = 0; LayMine(mH); } } //Switch weapons if (theState.IsButtonDown(Buttons.RightShoulder) && !oldState.IsButtonDown(Buttons.RightShoulder)) { weaponType = (weaponType == 0) ? 1 : 0; modeIndex = weaponType; } else if (theState.IsButtonDown(Buttons.LeftShoulder) && !oldState.IsButtonDown(Buttons.LeftShoulder)) { grenadeType = (grenadeType == 0) ? 1 : 0; } #endif shootingCounter += mH.GetGameTime().ElapsedGameTime.TotalSeconds; grenadeCounter += mH.GetGameTime().ElapsedGameTime.TotalSeconds; #endregion #region Ability #if WINDOWS if (keyState.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space)) { UsePower(mH); } #elif XBOX if (theState.IsButtonDown(Buttons.A) && !oldState.IsButtonDown(Buttons.A)) { UsePower(mH); } #endif #endregion #region Movement #if WINDOWS Vector2 dir = Vector2.Zero; if (keyState.IsKeyDown(Keys.W)) { dir.Y = -1; } else if (keyState.IsKeyDown(Keys.S)) { dir.Y = 1; } if (keyState.IsKeyDown(Keys.A)) { dir.X = -1; } else if (keyState.IsKeyDown(Keys.D)) { dir.X = 1; } if (dir != Vector2.Zero) { dir.Normalize(); accelerations.Add(dir); } #elif XBOX //Forward if (theState.ThumbSticks.Left.Y != 0 || theState.ThumbSticks.Left.X != 0) { accelerations.Add(new Vector2(theState.ThumbSticks.Left.X, theState.ThumbSticks.Left.Y * -1)); } #endif #endregion #region Finalize Direction acceleration = Vector2.Zero; foreach (Vector2 a in accelerations) { if (!float.IsNaN(a.X) && !float.IsNaN(a.Y)) { acceleration += a; } } drag = 0.1f; thrust = movementSpeed * drag; velocity += thrust * acceleration - drag * velocity; accelerations.Clear(); #endregion #region Rotation #if WINDOWS wantedRotation = PathHelper.Direction( CameraManager.Transform(position, mH.GetCameraManager().GetDisplacement(GetType())) + origin, new Vector2(mouseState.X, mouseState.Y)); if (wantedRotation < 0) { wantedRotation += MathHelper.TwoPi; } //Calculate turningSpeed to maximize speed and minimize jittering if (MathHelper.Distance(rotation, wantedRotation) < turningSpeed && turningSpeed > MathHelper.Pi / 160.0f) { turningSpeed /= 2.0f; } else if (MathHelper.Distance(rotation, wantedRotation) > turningSpeed && turningSpeed < maxTurningSpeed) { turningSpeed *= 2.0f; } //Apply turningSpeed to rotation in correct direction float otherRot = rotation + MathHelper.TwoPi * ((rotation > MathHelper.Pi) ? -1 : 1); //Same angle, different name to compensate for linear numbers float distADir = MathHelper.Distance(wantedRotation, rotation), //Archlength sorta from actual rotation distBDir = MathHelper.Distance(wantedRotation, otherRot); //Archlength sorta from same angle but 2pi over //If the usual angle is closer if (distADir < distBDir) { //Do normal rotation if (rotation > wantedRotation) { Turn(-1 * turningSpeed); } else if (rotation < wantedRotation) { Turn(turningSpeed); } } //Otherwise else { //Do a rotation using the new number, which is able to give the correct turning direction if (otherRot > wantedRotation) { Turn(-1.0f * turningSpeed); } else if (otherRot < wantedRotation) { Turn(turningSpeed); } } #elif XBOX if (theState.ThumbSticks.Right.X != 0 || theState.ThumbSticks.Right.Y != 0) { wantedRotation = (float)Math.Atan2(theState.ThumbSticks.Right.Y * -1, theState.ThumbSticks.Right.X); if (wantedRotation < 0) { wantedRotation += (float)Math.PI * 2; } //Calculate turningSpeed to maximize speed and minimize jittering if (Math.Abs(rotation - wantedRotation) < turningSpeed && turningSpeed > (float)Math.PI / 160) { turningSpeed /= 2; } else if (Math.Abs(rotation - wantedRotation) > turningSpeed && turningSpeed < maxTurningSpeed) { turningSpeed *= 2; } //Apply turningSpeed to rotation in correct direction float otherRot = rotation + ((float)Math.PI * 2) * ((rotation > Math.PI) ? -1 : 1); //Same angle, different name to compensate for linear numbers float distADir = (float)Math.Abs(wantedRotation - rotation), //Archlength sorta from actual rotation distBDir = (float)Math.Abs(wantedRotation - otherRot); //Archlength sorta from same angle but 2pi over //If the usual angle is closer if (distADir < distBDir) { //Do normal rotation if (rotation > wantedRotation) { Turn(-1 * turningSpeed); } else if (rotation < wantedRotation) { Turn(turningSpeed); } } //Otherwise else { //Do a rotation using the new number, which is able to give the correct turning direction if (otherRot > wantedRotation) { Turn(-1 * turningSpeed); } else if (otherRot < wantedRotation) { Turn(turningSpeed); } } } else { wantedRotation = rotation; } #endif #endregion PosUpdate(mH); if (indicator != null) { //Animation of indicator if (timer > endtime) { indicator.SetFrameIndex(indicator.GetFrameIndex() + 1); if (indicator.GetFrameIndex() > 5) { indicator.SetFrameIndex(0); } timer = 0; } else { timer += mH.GetGameTime().ElapsedGameTime.TotalSeconds; } indicator.position = new Vector2(position.X - origin.X, position.Y - origin.Y); indicator.Update(mH); } ChargePower(); #if WINDOWS oldState = keyState; #elif XBOX oldState = theState; #endif originPosition = position + origin; }