Beispiel #1
0
 SpriteFrame FontLetter::getSpriteFrame(const FontInfo& info) const
 {
     TextureRegion region(_region);
     region.offsetY = info.baseHeight-region.height-region.offsetY;
     region.offsetX = -region.offsetX;
     return SpriteFrame(_texture, region);
 }
Beispiel #2
0
void Spritesheet::parseFrames(Json::Value& rootElement)
{
   // Get the frames array in the spritesheet data
   Json::Value& framesElement = rootElement["frames"];
   numFrames = framesElement.size();
   
   // This spritesheet is well-formed only if the "frames" element is a non-empty array
   // (i.e. there are frames in the spritesheet)
   if(!framesElement.isArray() || numFrames <= 0)
   {
      DEBUG("No frames found in spritesheet.");
      T_T("Empty (invalid) spritesheet constructed.");
   }

   DEBUG("Loading frames...");
   frameList = new SpriteFrame[numFrames];
   for(int i = 0; i < numFrames; ++i)
   {
      Json::Value& currFrame = framesElement[i];
      
      // Get the current frame name
      std::string frameName = currFrame["name"].asString();
      if(frameName == UNTITLED_LINE)
      {
         // Skip untitled frames.
         continue;
      }
      
      // Make sure this frame name has not already been used in this file
      if(frameIndices.find(frameName) != frameIndices.end())
      {
         DEBUG("Duplicated name %s in spritesheet.", frameName.c_str());
         T_T("Parse error reading spritesheet.");
      }
      else
      {
         DEBUG("Adding frame %s...", frameName.c_str());
      }

      // Get the frame rectangle coordinates
      int left = currFrame["left"].asInt();
      int top = currFrame["top"].asInt();
      int right = currFrame["right"].asInt();
      int bottom = currFrame["bottom"].asInt();

      frameList[i] = SpriteFrame(left, top, right, bottom);
      DEBUG("Frame %s loaded in with coordinates %d, %d, %d, %d",
            frameName.c_str(), left, top, right, bottom);

      frameIndices[frameName] = i;
   }

   DEBUG("Frames loaded.");
}
Beispiel #3
0
//---------------------------------------------------------------------------- 
// Nome: HandleBrickCollsion(void)
// Desc: Trata colisão do tiro com os bricks do cenário
// Pams: nenhum
//---------------------------------------------------------------------------- 
void CShot::HandleBrickCollsion(void)
{
  CNGLLayer *p_LayLevel = p_SprShot->pr_Layer;
	//pega o tamanho do brick 
	int iBrickWidth = (int)p_LayLevel->BrickSize.fx;
	int iBrickHeight = (int)p_LayLevel->BrickSize.fy;

	//pega o quadro do tiro
	CNGLFrame SpriteFrame((int)p_SprShot->Position.fx,
												(int)p_SprShot->Position.fy,
                        (int)(p_SprShot->Position.fx + p_SprShot->pr_Image->FrameSize.fx),
												(int)(p_SprShot->Position.fy + p_SprShot->pr_Image->FrameSize.fy));

	//pega os indices dos bricks sobre os quais a extremidades do sprite estão
	int iX    = SpriteFrame.iLeft/iBrickWidth;
	int iY	  = SpriteFrame.iTop/iBrickHeight;
	int iMaxX = (SpriteFrame.iRight/iBrickWidth)+1;
	int iMaxY = (SpriteFrame.iBottom/iBrickHeight)+1;

	//testa a validade dos indices
  if(iX >= 0 && iY  >= 0)
	{
		int index = 0;
		//varre os bricks sobre os quais os sprite está
		for(iX = SpriteFrame.iLeft/iBrickWidth; iX <= iMaxX; iX++)
		{
			for(iY	= SpriteFrame.iTop/iBrickHeight; iY <= iMaxY; iY++)
			{
				//pega o indice no vetor da layer do brick
				index  = (iX < (int)p_LayLevel->NumBricks.fx)? iX : iX - (int)p_LayLevel->NumBricks.fx;
				index += (iY < (int)p_LayLevel->NumBricks.fy)? iY*(int)p_LayLevel->NumBricks.fx : (iY - (int)p_LayLevel->NumBricks.fy)*(int)p_LayLevel->NumBricks.fx;

				//se o brick existe
				if(p_LayLevel->p_Bricks[index])
				{
					//pega o frame do brick
					CNGLFrame BrickFrame;
					BrickFrame.iLeft	 = iX*iBrickWidth;
					BrickFrame.iRight  = (iX+1)*iBrickWidth;
					BrickFrame.iTop	   = iY*iBrickHeight;
					BrickFrame.iBottom = (iY+1)*iBrickHeight;

					//se os quadros do brick e o do sprite colidem
          if(BrickFrame.Collide(SpriteFrame))
					{
						ChangeState(SS_EXPLODE);
					}//if
				}//if
			}//for
		}//for
	}
}