public override void OnEnter() { dorfs = new List<Person>(); players = new List<Player>(); aiPlayers = new List<Player>(); hospitals = new List<Hospital>() ; Bloom = new BloomPostprocess.BloomComponent(Game); Bloom.Initialize(); Bloom.Settings = BloomPostprocess.BloomSettings.PresetSettings[5]; IsInitialized = true; MapHeight = 40; MapWidth = 40; Player.defib = new Player.defibCallbackType(defib); online = false; // DO NOT CHANGE, offline mode is now detected when server connection is refused SoundManager.Content = Game.Content; Camera = new OrbitCamera(Game.GraphicsDevice, 0, 0, 0.001f, new Vector3(0, 15, 0), new Vector3(-10, 10, 0), (float)Math.PI * 0.25f, Game.GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000.0f); ComponentManager = new ComponentManager(); ComponentManager.RootComponent = new LocatableComponent(ComponentManager, "root", null, Matrix.Identity, Vector3.Zero, Vector3.Zero); notification = null; particles = new ParticleManager(ComponentManager); EmitterData testData = new EmitterData(); testData.AngularDamping = 1.0f; List<Point> frm = new List<Point>(); frm.Add(new Point(0, 0)); frm.Add(new Point(1, 0)); frm.Add(new Point(0, 1)); frm.Add(new Point(1, 1)); testData.Animation = new Animation(Game.GraphicsDevice, Game.Content.Load<Texture2D>("electricity"), "electricity", 32, 32, frm, true, Color.White, 20f, 1.0f, 1.0f, false); testData.ConstantAccel = new Vector3(0, -1, 0); testData.LinearDamping = 0.9f; testData.AngularDamping = 0.9f; testData.EmissionFrequency = 1.0f; testData.EmissionRadius = 1.0f; testData.EmissionSpeed = 20.0f; testData.GrowthSpeed = -0.9f; testData.MaxAngle = 3.14159f; testData.MinAngle = 0.0f; testData.MaxParticles = 1000; testData.MaxScale = 1.0f; testData.MinScale = 0.1f; testData.MinAngular = -5.0f; testData.MaxAngular = 5.0f; testData.ParticleDecay = 0.1f; testData.ParticlesPerFrame = 0; testData.ReleaseOnce = true; testData.Texture = Game.Content.Load<Texture2D>("electricity"); particles.RegisterEffect("shock", testData); ChargeCooldown = 1.0f; CurrentChargeCooldown = 1.0f; InputManager inputManager = new InputManager(); InputManager.KeyPressedCallback += pressKey; InputManager.KeyReleasedCallback += releaseKey; sounds = new SoundManager(); wordsDict = new Dictionary<string, string>(); wordsDict.Add("MONSTER SAVE", "monstersave"); wordsDict.Add("DOUBLE SAVE", "doublesave"); wordsDict.Add("TRIPLE SAVE", "triplesave"); drawer2D = new Drawer2D(Game.Content, Game.GraphicsDevice); client = new Client(online); string name = client.Connect(); if (name == "error") { Console.Out.WriteLine("connection refused"); name = "0"; online = false; } Hospital hospital1 = new Hospital(new Vector3(-10, 0, -10), new Vector3(4, 2, 3), ComponentManager, Game.Content, Game.GraphicsDevice, "hospital", Color.Red, new Point(2, 0)); Hospital hospital2 = new Hospital(new Vector3(12, 0, 12), new Vector3(4, 2, 3), ComponentManager, Game.Content, Game.GraphicsDevice, "hospital", Color.Blue, new Point(1, 0)); hospitals.Add(hospital1); hospitals.Add(hospital2); Random r = new Random(1); for (int i = 0; i < 20; i++) // fnord { NPC npc; switch ((int)(detRand(r) * 3)) { case (0): npc = new Smoker(new Vector3(detRand(r) * 9, 5, detRand(r) * 10), ComponentManager, Game.Content, Game.GraphicsDevice); break; case (1): npc = new Fatter(new Vector3(detRand(r) * 9, 5, detRand(r) * 10), ComponentManager, Game.Content, Game.GraphicsDevice); break; case (2): npc = new Older(new Vector3(detRand(r) * 9, 5, detRand(r) * 10), ComponentManager, Game.Content, Game.GraphicsDevice); break; default: /* graphics don't exist yet, never reached */ npc = new Worker(new Vector3(detRand(r) * 9, 5, detRand(r) * 10 - 0), ComponentManager, Game.Content, Game.GraphicsDevice); break; } npc.velocityController.MaxSpeed = 1; npc.SetTag((i + 1000).ToString()); int al = (int)(detRand(r) * 2); npc.Team = hospitals[al]; npc.Velocity = new Vector3(0f, -0.5f, 0f); npc.HasMoved = true; dorfs.Add(npc); } player = new Player(name, new Vector3(hospital1.Component.LocalTransform.Translation.X + 5, hospital1.Component.LocalTransform.Translation.Y, hospital1.Component.LocalTransform.Translation.Z), ComponentManager, Game.Content, Game.GraphicsDevice, "surgeonwalk"); player.Velocity = new Vector3(0f, -0.5f, 0f); player.HasMoved = true; dorfs.Add(player); players.Add(player); if (!online) { aiPlayers.Add(new Player("1", new Vector3(hospital2.Component.LocalTransform.Translation.X - 5, hospital2.Component.LocalTransform.Translation.Y, hospital2.Component.LocalTransform.Translation.Z), ComponentManager, Game.Content, Game.GraphicsDevice, "surgeonwalk")); players.Add(aiPlayers.ElementAt(0)); dorfs.Add(aiPlayers.ElementAt(0)); aiPlayers.ElementAt(0).team = hospital2; VelocityController velocityController4 = new VelocityController(aiPlayers.ElementAt(0)); velocityController4.IsTracking = true; } VelocityController velocityController3 = new VelocityController(player); velocityController3.IsTracking = true; Vector3 boundingBoxPos = new Vector3(0, -2, 0); Vector3 boundingBoxExtents = new Vector3(MapWidth, 4, MapHeight); Vector3 boundingBoxMin = boundingBoxPos - boundingBoxExtents * 0.5f; Vector3 boundingBoxMax = boundingBoxPos + boundingBoxExtents * 0.5f; ground = (LocatableComponent)EntityFactory.GenerateBlankBox(new BoundingBox(boundingBoxMin, boundingBoxMax), ComponentManager, Game.Content, Game.GraphicsDevice, "newground", Point.Zero, Point.Zero, 128, 128); if (Convert.ToInt32(name) % 2 == 0) player.team = hospital1; else player.team = hospital2; SpriteBatch = new SpriteBatch(Game.GraphicsDevice); Shader = Game.Content.Load<Effect>("Hargraves"); SunMap = Game.Content.Load<Texture2D>("sungradient"); AmbientMap = Game.Content.Load<Texture2D>("ambientgradient"); TorchMap = Game.Content.Load<Texture2D>("torchgradient"); if (online) { AddNotification("Mash Space to Begin"); } base.OnEnter(); }
public override void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; CurrentChargeCooldown = Math.Min(CurrentChargeCooldown + dt, ChargeCooldown); doActions(); KeyboardState keyboardState = Keyboard.GetState(); InputManager.KeysUpdate(keyboardState); if (online) { foreach (Player p in players) { if (!p.isReady) return; } if (players.Count() < 2) return; } SoundManager.Update(gameTime, Camera); if (!Game.IsActive) { return; } Vector3 TargetVelocity = Vector3.Zero; ComponentManager.Update(gameTime, Camera); List<BoundingBox> collideBox = new List<BoundingBox>(); collideBox.Add(ground.GetBoundingBox()); foreach (Hospital h in hospitals) { collideBox.Add(h.Component.GetBoundingBox()); //collideBox.Add(h.InvisibleBox.GetBoundingBox()); } foreach (Person d in dorfs) { if (d.team != null) { d.teamCircle.IsVisible = (d is Player) ? true : false; d.teamCircle.Tint = d.team.Color; } else { d.teamCircle.IsVisible = false; } d.HasMoved = true; d.HandleCollisions(collideBox, (float)gameTime.ElapsedGameTime.TotalSeconds); if (d.GlobalTransform.Translation.X > MapWidth / 2 || d.GlobalTransform.Translation.X < -MapWidth / 2 || d.GlobalTransform.Translation.Z > MapHeight / 2 || d.GlobalTransform.Translation.Z < -MapWidth / 2 || d.GlobalTransform.Translation.Y < 0) { float x = Math.Max(Math.Min(d.GlobalTransform.Translation.X, MapWidth / 2), -MapWidth / 2); float z = Math.Max(Math.Min(d.GlobalTransform.Translation.Z, MapHeight / 2), -MapHeight / 2); float y = Math.Max(d.GlobalTransform.Translation.Y, 0); d.LocalTransform = Matrix.CreateTranslation(new Vector3(x, d.GlobalTransform.Translation.Y, z)); d.Velocity *= -0.1f; } } foreach (Person d in dorfs) { if (!(d is Player) && !d.IsDead) { foreach (Hospital h in hospitals) { if (d.GetBoundingBox().Intersects(h.Component.GetBoundingBox()) && d.team == h) { client.Write(encodePerson(d, Event.SCORE.ToString())); } } } } if (notification != null) { notification.displayLength -= dt; if (notification.displayLength < 0) { notification = null; } } foreach (Player p in aiPlayers) { NPC closestEnt = GetClosestNPC(p); if (closestEnt != null) { Vector3 fromHospital = (closestEnt.GlobalTransform.Translation - p.team.Component.GlobalTransform.Translation); fromHospital.Normalize(); fromHospital *= 0.5f; Vector3 diff = (closestEnt.GlobalTransform.Translation - p.GlobalTransform.Translation) + fromHospital; if (diff.Length() > 0.25f) { float mult = diff.Length() * 5.0f; diff.Normalize(); diff *= Math.Min(p.velocityController.MaxSpeed, mult); p.velocityController.targetVelocity = diff; } else { p.velocityController.targetVelocity = Vector3.Zero; p.Charging = true; if (p.DefibCharge >= 1.0f) { defib(p); p.Charging = false; p.DefibCharge = 0.0f; } } } } float alpha = 0.05f; Camera.Position *= 1.0f - alpha; Camera.Position += alpha * (player.GlobalTransform.Translation + new Vector3(10, 10, 0)); Camera.Target = alpha * player.GlobalTransform.Translation + (1.0f - alpha) * Camera.Target; Camera.Update(gameTime); NPC closest = GetClosestDeadNPC(player); if (closest != null) { float x = (float)(Math.Sin(gameTime.TotalGameTime.TotalSeconds * 5) * 0.5f + 0.5f); Color flash = new Color(1.0f, 1.0f, 1.0f, x); Color back = new Color(0, 0, 0, x); Drawer2D.DrawText("Revive! (Hold Space)", closest.GlobalTransform.Translation, flash, back); } Drawer2D.DrawText("Our Hospital", hospitals[0].Component.GlobalTransform.Translation, Color.White, Color.DarkRed); Drawer2D.DrawText("Their Hospital", hospitals[1].Component.GlobalTransform.Translation, Color.White, Color.DarkBlue); if (!PatientsExist()) { StateManager.SwitchState("WinState"); if (client.t != null) { Client.shouldExit = true; client.t.Join(); Client.shouldExit = false; } } base.Update(gameTime); }
public void AddNotification(string text, Hospital team = null, float time = 1.0f) { notification = new Notification(text, time); if (wordsDict.ContainsKey(text)) { SoundManager.Play2DSound(wordsDict[text]); } }