Esempio n. 1
0
/**
 * Handle jumping with given deviation.
 */
void Camera::jumpXY(int x, int y)
{
	int oldX = _mapOffset.x, oldY= _mapOffset.y;

	_mapOffset.x += x;
	_mapOffset.y += y;

	convertScreenToMap((_screenWidth / 2), (_visibleMapHeight / 2), &_center.x, &_center.y);
// if center goes out of map bounds, hold the scrolling
	if (_center.x > _mapsize_x -1 || _center.x < 0 || 
		_center.y > _mapsize_y -1  || _center.y < 0 )
	{
		for (int k=1; k<128; ++k) //try intermediate values
		{
			_mapOffset.x = oldX + x*k/128;
			_mapOffset.y = oldY + y*k/128;
			convertScreenToMap((_screenWidth / 2), (_visibleMapHeight / 2), &_center.x, &_center.y);
			if (_center.x > _mapsize_x -1 || _center.x < 0 || 
				_center.y > _mapsize_y -1  || _center.y < 0 )
			{
				//step back
				_mapOffset.x = oldX + x*(k-1)/128;
				_mapOffset.y = oldY + y*(k-1)/128;
				break;
			}
		}
	}
}
Esempio n. 2
0
/**
 * Handle scrolling with given deviation.
 */
void Camera::scrollXY(int x, int y, bool redraw)
{
	_mapOffset.x += x;
	_mapOffset.y += y;

	convertScreenToMap((_screenWidth / 2), (_screenHeight / 2), &_center.x, &_center.y);

	// if center goes out of map bounds, hold the scrolling (may need further tweaking)
	if (_center.x > _mapWidth - 1 || _center.y > _mapLength - 1 || _center.x < 0 || _center.y < 0)
	{
		_mapOffset.x -= x;
		_mapOffset.y -= y;
	}
	if (redraw) _map->draw();
}
Esempio n. 3
0
/**
 * Handle scrolling.
 */
void Camera::scroll()
{
	_mapOffset.x += _scrollX;
	_mapOffset.y += _scrollY;

	convertScreenToMap((_screenWidth / 2), (_screenHeight / 2), &_center.x, &_center.y);

	// if center goes out of map bounds, hold the scrolling (may need further tweaking)
	if (_center.x > _mapWidth - 1 || _center.y > _mapLength - 1 || _center.x < 0 || _center.y < 0)
	{
		_mapOffset.x -= _scrollX;
		_mapOffset.y -= _scrollY;
	}
	_map->draw();
}
Esempio n. 4
0
/**
 * Handle scrolling with given deviation.
 */
bool Camera::scrollXY(int x, int y, bool redraw)
{
	bool result = true;

	_mapOffset.x += x;
	_mapOffset.y += y;

	convertScreenToMap((_screenWidth / 2), (_visibleMapHeight / 2), &_center.x, &_center.y);
// if center goes out of map bounds, hold the scrolling
	if (_center.x > _mapsize_x -1 || _center.x < 0 || 
		_center.y > _mapsize_y -1  || _center.y < 0 )
	{
		_mapOffset.x -= x;
		_mapOffset.y -= y;
		result = false;
	}
	if (redraw) _map->draw();
	return result;
}
Esempio n. 5
0
/**
 * Handles scrolling with given deviation.
 * @param x X deviation.
 * @param y Y deviation.
 * @param redraw Redraw map or not.
 */
void Camera::scrollXY(int x, int y, bool redraw)
{
	_mapOffset.x += x;
	_mapOffset.y += y;

	do
	{
		convertScreenToMap((_screenWidth / 2), (_visibleMapHeight / 2), &_center.x, &_center.y);

		// Handling map bounds...
		// Ok, this is a prototype, it should be optimized.
		// Actually this should be calculated instead of slow-approximation.
		if (_center.x < 0)             { _mapOffset.x -= 1; _mapOffset.y -= 1; continue; }
		if (_center.x > _mapsize_x -1) { _mapOffset.x += 1; _mapOffset.y += 1; continue; }
		if (_center.y < 0)             { _mapOffset.x += 1; _mapOffset.y -= 1; continue; }
		if (_center.y > _mapsize_y -1) { _mapOffset.x -= 1; _mapOffset.y += 1; continue; }
		break;
	}
	while (true);

	_map->refreshSelectorPosition();
	if (redraw) _map->invalidate();
}
Esempio n. 6
0
/**
 * Handles jumping with given deviation.
 * @param x X deviation.
 * @param y Y deviation.
 */
void Camera::jumpXY(int x, int y)
{
	_mapOffset.x += x;
	_mapOffset.y += y;
	convertScreenToMap((_screenWidth / 2), (_visibleMapHeight / 2), &_center.x, &_center.y);
}