コード例 #1
0
ファイル: Map.cpp プロジェクト: hudovisk/Allegro
void Map::drawTile(int id,int x, int y)
{
	for(int k=0; k < tilesets.getSize(); k++)
	{
		Tileset* tileset = tilesets.get(k);
		if(id <= tileset->getLasttId() && id >= tileset->getFirstId())
		{
			id -= tileset->getFirstId();
			int tw = tileset->getTileWidth();
			int th = tileset->getTileHeight();
			int imw = al_get_bitmap_width(tileset->getImage());

			//tile
			int sx = id*tw % imw;
			int sy = id/(imw/tw)*th;

			al_draw_bitmap_region(tileset->getImage(),sx,sy,tileWidth,tileHeight,(x*tileWidth) - (xOffs%tileWidth),(y*tileHeight) - (yOffs%tileHeight),0);
		}
	}
}
コード例 #2
0
void MapperTilesetBox::draw(gcn::Graphics* graphics){
    // draw components
    InfraellyWindow::draw(graphics);

    //draw selection overlay
    if( !tilesetList->empty() ){
        Tileset *selectedTs = tilesetList->at( tilesetDropDown->getSelected() );
        if( selectedTs != NULL ){
            if( selectedTs->getImage() != NULL ){
                //tile width and height
                int tileWidth = selectedTs->getTileWidth();
                int tileHeight = selectedTs->getTileHeight();

                //calculate amount of px off the screen
                int offsetX = tilesetImage->getX();
                int offsetY = tilesetImage->getY();

                // convert pixel values to row, width
                int offCol = offsetX/tileWidth;
                int offRow = offsetY/tileHeight;



                //get the row and col of the selected tile
                int trueCol = selectedTile.getCol();
                int trueRow = selectedTile.getRow();


                //to find out the reletive row/col to draw to
                //  we must minus the offscreen tiles from the true tiles co-ords
                int drawCol = trueCol + offCol;
                int drawRow = trueRow + offRow;


                //calculate where to draw in pxs
                int drawX = (drawCol * tileWidth) + (tilesetImageScroller->getX() + getFrameSize());
                int drawY = (drawRow * tileHeight) + (tilesetImageScroller->getY() + getTitleBarHeight());


                //add offsets according to scroller
                drawX += offsetX%tileWidth;
                drawY += offsetY%tileHeight;


                //dimensions of the frame
                gcn::Rectangle d( drawX+selectedTs->getXOffset(),
                                  drawY+selectedTs->getYOffset(),
                                  tileWidth, tileHeight );

                //only draw if within region
                if(  ( d.x < tilesetImageScroller->getX()+tilesetImageScroller->getWidth() ) &&
                     ( d.x+d.width > tilesetImageScroller->getX() ) &&
                     ( d.y < tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() ) &&
                     ( d.y+d.height > tilesetImageScroller->getY()+getTitleBarHeight() )
                ){
                    //setcolour to blue
                    graphics->setColor( gcn::Color( 0, 0, 255) );
                    //draw a frame
                    graphics->drawRectangle( d );
                    //decrease the dimensions by one pixel
                    ++d.x;
                    ++d.y;
                    d.width -= 2;
                    d.height -= 2;
                    //draw another frame (inside prev one)
                    graphics->drawRectangle( d );
                } else {
                    //not in region, draw a bob
                    //off the left
                    if( (d.x+d.width) < tilesetImageScroller->getX() ){
                        d.x = tilesetImageScroller->getX();
                        d.y += (tileHeight/2)-5;
                    };
                    //off the right
                    if( d.x > (tilesetImageScroller->getWidth()+tilesetImageScroller->getX()) ){
                        d.x = tilesetImageScroller->getWidth()-10;
                        d.y += (tileHeight/2)-5;

                    };
                    //off the top
                    if( (d.y+d.height) < tilesetImageScroller->getY() ){
                        d.y = tilesetImageScroller->getY()+getTitleBarHeight();
                        d.x += (tileWidth/2)-5;
                    };
                    //off the bottom
                    if( d.y > (tilesetImageScroller->getHeight()+tilesetImageScroller->getY()+getTitleBarHeight())  ){
                        d.y = tilesetImageScroller->getY()+tilesetImageScroller->getHeight()+getTitleBarHeight() - 10;
                        d.x += (tileWidth/2)-5;
                    };
                    //draw the bob (5x5px box)
                    d.width = 10;
                    d.height = 10;
                    //setcolour to red
                    graphics->setColor( gcn::Color( 255, 0, 0) );
                    graphics->fillRectangle( d );
                }
            }
        }
    }
}