Пример #1
0
void Game::Run()//游戏运行
{
	//界面元素的创建
	static FullScrAni outline;
	static Text texlevel(675,217,20,20);
	static Text texfood(675,300,20,20);
	static Text texscore(675,387,20,20);

	static Button butpause(628,500,100,50);
	static Button butret(740,40,50,50);
	//界面元素动画的设置
	butpause.SetAni(ANI_BUTTON,pPanel->IsPause()?ANI_BUTTON_RECOVER:ANI_BUTTON_PAUSE);
	butret.SetAni(ANI_BUTTON,ANI_BUTTON_RETURN);

	outline.SetAni(ANI_OUTLINE);
	//响应
	butpause.Deal();
	butret.Deal();
	if(butpause.MousePressed())
	{//是否暂停
		butpause.Recover();
		pPanel->SetPause(!pPanel->IsPause());
	}

	outline.Draw();
	pPanel->DoFrame();
	//绘制
	butpause.Draw();
	butret.Draw();

	texlevel.SetText(level,RGB(255,255,255));
	texscore.SetText(pPanel->Score(),RGB(255,255,255));
	texfood.SetText(pPanel->RestFood(),RGB(255,255,255));
	texlevel.Draw();
	texscore.Draw();
	texfood.Draw();
	if(pPanel->Overed())
	{
		if(pPanel->Won())state=GAME_WIN;
		else state=GAME_FAIL;
		manager.Stop();
	}
	if(butret.MousePressed())
	{
		butret.Recover();
		Destroy();
		state=GAME_SHOWMENU;
	}
	
	roundtime+=1000/FPS;
	if(roundtime%1000<1000/FPS)//每秒储存一次
		SaveArchive();
}
Пример #2
0
int main(int argc, char* args[]) {

	//initialize SDL_ttf
	if (TTF_Init() == -1) {
		cerr << "TTF_Init: " << TTF_GetError() << endl;
//exit(2);
	}

	SDL_Texture* backGroundTexture; // the new SDL_Texture variable
	SDL_Texture* backimageTexture;
// *****************



	SDL_Init( SDL_INIT_EVERYTHING);

	//Create window
	g_pWindow = SDL_CreateWindow("Easy_Rider", SDL_WINDOWPOS_UNDEFINED,
	SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

	//Create Renderer
	g_pRenderer = SDL_CreateRenderer(g_pWindow, -1, SDL_RENDERER_ACCELERATED);

	//Load image from specified path
	SDL_Surface* loadedSurface = IMG_Load("image/background.png");

	//Create texture from surface pixels
	backGroundTexture = SDL_CreateTextureFromSurface(g_pRenderer,
			loadedSurface);

	SDL_Surface* riderSurface = SDL_LoadBMP("image/rider.bmp");

	//Color key image
	SDL_SetColorKey(riderSurface, SDL_TRUE,
			SDL_MapRGB(riderSurface->format, 102, 204, 255));

	//Create texture from surface pixels
	backimageTexture = SDL_CreateTextureFromSurface(g_pRenderer, riderSurface);

	//SDL_Rect rectRider = {320, 0, riderSurface->w};

// flipping a image
	Text txt;
	txt.Init(g_pRenderer);

	SDL_RenderClear(g_pRenderer);


	bool gamerunning = true;
	SDL_Event event;

	//	game loop
	while (gamerunning) {

		if (SDL_PollEvent(&event)!= 0) {
			if (event.type == SDL_QUIT)
				gamerunning = false;
		}
			SDL_RenderClear(g_pRenderer);
					SDL_RenderCopy(g_pRenderer, backGroundTexture, 0, 0);
					txt.Draw(g_pRenderer);
			        txt.UpDate(event);
					SDL_RenderPresent(g_pRenderer);



	}

	SDL_RenderPresent(g_pRenderer);

	//SDL_Delay(2000);

	return 0;
}