示例#1
0
文件: main.c 项目: dorkster/espada
//------------------------------
// Main game loop
//------------------------------
int main(int argc, char* argv[])
{
    srand(time(0));
        
    if(sys_init() == false) { return 1; }
    if(sys_loadfiles() == false) { return 1; }
    
    set_clips();
    sys_configload();
    
    while(quit == false)
    {
        startTimer = SDL_GetTicks();
        
        sys_input();
        game_logic();
        draw_everything();
        
        //Update the screen
        if(SDL_Flip(screen) == -1) { return 1; }
            
        endTimer = SDL_GetTicks();
        deltaTimer = endTimer - startTimer;
        if ( deltaTimer < ( 1000 / FPS ))
        {
            SDL_Delay( ( 1000 / FPS ) - deltaTimer );
        }
    }
    
    sys_configupdate();
    sys_cleanup();
    
    return 0;
}
示例#2
0
文件: logic.cpp 项目: ccapitalK/si2e
void engine_main_logic(){
    ENGINE_SCREEN_MANAGER.passthrough();
    draw_now=false;
    if(game_logic){game_logic();}
    particle_logic();
    while(!draw_now)
        event_logic();
}
示例#3
0
int main(int argc, char* args[])
{
	int ret = 0;
	int fbfd = 0;
	struct pollfd evpoll = {
		.events = POLLIN,
	};
	
	srand (time(NULL));

	evpoll.fd = open_evdev("Raspberry Pi Sense HAT Joystick");
	if (evpoll.fd < 0) {
		fprintf(stderr, "Event device not found.\n");
		return evpoll.fd;
	}

	fbfd = open_fbdev("RPi-Sense FB");
	if (fbfd <= 0) {
		ret = fbfd;
		printf("Error: cannot open framebuffer device.\n");
		goto err_ev; 
		
	}
	
	fb = mmap(0, 128, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
	if (!fb) {
		ret = EXIT_FAILURE;
		printf("Failed to mmap.\n");
		goto err_fb;
	}
	memset(fb, 0, 128);

	snake.tail = &snake.head;
	reset();
	while (running) {
		while (poll(&evpoll, 1, 0) > 0)
			handle_events(evpoll.fd);
		game_logic();
		if (check_collision(0)) {
			reset();
		}
		render();
		usleep (300000);
	}
	memset(fb, 0, 128);
	reset();
	munmap(fb, 128);
err_fb:
	close(fbfd);
err_ev:
	close(evpoll.fd);
	return ret;
}
void logic(void)
{
	switch(state)
	{
		case STATE_LOGO:
		{
			logo_logic();
			break;
		}
		case STATE_INTRO:
		{
			cinema_logic(cinema);
			if(cinema->position >= cinema->frames)
			{
				state = STATE_TITLE;
			}
			break;
		}
		case STATE_TITLE:
		{
			title_logic();
			break;
		}
		case STATE_GAME:
		{
			game_logic();
			break;
		}
		case STATE_ENDING:
		{
			cinema_logic(ending_cinema);
			if(ending_cinema->position >= ending_cinema->frames)
			{
				state = STATE_TITLE;
				current_menu = TITLE_MENU_MAIN;
			}
			break;
		}
	}
	t3f_poll_sound_queue();
}
示例#5
0
static void g_render() {

	static char sbuf[256];
//	SDL_FillRect(front, &game[0].cords, SDL_MapRGB(front->format, 255, 255, 255));
//	SDL_FillRect(front, &game[1].cords, SDL_MapRGB(front->format, 255, 0, 0));
	SDL_BlitSurface( gbg, 0, front, 0);

	{
		SDL_Rect rc = { 20, 50, 640/2-40, 480-50 };
		SDL_Rect rc2 = { 640/2+20, 50, 640/2-40, 480-50 };
		SDL_FillRect(front, &rc, 0x0);
		SDL_FillRect(front, &rc2, 0x0);
		render_grid(&game[0], rc.x+5, rc.y+3);
		render_grid(&game[1], rc2.x+5, rc2.y+3);
		sprintf(sbuf, "P1 Score: %d Lines: %d", game[0].score, game[0].lines);
		SDL_PrintText(front, font, 25, 65, SDL_MapRGB(front->format, 255, 0, 0), sbuf);
		sprintf(sbuf, "P2 Score: %d Lines: %d", game[1].score, game[1].lines);
		SDL_PrintText(front, font, 640/2+25, 65, SDL_MapRGB(front->format, 255, 255, 255), sbuf);
	}
	game_logic();

}