public override void UpdateState(GameTime gameTime) { base.UpdateState(gameTime); _map.Update(gameTime); MouseState ms = Mouse.GetState(); int _checkMonster = -1; // Kiem tra chuot co dang chi len quai vat hay khong for (int i = 0; i < _listMonsters.Count; ++i) { _listMonsters[i].Update(gameTime); if (_listMonsters[i].IsDyed || _listMonsters[i].IsDying) { continue; } if (_char != null && Math.Sqrt(Math.Pow(_listMonsters[i].X - _char.X, 2) - Math.Pow(_listMonsters[i].Y - _char.Y, 2)) < _listMonsters[i].Sight) { _listMonsters[i].Target = _char; } if (_listMonsters[i].CollisionRect.Contains(new Point((int)GlobalVariables.GameCursor.X, (int)GlobalVariables.GameCursor.Y))) { _checkMonster = i; } } if (_checkMonster != -1) { GlobalVariables.GameCursor.IsAttack = true; } else { GlobalVariables.GameCursor.IsIdle = true; } if (ms.LeftButton == ButtonState.Pressed) { if (ms.X < GlobalVariables.ScreenWidth && ms.Y < GlobalVariables.ScreenHeight && ms.X >= 0 && ms.Y >= 0) { if (!GlobalVariables.GameCursor.IsAttack) { Point newCell = _map.PointToCell(new Point((int)GlobalVariables.GameCursor.X, (int)GlobalVariables.GameCursor.Y)); if (_map.Matrix[newCell.Y][newCell.X] == true) { _char.CellToMove = Utility.FindPath(_map.Matrix, _map.PointToCell(new Point((int)_char.X, (int)_char.Y)), newCell); } _char.Target = null; } else { _char.Target = _listMonsters[_checkMonster]; } } } GlobalVariables.GameCursor.Update(gameTime); _char.Update(gameTime); _frog.Update(gameTime); }
public override void UpdateState(GameTime gameTime) { base.UpdateState(gameTime); if (!GlobalVariables.IsPauseGame) { float minX = Math.Abs(GlobalVariables.dX); float maxX = Math.Abs(GlobalVariables.dX) + GlobalVariables.ScreenWidth; float minY = Math.Abs(GlobalVariables.dY); float maxY = Math.Abs(GlobalVariables.dY) + GlobalVariables.ScreenHeight; GlobalVariables.GameCursor.IsIdle = true; GlobalVariables.AlreadyUseLeftMouse = false; GlobalVariables.AlreadyUseRightMouse = false; _healthBar.Update(gameTime); _lhSkillSelectionFrame.Update(gameTime); _rhSkillSelectionFrame.Update(gameTime); _skillBoard.Update(gameTime); _infoBoard.Update(gameTime); _listToDraw.Clear(); _map.Update(gameTime); for (int i = 0; i < _listObstacle.Count; ++i) { if (minX < _listObstacle[i].X && _listObstacle[i].X < maxX && minY < _listObstacle[i].Y && _listObstacle[i].Y < maxY) { _listObstacle[i].Update(gameTime); _listToDraw.Add(_listObstacle[i]); } } for (int i = 0; i < _listPortral.Count; ++i) { if (minX < _listPortral[i].X && _listPortral[i].X < maxX && minY < _listPortral[i].Y && _listPortral[i].Y < maxY) { _listPortral[i].Update(gameTime); _listToDraw.Add(_listPortral[i]); } } for (int i = 0; i < _listMonsters.Count; ++i) { if (minX < _listMonsters[i].X && _listMonsters[i].X < maxX && minY < _listMonsters[i].Y && _listMonsters[i].Y < maxY) { _listMonsters[i].Update(gameTime); _listToDraw.Add(_listMonsters[i]); if (_listMonsters[i].IsDyed) { _listMonsters.Remove(_listMonsters[i]); } } } for (int i = 0; i < _listProjectile.Count; ++i) { _listProjectile[i].Update(gameTime); if ((_listProjectile[i]._sprite[0].Itexture2D == _listProjectile[i]._sprite[0].Ntexture2D - 1 && _listProjectile[i].IsRemoveAfterEffect) || (_listProjectile[i].LifeTime <= 0 && !_listProjectile[i].IsRemoveAfterEffect)) { _listProjectile.Remove(_listProjectile[i]); } } _char.Update(gameTime); _listToDraw.Add(_char); if (_char.IsDyed) { int nObjectManager = 4; GameObjectManager[] objectManagerArray = new GameObjectManager[nObjectManager]; objectManagerArray[0] = new ButtonManger(@"./Data/XML/buttonmanager.xml"); objectManagerArray[1] = new BackgroundManager(@"./Data/XML/menubg.xml"); objectManagerArray[2] = new MenuFrameManager(@"./Data/XML/menuframe.xml"); objectManagerArray[3] = new GameTitleManager(@"./Data/XML/gametitle.xml"); GlobalVariables.dX = 0; GlobalVariables.dY = 0; Owner.GameState.ExitState(); Owner.GameState = new StateLoading(); Owner.GameState.InitState(null, this.Owner); ((StateLoading)Owner.GameState).GetDataLoading(this.Owner.Content, @"./Data/XML/loadingtomenu.xml", objectManagerArray, typeof(StateMenu)); Owner.GameState.EnterState(); Owner.ResetElapsedTime(); } if (GlobalVariables.LastBoss.IsDying) { if (GlobalVariables.BackgroundSound.Name != "soulsrelease") { GlobalVariables.BackgroundSound = GlobalVariables.SoundBank.GetCue("soulsrelease"); GlobalVariables.BackgroundSound.Play(); } } if (GlobalVariables.LastBoss.IsDyed) { GlobalVariables.IsPauseGame = true; } _displayMessageLayer.Update(gameTime); _frog.Update(gameTime); } else { if (GlobalVariables.LastBoss.IsDyed) { Owner.Exit(); } else { _subMenu.Update(gameTime); } } }