Пример #1
0
inline void	SetCam(ID::Drawable* d, int x, int y)
{
	Cam*	c;
	int	offsetX;
	int	offsetY;
	int16_t	posX;
	int16_t	posY;
	int	caseX;
	int	caseY;

	c = Cam::GetInstance();
	d->GetOffset(&offsetX, &offsetY);
	d->GetPos(&posX, &posY);
	caseX = c->GetMapWidth() * (x - offsetX - posX) / d->GetWidth();
	caseY = c->GetMapHeight() * (y - offsetY - posY) / d->GetHeight();
	c->SetCam(caseX, caseY);
}
Пример #2
0
int	Map_Drawable::RefreshToSurface(ID::Surface* s,
				       int x, int y)
{
	Game*					g;
	Cam*					c;
	Map*					m;
	Light_Drawable*				cases;
	uint32_t				i;
//	uint32_t				indexSaver;
	uint32_t				tmpSaver;
	std::list<Unit*>::iterator		itU;
	std::list<Unit*>::iterator		endU;
	int					xMin;
	int					yMin;
	int					xMax;
	int					yMax;
	int					offsetCamX;
	int					offsetCamY;
	ID::Draw_Geometry_Circle*		focus;
	double					xU;
	double					yU;
	bool					selected;

	g = Game::GetInstance();
	c = Cam::GetInstance();
	m = Map::GetInstance();
	focus = ID::Draw_Geometry_Circle::GetInstance();

	if (this->__RefreshGrounds(UNDER_BACKGROUND, ON_BACKGROUND, s, x, y) == -1)
		return -1;

	cases = c->GetCases();
	offsetCamX = c->GetOffsetX();
	offsetCamY = c->GetOffsetY();
	xMax = c->GetCameraWidth() / CASE_SIDE_PIXELS;
	yMax = c->GetCameraHeight() / CASE_SIDE_PIXELS;
//	indexSaver = ((c->GetY() / CASE_SIDE_PIXELS) -
//		      (c->GetCameraHeightRayon() / CASE_SIDE_PIXELS)) *
//		     (c->GetMapWidth() / CASE_SIDE_PIXELS) +
//		     (c->GetX() / CASE_SIDE_PIXELS - c->GetCameraWidthRayon() / CASE_SIDE_PIXELS);
	tmpSaver = g->currentTick;
	yMin = 0;
	while (yMin < yMax)
	{
		xMin = 0;
		i = ((yMin + (c->GetOffsetY() / CASE_SIDE_PIXELS)) *
		     (c->GetMapWidth() / CASE_SIDE_PIXELS)) +
		    (c->GetOffsetX() / CASE_SIDE_PIXELS);
		while (xMin < xMax)
		{
			itU = m->cases[i].units.begin();
			endU = m->cases[i].units.end();
			while (itU != endU)
			{
				if (((*itU)->GetModel()->GetType() == TYPE_GROUND ||
				     (*itU)->GetModel()->GetType() == 3) &&
				    (*itU)->GetUpdateSaver() != tmpSaver)
				{
					(*itU)->SetUpdateSaver(tmpSaver);
					(*itU)->GetPositionXY(&xU, &yU);
					selected = (*itU)->GetTickSelection() == g->lastSelection;
					focus->Draw(s,
						    xU * CASE_SIDE_PIXELS - offsetCamX,
						    yU * CASE_SIDE_PIXELS - offsetCamY,
						    (*itU)->GetModel()->GetSize(),
						    selected,
						    &(m->_colorsPalette[(*itU)->GetPlayer()->GetID()]));
				}
				++itU;
			}
			++xMin;
			++i;
		}
		++yMin;
	}

	if (this->__RefreshGrounds(MIDDLEGROUND, MIDDLEGROUND, s, x, y) == -1)
		return -1;

	tmpSaver = g->currentTick + 1;
//	i = indexSaver;
	yMin = 0;
//	std::cout << "- - - - - - - - \n";
	while (yMin < yMax)
	{
		xMin = 0;
		i = ((yMin + (c->GetOffsetY() / CASE_SIDE_PIXELS)) *
		     (c->GetMapWidth() / CASE_SIDE_PIXELS)) +
		    (c->GetOffsetX() / CASE_SIDE_PIXELS);
		while (xMin < xMax)
		{
			itU = m->cases[i].units.begin();
			endU = m->cases[i].units.end();
//			std::cout << i << "	";
			while (itU != endU)
			{
				if (((*itU)->GetModel()->GetType() == TYPE_AIR ||
				     (*itU)->GetModel()->GetType() == 4) &&
				    (*itU)->GetUpdateSaver() != tmpSaver)
				{
//					std::cout << "|";
					(*itU)->SetUpdateSaver(tmpSaver);
					(*itU)->GetPositionXY(&xU, &yU);
					selected = ((*itU)->GetTickSelection() == g->lastSelection);
					focus->Draw(s,
						    xU * CASE_SIDE_PIXELS - offsetCamX,
						    yU * CASE_SIDE_PIXELS - offsetCamY,
						    (*itU)->GetModel()->GetSize(),
						    selected,
						    &(m->_colorsPalette[(*itU)->GetPlayer()->GetID()]));
				}
				++itU;
			}
			++xMin;
			++i;
		}
//		std::cout << "\n";
		++yMin;
	}

	if (this->__RefreshGrounds(HIGHGROUND, HIGHGROUND, s, x, y) == -1)
		return -1;

	tmpSaver = g->currentTick - 1;
	//i = indexSaver;
	yMin = 0;
	while (yMin < yMax)
	{
		i = ((yMin + (c->GetOffsetY() / CASE_SIDE_PIXELS)) *
		     (c->GetMapWidth() / CASE_SIDE_PIXELS)) +
		    (c->GetOffsetX() / CASE_SIDE_PIXELS);
		xMin = 0;
		while (xMin < xMax)
		{
			itU = m->cases[i].units.begin();
			endU = m->cases[i].units.end();
			while (itU != endU)
			{
				if ((*itU)->GetUpdateSaver() != tmpSaver)
				{
					(*itU)->SetUpdateSaver(tmpSaver);
					(*itU)->GetPositionXY(&xU, &yU);
					this->__RefreshBars(s,
							    xU * CASE_SIDE_PIXELS - offsetCamX - (*itU)->GetModel()->GetSize(),
							    yU * CASE_SIDE_PIXELS - offsetCamY - (*itU)->GetModel()->GetSize() - 5,
							    (*itU)->GetModel()->GetSize(),
							    (*itU)->GetHP(),
							    (*itU)->GetModel()->GetHPMax());
				}
				++itU;
			}
			++xMin;
			++i;
		}
		++yMin;
	}

	if (this->__RefreshGrounds(FOREGROUND, FOREGROUND, s, x, y) == -1)
		return -1;

	this->SetInvalidate(false);
	return 0;
}