Пример #1
0
/// Get the position of a grid point
static void getGridPos(Vector3i *result, int x, int y, bool center, bool water)
{
	if (center)
	{
		Vector3i a,b,c,d;
		getGridPos(&a, x  , y  , false, water);
		getGridPos(&b, x+1, y  , false, water);
		getGridPos(&c, x  , y+1, false, water);
		getGridPos(&d, x+1, y+1, false, water);
		averagePos(result, &a, &b, &c, &d);
		return;
	}
	result->x = world_coord(x);
	result->z = world_coord(-y);
	
	if (x <= 0 || y <= 0 || x >= mapWidth || y >= mapHeight)
	{
		result->y = 0;
	}
	else
	{
		result->y = map_TileHeight(x, y);
		if (water)
		{
			result->y = map_WaterHeight(x, y);
		}
	}
}
Пример #2
0
void GameWidget::mouseReleaseEvent(QMouseEvent *event)
{
    if(selection.size() < 2 or !selection.contains(getGridPos(event->x(), event->y())))
        return; //nothing selected or mouse pointer not in selection

    //backup
    oldscore = score;
    for(int x = 0; x < grid_size; x++)
        for(int y = 0; y < grid_size; y++)
            old_grid[x][y] = grid[x][y];

    foreach(Box pos, selection) {
        if(use_animations)
            old_grid[pos.x][pos.y].scale_step = num_scale_steps-1;

        grid[pos.x][pos.y] = Bubble(); //remove bubbles
    }

    score += selection.size()*selection.size();
    selection.clear();

    emit enableUndo(true);
    emit activity();

    compressBubbles();

#ifndef Q_WS_MAEMO_5
    mouseMoveEvent(event); //draw selection if there's a new set of connected bubbles
#endif
}
void TowerSelectLayer::showFor_BuildSpellPos()
{
	//Point pos = Point(msg.at("x").asFloat(), msg.at("y").asFloat());
	if (m_state != ETowerSelectLayerState::ShowFor_BuildSpellPos)
	{
		m_state = ETowerSelectLayerState::ShowFor_BuildSpellPos;
		//m_gridPos = (GridPos*)msg.at("GridPos").asInt();
		//selectLayer->setPosition(pos);
		this->hideAllButton();

		const int* around = m_gridPos->getAroundGridPosID();
		auto gamemap = GameMap::getInstance();
		for (int i = 0; i < 8; i++)
			if (around[i] != -1 && gamemap->getGridPos(around[i])->getType() == EGridPosType::GridPosType_Empty)
			{
				a_bt[i]->setSpriteFrame(StringUtils::format("TowerSelect_SpellPos_%03d.png", i));
				a_number[i]->setVisible(true);
				a_bg[i]->setVisible(true);
				a_layer[i]->setVisible(true);
			}

		//Color3B color = Color3B(msg.at("color_r").asInt(), msg.at("color_g").asInt(), msg.at("color_b").asInt());
		//bg_circle->setColor(color);
		this->show();
	}
}
Пример #4
0
/**
 * Set the terrain and water geometry for the specified sector
 */
static void setSectorGeometry(int x, int y,
                             RenderVertex *geometry, RenderVertex *water,
                             int *geometrySize, int *waterSize)
{
	Vector3i pos;
	int i,j;
	for (i = 0; i < sectorSize+1; i++)
	{
		for (j = 0; j < sectorSize+1; j++)
		{
			// set up geometry
			getGridPos(&pos, i+x*sectorSize, j+y*sectorSize, false, false);
			geometry[*geometrySize].x = pos.x;
			geometry[*geometrySize].y = pos.y;
			geometry[*geometrySize].z = pos.z;
			(*geometrySize)++;

			getGridPos(&pos, i+x*sectorSize, j+y*sectorSize, true, false);
			geometry[*geometrySize].x = pos.x;
			geometry[*geometrySize].y = pos.y;
			geometry[*geometrySize].z = pos.z;
			(*geometrySize)++;
			
			getGridPos(&pos, i+x*sectorSize, j+y*sectorSize, false, true);
			water[*waterSize].x = pos.x;
			water[*waterSize].y = pos.y;
			water[*waterSize].z = pos.z;
			(*waterSize)++;

			getGridPos(&pos, i+x*sectorSize, j+y*sectorSize, true, true);
			water[*waterSize].x = pos.x;
			water[*waterSize].y = pos.y;
			water[*waterSize].z = pos.z;
			(*waterSize)++;
		}
	}
}
Пример #5
0
bool TerrainBlock::castRay(const Point3F &start, const Point3F &end, RayInfo *info)
{
   if( castRayI(start, end, info, false) )
   {
      // Set intersection point.

      info->setContactPoint( start, end );

      // Set material at contact point.

      Point2I gridPos = getGridPos( info->point );
      info->material = getMaterialInst( gridPos.x & BlockMask, gridPos.y & BlockMask );

      return true;
   }
   else
      return false;
}
Пример #6
0
void GameWidget::mouseMoveEvent(QMouseEvent *event)
{
    if(event->buttons())
        return; //don't change selection while mouse button is down

    const Box hovered = getGridPos(event->x(), event->y());
    if(selection.contains(hovered))
        return; //cursor in old selection, nothing new

    selection.clear();
    if(hovered.x != -1) {
        getConnectedBubbles(hovered, selection);

        if(selection.size() == 1)
            selection.clear(); //don't select single bubbles
    }
    update();
}
Пример #7
0
bool TerrainBlock::castRay(const Point3F &start, const Point3F &end, RayInfo *info)
{
	PROFILE_SCOPE( TerrainBlock_castRay );

   if ( !castRayI(start, end, info, false) )
      return false;
      
   // Set intersection point.
   info->setContactPoint( start, end );
   getTransform().mulP( info->point );    // transform to world coordinates for getGridPos

   // Set material at contact point.
   Point2I gridPos = getGridPos( info->point );
   U8 layer = mFile->getLayerIndex( gridPos.x, gridPos.y );
   info->material = mFile->getMaterialMapping( layer );

   return true;
}
Пример #8
0
/**
 * Set the decals for a sector. This takes care of both the geometry and the texture part.
 */
static void setSectorDecals(int x, int y,
                            DecalVertex *decaldata,
                            int *decalSize)
{
	Vector3i pos;
	Vector2f uv[2][2], center;
	int a,b;
	int i,j;

	for (i = x*sectorSize; i < x*sectorSize+sectorSize; i++)
	{
		for (j = y*sectorSize; j < y*sectorSize+sectorSize; j++)
		{
			if (i < 0 || j < 0 || i >= mapWidth || j >= mapHeight)
			{
				continue;
			}
			if (TILE_HAS_DECAL(mapTile(i, j)))
			{
				getTileTexCoords(*uv, mapTile(i,j)->texture);
				averageUV(&center, *uv);
				
				getGridPos(&pos, i, j, true, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = center.x;
				decaldata[*decalSize].v = center.y;
				(*decalSize)++;
				a = 0; b = 1;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;
				a = 0; b = 0;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;
				
				getGridPos(&pos, i, j, true, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = center.x;
				decaldata[*decalSize].v = center.y;
				(*decalSize)++;
				a = 1; b = 1;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;
				a = 0; b = 1;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;

				getGridPos(&pos, i, j, true, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = center.x;
				decaldata[*decalSize].v = center.y;
				(*decalSize)++;
				a = 1; b = 0;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;
				a = 1; b = 1;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;

				getGridPos(&pos, i, j, true, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = center.x;
				decaldata[*decalSize].v = center.y;
				(*decalSize)++;
				a = 0; b = 0;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;
				a = 1; b = 0;
				getGridPos(&pos, i+a, j+b, false, false);
				decaldata[*decalSize].x = pos.x;
				decaldata[*decalSize].y = pos.y;
				decaldata[*decalSize].z = pos.z;
				decaldata[*decalSize].u = uv[a][b].x;
				decaldata[*decalSize].v = uv[a][b].y;
				(*decalSize)++;
			}
		}
	}
}