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 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; }