示例#1
0
void init(void) {
    All * a = global_a;
    all_init(a);
    land_display_title("Yellow and Dangerous");
    reload_fonts();
#line 148
    a->up = 0;
    a->down = 0;
    a->left = 0;
    a->right = 0;
    a->jump = 0;
#line 154
    a->text = (LandColor) {0, 0, 0, 1};
#line 156
    config_controls_read();
#line 158
    game_setup(land_display_width(), land_display_height());
#line 160
    render_setup();
#line 162
    a->show_fps = 0;
#line 164
    for (int i = 0; i < 10; i += 1) {
        a->cheatpos [i] = 0;
    }
}
示例#2
0
int main(void)
{
    // Boot
    struct cRGB color = {0, 0, 10};
    leds_set(1, color);
    _delay_ms(1000);
    leds_off();

    // Set up game
    game_setup();

    while(1) {
        // Game loop
        game_loop();
    }

    return 0;
}
示例#3
0
void Apep::run(){
    assert("You must initialize engine before run!" && back_buffer != nullptr);
    clean_screen();

    if (!game_setup()) return;

    while (game_update()) {

        while (_kbhit())
            key(_getch());
        
        game_draw();
        flush();

        Sleep(10);
    }

    game_cleanup();
}
示例#4
0
int main(int argc, char **argv)
{
	
	/*-----------------------------------------------------------------------------
	 *  Very important to note that XInitThreads is a linux implementation only
	 *-----------------------------------------------------------------------------*/
	XInitThreads();
	JNX_LOG(NULL,"Starting game setup\n");	

	jnx_hashmap *config = create_configuration();
	
	if(game_setup(config) == 0)
	{
		game_run();
	}
	else{
		return 1;
	}	
	return 0;
}
示例#5
0
static PRESULT sudoku_setup_callback(POBJECT_HEAD obj, VEVENT event, UINT32 param1, UINT32 param2)
{
    return game_setup(obj, event, param1, param2);
}
示例#6
0
 //------------------------------------------------------------
 // La función principal main()
 //------------------------------------------------------------
 int main(int argc, char **argv)
 {
     // Iniciar Allegro (y añadidos)
     al_init();
     al_init_image_addon();
     al_init_primitives_addon();
  
     // Instalar el mouse, teclado, etc.
     al_install_keyboard();
     al_install_mouse();
  
     if (FULLSCREEN)
         al_set_new_display_flags(ALLEGRO_FULLSCREEN);
  
     // Crear el "display"
     display = al_create_display(SCREEN_W, SCREEN_H);
  
     if (!SHOW_CURSOR)
         al_hide_mouse_cursor(display);
  
     // Poner el título de la ventana
     al_set_window_title(display, WINDOW_TITLE);
  
     // Creamos el timer (controlador de FPS)
     timer = al_create_timer(1.0 / FRAMERATE);
  
     // Creamos la 'pila' de eventos
     event_queue = al_create_event_queue();
  
     // Preparamos el juego
     game_setup();
  
     // Los eventos que usaremos
     al_register_event_source(event_queue, al_get_keyboard_event_source());
     al_register_event_source(event_queue, al_get_mouse_event_source());
     al_register_event_source(event_queue, al_get_display_event_source(display));
     al_register_event_source(event_queue, al_get_timer_event_source(timer));
  
     al_start_timer(timer);
  
     // Si esta variable se pone a 0, el juego terminará de inmediato
     game_is_running = 1;
  
     ALLEGRO_EVENT event;
  
     // El 'loop' principal del juego
     while (game_is_running)
     {
         al_wait_for_event(event_queue, &event);
  
         // Si el botón para cerrar fue presionado...
         if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
             break;
  
         // Actualizamos las teclas
         if (event.type == ALLEGRO_EVENT_KEY_DOWN)
         {
             // Al presionar <Esc> el juego terminará
             if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
                 game_is_running = 0;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_LEFT)
                 key[KEY_LEFT] = 1;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_RIGHT)
                 key[KEY_RIGHT] = 1;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_UP)
                 key[KEY_UP] = 1;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_DOWN)
                 key[KEY_DOWN] = 1;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_X)
                 key[KEY_X] = 1;
         }
  
         // Actualizamos las teclas
         if (event.type == ALLEGRO_EVENT_KEY_UP)
         {
             if (event.keyboard.keycode == ALLEGRO_KEY_LEFT)
                 key[KEY_LEFT] = 0;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_RIGHT)
                 key[KEY_RIGHT] = 0;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_UP)
                 key[KEY_UP] = 0;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_DOWN)
                 key[KEY_DOWN] = 0;
  
             if (event.keyboard.keycode == ALLEGRO_KEY_X)
                 key[KEY_X] = 0;
         }
  
         if (event.type == ALLEGRO_EVENT_TIMER)
         {
             game_update();
             redraw = 1;
         }
  
         if (redraw)
         {
             redraw = 0;
  
             al_clear_to_color(al_map_rgb(0, 0, 0));
  
             game_render();
  
             al_flip_display();
         }
     }
  
     al_destroy_display(display);
     al_destroy_timer(timer);
     al_destroy_event_queue(event_queue);
  
     game_shutdown();
  
     return 0;
 }
示例#7
0
文件: game.c 项目: phmagic/snakey
static void game_start()
{
    game_setup();
    game_timer = app_timer_register(GAME_TICK_INTERVAL, game_tick, NULL);
}
示例#8
0
int main(int argc, char **argv)
{
	int i, cc;
	char msg[MSG_BFR_SZ];
	char tag[MSG_BFR_SZ];

	struct player_data *p = NULL;

	--argc; ++argv;
	setbuf(stdout, NULL);
	setbuf(stdin , NULL);

	if (!client_setup(&argc, &argv))
		return EXIT_FAILURE;

	recv(msg); sscanf(msg, "%*s %d", &SELF.id);
	sprintf(msg, "NAME %s", BOT_NAME); send(msg);

	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "READY")) break;
		else if (!strcmp(tag, "PLAYERS"))
		{
			sscanf(msg, "%*s %u", &numplayers);
			for (i = 0, p = players; i < numplayers; ++i, ++p)
			{
				recv(msg); sscanf(msg, "%u %u", &p->id, &p->pool);
				p->wager = p->card = p->active = 0;
			}
		}
		else if (!strcmp(tag, "CARDS"))
			sscanf(msg, "%*s %u %u", &XRANGE, &XDUP);
		else if (!strcmp(tag, "ANTE"));
			sscanf(msg, "%*s %*d %u", &ROUNDS_TO_DBL);
	}

	if (!p) EXPECTED(tag, "PLAYERS");
	copyself(); game_setup(players, numplayers);

	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "ENDGAME")) break;
		else if (!strcmp(tag, "ROUND"))
		{
			unsigned int rnum, pstart, rante;
			sscanf(msg, "%*s %u %u %u", &rnum, &pstart, &rante);
			copyself(); round_start(rnum, pstart, rante);

			while ((cc = recv(msg)))
			{
				sscanf(msg, "%s", tag);
				if (!strcmp(tag, "TURN"))
				{
					for (i = 0, p = players; i < numplayers; ++i, ++p)
					{
						recv(msg);
						sscanf(msg, "%u %u %u %u %u", &p->id, &p->card, &p->pool, 
							&p->wager, &p->active);
					}

					copyself(); recv(tag);
					if (strcmp(tag, "GO")) EXPECTED(tag, "GO");
					int k = player_turn(players, numplayers);

					// perform the chosen action
					switch (k)
					{
						case CALL: sprintf(msg, "CALL"); break;
						case FOLD: sprintf(msg, "FOLD"); break;
						default:   sprintf(msg, "WAGER %d", k); break;
					}
					send(msg);
				}
				else if (!strcmp(tag, "ENDROUND"))
				{
					int winnings; sscanf(msg, "%*s %u", &winnings);
					for (i = 0, p = players; i < numplayers; ++i, ++p)
					{
						recv(msg); p->wager = p->active = 0;
						sscanf(msg, "%u %u %u", &p->id, &p->card, &p->pool);
					}
					copyself(); round_end(players, numplayers, winnings);
					break;
				}
				// got an unexpected message...
				else EXPECTED(tag, "TURN/ENDROUND");
			}
		}
		// got an unexpected message...
		else EXPECTED(tag, "ROUND/ENDGAME");
	}

	game_end();
	return EXIT_SUCCESS;
}
示例#9
0
int main(int argc, char **argv)
{
	int i, cc;
	char msg[MSG_BFR_SZ];
	char tag[MSG_BFR_SZ];

	struct player_data *p = NULL;

	--argc; ++argv;
	setbuf(stdout, NULL);
	setbuf(stdin , NULL);
	
	struct timeval tv;
	gettimeofday(&tv, NULL);
	if (!client_setup(&argc, &argv))
		return EXIT_FAILURE;

	recv(msg); sscanf(msg, "%*s %d", &SELF.id);
	sprintf(msg, "NAME %s", BOT_NAME); send(msg);
	
	srand(tv.tv_usec+SELF.id);
	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "READY")) break;
		else if (!strcmp(tag, "BOARD"))
			sscanf(msg, "%*s %u", &BOARDSIZE);
		else if (!strcmp(tag, "PLAYERS"))
		{
			sscanf(msg, "%*s %u", &NUMPLAYERS);
			for (i = 0, p = players; i < NUMPLAYERS; ++i, ++p)
			{
				p->id = i;
				p->lastscore = p->score = 0;
			}
		}
		else if (!strcmp(tag, "ROUNDS"))
			sscanf(msg, "%*s %u", &NUMROUNDS);
	}

	copyself(); game_setup(players);

	unsigned int rnum;
	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "ENDGAME")) break;
		else if (!strcmp(tag, "ROUND"))
		{
			unsigned int rnum;
			sscanf(msg, "%*s %u", &rnum);
			
			while ((cc = recv(msg)))
			{
				sscanf(msg, "%s", tag);
				
				if (!strcmp(tag, "GO")) break;
				else EXPECTED(tag, "GO");
			}

			copyself();
			player_turn(rnum, players);

			clamp(&SELF.cow.x, 0, BOARDSIZE);
			clamp(&SELF.cow.y, 0, BOARDSIZE);

			clamp(&SELF.fence1.x, 0, BOARDSIZE);
			clamp(&SELF.fence2.x, SELF.fence1.x, BOARDSIZE);

			clamp(&SELF.fence1.y, 0, BOARDSIZE);
			clamp(&SELF.fence2.y, SELF.fence1.y, BOARDSIZE);

			sprintf(msg, "MOVE %u %u %u %u %u %u"
			,	SELF.cow.x, SELF.cow.y
			,	SELF.fence1.x, SELF.fence1.y
			,	SELF.fence2.x, SELF.fence2.y
			);
			send(msg);
			
			while ((cc = recv(msg)))
			{
				sscanf(msg, "%s", tag);
				
				if (!strcmp(tag, "NEXT")) break;
				else if (!strcmp(tag, "PLAYER"))
				{
					sscanf(msg, "%*s %d", &i);
					p = &players[i];

					sscanf(msg, "%*s %*d %u %u %u %u %u %u %u %u"
					,	&p->cow.x, &p->cow.y
					,	&p->fence1.x, &p->fence1.y
					,	&p->fence2.x, &p->fence2.y
					,	&p->lastscore, &p->score
					);
				}
			}
		}
		
		// got an unexpected message...
		else EXPECTED(tag, "ROUND/ENDGAME/MOVE/UPDATE");
	}

	quit: game_end();
	return EXIT_SUCCESS;
}
示例#10
0
void game_run()
{
	int x, y, a, b, c;

	unsigned short padbuf;

	while(speed_counter > 0)
	{
		scc++;
		
		if(vibration_cntdown > 0)
		{
			printf("vibration = %d\n", vibration_cntdown);
			pad_enable_vibration(0);
			pad_set_vibration(0, 0xFF, 0x80);
			vibration_cntdown--;
			
			if(vibration_cntdown == 0)
				pad_set_vibration(0, 0, 0);
		}	
		
		PSX_ReadPad(&padbuf, NULL);
		
		if(scc == 5 && !game_over)
		{
			if(snake_dir <= SNAKE_DIR_RIGHT)
			{
				if(padbuf & PAD_UP)
					snake_dir = SNAKE_DIR_UP;
							
				if(padbuf & PAD_DOWN)
					snake_dir = SNAKE_DIR_DOWN;
			}
			else
			{	
				if(padbuf & PAD_LEFT)	
					snake_dir = SNAKE_DIR_LEFT;
							
				if(padbuf & PAD_RIGHT)
					snake_dir = SNAKE_DIR_RIGHT;
			}
			
			for(y = 0; y < 29; y++)
				for(x = 0; x < 40; x++)
				{
					if(snake_array[y][x] == snake_size)
					{
						switch(snake_dir)
						{
							case SNAKE_DIR_LEFT:
								b = y;
								a = x-1;
							break;
							case SNAKE_DIR_RIGHT:
								b = y;
								a = x+1;
							break;								
							case SNAKE_DIR_UP:
								b = y-1;
								a = x;
							break;
							case SNAKE_DIR_DOWN:
								b = y+1;
								a = x;
							break;
						}
						
						c = check_snake_collision(a,b);
						
						if(c)
						{
							snake_array[b][a] = snake_size+1;
							
							if(c==2)
							{
								snake_size++;
								score+=100;
								//printf("%d\n", score);
								SsKeyOn(2);
								new_apple();
							}
						}
						else
						{
							vibration_cntdown = 10;
							game_over = 1;
							SsKeyOff(0);
							SsKeyOn(1);
							scc = 0;
						}
						
						if(snake_array[y][x] == 1 && c!=2)
							snake_array[y][x] = 0;
						
						goto out_of_collision_checking;
					}
				}
out_of_collision_checking:				
			for(y = 0; y < 29; y++)
				for(x = 0; x < 40; x++)
					if(snake_array[y][x]&&snake_array[y][x]<0x80&&c!=2)
						snake_array[y][x]--;
			
			scc = 0;
		}
		else if(game_over)
		{
			scc++;
			
			if(scc >= 510)
			{
				if((padbuf & PAD_CROSS) && !cross_pressed)
				{
					game_setup();
					cross_pressed = 1;
				}
				else if((padbuf & PAD_CIRCLE) && !circle_pressed)
				{
					circle_pressed = 1;
					GsSetVideoMode(320, 240, pal_or_ntsc_selection());
					game_setup();
				}
			
				if(!(padbuf & PAD_CROSS))
					cross_pressed = 0;
				
				if(!(padbuf & PAD_CIRCLE))
					circle_pressed = 0;
			}
		}
			
		speed_counter--;
	}
	

	if(screen_old)
	{
		game_rect.x = 0;
		game_rect.y = 0;
		game_rect.w = 320;
		game_rect.h = 240;
		game_rect.r = 0;
		game_rect.g = 0;
		game_rect.b = 0;
		game_rect.attribute = 0;
			
		GsSortRectangle(&game_rect);
		
		game_sprite.x = 0;
		game_sprite.y = 0;
		game_sprite.w = 256;
		game_sprite.h = 240;
		game_sprite.u = 0;
		game_sprite.v = 0;
		game_sprite.r = NORMAL_LUMINOSITY;
		game_sprite.g = NORMAL_LUMINOSITY;
		game_sprite.b = NORMAL_LUMINOSITY;
		game_sprite.tpage = 5;
		game_sprite.attribute = COLORMODE(COLORMODE_16BPP);
		
		GsSortSimpleSprite(&game_sprite);
		
		game_sprite.x += 256;
		game_sprite.w = 64;
		game_sprite.tpage = 9;
			
		GsSortSimpleSprite(&game_sprite);	
			
		game_rect.w = 8;
		game_rect.h = 8;
		game_rect.attribute = ENABLE_TRANS | TRANS_MODE(0);
			
		for(y = 0; y < 29; y++)
		{
			for(x = 0; x < 40; x++)
			{
				game_rect.x = x * 8;
				game_rect.y = y * 8;
					
				if(snake_array[y][x] >= 1 && snake_array[y][x] <= 0x7F)
				{
					game_rect.r = 0;
					game_rect.g = 255;
					game_rect.b = 0;
					GsSortRectangle(&game_rect);
				}
				else if(snake_array[y][x] == 0x80)
				{
					game_rect.r = 255;
					game_rect.g = 0;
					game_rect.b = 255;
					GsSortRectangle(&game_rect);
				}
				else if(snake_array[y][x] == 0x81)
				{
					game_rect.r = 0;
					game_rect.g = 0;
					game_rect.b = 128;
					GsSortRectangle(&game_rect);
				}
			}
		}
		
		sprintf(string_buf, "SCORE: %d", score);
		game_print(string_buf, 0, 232);

		if(game_over)
		{

			game_rect.w = 320;
			game_rect.h = 240;
			
			game_rect.x = 0;
			game_rect.y = 0;
			
			if(scc<=255)x=scc;else x=255;
			
			game_rect.r = x;
			game_rect.g = x;
			game_rect.b = x;
			game_rect.attribute = ENABLE_TRANS|TRANS_MODE(2);
					
			GsSortRectangle(&game_rect);
			
			if(scc>=300)
			{
				game_center_print("GAME OVER!", 160, 120);
			}
			
			if(scc>=420)
				game_center_print("WHAT DO YOU WANT TO DO NOW?", 160, 136);
				
			if(scc>=450)
				game_center_print("PRESS X TO RESTART THE GAME.",160, 152);
			
			if(scc>=480)
				game_center_print("PRESS O FOR PAL/NTSC SELECTION SCREEN.",160,168);	
				
			if(scc>=510)
				game_center_print("MADE WITH PSXSDK BY GIUSEPPE GATTA, 2010", 160, 200);
		}
			
		GsDrawList();
		
// While the graphic synthesizer (video card) is drawing
// just sleep.				
		while(GsIsDrawing());

// Swap drawing and display Y position, and swap list array
// to use. In this way we achieve a double buffer.
		
		if(game_dispenv.y == 0)
		{
			game_dispenv.y = 256;
			game_drawenv.y = 0;
		}
		else
		{
			game_dispenv.y = 0;
			game_drawenv.y = 256;
		}
			
		GsSetDispEnv(&game_dispenv);
		GsSetDrawEnv(&game_drawenv);
			
		screen_old = 0;
	}
}
示例#11
0
int main()
{
	int c;

// Initialize
	game_init();
	
	printf("PSXsnake\n");
	printf("(c) 2009 Giuseppe Gatta\n");
	printf("Made with PSXSDK\n\n");
	
	load_file_into_buffer("cdrom:FONT.TIM;1");
	GsImageFromTim(&game_image, file_buffer);
	
	GsUploadImage(&game_image);
	
	game_clut[0] = 0x0;
	game_clut[1] = 0x7fff;
	
	LoadImage(game_clut, 640, 24, 16, 1);
	
	GsSetVideoMode(320, 240, EXAMPLES_VMODE);
	
	vmode = pal_or_ntsc_selection();
	
	//printf("vmode = %d\n", vmode);
	
	GsSetVideoMode(320, 240, vmode);
	
	
	load_file_into_buffer("cdrom:BACKGRND.TIM;1");
	GsImageFromTim(&game_image, file_buffer);
	
	GsUploadImage(&game_image);
	
	sample_pos[0] = SPU_DATA_BASE_ADDR;
	c = load_file_into_buffer("cdrom:MUSIC.RAW;1");
	SsUpload(file_buffer, c, sample_pos[0]);
	
	if(c&0x7)
	{
		c|=0x7;
		c++;
	}
	
	sample_pos[1] = c + sample_pos[0];
	c = load_file_into_buffer("cdrom:BOMB.RAW;1");
	SsUpload(file_buffer, c, sample_pos[1]);
	
	/* ... */
	if(c&0x7)
	{
		c|=0x7;
		c++;
	}
	
	sample_pos[2] = c + sample_pos[1];
	c = load_file_into_buffer("cdrom:APPLE.RAW;1");
	SsUpload(file_buffer, c, sample_pos[2]);
	
	SsVoiceStartAddr(0, sample_pos[0]);
	SsVoiceStartAddr(1, sample_pos[1]);
	SsVoiceStartAddr(2, sample_pos[2]);
	
	SsVoiceVol(0, 0x3fff, 0x3fff);
	SsVoiceVol(1, 0x3fff, 0x3fff);
	SsVoiceVol(2, 0x3fff, 0x3fff);
	
	SsVoicePitch(0, 0x1000 / (44100 / 11025));
	SsVoicePitch(1, 0x1000 / (44100 / 11025));
	SsVoicePitch(2, 0x1000);
	
	game_setup();
	
	SetVBlankHandler(game_vblank_handler);
	
	
	while(1)
		game_run();
		
	return 0;
}
示例#12
0
static inline void boot()
{
    RECT rect;
    CLOCK clock;

    RECT ball_rect;
    VEL ball_vel;
    BALL ball;

    ball.rect = ball_rect;
    ball.vel = ball_vel;

    RECT bat_rect;
    BAT bat;

    bat.rect = bat_rect;

    char chlives[4];

    chlives[0] = '=';
    chlives[1] = '$';
    chlives[2] = '&';
    chlives[3] = '|';

    BTYPE btypes[NBTYPES];

    btypes[0].lives = 1;
    btypes[0].score = 2;

    btypes[1].lives = 2;
    btypes[1].score = 4;

    btypes[2].lives = 3;
    btypes[2].score = 8;

    btypes[3].lives = 4;
    btypes[3].score = 16;

    BRICK bricks[NBRICKS];

    int konami_keys[10];

    konami_keys[0] = KEY_UP;
    konami_keys[1] = KEY_UP;
    konami_keys[2] = KEY_DOWN;
    konami_keys[3] = KEY_DOWN;
    konami_keys[4] = KEY_LEFT;
    konami_keys[5] = KEY_RIGHT;
    konami_keys[6] = KEY_LEFT;
    konami_keys[7] = KEY_RIGHT;
    konami_keys[8] = 'B';
    konami_keys[9] = 'A';

    KONAMI konami;

    konami.nkeys = 10;
    konami.keys = konami_keys;

    GAME game;

    game.win = stdscr;
    game.rect = rect;
    game.clock = clock;
    game.ball = &ball;
    game.bat = &bat;

    game.nchlives = NCHLIVES;
    game.chlives = chlives;

    game.nbtypes = NBTYPES;
    game.btypes = btypes;

    game.nbricks = NBRICKS;
    game.rbricks = NBRICKS;
    game.bricks = bricks;

    game.title = "Ncurses C Breakout";

#ifdef DEBUG
    game.debug = true;
#else
    game.debug = false;
#endif

    game.konami = &konami;

    game_setup(&game);
    game_run(&game);
}