private void move() { directionsToDPad_[ACharacter.EOrientation.UP] = currentState.DPad.Up; directionsToDPad_[ACharacter.EOrientation.DOWN] = currentState.DPad.Down; directionsToDPad_[ACharacter.EOrientation.LEFT] = currentState.DPad.Left; directionsToDPad_[ACharacter.EOrientation.RIGHT] = currentState.DPad.Right; foreach (var pair in directionsToDPad_) { if (pair.Value == ButtonState.Pressed || hero_.getOrientation() == pair.Key) { if (levelManager_.directionFree(hero_.getX(), hero_.getY(), pair.Key)) { hero_.setOrientation(pair.Key); if (levelManager_.pixelPowerEat(hero_.getX(), hero_.getY())) { hero_.setPowerUp(); som_.play(SoundManager.ESound.PAUSE, 0.5f); } else if (levelManager_.pixelEat(hero_.getX(), hero_.getY())) { hero_.eatPallet(); som_.play(SoundManager.ESound.CHOMP, -0.9f, 0.2f); } hero_.setBlocked(false); } else if (hero_.getOrientation() == pair.Key) { hero_.setBlocked(true); } } } }
internal ACharacter.EOrientation getPacManDirection(Hero h, ACharacter m) { int x = (int)((m.getX() - h.getX()) / 8); // POSITIF == LEFT NEGATIF == RIGHT int y = (int)((m.getY() - h.getY()) / 8); // POSITIF == UP NEGATIF == DOWN if (Math.Abs(x) > Math.Abs(y)) { return(x > 0 ? ACharacter.EOrientation.LEFT : ACharacter.EOrientation.RIGHT); } return(y > 0 ? ACharacter.EOrientation.UP : ACharacter.EOrientation.DOWN); }
public void updateHeroPosition(Hero h) { heroPos_.X = h.getX() + 8; heroPos_.Y = h.getY() + 8; }
internal ACharacter.EOrientation getPacManDirection(Hero h, ACharacter m) { int x = (int)((m.getX() - h.getX()) / 8); // POSITIF == LEFT NEGATIF == RIGHT int y = (int)((m.getY() - h.getY()) / 8); // POSITIF == UP NEGATIF == DOWN if (Math.Abs(x) > Math.Abs(y)) return x > 0 ? ACharacter.EOrientation.LEFT : ACharacter.EOrientation.RIGHT; return y > 0 ? ACharacter.EOrientation.UP : ACharacter.EOrientation.DOWN; }