Esempio n. 1
0
int classic_game(void) {
	srand((unsigned int)time(NULL));
	Uint8 r=((rand()%128)+128);
	Uint8 g=((rand()%128)+128);
	Uint8 b=((rand()%128)+128);
	Game_Snake S;
	int d=-1;
	SDL_Event e;
	Uint32 ticks;
	while(1) {
		ticks=SDL_GetTicks();
		SDL_RenderClear(gRenderer);
		SDL_SetRenderDrawColor(gRenderer, r, g, b, 0xFF);
		while(SDL_WaitEventTimeout(&e, 4)) {
			if(e.type==SDL_QUIT) {
				exit(0);
			}
			else if(e.type==SDL_KEYDOWN && e.key.repeat==0) {
				switch(e.key.keysym.sym) {
					case SDLK_ESCAPE:
						SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
						show_gameover(S.getscore());
						return S.getscore();
					case SDLK_UP:
						d=UP;
						break;
					case SDLK_DOWN:
						d=DOWN;
						break;
					case SDLK_RIGHT:
						d=RIGHT;
						break;
					case SDLK_LEFT:
						d=LEFT;
						break;
				}
				if(diff(S.getfdir(), d)!=2 && d!=S.getfdir()) {
					S.createnode(d);
				}
			}
		}
		S.movesnake();
		S.render();
		if(S.getcoll()) {
			SDL_Delay(TIMEOUT_LONG);
			SDL_RenderClear(gRenderer);
			SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
			wait();
			show_gameover(S.getscore());
			return S.getscore();
		}
		SDL_RenderPresent(gRenderer);
		while(SDL_GetTicks()-ticks<16) {
			SDL_Delay(1);
		}
	}
}
Esempio n. 2
0
// 그래픽 출력-
void Tetris::Render()
{
	switch( stage )
	{
	case INIT: 
		show_logo();
		break;
	case READY:
		input_data();
		break;
	case RUNNING: 
		m_block->Draw();
		show_gamestat();
		if( m_full_line_num != 0 )
			full_line_erase();
		break;
	case SUCCESS:
		m_block->Draw();
		show_gamestat();
		show_cleargame();
		break;
	case FAILED:
		m_block->Draw();
		show_gamestat();
		show_gameover();
		break;
	case RESULT :
		break;
	}
}