Пример #1
0
/**
 * Process movement for cardinal (90 degree) and ordinal (45 degree) directions
 * If we encounter an obstacle at 90 degrees, stop.
 * If we encounter an obstacle at 45 or 135 degrees, slide.
 */
bool MapCollision::move(float &x, float &y, float _step_x, float _step_y, int movement_type, int collide_type) {
	// when trying to slide against a bottom or right wall, step_x or step_y can become 0
	// this causes diag to become false, making this function return false
	// we try to catch such a scenario and return true early
	bool force_slide = (_step_x != 0 && _step_y != 0);

	while (_step_x != 0 || _step_y != 0) {

		float step_x = 0;
		if (_step_x > 0) {
			// find next interesting value, which is either the whole step, or the transition to the next tile
			step_x = std::min(ceilf(x) - x, _step_x);
			// if we are standing on the edge of a tile (ceilf(x) - x == 0), we need to look one tile ahead
			if (step_x <= MIN_TILE_GAP) step_x = std::min(1.f, _step_x);
		}
		else if (_step_x < 0) {
			step_x = std::max(floorf(x) - x, _step_x);
			if (step_x == 0) step_x = std::max(-1.f, _step_x);
		}

		float step_y = 0;
		if (_step_y > 0) {
			step_y = std::min(ceilf(y) - y, _step_y);
			if (step_y <= MIN_TILE_GAP) step_y = std::min(1.f, _step_y);
		}
		else if (_step_y < 0) {
			step_y = std::max(floorf(y) - y, _step_y);
			if (step_y == 0) step_y	= std::max(-1.f, _step_y);
		}

		_step_x -= step_x;
		_step_y -= step_y;

		if (!smallStep(x, y, step_x, step_y, movement_type, collide_type)) {
			if (force_slide) {
				if (!smallStepForcedSlideAlongGrid(x, y, step_x, step_y, movement_type, collide_type))
					return false;
			}
			else {
				if (!smallStepForcedSlide(x, y, step_x, step_y, movement_type, collide_type))
					return false;
			}
		}
	}
	return true;
}
Пример #2
0
void MiniMap::updateMiniMap( Game& game ){
    Map &m = game.map;

    if( imgMinimap.width() !=width() &&
        imgMinimap.height()!=height()  ) {
      int w = width(), h = height();
      imgMinimap = QImage( w, h, QImage::Format_RGB32 );
      imgFog     = QImage( w, h, QImage::Format_RGB32 );
      step = 0;
      updateBackground(m);
      }

    if( game.interactive().size() ){
      int countStp = std::min((int)game.interactive().size(), 100);
      for(int i=0; i<countStp; ++i){
        if( step >= (size_t)game.interactive().size() ){
          step = 0;
          surface = QPixmap::fromImage( imgMinimap );
          update();
          updateBackground(m);
          }

        if( game.interactive().size() )
          smallStep(game);
        ++step;
        }
      } else {
      if( step%2==0 ){
        surface = QPixmap::fromImage( imgMinimap );
        updateBackground(m);
        update();
        }

      ++step;
      }

    }