protected override void Initialize() { base.Initialize(); _CurrentGameState = GameState.MainMenu; GameSet = false; _Audio = new Audio(); _Audio.Initialize(); _3DEngine = new Engine3D(ref _Audio); _3DEngine.Initialize(Content); #region Text _TextList = new List<Text>(); _TextList.Add(new Text("Health: ", new Vector2(graphics.PreferredBackBufferWidth * 0.70f, graphics.PreferredBackBufferHeight * 0.75f))); _TextList.Add(new Text("Time Remaining: ", new Vector2(graphics.PreferredBackBufferWidth * 0.56f, graphics.PreferredBackBufferHeight * 0.8f))); _TextList.Add(new Text("sec ", new Vector2(graphics.PreferredBackBufferWidth * 0.85f, graphics.PreferredBackBufferHeight * 0.8f))); _Health = new Text("0", new Vector2(graphics.PreferredBackBufferWidth * 0.81f, graphics.PreferredBackBufferHeight * 0.75f)); _Timer = new Text("30", new Vector2(graphics.PreferredBackBufferWidth * 0.81f, graphics.PreferredBackBufferHeight * 0.8f)); _TextList.Add(_Health); _TextList.Add(_Timer); #endregion }
public GameState Update(GameTime gameTime, Text Health, Text Timer) { Controls(); int ChefCount = 0; Random r = new Random(); List<Food> Temp = new List<Food>(); _Player.Update(gameTime); _Camera.Update(gameTime, _Player); _IceCream.Update(gameTime); Health.SetText(Convert.ToString(Convert.ToInt32(_Player._Strength))); _Elapse += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (_Elapse > 1000f) { Timer.SetText(Convert.ToString(Convert.ToInt32(Timer.GetText()) - 1)); _Elapse -= 1000; } #region Player foreach (Food node in _FoodList) if (!_Player._HoldingFood && _Player._Bound.Intersects(node._Bound)) { _Player.PickUp(node._Type, node._Strength); Temp.Add(node); } foreach (Food node in Temp) _FoodList.Remove(node); Temp.Clear(); foreach (Hole node in _HoleList) { if (_Player._Bound.Intersects(node._Bound)) { _Player.UpdatePosition(Vector3.Zero); _Player.ReduceHealth(50); } if (node._ChefList.Count > 0 && _Player._Bound.Intersects(node._ChefList[0]._Bound)) { _Player.ReduceHealth(20); node.Clear(); } } foreach (Food node in _ThrownList) if (_Player._Bound.Intersects(node._Bound)) { _Player.ReduceHealth(node._Strength); Temp.Add(node); } if (_Player._Bound.Intersects(_IceCream._Bound)) { return GameState.Clear; } if (Convert.ToInt32(Health.GetText()) <= 0) return GameState.GameOver; #endregion #region Enemy foreach (Hole h in _HoleList) { if (h._Moving && h._ChefList.Count > 0) { bool clear = false; while (!clear) { int HoleNum = r.Next(_HOLECOUNT); if (_HoleList[HoleNum]._ChefList.Count <= 0 && _HoleList[HoleNum] != h) { Chef temp = h._ChefList[0].Clone(h._Position); _HoleList[HoleNum].Summon(temp); h.Clear(); clear = true; } } } foreach (Chef c in h._ChefList) { if (c._Throw) { c.Throw(); Food f = _TypeList[r.Next(_TypeList.Count())].Clone(); Vector3 p = c._Position + new Vector3(0, 1.5f, 0) + c._PlayerDirection; Vector3 v = c._PlayerDirection * (c._Strength / 5); f.Thrown(p, v); _ThrownList.Add(f); } foreach (Food node in _ThrownList) { if (c._Bound.Intersects(node._Bound)) { c.ReduceHealth(node._Strength); Temp.Add(node); _Audio.Play("Enemy", "Doh"); } if (c._Moving && c._Bound.Intersects(node._Bound)) { c.ReduceHealth(_ChefStrength); Temp.Add(node); _Audio.Play("Enemy", "Doh"); } } c.Update(gameTime, _Player._Position); } h.Update(gameTime, _Audio); } foreach (Hole node in _HoleList) if (node._StartSpawn) ChefCount++; for (int i = ChefCount; i < _CHEFCOUNT; ++i) { int j = 0; do { j = r.Next(_HoleList.Count); } while (_HoleList[j]._StartSpawn && _HoleList[j]._ChefList.Count == 1); _HoleList[j].Summon(); } #endregion #region Food foreach (Food node in _ThrownList) { node.Update(gameTime); if (!node._Bound.Intersects(_Bounds)) Temp.Add(node); } foreach (Food node in Temp) _ThrownList.Remove(node); Temp.Clear(); #endregion return GameState.Playing; }