void InputHandle(GameTime gameTime) { if ((GesturesInput.GetInstance().GetGestureType() == GestureType.FreeDrag || GesturesInput.GetInstance().GetGestureType() == GestureType.HorizontalDrag || GesturesInput.GetInstance().GetGestureType() == GestureType.Hold || GesturesInput.GetInstance().GetGestureType() == GestureType.VerticalDrag) && (m_gridState == Grid_State.Wait || m_gridState == Grid_State.Touching)) { Vector2 posTap = GesturesInput.GetInstance().GetGesturePosition(); int tempI = (int)(posTap.Y - EXTRAPOS.Y) / TILE; int tempJ = (int)(posTap.X - EXTRAPOS.X) / TILE; for (int i = 0; i < m_listCell.Count; i++) { if (m_listCell[i].IsContain(posTap)) { if (isAvailable(tempI, tempJ) && (m_currentCellType == m_listCell[i].m_type || m_currentCellType == Cell_Type.None)) { m_lastCellPos = m_listCell[i].m_position; m_lastIndexI = m_listCell[i].m_indexI; m_lastIndexJ = m_listCell[i].m_indexJ; if (m_listCell[i].m_state == Cell_State.NoTouch) { switch (m_listCell[i].m_type) { case Cell_Type.Type01: SoundManager.GetInstance().PlaySound(ESound.TouchType1); break; case Cell_Type.Type02: SoundManager.GetInstance().PlaySound(ESound.TouchType2); break; case Cell_Type.Type03: SoundManager.GetInstance().PlaySound(ESound.TouchType3); break; case Cell_Type.Type04: SoundManager.GetInstance().PlaySound(ESound.TouchType4); break; case Cell_Type.Type05: SoundManager.GetInstance().PlaySound(ESound.TouchType5); break; case Cell_Type.Type06: SoundManager.GetInstance().PlaySound(ESound.TouchType6); break; case Cell_Type.Type07: SoundManager.GetInstance().PlaySound(ESound.TouchType7); break; case Cell_Type.Type08: SoundManager.GetInstance().PlaySound(ESound.TouchType8); break; } m_listCell[i].setBeginTouch(); m_listTouch.Add(m_listCell[i]); if (m_currentCellType == Cell_Type.None) { m_currentCellType = m_listCell[i].m_type; m_gridState = Grid_State.Touching; } } } } } } if (GesturesInput.GetInstance().GetGestureType() == GestureType.DragComplete) { DragCompleteHandle(); } if (m_countFalling == 0 && m_gridState == Grid_State.Falling) { m_gridState = Grid_State.Wait; } }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (Global.Back == true) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); ModeScreen modeScreen = new ModeScreen(); ScreenManager.AddScreen(modeScreen); this.ExitScreen(); return; } GesturesInput.GetInstance().Update(gameTime); if (GesturesInput.GetInstance().GetGestureType() == GestureType.Tap) { Microsoft.Xna.Framework.Point posTap = GesturesInput.GetInstance().GetGesturePoint(); if (pauseButton.Contains(posTap)) { if (Global.GAMESTATE == GameState.Running) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); Global.GAMESTATE = GameState.PauseGame; GesturesInput.GetInstance().Reset(); return; } } if (resumeButton.Contains(posTap)) { if (Global.GAMESTATE == GameState.PauseGame) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); Global.GAMESTATE = GameState.Running; m_grid.DragCompleteHandle(); GesturesInput.GetInstance().Reset(); return; } } if (restartButton.Contains(posTap)) { if (Global.GAMESTATE == GameState.PauseGame) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); Reset(); Global.GAMESTATE = GameState.Running; GesturesInput.GetInstance().Reset(); return; } } if (menuButton.Contains(posTap)) { if (Global.GAMESTATE == GameState.PauseGame) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); MenuScreen menuScreen = new MenuScreen(); ScreenManager.AddScreen(menuScreen); this.ExitScreen(); GesturesInput.GetInstance().Reset(); return; } } if (musicButton.Contains(posTap)) { if (Global.GAMESTATE == GameState.PauseGame) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); if (Global.SOUND == true) { SoundManager.GetInstance().StopSongs(); //SoundManager.GetInstance().PauseSong(); Global.SOUND = false; } else { Global.SOUND = true; SoundManager.GetInstance().PlaySong(ESong.Background); //SoundManager.GetInstance().ResumeSong(); } GesturesInput.GetInstance().Reset(); return; } } if (Global.GAMESTATE == GameState.EndGame) { if (Global.GAMEMODE == GameMode.EasyClassic || Global.GAMEMODE == GameMode.NormalClassic) { if (classic_MenuButton.Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); MenuScreen menuScreen = new MenuScreen(); ScreenManager.AddScreen(menuScreen); this.ExitScreen(); GesturesInput.GetInstance().Reset(); return; } if (classic_PlayAgainButton.Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); Reset(); Global.GAMESTATE = GameState.Running; GesturesInput.GetInstance().Reset(); return; } } if (Global.GAMEMODE == GameMode.Level) { if (level_MenuButton.Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); MenuScreen menuScreen = new MenuScreen(); ScreenManager.AddScreen(menuScreen); this.ExitScreen(); GesturesInput.GetInstance().Reset(); return; } if (level_NextLevelButton.Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); int newLevel = m_levelManager.m_currentLevel + 1; m_levelManager.NewLevel(); SetLevel(newLevel); Reset(); Global.GAMESTATE = GameState.Running; GesturesInput.GetInstance().Reset(); return; } if (level_RetryButton.Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); Reset(); Global.GAMESTATE = GameState.Running; GesturesInput.GetInstance().Reset(); return; } } } } m_grid.Update(gameTime); m_gameTimeManager.Update(gameTime); m_pointManager.Update(gameTime); if (Global.GAMEMODE == GameMode.Level) { if (Global.GAMESTATE == GameState.Running && m_levelManager.isWin()) { SoundManager.GetInstance().PlaySound(ESound.LevelComplete); Global.GAMESTATE = GameState.BeforeEndGame; return; } } if (Global.GAMEMODE == GameMode.EasyClassic || Global.GAMEMODE == GameMode.NormalClassic) { if (Global.GAMESTATE == GameState.Running && m_gameTimeManager.IsLose()) { Global.GAMESTATE = GameState.BeforeEndGame; SoundManager.GetInstance().PlaySound(ESound.ClassicComplete); return; } } if (Global.GAMESTATE == GameState.BeforeEndGame) { m_completeTime -= (float)gameTime.ElapsedGameTime.Milliseconds / 1000.0f; m_completePos += m_AccleComplete * (float)gameTime.ElapsedGameTime.Milliseconds; if (m_completeTime <= 0) { Global.GAMESTATE = GameState.EndGame; DataManager.GetInstance().LevelCount++; if ((DataManager.GetInstance().LevelCount % 5) == 0) { } m_completeTime = 0; if (Global.GAMEMODE == GameMode.Level) { int newLevel = m_levelManager.m_currentLevel + 1; if (newLevel > DataManager.GetInstance().CurrentLevel) { DataManager.GetInstance().CurrentLevel = newLevel; } } } } GesturesInput.GetInstance().Reset(); base.Update(gameTime, otherScreenHasFocus, false); }
public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (Global.Back == true) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); ModeScreen modeScreen = new ModeScreen(); ScreenManager.AddScreen(modeScreen); this.ExitScreen(); return; } GesturesInput.GetInstance().Update(gameTime); if (GesturesInput.GetInstance().GetGestureType() == GestureType.Tap) { Point posTap = GesturesInput.GetInstance().GetGesturePoint(); if (backToMenuButton.Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); MenuScreen menuScreen = new MenuScreen(); ScreenManager.AddScreen(menuScreen); this.ExitScreen(); GesturesInput.GetInstance().Reset(); return; } for (int i = 0; i < m_level; i++) { if (m_buttonLevelList[i].Contains(posTap)) { SoundManager.GetInstance().PlaySound(ESound.SelectButton); MainGameScreen mainGameScreen = new MainGameScreen(); mainGameScreen.SetModeGame(GameMode.Level); int level = i + 1; mainGameScreen.SetLevel(level); ScreenManager.AddScreen(mainGameScreen); GesturesInput.GetInstance().Reset(); this.ExitScreen(); GesturesInput.GetInstance().Reset(); return; } } } if (GesturesInput.GetInstance().GetDirDrag() == DirDrag.Left_Right) { if (m_state != LevelScreenState.Moving) { m_state = LevelScreenState.Moving; m_VelocX = -VELOC_X; m_MovingX = 0; GesturesInput.GetInstance().Reset(); } } if (GesturesInput.GetInstance().GetDirDrag() == DirDrag.Right_Left) { if (m_state != LevelScreenState.Moving) { m_state = LevelScreenState.Moving; m_VelocX = VELOC_X; m_MovingX = 0; GesturesInput.GetInstance().Reset(); } } if (m_state == LevelScreenState.Moving) { MovingScreen(-(int)m_MovingX); m_MovingX += m_VelocX * (float)gameTime.ElapsedGameTime.Milliseconds; if (m_VelocX > 0) { if (m_MovingX >= VIEWPORT_WIDTH) { m_state = LevelScreenState.Wait; MovingScreen(VIEWPORT_WIDTH); m_MovingX = 0; m_VelocX = 0; } else { MovingScreen((int)m_MovingX); } } if (m_VelocX < 0) { if (m_MovingX <= -VIEWPORT_WIDTH) { m_state = LevelScreenState.Wait; MovingScreen(-VIEWPORT_WIDTH); m_MovingX = 0; m_VelocX = 0; } else { MovingScreen((int)m_MovingX); } } if (_srcRect.X < 0) { int BonusDeltaX = _srcRect.X - 0; MovingScreen(-BonusDeltaX); } if (_srcRect.X > MAXPOS_X) { int BonusDeltaX = _srcRect.X - MAXPOS_X; MovingScreen(-BonusDeltaX); } } UpdateCurrentLevelGrid(); base.Update(gameTime, otherScreenHasFocus, false); }