/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here Texture2D tex = Content.Load<Texture2D>("player"); Texture2D civ_tex1 = Content.Load<Texture2D>("civ1"); player = new Player(new Vector2(50f, 50f), tex); civilians.Add(new Civilian(new Vector2(100f, 100f), civ_tex1)); civilians.Add(new Civilian(new Vector2(200f, 100f), civ_tex1)); civilians.Add(new Civilian(new Vector2(300f, 100f), civ_tex1)); civilians.Add(new Civilian(new Vector2(400f, 50f), new Vector2(0,-1), Civilian.CivilianStates.Default,civ_tex1)); targetBorder = new Texture2D(GraphicsDevice, 1, 1); targetBorder.SetData(new[] { Color.White }); font = Content.Load<SpriteFont>("SpriteFont1"); }
public void Update(Player player, List<Entity> entities) { if (civilianState != CivilianStates.Dead) { #region Civilian_State_Check // Set state to alarmed if player is close if (Math.Abs((Origin - player.Origin).Length()) < 200) { CivilianState = Civilian.CivilianStates.Alarmed; } #endregion if (lifeTime.ElapsedMilliseconds >= headingChangeMillis) { //Random gen = new Random(); double rnd; Vector2 rot; #region Civilian_Behavior_Rules switch (this.civilianState) { case CivilianStates.Default: rnd = Constants.gen.Next(0, 46) - 22.5; rnd *= Math.PI / 180; // Needs to convert degrees to radians. Perhaps a static helper method in constants? rot = this.Heading; break; case CivilianStates.Alarmed: rnd = Constants.gen.Next(0, 91) - 45; rnd *= Math.PI / 180; // Needs to convert degrees to radians. Perhaps a static helper method in constants? rot = this.Origin - player.Origin; break; default: rnd = 0.0; rot = this.Heading; break; } #endregion rot.X = (rot.X * (float)Math.Cos(rnd)) + (rot.Y * (float)Math.Sin(rnd)); rot.Y = (rot.Y * (float)Math.Cos(rnd)) - (rot.X * (float)Math.Sin(rnd)); this.Heading = rot; headingChangeMillis = lifeTime.ElapsedMilliseconds + Constants.gen.Next(500, 1000); } moveCivilian(entities); } }
protected void initGameObjects() { shootTimer = 0; player = new Player(new Vector2(1050f, 400f), player_tex); civilians.Clear(); civilians.Add(new Civilian(new Vector2(100f, 300f), civ_tex1)); civilians.Add(new Civilian(new Vector2(320f, 290f), civ_tex1)); civilians.Add(new Civilian(new Vector2(400f, 400f), civ_tex1)); civilians.Add(new Civilian(new Vector2(500f, 400f), civ_tex1)); civilians.Add(new Civilian(new Vector2(600f, 400f), civ_tex1)); bullets.Clear(); envObjects.Clear(); envObjects.Add(new EnvironmentalObject(new Vector2(850f, 210f), truck_red, new Rectangle(0, 0, 300, 130))); // car envObjects.Add(new EnvironmentalObject(new Vector2(80f, 390f), truck_red, new Rectangle(0, 0, 300, 130))); // car //envObjects.Add(new EnvironmentalObject(new Vector2(0f, 0f), env_tex, new Rectangle(0, 0, 438, 193))); //envObjects.Add(new EnvironmentalObject(new Vector2(0f, 504f), env_tex, new Rectangle(0, 0, 446, 220))); gameover = false; gameover_suicide = false; isStateKeyPressed = false; score = 0; combo = 0; combo_counter = 0; MediaPlayer.IsRepeating = true; MediaPlayer.Play(bgm); }