예제 #1
0
파일: Ia.cpp 프로젝트: simbaste/Bomberman
void	Ia::layingBomberPU()
{
  if (_nbBomb > 0)
    if (isPowerUp(_map->getCell(_posY - 1, _posX)) ||
	isPowerUp(_map->getCell(_posY + 1, _posX)) ||
	isPowerUp(_map->getCell(_posY, _posX - 1)) ||
	isPowerUp(_map->getCell(_posY, _posX + 1))) {
      _map->putBomb(device, *this);
      _map->setCell(_posY, _posX, Tile::BOMB);
    }
}
예제 #2
0
파일: Ia.cpp 프로젝트: simbaste/Bomberman
bool	Ia::takePowerUp()
{
  if (isPowerUp(_map->getCell(_posY, _posX + 1))) {
    _direction = Direction::RIGHT;
    return true;
  } else if (isPowerUp(_map->getCell(_posY - 1, _posY))) {
    _direction = Direction::DOWN;
    return true;
  } else if (isPowerUp(_map->getCell(_posY, _posY - 1))) {
    _direction = Direction::LEFT;
    return true;
  } else if (isPowerUp(_map->getCell(_posY + 1, _posY))) {
    _direction = Direction::UP;
    return true;
  }
  return false;
}
예제 #3
0
파일: Ia.cpp 프로젝트: simbaste/Bomberman
bool	Ia::getUp()
{
  if (_map->getCell(_posY + 1, _posX) == Tile::EMPTY ||
      _map->getCell(_posY + 1, _posX) == Tile::CHARACTER ||
      _map->getCell(_posY + 1, _posX) == Tile::INTEL ||
      isPowerUp(_map->getCell(_posY + 1, _posX)) == true ||
      _map->getCell(_posY + 1, _posX) == Tile::EXPLOSION)
    return true;
  if (decision == false)
    changeDir();
  return false;
}
예제 #4
0
파일: Ia.cpp 프로젝트: simbaste/Bomberman
Direction	Ia::lookPowerUp()
{
  for (unsigned int i = _posY; i < _map->getMap().size(); i++) {
    if (isPowerUp(_map->getCell(i, _posX))) {
      return Direction::UP;
    }
  }
  for (unsigned int i = _posY; i > 0; i--) {
    if (isPowerUp(_map->getCell(i, _posX))) {
      return Direction::DOWN;
    }
  }
  for (unsigned int i = _posX; i < _map->getMap()[0].size(); i++) {
    if (isPowerUp(_map->getCell(_posY, i))) {
      return Direction::RIGHT;
    }
  }
  for (unsigned int i = _posX; i > 0; i--) {
    if (isPowerUp(_map->getCell(_posY, i))) {
      return Direction::LEFT;
    }
  }
  return Direction::NOP;
}
예제 #5
0
파일: Pacman.cpp 프로젝트: pisc3s/Pacman
//Movement Function
void Pacman::move() {
	if (isPowerUp()) {
		setPowerUp(false);
	}

	//If there is next direction then check is there any obstacle
	//If it has no obstacle then it will become the current direction
	switch (NEXT_DIRECTION) {
	case UP:
		y -= VEL;
		if (!isObstacle()) {
			DIRECTION = NEXT_DIRECTION;
		}
		y += VEL;
		break;

	case RIGHT:
		x += VEL;
		if (!isObstacle()) {
			DIRECTION = NEXT_DIRECTION;
		}
		x -= VEL;
		break;

	case DOWN:
		y += VEL;
		if (!isObstacle()) {
			DIRECTION = NEXT_DIRECTION;
		}
		y -= VEL;
		break;

	case LEFT:
		x -= VEL;
		if (!isObstacle()) {
			DIRECTION = NEXT_DIRECTION;
		}
		x += VEL;
		break;
	}

	//Move to the direction set and with equivalent sprite animation
	switch (DIRECTION) {
	case UP:
		angle = 270;
		flip = SDL_FLIP_NONE;
		y -= VEL;
		if (isObstacle()) {
			y += VEL;
		}
		else {
			eat();
		}
		break;

	case RIGHT:
		angle = 0;
		flip = SDL_FLIP_NONE;
		x += VEL;
		if (isObstacle()) {
			x -= VEL;
		}
		else {
			eat();
		}
		break;

	case DOWN:
		angle = 90;
		flip = SDL_FLIP_NONE;
		y += VEL;
		if (isObstacle()) {
			y -= VEL;
		}
		else {
			eat();
		}
		break;

	case LEFT:
		flip = SDL_FLIP_HORIZONTAL;
		angle = 0;
		x -= VEL;
		if (isObstacle()) {
			x += VEL;
		}
		else {
			eat();
		}
		break;
	}
}