コード例 #1
0
ファイル: image.cpp プロジェクト: cantidio/gorgonCpp
int main()
{
	allegro_init();
	install_keyboard();
	try
	{
		ImageLoader::setLoader(new ImageLoaderMagick());
		Video::init("Teste da classe Image");//iniciamos a classe de vídeo
		Video video = Video::get();//pegamos um ponteiro para classe de vídeo para mais fácil acesso
		int angle1	= 0;
		int angle2	= 255;

		//criamos 2 imagens de 50 x 30
		Image normal(50,30);
		Image normal1(50,30);

		normal.drawText("Teste",0,0,makecol(0,0,255));	//desenhamos o texto Teste de azul na imagem
		normal1.drawText("Teste",0,0,makecol(255,0,0));	//desenhamos o texto Teste de vermelho na imagem
		while(!key[KEY_ESC])
		{
			video.clear();//limapamos o buffer do vídeo
			video.drawImage(normal,50,50);
			video.drawImage(normal1,150,50);
			for(register int i = 0; i < 5; i++)
			{
				for(register int j = 0; j < 4; j++)
				{
					const int ang = ((i+j)%2) ? angle1 : angle2;
					video.drawImageRoteted(normal1	,80+i*40,70+j*40,ang		);
					video.drawImageRoteted(normal	,80+i*40,70+j*40,ang+128+64	);
					video.drawImageRoteted(normal1	,80+i*40,70+j*40,ang+128	);
					video.drawImageRoteted(normal	,80+i*40,70+j*40,ang+64		);
				}
			}
			video.drawText("Teste da classe Image.",10,0,makecol(255,255,255));
			video.drawText(10,10,makecol(255,255,255),-1,"Angle  : %d",angle1);
			video.drawText(10,20,makecol(255,255,255),-1,"Angle2 : %d",angle2);
			video.show();

			angle1 += 2;
			angle2 -= 2;
			if(angle2 < 0) angle2=255;
			if(angle1 >= 255) angle1=0;
		}
	}
	catch(Exception& e)
	{
		cout << e.getMessage() << endl;
	}
	return 0;
}END_OF_MAIN()
コード例 #2
0
ファイル: sprite.cpp プロジェクト: cantidio/gorgonCpp
int main()
{
	allegro_init();
	install_keyboard();
	try
	{
		ImageLoader::setLoader(new ImageLoaderMagick());
		Video::init("Teste da classe Sprite");
		Video video = Video::get();
		Sprite normal(Image("../resources/pcx24bits.pcx"),0,0,12,47);
		normal.save("sprite.gspr");
		Sprite normal1("sprite.gspr");
		int angle1 = 0;
		int angle2 = 0;
		while(!key[KEY_ESC])
		{
			video.clear();
			for(int i=0; i<5; i++)
			{
				for(int j=0; j<4; j++)
				{
					int ang= ((i+j)%2) ? angle1 : angle2;
					video.drawSpriteRoteted(normal1	,80+i*40,70+j*40,ang		);
					video.drawSpriteRoteted(normal1	,80+i*40,70+j*40,ang+128+64	);
					video.drawSpriteRoteted(normal1	,80+i*40,70+j*40,ang+128	);
					video.drawSpriteRoteted(normal1	,80+i*40,70+j*40,ang+64		);
				}
			}
			//video->drawImageStretched(normal1,20,30,normal1.getWidth(),normal1.getHeight());
			//video->drawImageStretched(normal2,20,90,normal2.getWidth(),normal2.getHeight());
	//		video->drawSpriteRoteted(normal1,80,80,angle1);
		//	video->drawSpriteRoteted(normal1,80,80,angle2);
			video.drawText("Teste da classe Sprite.",10,0,makecol(255,255,255));
			video.drawText(10,10,makecol(255,255,255),-1,"Angle1: %d",angle1);
			video.drawText(10,20,makecol(255,255,255),-1,"Angle2: %d",angle2);
			video.show();
			angle1+=2;
			angle2-=2;
			if(angle2<0)	angle2 = 255;
			if(angle1>=255)	angle1 = 0;
		}
	}
	catch(Core::Exception& e)
	{
		cout << e.what();
	}
	return 0;
}
コード例 #3
0
ファイル: spritepack.cpp プロジェクト: cantidio/gorgonCpp
int main(int argc, char** argv)
{
	allegro_init();
	install_keyboard();
	bool trans = false;
	try
	{
//		ImageLoader::setLoader(new ImageLoaderMagick());
		ImageLoader::setLoader(new ImageLoaderSDL());
		ImageLoader::getLoader().setSaveFormat("PNG");
		//ImageLoader::setLoader(new Gorgon::ImageLoaderAutodetect());
		Video::init("Teste da classe SpritePack",1280,720);
		
		Video		video = Video::get();
		SpritePack	gspk;
		if(argc > 2)
		{
			if(std::string(argv[1]).compare("-image") == 0)
			{
				gspk = SpriteSheet(Image(argv[2]),0xFF0000);
			}
			else if(std::string(argv[1]).compare("-spritepack") == 0)
			{
				gspk.load(argv[2]);
			}
			else if(std::string(argv[1]).compare("-sff") == 0)
			{
				gspk = SpritePackSff(std::string(argv[2]));
			}
			else if(std::string(argv[1]).compare("-script") == 0)
			{
				gspk = SpritePackLua(argv[2]);
			}
			else
			{
				printf("opções erradas!\n");
				usageMSG();
				return 0;
			}
		}
		else
		{
//			gspk = SpritePackSff("~/mugen/Alucard/Alucard.sff");
			gspk = SpritePackSff("/home/cantidio/mugen/Alucard/Alucard.sff");
			/*usageMSG();
			return 0;*/
		}
		showCommands();
		

		Sprite buffer(Image(1280,720));
		int counter		= 0;
		int onionIndex	= 0;
		while(!key[KEY_ESC])
		{
			buffer.clear();
			buffer.drawSpriteTrans(gspk[onionIndex],Point(X,Y),0.5);
			(trans) ? buffer.drawSprite(gspk[counter],Point(X,Y)) : buffer.blitSprite(gspk[counter],Point(X,Y));
			buffer.drawRectangle(Point(X-1,Y-1),Point(X+1,Y+1),0xFFFFFF,true);//draw a hot spot
			video.clear();

			video.blitSpriteStretched(buffer,Point(-X * (zoom-1),-Y * (zoom-1)),zoom,zoom);

			video.drawText("Gorgon SpritePack View",10,10,0xFFFFFF);
			video.drawText(Point(10,30),0xFFFFFF,-1,"Width:   %d",gspk[counter].getWidth());
			video.drawText(Point(10,40),0xFFFFFF,-1,"Height:  %d",gspk[counter].getHeight());
			video.drawText(Point(10,50),0xFFFFFF,-1,"Group:   %d",gspk[counter].getGroup());
			video.drawText(Point(10,60),0xFFFFFF,-1,"Index:   %d",gspk[counter].getIndex());
			video.drawText(Point(10,70),0xFFFFFF,-1,"xOffset: %d",gspk[counter].getOffset().getX());
			video.drawText(Point(10,80),0xFFFFFF,-1,"yOffset: %d",gspk[counter].getOffset().getY());
			video.drawText(Point(10,90),0xFFFFFF,-1,"counter: %d",counter);
			video.show();

			if(key[KEY_LCONTROL])
			{
				if(key[KEY_S])
				{
					std::string file1;
					std::string file2;

					printf("Digite o nome do spritepack a ser salvo:\n");
					cin >> file1;
					file2 = file1;

					file1.append(".lua");
					file2.append(".gspk");
					printf("salvando...");
					SpritePackLua a(gspk);
					a.save(file1);
					gspk.save(file2);
					printf("[ok]\n");
				}
				else if(key[KEY_T])
				{
					printf("trim sprite all\n");
					for(int i = 0; i < gspk.getSize(); ++i)
					{
						gspk[i].clipNoBorder();
					}
					printf("%d sprites trimmed.\n",gspk.getSize());
				}
				else if(key[KEY_Q])
				{
					printf("toogle transparence\n");
					trans = trans ? false : true;
				}
				else if(key[KEY_1])
				{
					printf("mark sprite %d to onion skin.\n",counter);
					onionIndex = counter;
				}
				else if(key[KEY_MINUS])
				{
					--zoom;
				}
				else if(key[KEY_EQUALS])
				{
					++zoom;
				}
				if(key[KEY_UP])
				{
					gspk[counter].setOffset( gspk[counter].getOffset() - Point(0,1) );
				}
				else if (key[KEY_DOWN])
				{
					gspk[counter].setOffset( gspk[counter].getOffset() + Point(0,1) );
				}
				if(key[KEY_RIGHT])
				{
					gspk[counter].setOffset( gspk[counter].getOffset() + Point(1,0) );
				}
				else if (key[KEY_LEFT])
				{
					gspk[counter].setOffset( gspk[counter].getOffset() - Point(1,0) );
				}
			}
			else if(key[KEY_LSHIFT])
			{
				if(key[KEY_UP])
				{
					gspk[counter].setGroup(gspk[counter].getGroup() - 1);
				}
				else if (key[KEY_DOWN])
				{
					gspk[counter].setGroup(gspk[counter].getGroup() + 1);
				}
				else if(key[KEY_LEFT])
				{
					gspk[counter].setIndex(gspk[counter].getIndex() - 1);
				}
				else if (key[KEY_RIGHT])
				{
					gspk[counter].setIndex(gspk[counter].getIndex() + 1);
				}
				else if(key[KEY_T])
				{
					printf("trim sprite\n");
					gspk[counter].clipNoBorder();
				}
			}
			else
			{
				if(key[KEY_RIGHT])
				{
					++counter;
					if(counter >= gspk.getSize())
						counter = 0;
				}
				else if(key[KEY_LEFT])
				{
					--counter;
					if(counter < 0)
						counter = gspk.getSize() - 1;
				}
			}

			key[KEY_MINUS]=key[KEY_EQUALS]=key[KEY_1]=key[KEY_S]=key[KEY_Q]=key[KEY_T]=key[KEY_DOWN]=key[KEY_UP]=key[KEY_LEFT]=key[KEY_RIGHT]=key[KEY_ENTER]=0;
		}