Exemple #1
0
void CGeneral::AnimSelfDrawn(const CTile &t)
{
   EraseArea(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);
   UpdateScreen(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);
   int i;
   SDL_Rect dstrect;

   PlaySound(SND_FLASH);
   for (i = 0; i < 12; i++) {
      EraseArea(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);
      EraseArea(dstrect.x, dstrect.y, dstrect.w, 30);

      dstrect.x = 245;
      dstrect.y = 235;
      dstrect.w = m_imgFlash1->w;
      dstrect.h = m_imgFlash1->h;

      SDL_BlitSurface(m_imgFlash1, NULL, gpScreen, &dstrect);
      DrawTile(t, 280, 255);
      UpdateScreen(20, 235, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 235);

      UTIL_Delay(50);

      EraseArea(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);
      EraseArea(dstrect.x, dstrect.y, dstrect.w, 30);

      dstrect.w = m_imgFlash2->w;
      dstrect.h = m_imgFlash2->h;

      SDL_BlitSurface(m_imgFlash2, NULL, gpScreen, &dstrect);
      DrawTile(t, 280, 255);
      UpdateScreen(20, 235, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 235);
      UTIL_Delay(50);
   }

   UTIL_Delay(20);
   EraseArea(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);
   EraseArea(dstrect.x, dstrect.y, dstrect.w, 30);

   dstrect.w = m_imgFlash1->w;
   dstrect.h = m_imgFlash1->h;

   SDL_BlitSurface(m_imgFlash1, NULL, gpScreen, &dstrect);
   DrawTile(t, 280, 255);
   DrawUTF8Text(msg("out_selfdrawn"), 215, 265, 2, 255, 255, 255);
   UpdateScreen(20, 205, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 205);
   UTIL_Delay(1000);
   EraseArea(20, 265, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 265);
   EraseArea(dstrect.x, dstrect.y, dstrect.w, 30);
   UpdateScreen(20, 205, TILE_WIDTH * 10, 303 + TILE_HEIGHT_SHOWN - 205);
}
Exemple #2
0
//********************************************************************************
bool CExplosionEffect::Draw(SDL_Surface* pDestSurface)
//Draw the effect.
//
//Returns:
//True if effect should continue, or false if effect is done.
{
	const UINT dwTimeElapsed = TimeElapsed();
	if (dwTimeElapsed >= this->dwDuration)
		return false; //Effect is done.

	if (!pDestSurface) pDestSurface = GetDestSurface();

	//Draw shrinking explosion.
	const float fPercent = (this->dwDuration - dwTimeElapsed) / (float)this->dwDuration;
	ASSERT(fPercent >= 0.0);
	ASSERT(fPercent <= 1.0);
	UINT wTile = TI_EXPLOSION_1;
	if (fPercent < 0.30)
		wTile = TI_EXPLOSION_4;
	else if (fPercent < 0.55)
		wTile = TI_EXPLOSION_3;
	else if (fPercent < 0.80)
		wTile = TI_EXPLOSION_2;

	DrawTile(wTile, pDestSurface);

	//Continue effect.
	return true;
}
Exemple #3
0
void CMapView::DrawMegaTile(CDC* pDC, int x, int y)
{
    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    int r = y * pDoc->GetWidth() + x;
    CTile Tile = pDoc->GetTile(r);

    if (m_ViewMode == VIEW_MODE_TILES)
    {
        for (int ye = 0; ye < 4; ye++)
        {
            for (int xe = 0; xe < 4; xe++)
            {
                DrawTile(pDC, x,y,xe,ye, Tile);
            }
        }
    }
    else
    {
        ASSERT(m_ViewMode == VIEW_MODE_ELEVATION);

        BYTE v = (BYTE)(Tile.Elevation);
        v = (BYTE)min(255, v*5); // make difference in color more noticable
        pDC->FillSolidRect(x*40, y*40, 40,40, RGB(v,v,v));
    }
}
void BuildGameWorld()
{
	HRESULT result;
	int x, y;
	LPDIRECT3DSURFACE9 tiles;

	//load the bitmap image containing all the tiles
	tiles = LoadSurface("groundtiles.bmp");

	//create the scrolling game world bitmap
	result = d3ddev->CreateOffscreenPlainSurface(
		GAMEWORLDWIDTH,         //width of the surface
		GAMEWORLDHEIGHT,        //height of the surface
		D3DFMT_X8R8G8B8,		
		D3DPOOL_DEFAULT,		
		&gameworld,             //pointer to the surface
		NULL);

	if (result != D3D_OK)
	{
		MessageBox(NULL,"Error creating working surface!","Error",0);
		return;
	}

	//fill the gameworld bitmap with tiles
	for (y=0; y < MAPHEIGHT; y++)
		for (x=0; x < MAPWIDTH; x++)
			DrawTile(tiles, MAPDATA[y * MAPWIDTH + x], 64, 64, 16, 
			gameworld, x * 64, y * 64);

	//now the tiles bitmap is no longer needed
	tiles->Release();
}
Exemple #5
0
int TerrainSet::Load( MemBuffer &file, const char *setname ) {
  int rc = -1;

  if ( file.Read32() == FID_TERRAINSET ) {
    num_tiles = file.Read16();

    for ( int i = 0; i < 10; ++i )
      classid[i] = file.Read16();

    if ( !LoadTerrainTypes( file ) && !TileSet::Load( file, setname ) )
      // create the fog surface. This is kept separate from the tiles
      // surface so that we don't need to modify the alpha value each
      // time we want fog
      fog.Create( TileWidth(), TileHeight(), 16, SDL_SWSURFACE );
      fog.SetAlpha( FOG_ALPHA, SDL_SRCALPHA );
      fog.SetColorKey( Color(CF_COLOR_WHITE) );
      fog.DisplayFormat();
      fog.Flood( Color(CF_COLOR_WHITE) );
      DrawTile( IMG_FOG, &fog, 0, 0, fog );

      rc = 0;
  }

  return rc;
}
Exemple #6
0
static void
RefreshWindow(void)
{
	int xpos, ypos;

	GrSetGCForeground(gc1, WHITE);
	GrSetGCBackground(gc1, RED);

	/* draw the buttons */
	GrRect(buttons, gc1, 0, 0, (calc_width - 12)/2, 34);
	GrRect(buttons, gc1, (calc_width - 8)/2, 0, (calc_width - 12)/2, 34);

#if 0	/* for when center align text works */
	GrText(buttons, gc1, (calc_width - 10)/4, 22, "Again", 5, 0);
	GrText(buttons, gc1, (calc_width - 10)*3/4, 22, "Quit", 4, 0);
#else
	GrText(buttons, gc1, 5, 22, "Again", 5, 0);
	GrText(buttons, gc1, (calc_width / 2) + 5, 22, "Quit", 4, 0);
#endif
	
	/* draw the tiles */
	for (ypos=0; ypos< HEIGHT_IN_TILES; ypos++){
		for (xpos=0; xpos< WIDTH_IN_TILES; xpos++){
			DrawTile(xpos, ypos);
		}
	}
}
Exemple #7
0
void CGeneral::DrawTiles(const CTile t[], int num, int x, int y, int dir, int size)
{
   int i;

   if (dir == COMPUTER_SHOWN) {
      // Draw computer's tiles in reverse order
      for (i = num - 1; i >= 0; i--) {
         DrawTile(t[i], (int)(x + (num - i - 1) * TILE_WIDTH * (size ? 1 : 0.7)),
            y, dir, size);
      }
   } else {
      // Otherwise draw in normal order
      for (i = 0; i < num; i++) {
         DrawTile(t[i], (int)(x + i * TILE_WIDTH * (size ? 1 : 0.7)), y, dir, size);
      }
   }
}
Exemple #8
0
void cEdiPaint::DrawBrushAt( Brush* brush, int x, int y, float zoom, BOOL anim )
{
	if(brush==NULL) return;
	int idx = TileFind(brush->tile);
	// if(idx==-1) return;

	iRect map = brush->map;
	int mw = static_cast<int>(brush->mapWith());
	int mh = static_cast<int>(brush->mapHeight());
	float ms = brush->mapScale();
	if( mw==0 || mh==0 ) return;

	fRect oldclip = R9_GetClipping();
	fRect newclip( (float)x, (float)y, (float)x+zoom*brush->size.x, (float)y+zoom*brush->size.y );
	R9_AddClipping(newclip);
	if(!R9_IsClipping()) { R9_SetClipping(oldclip); return; } // fully clipped

	if(idx==-1) // no tile
	{
		dword color = brush->color & 0xffff40ff;
		R9_DrawLine( fV2(newclip.p1.x,newclip.p1.y),		fV2(newclip.p2.x-1,newclip.p1.y),	color );
		R9_DrawLine( fV2(newclip.p2.x-1,newclip.p1.y),		fV2(newclip.p2.x-1,newclip.p2.y-1),	color );
		R9_DrawLine( fV2(newclip.p2.x-1,newclip.p2.y-1),	fV2(newclip.p1.x,newclip.p2.y-1),	color );
		R9_DrawLine( fV2(newclip.p1.x,newclip.p2.y-1),		fV2(newclip.p1.x,newclip.p1.y),		color );
		R9_DrawLine( fV2(newclip.p1.x,newclip.p1.y),		fV2(newclip.p2.x-1,newclip.p2.y-1),	color );
		R9_DrawLine( fV2(newclip.p2.x-1,newclip.p1.y),		fV2(newclip.p1.x,newclip.p2.y-1),	color );
		R9_SetClipping(oldclip);
		return;
	}

	int cx = (brush->size.x+mw-1) / mw;
	int cy = (brush->size.y+mh-1) / mh;


	int xt=x;
	for(int i=0;i<cy;i++)
	{
		x = xt;
		for(int j=0;j<cx;j++)
		{
			DrawTile( idx, x, y, map, brush->color, brush->flip, brush->frame, brush->shader, zoom*ms );
			x+=(int)(zoom*mw);
		}
		y+=(int)(zoom*mh);
	}

	if(m_brushrect)
	{
		dword color = 0xa04040ff;
		R9_DrawLine( fV2(newclip.p1.x,newclip.p1.y),		fV2(newclip.p2.x-1,newclip.p1.y),	color );
		R9_DrawLine( fV2(newclip.p2.x-1,newclip.p1.y),		fV2(newclip.p2.x-1,newclip.p2.y-1),	color );
		R9_DrawLine( fV2(newclip.p2.x-1,newclip.p2.y-1),	fV2(newclip.p1.x,newclip.p2.y-1),	color );
		R9_DrawLine( fV2(newclip.p1.x,newclip.p2.y-1),		fV2(newclip.p1.x,newclip.p1.y),		color );
	}

	R9_SetClipping(oldclip);
}
Exemple #9
0
///////////////////
// Draw the city
void CCity::Draw(CCamera *cCamera)
{
	// Just draw all the tiles
	tile_t *t = tTiles;
	int x,y;

	for(y=0;y<iHeight;y++)
		for(x=0;x<iWidth;x++)
			DrawTile(t++);
	
}
Exemple #10
0
//---------------------------------------------------------------------------------
// Draws a 3x3 side of the rubiks cube. as with DrawTile, assumes that all rotation
// has already been performed.
//---------------------------------------------------------------------------------
void RubiksCube::DrawLine(RubikLine line, int32 x, int32 y, int32 z, int32 size) {
//---------------------------------------------------------------------------------
	int color; // generate an int to signify tile colour (see enum RC_Color)
	glBegin(GL_QUADS); //start drawin squares
	for(int i=0; i<3; i++)
	{
		color = line.tile[i].color; //get this tile's colour
		DrawTile(color, x, y + mulf32(inttof32(i),size), z, size, false); // draw the tile at (i,j)
	}
	glEnd(); // stop drawin squares

}
Exemple #11
0
    void Draw()
    {
        DrawBegin();

        // Draw the background TODO: Fix glitches over the edge of the level?
        for (int x=0;x<=(320/16);x++)
        {
            for (int y=0;y<=(240/16);y++)
            {
                DrawTile(x*16-(xscroll/4)%16,y*16-(yscroll/4)%16,
                        (x+1)*16-(xscroll/4)%16,(y+1)*16-(yscroll/4)%16,17);
            }
        }

        // Draw each tile plane
        for (IPlane i = Planes.begin(); i != Planes.end(); i++) (*i)->Draw(-xscroll,-yscroll,rsb);

        // Draw each plumber
        for (IMover i = Movers.begin(); i != Movers.end(); i++) (*i)->Draw(-xscroll,-yscroll);

        // Draw each fallers
        for (IFaller i = Fallers.begin(); i != Fallers.end(); i++) (*i)->Draw(-xscroll,-yscroll);
        
        // Diagnostic information HUD
        if (PBACK->jumping)
          DrawTile(0,240-16,16,240,484);

        if (PBACK->jumpthrust>0)
          DrawTile(16,240-16,32,240,4*32+19);

        if (diagCollision)
          DrawTile(32,240-16,48,240,64*32+9);

        // Relinquish the GL
        DrawEnd();

        static unsigned int errstore=0;
        glError("Game::Draw()", &errstore);
    }
Exemple #12
0
	void CPlot::RefreshPlot(CDC* pDC)
	{	
		// 更新布局
		RefreshLayout();
		// 绘制背景
		DrawBackground(pDC);
		// 绘制坐标轴
		DrawAxises(pDC);
		// 绘制网格
		DrawGrids(pDC);
		// 绘制图例
		DrawLegend(pDC,m_rectLegend);
		// 绘制标题
		DrawTile(pDC,m_rectTitle);
		// 绘制曲线
		DrawLines(pDC);
	}
Exemple #13
0
void XMapLayerImage::Draw( void )
{
    switch( m_DrawType )
    {
    case xNORMAL:
        DrawNormal();
        break;
    case xSTRETCH:
        DrawStretch();
        break;
    case xTILE:
        DrawTile();
        break;
    default:
        XBREAK(1);
    }
}
void RenderInfinitePlane(const int tileSize, int nTilesRow, const float y0, const float cam_x, const float cam_z)
{
	int x, z;
	int x0 = int(cam_x / tileSize);
	int z0 = int(cam_z / tileSize);
	x0 *= tileSize;
	z0 *= tileSize;
	nTilesRow = int(nTilesRow * 0.5);

	for(x = x0 - nTilesRow * tileSize; x < x0 + nTilesRow * tileSize; x += tileSize)
	{
		for(z = z0 - nTilesRow * tileSize; z < z0 + nTilesRow * tileSize; z += tileSize)
		{
			DrawTile(float(x), y0, float(z), float(tileSize));
		}
	}
}
Exemple #15
0
//---------------------------------------------------------------------------------
// Draws a 3x3 side of the rubiks cube. as with DrawTile, assumes that all rotation
// has already been performed.
//---------------------------------------------------------------------------------
void RubiksCube::DrawSide(RubikSide side, int sideNum, int32 x, int32 y, int32 z, int32 size, bool picking) {
//---------------------------------------------------------------------------------
	int color; // generate an int to signify tile colour (see enum RC_Color)
	glBegin(GL_QUADS); //start drawin squares
	for(int i=0; i<3; i++)
	{
		for(int j=0; j<3; j++)
		{
			color = side.tile[i][j].color; //get this tile's colour
			if(picking) startCheck(); // if picking...
			DrawTile(	color,
						x + mulf32(inttof32(i),divf32(size,inttof32(3))),
						y + mulf32(inttof32(j),divf32(size,inttof32(3))),
						z,
						divf32(size,inttof32(3)),
						picking); // draw the tile at (i,j)
			if(picking) endCheck(sideNum, i, j); // if picking...
		}
	}
	glEnd(); // stop drawin squares

}
Exemple #16
0
void Console::Render()
{
    if( !IsEnabled() )
        return;

    //TODO: Clean up this nonsense

    static float sTestAlpha = 0.75;
    Vec2i winDimensions;
    winDimensions.X = theCamera.GetWindowWidth();
    winDimensions.Y = theCamera.GetWindowHeight();

    static float fScreenHeightPct = 0.5f;
    static int sTextBoxBorder = winDimensions.Y/192;
    static int sTextBoxHeight = winDimensions.Y/32 + sTextBoxBorder;

    int consoleBGHeight = (int)(fScreenHeightPct * (float)winDimensions.Y);

    int consoleBGBottomY = consoleBGHeight;

    glColor4f(0.0f,0.0f,0.0f,sTestAlpha);
    DrawTile(0, consoleBGBottomY, winDimensions.X, consoleBGHeight );

    //Draw log
    static int sLogXPos = sTextBoxBorder;
    int logYPos = consoleBGBottomY - sTextBoxBorder;
    if (_buffer.size() > 0)
    {
        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        StringList::iterator it = _buffer.end();
        while (it != _buffer.begin())
        {
            it--;
            /* Vector2 textSize = */ DrawGameText( *it, "ConsoleSmall", sLogXPos, logYPos );
            logYPos -= (int)_lineHeight + sTextBoxBorder;
        }
    }

    //Draw text box border
    glColor4f(0.0f,1.0f,0.0f,sTestAlpha/2.0f);
    int textBoxBottomY = consoleBGBottomY + sTextBoxHeight;
    DrawTile(0, textBoxBottomY, winDimensions.X, sTextBoxHeight );

    //Draw text box

    int textBoxHeight = sTextBoxHeight - sTextBoxBorder;
    int textBoxWidth = winDimensions.X - sTextBoxBorder;
    int textBoxXPos = (winDimensions.X - textBoxWidth)/2;
    int textBoxYPos = textBoxBottomY - (sTextBoxHeight-textBoxHeight)/2;

    glColor4f(0.0f,0.0f,0.0f,sTestAlpha);
    DrawTile(textBoxXPos, textBoxYPos, textBoxWidth, textBoxHeight);

    textBoxXPos += sTextBoxBorder;
    textBoxYPos -= sTextBoxBorder + (sTextBoxBorder/2);

    glColor4f(0.0f,1.0f,0.0f,1.0f);
    String printInput = _prompt;
    printInput += _currentInput.substr(0, _cursorPos);

    if(_bCursorDisp)
    {
        printInput += "|";
    }
    else
    {
        printInput += " ";
    }

    if (_cursorPos < _currentInput.length())
    {
        printInput += _currentInput.substr(_cursorPos, _currentInput.length());
    }

    DrawGameText(printInput.c_str(), "ConsoleSmall", textBoxXPos, textBoxYPos);

    //Draw autocomplete
    static int sMaxAutoCompleteLines = MAX_AUTO_COMPLETE;
    int numAutoCompleteLines = MathUtil::Min(sMaxAutoCompleteLines, (int)_autoCompleteList.size() );
    int autoCompleteBottomY = textBoxBottomY + (numAutoCompleteLines * sTextBoxHeight);
    int autoCompleteStartY = textBoxBottomY + 2*sTextBoxHeight/3;

    int autoCompleteXPos = textBoxXPos + winDimensions.Y / 24;
    int autoCompleteBoxXPos = autoCompleteXPos - sTextBoxBorder;

    glColor4f(0.0f,0.0f,0.0f,sTestAlpha);
    DrawTile(autoCompleteBoxXPos, autoCompleteBottomY, winDimensions.X-autoCompleteBoxXPos, numAutoCompleteLines * sTextBoxHeight);

    glColor4f(0.0f,1.0f,0.0f,1.0f);
    Vector2 outPos((float)autoCompleteXPos, (float)autoCompleteStartY);
    for( int i = 0; i < numAutoCompleteLines; i++ )
    {
        if( (int)_autoCompleteList.size() > sMaxAutoCompleteLines-1 && i == sMaxAutoCompleteLines-1 )
            DrawGameText( "...", "ConsoleSmall", autoCompleteXPos, (int)outPos.Y );
        else
            DrawGameText( _autoCompleteList[i].c_str(), "ConsoleSmall", autoCompleteXPos, (int)outPos.Y );
        outPos.Y += sTextBoxHeight;
    }


}
Exemple #17
0
static void
MoveTile(int xpos, int ypos)
{
	/* check all possible moves to see if there is the blank (N,E,S,W) */
	if (ypos > 0 && value[xpos][ypos - 1] == MAX_TILES) {
		value[xpos][ypos - 1] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos, ypos - 1);
		DrawTile(xpos, ypos);
	}

	if (xpos < (WIDTH_IN_TILES - 1) && value[xpos + 1][ypos] == MAX_TILES) {
		value[xpos + 1][ypos] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos + 1, ypos);
		DrawTile(xpos, ypos);
	}

	if (ypos < (HEIGHT_IN_TILES - 1) && value[xpos][ypos + 1] == MAX_TILES) {
		value[xpos][ypos + 1] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos, ypos + 1);
		DrawTile(xpos, ypos);
	}

	if (xpos > 0 && value[xpos - 1][ypos] == MAX_TILES) {
		value[xpos - 1][ypos] = value[xpos][ypos];
		value[xpos][ypos] = MAX_TILES;
		DrawTile(xpos - 1, ypos);
		DrawTile(xpos, ypos);
	}

	/* check for a winner */
	if (value[WIDTH_IN_TILES - 1][HEIGHT_IN_TILES - 1] == MAX_TILES) {
		int winner = 0;
		for (ypos=0; ypos< HEIGHT_IN_TILES; ypos++){
			for (xpos=0; xpos< WIDTH_IN_TILES; xpos++){
				if (value[xpos][ypos] == winner + 1)
					winner++;
				else 
					winner=0;
			}
		}
		if (winner == MAX_TILES) {
			/* Do winning screen */
			int loop = MAX_TILES;
			for(loop=0; loop < MAX_TILES; loop++) {
				for(winner=0; winner < (MAX_TILES - loop) ; winner++) {

					/* move tiles around */
					xpos = winner % WIDTH_IN_TILES;
					ypos = (int)(winner/WIDTH_IN_TILES);
					value[xpos][ypos] = loop + winner + 1; 
					DrawTile(winner % WIDTH_IN_TILES, (int)(winner/WIDTH_IN_TILES));
				}
				GrFlush();
				for(winner=0; winner < 10000000 ; winner++);
					/* delay loop */
			}
			/* Print message */
			GrSetGCForeground(gc1, WHITE);
			GrSetGCBackground(gc1, RED);
			GrText(tiles, gc1, ((WIDTH_IN_TILES * tile_width)/2) - 40, (HEIGHT_IN_TILES * tile_height)/2, "Well Done!!", -1, 0);
		}
				
	}
}
Exemple #18
0
void Tileset::DrawRandom(RenderDevice::Renderer & render, int x, int y)  {
   DrawTile(render, rand() % _numTiles + 1, x, y);
}
void LevelView::DrawTile(Tile * tile, HDC hdc, RECT rect)
{
	DrawTile(tile, hdc, rect, 0, 0);
}
void LevelView::DrawTile(Tile * tile, HDC hdc, RECT rect, int offsetX)
{
	DrawTile(tile, hdc, rect, offsetX, 0);
}
Exemple #21
0
 void Plumber :: Draw(int xof, int yof)
 {
     if (spinning)
     {
         spinface++;
         spinface%=8;
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-32, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof-16, 
                  512+((spinface/2)%2)*(spinface>3?2:1)+32*(small?0:2));
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-16, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof, 
                  512+((spinface/2)%2)*(spinface>3?2:1)+32*(small?1:3));
     }
     else  if (ducking)
     {
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-32, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof-16, 
                  512+6+32*(small?0:2));
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-16, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof, 
                  512+6+32*(small?1:3));
     }
     else if (jumping && vy <=0)
     {
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-32, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof-16, 
                  512+4+32*(small?0:2));
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-16, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof, 
                  512+4+32*(small?1:3));
     }
     else if (jumping && vy > 0)
     {
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-32, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof-16, 
                  512+5+32*(small?0:2));
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-16, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof, 
                  512+5+32*(small?1:3));
     }
     else if ((left && vx<=0)||(!left&&vx>=0))
     {
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-32, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof-16, 
                  512+(step?0:3)+32*(small?0:2));
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-16, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof, 
                  512+(step?0:3)+32*(small?1:3));
     }
     else
     {
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-32, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof-16, 
                  512+8+32*(small?0:2));
         DrawTile(int(x+P_X_OFF) +(left? 16:0) +xof, int(y+P_Y_OFF) +yof-16, 
                  int(x+P_X_OFF) +(left? 0:16) +xof, int(y+P_Y_OFF) +yof, 
                  512+8+32*(small?1:3));
     }
 }
void LevelView::Draw(HDC hDC, RECT rect, int xFrom, int xTo)
{
	if(!pWorld->Instance()->menu)
	{
		if(myTiles != NULL)
		{
			// iterate trew all tiles
			vector<Tile*>::iterator iterator = myTiles->begin();
			while(iterator!=myTiles->end())
			{
				Tile * tile = *iterator;
				if(ShouldDrawTile(tile, xFrom, xTo))
					DrawTile(tile, hDC, rect, -1 * xFrom);
				iterator++;
			}
		}

#pragma region surfaces
		if(Renderer::ShowSurfaces)
		{
			vector<Surface*> tempList;
			if(surfaces != NULL)
			{
				vector<Surface*>::iterator surfIterator = surfaces->begin();
				while(surfIterator != surfaces->end())
				{
					Surface * surf = *surfIterator;
					tempList.push_back(surf);
					surfIterator++;
				}
			}
			
			HPEN hPen = CreatePen(PS_SOLID, 1, RGB(255, 25, 5));
			HPEN hPenIce = CreatePen(PS_SOLID, 1, RGB(25, 5, 255));
			HPEN cloud = CreatePen(PS_DOT, 1, RGB(255, 25, 5));
			HPEN cloudIce = CreatePen(PS_DOT, 1, RGB(25, 5, 255));
			SelectObject(hDC, hPen);

			vector<Surface*>::iterator surfIterator = tempList.begin();
			while(surfIterator != tempList.end())
			{				
				Surface * surface = *surfIterator;

				if(surface->isIce)
					if(surface->isCloud)
						SelectObject(hDC, cloudIce);
					else
						SelectObject(hDC, hPenIce);
				else
					if(surface->isCloud)
						SelectObject(hDC, cloud);
					else
						SelectObject(hDC, hPen);

				if(surface->isSlope!=0)
				{
					if (surface->isSlope==1)
					{
						MoveToEx(hDC,surface->xFrom - xFrom, surface->yFrom,NULL);
						LineTo(hDC,surface->xTo - xFrom, surface->yFrom + (surface->yTo - surface->yFrom));
					}
					else
					{
						MoveToEx(hDC,surface->xFrom - xFrom, surface->yTo,NULL);
						LineTo(hDC,surface->xTo - xFrom, surface->yTo+ (surface->yFrom - surface->yTo));
					}
				}
				else
					Rectangle(hDC, surface->xFrom - xFrom, surface->yFrom, surface->xTo - xFrom, surface->yFrom + (surface->yTo - surface->yFrom));
				
				surfIterator++;
			}
			DeleteObject(hPen);
			DeleteObject(cloud);		
			DeleteObject(hPenIce);
			DeleteObject(cloudIce);		
		}
#pragma endregion

#pragma region fps
		if(Renderer::ShowFps)
		{
			SYSTEMTIME now;
			GetSystemTime(&now);

			int difInSec = now.wSecond - st.wSecond;
			int difInMSec = now.wMilliseconds - st.wMilliseconds;
			int ms1 = now.wMilliseconds;

			if(difInSec != 0)
				difInMSec = difInMSec + 1000;

			ostringstream s;
			s << "FPS: ";
			if(difInMSec == 0)
				s << "1000+";
			else
			{
				float temp_fps = (float)(1000 / difInMSec);
				int temp2_fps = (int)temp_fps;
				s << (temp2_fps);
			}

			// cast to c_string
			LPCSTR fps = "";
			string temp; 
			temp = s.str();
			fps = temp.c_str();


			if(st.wSecond == now.wSecond)
				TextOut(hDC, 15, 15, fps, strlen(fps));
			else
				TextOut(hDC, 15, 15, "FPS:", strlen("FPS:"));

			// set the time of the last update to this
			st = now;
		}
#pragma endregion

	}
}
Exemple #23
0
void CGeneral::AnimOut(const CTile &t)
{
   EraseArea(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 94);
   UpdateScreen(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 64);
   int i;
   SDL_Rect dstrect, dhand;

   SDL_Surface *save = SDL_CreateRGBSurface(gpScreen->flags & (~SDL_HWSURFACE),
      m_imgHand->w, m_imgHand->h, gpScreen->format->BitsPerPixel,
      gpScreen->format->Rmask, gpScreen->format->Gmask,
      gpScreen->format->Bmask, gpScreen->format->Amask);

   dhand.x = 218;
   dhand.y = 125;
   dhand.w = m_imgHand->w;
   dhand.h = m_imgHand->h;

   SDL_BlitSurface(gpScreen, &dhand, save, NULL);
   SDL_BlitSurface(m_imgHand, NULL, gpScreen, &dhand);
   UpdateScreen(dhand.x, dhand.y, dhand.w, dhand.h);

   PlaySound(SND_FLASH);
   dhand.h = m_imgFlash2->h - (125 - 94);
   for (i = 0; i < 10; i++) {
      EraseArea(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 94);
      EraseArea(245, 94, m_imgFlash2->w, m_imgFlash2->h);

      dstrect.x = 245;
      dstrect.y = 94;
      dstrect.w = m_imgFlash1->w;
      dstrect.h = m_imgFlash1->h;

      SDL_BlitSurface(m_imgFlash1, NULL, gpScreen, &dstrect);
      DrawTile(t, 280, 104);
      SDL_BlitSurface(m_imgHand, NULL, gpScreen, &dhand);
      UpdateScreen(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 64);

      UTIL_Delay(50);

      EraseArea(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 94);
      EraseArea(dstrect.x, dstrect.y, dstrect.w, dstrect.h);

      dstrect.w = m_imgFlash2->w;
      dstrect.h = m_imgFlash2->h;
      SDL_BlitSurface(m_imgFlash2, NULL, gpScreen, &dstrect);
      DrawTile(t, 280, 104);
      SDL_BlitSurface(m_imgHand, NULL, gpScreen, &dhand);
      UpdateScreen(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 64);
      UTIL_Delay(50);
   }

   dhand.h = m_imgHand->h;
   UTIL_Delay(120);
   DrawUTF8Text(msg("out_discard"), 215, 114, 2, 255, 255, 255);
   UpdateScreen(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 64);
   UTIL_Delay(1000);
   EraseArea(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 94);
   EraseArea(dstrect.x, dstrect.y, dstrect.w, dstrect.h);
   SDL_BlitSurface(save, NULL, gpScreen, &dhand);
   SDL_FreeSurface(save);
   UpdateScreen(620 - 10 * TILE_WIDTH, 94, TILE_WIDTH * 10, 132 + TILE_HEIGHT_SHOWN - 64);
   UpdateScreen(dhand.x, dhand.y, dhand.w, dhand.h);
}
BOOL TilePropWindow::DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch ( msg )
    {
        case WM_ACTIVATE:
            if ( LOWORD(wParam) != WA_INACTIVE )
                chkd.SetCurrDialog(hWnd);
            break;

        case WM_INITDIALOG:
            {
                HWND hEdit = GetDlgItem(hWnd, IDC_EDIT_TILEVALUE);
                SendMessage(hEdit, EM_SETLIMITTEXT, 10, 0);
                UpdateTile();
                PostMessage(hWnd, WM_NEXTDLGCTL, (WPARAM)hEdit, true);
                return true;
            }
            break;

        case WM_PAINT:
            {
                RECT rect;
                GetClientRect(hWnd, &rect);
                int width = 32,
                    height = 32;
                PAINTSTRUCT ps;
                HDC hDC = BeginPaint(hWnd, &ps),
                    MemhDC = CreateCompatibleDC(hDC);
                HBITMAP Membitmap = CreateCompatibleBitmap(hDC, width, height);
                SelectObject(MemhDC, Membitmap);

                TCHAR lpszTile[11];
                int TextLength = WORD(SendDlgItemMessage(hWnd, IDC_EDIT_TILEVALUE, EM_LINELENGTH, 0, 0));
                *((LPWORD)lpszTile) = TextLength;
                SendDlgItemMessage(hWnd, IDC_EDIT_TILEVALUE, EM_GETLINE, 0, (LPARAM)lpszTile);
                lpszTile[TextLength] = '\0';

                u16 tile = atoi(lpszTile), tileset = CM->getTileset();
                TileSet* tiles = &chkd.scData.tilesets.set[tileset];

                HBRUSH brush = CreateSolidBrush(RGB(166, 156, 132));
                FillRect(MemhDC, &rect, brush);
                DeleteObject(brush);

                BITMAPINFO bmi = GetBMI(32, 32);
                DrawTile(MemhDC, tiles, 0, 0, tile, bmi, 0, 0, 0);
                BitBlt(hDC, 55, 50, width, height, MemhDC, 0, 0, SRCCOPY);

                BITMAPINFO bmiMini = GetBMI(8, 8);
                for ( int yMiniTile=0; yMiniTile<4; yMiniTile++ )
                {
                    for ( int xMiniTile=0; xMiniTile<4; xMiniTile++ )
                        DrawMiniTileElevation(hDC, tiles, 350+xMiniTile*9, 50+yMiniTile*9, tile, xMiniTile, yMiniTile, bmiMini);
                }
                
                DeleteObject(Membitmap);
                DeleteDC    (MemhDC);
                DeleteDC    (hDC);
            }
            break;

        case WM_DESTROY:
            EndDialog(hWnd, IDCANCEL);
            break;

        default:
            return false;
            break;
    }
    return 0;
}
/**
* Initialize world node.
*/
HRESULT WorldNode::Initialize(IDirect3DDevice9* pd3dDevice)
{
    WCHAR wsNewPath[ MAX_PATH ];

    // search and load floor texture
    DXUTFindDXSDKMediaFileCch(wsNewPath, sizeof(wsNewPath), m_sFloorFilename.c_str());
    if( FAILED(D3DXCreateTextureFromFile(
        pd3dDevice,
        wsNewPath,
        &m_pFloorTexture)) )
    {
        return E_FAIL;
    }

    // search and load wall texture
    DXUTFindDXSDKMediaFileCch(wsNewPath, sizeof(wsNewPath), m_sWallFilename.c_str());
    if( FAILED(D3DXCreateTextureFromFile(
        pd3dDevice,
        wsNewPath,
        &m_pWallTexture)) )
    {
        return E_FAIL;
    }

    // save grid size
    iWorldHeight = m_worldFile.GetHeight();
    iWorldWidth = m_worldFile.GetWidth();

    // draw tiles for each row and column entry
    for(int col = 0; col < m_worldFile.GetWidth(); col++)
    {
        for(int row = 0; row < m_worldFile.GetHeight(); row++)
        {
            // compute cube base coordinates
            float x = col * kWorldScale;
            float y = 0.0f;
            float z = row * kWorldScale;

            // check row/col for cell
            switch(m_worldFile(row,col))
            {
                case WorldFile::OCCUPIED_CELL:
                {
                    // draw cube top
                    DrawTile(x, y, z, kWorldScale, kTop, kWall);

                    // check for occupied cells next to cell, draw cube sides if not occupied

                    // left
                    if(m_worldFile(row,col-1) == WorldFile::EMPTY_CELL || m_worldFile(row,col-1) == WorldFile::INVALID_CELL)
                        DrawTile(x, y, z, kWorldScale, kLeft, kWall);

                    // right
                    if(m_worldFile(row,col+1) == WorldFile::EMPTY_CELL || m_worldFile(row,col+1) == WorldFile::INVALID_CELL)
                        DrawTile(x, y, z, kWorldScale, kRight, kWall);

                    // upper
                    if(m_worldFile(row+1,col) == WorldFile::EMPTY_CELL || m_worldFile(row+1,col) == WorldFile::INVALID_CELL)
                        DrawTile(x, y, z, kWorldScale, kUpper, kWall);

                    // lower
                    if(m_worldFile(row-1,col) == WorldFile::EMPTY_CELL || m_worldFile(row-1,col) == WorldFile::INVALID_CELL)
                        DrawTile(x, y, z, kWorldScale, kLower, kWall);

                    break;
                }
                default:
                {
                    // draw floor
                    DrawTile(x, y, z, kWorldScale, kBottom, kFloor);
                    break;
                }
            }
        }
    }
    
    // create vertex declaration
    HRESULT result = pd3dDevice->CreateVertexDeclaration(m_sCustomVertexDeclaration, &m_pCVDeclaration);

    return result;
}
Exemple #26
0
void TilemapLayer::Draw(int z_order) {
	if (!visible) return;

	// Get the number of tiles that can be displayed on window
	int tiles_x = (int)ceil(DisplayUi->GetWidth() / (float)TILE_SIZE);
	int tiles_y = (int)ceil(DisplayUi->GetHeight() / (float)TILE_SIZE);

	// If ox or oy are not equal to the tile size draw the next tile too
	// to prevent black (empty) tiles at the borders
	if (ox % TILE_SIZE != 0) {
		++tiles_x;
	}
	if (oy % TILE_SIZE != 0) {
		++tiles_y;
	}

	for (int x = 0; x < tiles_x; x++) {
		for (int y = 0; y < tiles_y; y++) {

			// Get the real maps tile coordinates
			int map_x = ox / TILE_SIZE + x;
			int map_y = oy / TILE_SIZE + y;

			if (width <= map_x || height <= map_y) continue;

			int map_draw_x = x * TILE_SIZE - ox % TILE_SIZE;
			int map_draw_y = y * TILE_SIZE - oy % TILE_SIZE;

			// Get the tile data
			TileData &tile = data_cache[map_x][map_y];

			int map_draw_z = tile.z;

			if (map_draw_z > 0) {
				if (map_draw_z < 9999) {
					map_draw_z += y * TILE_SIZE;
					if (y == 0) map_draw_z += TILE_SIZE;
				}
			}

			// Draw the tile if its z is being draw now
			if (z_order == map_draw_z) {
				if (layer == 0) {
					// If lower layer

					if (tile.ID >= BLOCK_E && tile.ID < BLOCK_E + BLOCK_E_TILES) {
						int id = substitutions[tile.ID - BLOCK_E];
						// If Block E

						int row, col;

						// Get the tile coordinates from chipset
						if (id < 96) {
							// If from first column of the block
							col = 12 + id % 6;
							row = id / 6;
						} else {
							// If from second column of the block
							col = 18 + (id - 96) % 6;
							row = (id - 96) / 6;
						}

						DrawTile(*chipset_screen, map_draw_x, map_draw_y, row, col, false);
					} else if (tile.ID >= BLOCK_C && tile.ID < BLOCK_D) {
						// If Block C

						// Get the tile coordinates from chipset
						int col = 3 + (tile.ID - BLOCK_C) / 50;
						int row = 4 + animation_step_c;

						// Draw the tile
						DrawTile(*chipset_screen, map_draw_x, map_draw_y, row, col, false);
					} else if (tile.ID < BLOCK_C) {
						// If Blocks A1, A2, B

						// Draw the tile from autotile cache
						TileXY pos = GetCachedAutotileAB(tile.ID, animation_step_ab);
						DrawTile(*autotiles_ab_screen, map_draw_x, map_draw_y, pos.y, pos.x, true);
					} else {
						// If blocks D1-D12

						// Draw the tile from autotile cache
						TileXY pos = GetCachedAutotileD(tile.ID);
						DrawTile(*autotiles_d_screen, map_draw_x, map_draw_y, pos.y, pos.x, true);
					}
				} else {
					// If upper layer

					// Check that block F is being drawn
					if (tile.ID >= BLOCK_F && tile.ID < BLOCK_F + BLOCK_F_TILES) {
						int id = substitutions[tile.ID - BLOCK_F];
						int row, col;

						// Get the tile coordinates from chipset
						if (id < 48) {
							// If from first column of the block
							col = 18 + id % 6;
							row = 8 + id / 6;
						} else {
							// If from second column of the block
							col = 24 + (id - 48) % 6;
							row = (id - 48) / 6;
						}

						// Draw the tile
						DrawTile(*chipset_screen, map_draw_x, map_draw_y, row, col, false);
					}
				}
			}
		}
	}
}