Example #1
0
void Logic::processMovement(Pacman &pacman, Maze &maze)
{
	Vector2<int> coords(0,0);

	switch(pacman.getDirection())	
	{
		case Direction::UP:
			coords.x = pacman.getPosition().x;
			coords.y = pacman.getPosition().y - 1;
			break;

		case Direction::DOWN:
			coords.x = pacman.getPosition().x;
			coords.y = pacman.getPosition().y + 1;
			break;

		case Direction::LEFT:
			coords.x = pacman.getPosition().x - 1;
			coords.y = pacman.getPosition().y;
			break;

		case Direction::RIGHT:
			coords.x = pacman.getPosition().x + 1;
			coords.y = pacman.getPosition().y;
			break;

		case Direction::STOP:
			coords.x = pacman.getPosition().x;
			coords.y = pacman.getPosition().y;
			break;
	}

	if(maze.getMaze()[coords.x][coords.y].getType() != Type::NOTHING)
	{
		if(Physics::isIntersects(&pacman, &maze.getMaze()[coords.x][coords.y], pacman.getDirection()))
		{
			switch(maze.getMaze()[coords.x][coords.y].getType())
			{
			case Type::PILL:
					pacman.setScore(pacman.getScore() + 2);
					maze.getMaze()[coords.x][coords.y].setType(Type::NOTHING);
					cellsToChange.setXY(coords.x, coords.y);
					break;

				case Type::BONUS:
					break;

				case Type::WALL:
					pacman.setDirection(Direction::STOP);
					break;
			}
		}
	}

	pacman.setMovingVector();
}
Example #2
0
void	IA::update(GameEngine *game, Maze &maze)	{
  std::list<Bomb *>::iterator		it_bomb = this->m_bomb.begin();
  int	action;
  int	x;
  int	y;

  if (this->m_time > 42) {
    this->m_time = 0;
    x = this->m_position % this->m_width;
    y = this->m_position / this->m_width;
    this->IsAlive(maze);
    if (this->m_alive) {
      action = this->m_lua->getPosition(maze.getMaze(), x, y);
      if (action == -1)
	throw ErrorBomberman("Error with lua bind", "IA");
      else if (action < IA_NONE)
	(this->*m_func[action])(maze, game->getClock());
    }
  }
  this->m_time = this->m_time + 1;
  try {
    while (it_bomb != this->m_bomb.end()) {
      (*it_bomb)->update(game->getClock(), maze);
      if ((*it_bomb)->getState() == TODELETE) {
	delete *it_bomb;
	it_bomb = this->m_bomb.erase(it_bomb);
      }
      ++it_bomb;
    }
  }
  catch (ErrorBomberman const &e) {
    throw ErrorBomberman(e.what(), "IA");
  }
}
Example #3
0
void	IA::MoveDown(Maze &maze, gdl::Clock &)	{
  if (this->m_alive == true) {
    this->m_direction = DOWN;
    this->m_tomove = this->move(maze.getMaze(), maze.getWidth());
  }
}
Example #4
0
void	IA::MoveRight(Maze &maze, gdl::Clock &)	{
  if (this->m_alive == true) {
    this->m_direction = RIGHT;
    this->m_tomove = this->move(maze.getMaze(), maze.getWidth());
  }
}