Esempio n. 1
0
static void do_game(game_t *p_game)
{
  while(1)
    {
      uint32_t before, after;
      uint32_t keys;

      before = vGetTickCount(); /* Get the current ms ticks */

      keys = vGetButtonData();
      handle_input(p_game, keys);
      move_hero(p_game, &p_game->player);

      if (keys & KEY_SELECT)
	return;
      draw_game(p_game);

      after = vGetTickCount(); /* Get the current ms ticks */
      /* Every loop iteration should take about SLEEP_PERIOD, see to that */
      if ((after - before) < SLEEP_PERIOD)
	{
	  msSleep( SLEEP_PERIOD - (after-before) );
	}
    }
}
Esempio n. 2
0
int main(void)
{
	int i;

	srand((unsigned)time(NULL));
	setcursortype(NOCURSOR);
	draw_title(); 
	reset();

	while (1)
	{
		for (i = 0; i<5; i++) //블록이 한칸떨어지는동안 5번 키입력받을 수 있음 
		{ 
			process_key(); //키입력확인 
			draw_game();
			Sleep(speed);
			if (crush_on&&check_crush(bx, by + 1, b_rotation) == false) 
				Sleep(100); //블록이 충돌중인경우 추가로 이동및 회전할 시간을 갖음
			if (space_key_on == 1) //스페이스바를 누른경우(hard drop) 추가로 이동및 회전할수 없음 break; 
			{ 
				space_key_on = 0;
				break;
			}
		}
		move_down();  
		check_level_up(); 
		check_game_over(); 
		if (new_block_on == 1)
			new_block(); // 뉴 블럭 flag가 있는 경우 새로운 블럭 생성 
	}
}
Esempio n. 3
0
File: 2048.c Progetto: theta43/2048
int
main (void)
{
	bool win_condition = false;
	int ret, ch;

	puts ("Playing 2048 " VERSION " in ASCII mode");

	init_tiles (&game);

	ch = ret = 0;
	do {
		draw_game ();
		printf ("move [wasd]: ");
		fflush (NULL);

		if (ch == 0)
			continue;

		enum tile_dir dir = -1;

		switch (ch) {
		case 'W': dir = UP;	break;
		case 'A': dir = LEFT;	break;
		case 'S': dir = DOWN;	break;
		case 'D': dir = RIGHT;	break;
		default: continue;
		}

		if (move_tiles (&game, dir) == -1)
			break;

		if (game.max_tile == 2048 && !win_condition) {
			win_condition = 1;
			if (!ask_yn ("You won! Do you wish to continue? [Y/n]"))
				break;
		}

	} while ((ch = toupper(getchar())) != EOF);

	destroy_tiles (&game);

	printf ("\nScore: %d\n", game.score);
	if (game.max_tile < 2048) {
		puts ("You lost. Better luck next time\n");
		return 1;
	}

	return 0;
}
Esempio n. 4
0
int main(void)
{
    int w, h;
    for (h = 0; h < 90; ++h) {
        for (w = 0; w < 120; ++w) {
            map_color_scalar[h][w] = 0.f;
        }
    }

    chat_index = 0;

    TCOD_console_init_root(160, 128, "console rpg v0.01", true);
    TCOD_console_t map_console = TCOD_console_new(122, 92);
    TCOD_console_t chat_console = TCOD_console_new(122, 30);
    TCOD_map_t map = TCOD_map_new(120, 90);
    TCOD_text_t chat = TCOD_text_init(1, 28, 120, 1, 255);
    TCOD_text_set_properties(chat, TCOD_CHAR_BLOCK1, 2, ">> ", 4);
    TCOD_mouse_show_cursor(true);
    TCOD_console_set_keyboard_repeat(0, 50); 
    TCOD_sys_set_fps(60);
    end_game = entering_text = false;
    x = y = 10.f;
    vx = vy = 10.f;
    w_key = a_key = s_key = d_key = false;

    /* TODO generate map properties differently -- load from file, etc. */
    for (h = 0; h < 90; ++h) {
        for (w = 0; w < 120; ++w) {
            if (h == 0 || h == 89 || w == 0 || w == 99 || (w == 24 && h != 14 && h != 15)) {
                TCOD_map_set_properties(map, w, h, false, false);
            }
            else {
                TCOD_map_set_properties(map, w, h, true, true);
            }
        }
    }

    /* TODO game loop */
    while (!end_game && !TCOD_console_is_window_closed()) {
        handle_input(chat);
        update_game(map);
        draw_game(map_console, map, chat_console, chat);
    }

    free_stuff();
    return EXIT_SUCCESS;
}
Esempio n. 5
0
int main(int argc, char **argv) {
    srand((unsigned)time(NULL));

    allegro_init();
    install_keyboard();
    install_timer();
    set_color_depth(32);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0);
    BITMAP *orig_screen = screen;
    screen = create_bitmap(SCREEN_W, SCREEN_H);

    LOCK_VARIABLE(timer);
    LOCK_FUNCTION(timer_increment);
    install_int_ex(timer_increment, BPS_TO_TIMER(60));

    int need_redraw = 1;
    Game game;
    init_game(&game);

    while(!game.end) {
        for(; timer > 0; --timer) {
            need_redraw = 1;
            get_input(&game);
            update_game(&game);

            if(timer > 4) {
                timer = 0;
                break;
            }
        }

        if(need_redraw) {
            clear_to_color(screen, makecol(0,0,0));
            draw_game(&game, screen);
            blit(screen, orig_screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
        }
        else
            sched_yield();
    }

    delete_list(game.asteroids);
    delete_list(game.shot);
    delete_list(game.particles);

    return 0;
}
Esempio n. 6
0
void reset(void) //각종 변수 초기화
{
	level = 1; 
	level_goal = 1000;
	key = 0;
	crush_on = 0;
	cnt = 0;
	score = 0;
	speed = 100;

	system("cls"); //화면지움 
	reset_game();
	draw_stat();
	draw_game();

	b_type_next = rand() % 7; //다음번에 나올 블록 종류를 랜덤하게 생성 
	new_block(); //새로운 블록을 하나 만듦  
}
Esempio n. 7
0
void ram(void){
	while(1) {
    if (!screen_intro())
     return;
    init_game();
    while(game.ships > 0){
      game.ticks++;
      lcdFill(0);
      conrtols();
      draw_game();
      lcdDisplay();
      delayms_queue_plus(12,0);
      if(game.shot_delay > 0){
        game.shot_delay--;
      }
    }
    draw_splash();
	}
}
Esempio n. 8
0
void retro_run(void)
{
   input_poll_cb();

   ks.up     = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
   ks.right  = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT);
   ks.down   = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
   ks.left   = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT);
   ks.start  = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
   ks.select = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT);
   ks.a      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
   ks.b      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
   ks.x      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
   ks.y      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);

   update_game();

   draw_game();

   video_cb(fb, SCREEN_WIDTH, SCREEN_HEIGHT, fbpitch*2);
}
Esempio n. 9
0
void draw(Game_Data *data)
{
	switch(current_state)
	{
		case GAME:
		draw_game(data);
		break;
		case TITLE:
		draw_title(data);
		break;
		case MENU:
		draw_menu(data);
		break;
		case GAME_OVER:
		draw_game_over(data);
		break;
		case OUT_OF_MEMORY:
		draw_oom(data);
		break;
	}
}
Esempio n. 10
0
int main()
{
	
		printf_s("\n\n\n\n\n\n\n\n");
		
		while(player_status){

			enemys_alive();
			enemys_movement();
			draw_game();
			events();
		
			Sleep(100);
			time++;
			printf_s("  Score:%d", score);
			printf_s("\r");
		}
		player_died();
		getchar();
	
	return 0;
}
Esempio n. 11
0
int main(void)
{
#if !SDL
	//wdt_enable(WDTO_1S);

	// I/O ports

	DDRB = 0x17;
	PORTB = 0x00 | (1<<5);
	//input logic disable on adc3
	DIDR0 = (1<<ADC3D);

	//timer0
	
	//set clock divider to 1024
	TCCR0B |= (1<<CS02) | (1<<CS00);
	//compare value 49 -> 20Hz
	//OCR0B = 49;
	OCR0B = 3;
	//enable compare match B interrupt
	TIMSK |= (1<<OCIE0B);

	//timer1

	//      CK/64
	//TCCR1 = (1<<CS12) | (1<<CS11) | (1<<CS10);
	//overflow interrupt
	//TIMSK |= (1<<TOIE1);

	//external interrupts
	
	//enable pin change interrupt
	//GIMSK = (1<<PCIE);
	//enable only on PB3
	//PCMSK = (1<<3);
	
	//adc
	
	//       enable      clk/16
	//ADCSRA = (1<<ADEN) | (1<<ADPS2);
	//       enable      clk/2
	ADCSRA = (1<<ADEN) | (1<<ADPS0);

	/*//if it's a watchdog reset
	if(mcusr_mirror & (1<<WDRF)){
		if(getkey() == DIR_NONE){
			set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			sleep_mode();
		}
	}*/

	//wdt_enable(WDTO_4S);

#else

	SDL_Init(SDL_INIT_VIDEO);
	if (!(screen = SDL_SetVideoMode(80, 48, 32, SDL_SWSURFACE)))
		return EXIT_FAILURE;

	SDL_WM_SetCaption("elladunkku", NULL);

#endif

	/*g_highscore = eeprom_read_byte(0);
	if(g_highscore == 0xff) g_highscore = 0;*/
	/*g_highscore = eeprom_read_word(0);
	if(g_highscore == 0xffff) g_highscore = 0;*/

start:

	lcd_init();

	//lcd_locate(10,2);
	//lcd_locate8((2<<4)+1);
	//lcd_printstrP(PSTR("C55 PRESENTS"));
	//_delay_ms(1000);

	sei();

	for(;;){

		next_level(true);
		draw_game();

		//main loop

		g_counter0 = 0;
		//TCNT0 = 0;
		for(;;){
#if SDL
			++g_counter0;
			SDL_WaitEvent(&g_event);
			if (g_event.type == SDL_QUIT)
				goto quit;
#endif

			// TODO: If nothing happens for a long time, go to sleep

			int8_t key = getkey();
			if(key == DIR_NONE)
				continue;

			uint8_t num_enemy_moves = move_player(key);
			switch(num_enemy_moves){
			case 2:
				step_enemies();
				draw_game();
			case 1:
				step_enemies();
			}
			draw_game();

			if(g_hp <= 0){
				_delay_ms(5000);
				while(getkey() == DIR_NONE);
				next_level(true); // Reset game
				draw_game();
			}

			/*int8_t lastdir_inv = -g_next_dir;
			while(g_counter0 < 6){
			//while(TCNT0 < 6*3){
				int8_t key = getkey();
				if(key == DIR_NONE) continue;
				if(key == lastdir_inv) continue;
				g_next_dir = key;
				g_random += g_counter0;
			}
			TCNT0 = 0;
			g_counter0 = 0;
			uint8_t ret = snake_move_and_draw();
			if(ret == 1){
				snake_draw(0xaa);
				draw_block(g_snake[g_snake_end], 0xff);
				//lcd_locate(83,5);
				lcd_locate8((0<<4)+4);
				if(g_points > g_highscore){
					g_highscore = g_points;
					//eeprom_write_byte(0, g_highscore);
					eeprom_write_word(0, g_highscore);
				}
				_delay_ms(200);
				break;
			}*/
		}

#if !SDL
		while(getkey() != DIR_NONE);
		//TCNT0 = 0;
		g_counter0 = 0;
		while(getkey() == DIR_NONE){
			if(g_counter0 >= 200){
				cli();

				/*lcd_cls();
				lcd_locate8((1<<4)+0);
				lcd_printstrP(PSTR("GREETINGS  ELLA  TEJEEZ  3210"));
				_delay_ms(2000);*/
				/*lcd_locate8((1<<4)+1);
				lcd_printstrP(PSTR("GREETINGS ELLA TEJEEZ"));
				lcd_locate8((2<<4)+1);
				lcd_printstrP(PSTR("ELLA"));
				lcd_locate8((3<<4)+1);
				lcd_printstrP(PSTR("TEJEEZ"));*/
				/*lcd_cls();
				lcd_locate8((1<<4)+3);
				lcd_put5digit(2048);
				lcd_locate8((2<<4)+3);
				lcd_put5digit(128);
				lcd_locate8((3<<4)+3);
				lcd_put5digit(55);
				_delay_ms(2000);*/
				
				lcd_cls();
				lcd_powerdown();

				ADCSRA = 0 | (1<<ADPS0);
				DIDR0 = 0;
				CLKPR = 0x80;
				CLKPR = (1<<CLKPS3); //256
				while(PINB & (1<<3));
				//while(getkey() == DIR_NONE);
				CLKPR = 0x80;
				CLKPR = 0;
				DIDR0 = (1<<ADC3D);
				ADCSRA = (1<<ADEN) | (1<<ADPS0);

				goto start;
			}
		}
#endif
	}

#if SDL
quit:
	SDL_Quit();
#endif
	return 0;
}
Esempio n. 12
0
void Life::timer_game(int = 0){
	static_this->field.make_step();
	draw_game();
	glutTimerFunc(50, &Life::timer_game, 0);
}
Esempio n. 13
0
File: game.c Progetto: allenbo/chess
Game* 
create_game(GtkWidget* widget, GdkPixmap* pixmap) {
	Game* game = (Game*)malloc(sizeof(Game));
	game->board = create_board();
	game->red   = create_user(red);
	game->black = create_user(black);

	//create all chessman
	int index = 0;
	int i = 0;
	//create the red soldiers
	for(i=0; i<5; i++) {
		game->man[index] = create_chessman(red, soldier, index, game->board,
				game->red, red_soldier_image,3, i*2);
		index ++;
	}
	//create the red cannons
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, cannon, index, game->board,
				game->red, red_cannon_image,2, 6*i + 1);
		index ++;
	}
	//create the red tanks
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, tank, index, game->board,
				game->red, red_tank_image,0, 8*i);
		index ++;
	}
	//create the red horses
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, horse, index, game->board,
				game->red, red_horse_image, 0, 6*i +1);
		index ++;
	}
	//create the red chancellors
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, chancellor, index, game->board,
				game->red, red_chancellor_image, 0, 4*i +2);
		index ++;
	}
	//create the red scholars
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(red, scholar, index, game->board,
				game->red, red_scholar_image, 0, 2*i +3);
		index ++;
	}
	game->man[index] = create_chessman(red, general, index, game->board,
			game->red, red_general_image, 0, 4);
	index ++;
	//create the black soldiers
	for(i=0; i<5; i++) {
		game->man[index] = create_chessman(black, soldier, index, game->board,
				game->black, black_soldier_image, 6, i*2);
		index ++;
	}
	//create the black cannons
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, cannon, index, game->board,
				game->black, black_cannon_image, 7, 6*i + 1);
		index ++;
	}
	//create the black tanks
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, tank, index, game->board,
				game->black, black_tank_image, 9, 8*i);
		index ++;
	}
	//create the black horses
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, horse, index, game->board,
				game->black, black_horse_image, 9, 6*i +1);
		index ++;
	}
	//create the black chancellors
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, chancellor, index, game->board,
				game->black, black_chancellor_image, 9, 4*i +2);
		index ++;
	}
	//create the black scholars
	for(i = 0; i < 2; i ++) {
		game->man[index] = create_chessman(black, scholar, index, game->board,
				game->black, black_scholar_image, 9, 2*i +3);
		index ++;
	}
	game->man[index] = create_chessman(black, general, index, game->board,
			game->black, black_general_image, 9, 4);
	index ++;
	game->current_user = game->red;
	game->current_man = NULL;
	game->level = 0;
	game->mode  = 0;

	draw_game(game, pixmap);
	gtk_widget_draw(widget, NULL);
	return game;
}
Esempio n. 14
0
int main(int argc, char *argv[])
{
    char c;
    int status = 0;
    
    printf("Hello World, I'm game!\n");
    
    status = init_display();
    if (status != 0)
    {
        printf("Error: Failed to init display\n");
        return status;
    }
    
    status = init_driver();
    if (status != 0)
    {
        printf("Error: Failed to init driver\n");
        destroy_display();
        return status;
    }
    
    status = setup_handler();
    if (status != 0)
    {
        printf("Error: Failed to init signal handler\n");
        destroy_display();
        close(file_gamepad_driver);
        return status;
    }
    time_handler();
    
    /* Intializes random number generator */
    srand((unsigned) time(&t));
    
    sigset_t myset;
    (void) sigemptyset(&myset);

    while(1)
    {
        clear_LCD();       
        draw_game();
        draw_score(p1_score, p2_score);
        redraw();
        
        waitForButton();      
        printf("start game\n");
        
        while((p1_score < 5) && (p2_score < 5))
        {
            random_timer = (rand() % 3) + 2;
            startTimer(random_timer);
            waitForTimer();
            
            random_button = (rand() % 4);
            
            draw_button(random_button, true, RED);
            redraw();
            
            gettimeofday(&time_button_appears, NULL);

            // start timer
            startTimer(3);
            buf = 0;
            while((playerButtonPressed(random_button) == 0) && (timer_expired == false))
            {
                waitForButton(); 
            }
            
            stopTimer();
            if (timer_expired == false)
            {
                time_elapsed = getGameTime();
                draw_time(time_elapsed, BLUE);
                redraw();
            }
      
            if (playerButtonPressed(random_button) == P1)
            {
                p1_score++;
                p1_time += time_elapsed;
                
            }
            else if (playerButtonPressed(random_button) == P2)
            {
                p2_score++;    
                p2_time += time_elapsed;
            }
                
            draw_score(p1_score, p2_score);    
            reset_button(random_button);
            redraw();
            
        }
        // draw winner
        button_pressed = 0;
        if (p1_score == 5)
        {
            winner = P1;
            winner_time = p1_time;
        }
        else if (p2_score == 5)
        {
            winner = P2;
            winner_time = p2_time;
        }
        
        while(button_pressed == 0)
        {
            startTimer(1);
            winner_blink(winner, winner_time);
            waitForTimer();
        }
               
        // print waiting
        waitForButton();
        p1_score = 0;
        p1_time = 0;
        p2_score = 0;
        p2_time = 0;
    }

}
Esempio n. 15
0
void check_level_up(void) //레벨 체크하는 함수
{
	int i;

	if (cnt >= 10) //레벨별로 10줄씩 없애야함. 10줄이상 없앤 경우 
	{ 
		draw_game();
		level_up_on = 1; //레벨업 flag를 띄움 
		level = level + 1;
		cnt = 0; //지운 줄수 초기화   

		for (i = 0; i<4; i++) //애니메이션
		{
			gotoxy(main_x_start + (width_x / 2) - 3, main_y_start + 4);
			printf("             ");
			gotoxy(main_x_start + (width_x / 2) - 2, main_y_start + 6);
			printf("             ");
			Sleep(200);

			gotoxy(main_x_start + (width_x / 2) - 3, main_y_start + 4);
			printf("Level Up!");
			gotoxy(main_x_start + (width_x / 2) - 2, main_y_start + 6);
			printf("Speed Up!");
			Sleep(200);
		}

		reset_game_tmp(); //텍스트를 지우기 위해 game_tmp을 초기화.
		check_line(); //블록으로 모두 채운것 지우기  

		switch (level) //레벨별로 속도를 조절
		{ 
		case 2:
			speed = 50;
			break;
		case 3:
			speed = 40;
			break;
		case 4:
			speed = 30;
			break;
		case 5:
			speed = 20;
			break;
		case 6:
			speed = 10;
			break;
		case 7:
			speed = 5;
			break;
		case 8:
			speed = 3;
			break;
		case 9:
			speed = 1;
			break;
		case 10:
			speed = 0;
			break;
		}
		level_up_on = 0; //레벨업 flag꺼줌
	}
}
Esempio n. 16
0
int real_main() {
    srand48(time(NULL));

    if (!al_init()) {
        puts("Could not initialise allegro");
        return 1;
    }
    if (!al_install_keyboard()) {
        puts("Could not initialise allegro keyboard subsystem");
        return 1;
    }
    keys = malloc(sizeof(ALLEGRO_KEYBOARD_STATE));
    if (!init_font()) {
        puts("Could not initialise allegro font subsystem");
        return 1;
    }

    al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);

    ALLEGRO_DISPLAY* display = al_create_display(1, 1);
    if (!display) {
        puts("Could not initialise allegro display");
        return 1;
    }

    Vector size = new_vector();
    size.x = al_get_display_width(display);
    size.y = al_get_display_height(display);

    Game* game = new_game(size);
    int i;
    for (i = 0; i < ASTEROIDN; i++)
        spawn_asteroid(game);

    ALLEGRO_TIMER* timer = al_create_timer(1.0/FPS);

    ALLEGRO_EVENT_QUEUE *timereq = al_create_event_queue();
    ALLEGRO_EVENT_QUEUE *genericeq = al_create_event_queue();
    if (!timereq || !genericeq) {
        puts("Could not create allegro event queue");
        return 1;
    }
    al_register_event_source(timereq, al_get_timer_event_source(timer));

    al_register_event_source(genericeq, al_get_keyboard_event_source());
    al_register_event_source(genericeq, al_get_display_event_source(display));

    al_start_timer(timer); // Start generating timer events
    ALLEGRO_EVENT *timerevent = malloc(sizeof(ALLEGRO_EVENT));
    ALLEGRO_EVENT *genericevent = malloc(sizeof(ALLEGRO_EVENT));

    float last_drawn, now;
    last_drawn = now = al_get_time();
    while (game->status != Quit) {
        al_get_keyboard_state(keys);

        al_wait_for_event(timereq, NULL);
        al_get_next_event(timereq, timerevent);
        // No need to fill up the queue if we are late drawing frames
        al_flush_event_queue(timereq);

        handle_key_status(game, keys);

        while(al_get_next_event(genericeq, genericevent))
            switch(genericevent->type) {
            case ALLEGRO_EVENT_KEY_DOWN:
                handle_key_event(game, genericevent->keyboard.keycode);
                break;

            case ALLEGRO_EVENT_DISPLAY_RESIZE:
                game->size.x = genericevent->display.x;
                game->size.y = genericevent->display.y;
                al_acknowledge_resize(display);
                break;

            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                game->status = Quit;
                break;
            }

        now = al_get_time();
        update_game(game, now - last_drawn);
        last_drawn = now;

        draw_game(game, game->status == Playing ? 1 : 0.2);
        switch(game->status) {
        case Playing:
            break;
        case Paused:
            draw_paused(game);
            break;
        case Won:
            draw_won(game);
            break;
        case Lost:
            draw_lost(game);
            break;
        default:
            break;
        }

        al_flip_display();
    }

    free(timerevent);
    free(genericevent);
    delete_game(game);
    return 0;
}
Esempio n. 17
0
int main(int argc, char *argv[])
{
    WINDOW *my_win, *score;
    WINDOW **car;
    game newGame, tmpGame;
    MEVENT event;

    int ch = 0, choosenCar = -1, soluce_move = 0;
    char message[1024];
    bool quit = false;
    bool show_solution = false;
    gameStruct *resultSolv = NULL;
    //INIT
    setup();
    //END INIT
    //Wait for good size
    wait_for_size(MINH, MINW);
    //Instruction
    show_instruction(MINH, MINW);
    while (!quit) {
        quit = false;
        show_solution = false;
        soluce_move = 0;
        strcpy(message, "Playing");
        //Select game
        newGame = select_game();
        //Check for level file
        if (handle_level(&tmpGame)) {
            delete_game(newGame);
            newGame = tmpGame;
            MAXCOL = game_width(newGame);
            MAXROW = game_height(newGame);
            MINH = MAXROW * SIZE + 2;
            MINW = MAXCOL * SIZE;
        }
        car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame));
        //First draw
        draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        //Loop while the game is not finished
        while (!game_over(newGame)) {
            //Print on bottom of grid
            mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :");
            ch = getch();
            if (ch == 's' && !show_solution) {
                show_solution = true;
                strcpy(message, "Solution");
                resultSolv = solv(newGame, gameOverRh,true);
                if(!resultSolv){
                    strcpy(message, "No solution");
                    show_solution=false;
                }
            }
            if (show_solution) {
                newGame = play_solution(newGame, resultSolv, soluce_move++);
            } else {
                if (KEY_MOUSE == ch) {
                    /* Mouse event. */
                    if (OK == getmouse(&event)) {
                        choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame));
                    }
                } else {
                    if (ch == 'q') {
                        quit = true;
                        break;
                    }
                    play_input(newGame, ch, &choosenCar);
                }
            }
            wait_for_size(MINH, MINW);
            erase_game(newGame, my_win, car, score);
            draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        }
        if (!quit) {
            display_score(newGame);
        }
        for (int i = 0; i < game_nb_pieces(newGame); i++) {
            destroy_win(car[i]);
        }
        destroy_win(my_win);
        destroy_win(score);
        free(car);
        delete_game(newGame);
        if (resultSolv != NULL) {
            delete_game(resultSolv->current);
            free(resultSolv->move);
            free(resultSolv);
            resultSolv = NULL;
        }
    }
    endwin(); /* End curses mode		  */
    return 0;
}
Esempio n. 18
0
void NETHER::draw(int width,int height)
{
	float lightpos2[4]={0,0,1000,0};
	float tmpls[4]={1.0F,1.0F,1.0F,1.0};
	float tmpld[4]={0.6F,0.6F,0.6F,1.0};
	float tmpla[4]={0.2F,0.2F,0.2F,1.0};
    float ratio;
	int split = int((width*25.0F)/32.0F);
	int splity = 0;

	if (show_radar) splity = int((height*2.0F)/15.0F)+1;
			   else splity = 0;

	/* Enable Lights, etc.: */ 
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0,GL_AMBIENT,tmpla);
	glLightfv(GL_LIGHT0,GL_DIFFUSE,tmpld);
	glLightfv(GL_LIGHT0,GL_SPECULAR,tmpls);
	glEnable(GL_LIGHTING);
	glEnable(GL_COLOR_MATERIAL);
	glShadeModel( GL_SMOOTH );
	glCullFace( GL_BACK );
	glFrontFace( GL_CCW );
    glEnable( GL_CULL_FACE );
	glEnable( GL_SCISSOR_TEST );  
	glEnable( GL_DEPTH_TEST );
	glDepthFunc( GL_LEQUAL );
	glClearStencil(0);
	
	/* Draw the GAME screen: */ 
	glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
    glClearColor(0,0,0,0.0);
    glViewport(0,splity,split,height-splity);
	ratio=float(split)/float(height-splity);
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    gluPerspective( 30.0, ratio, 1.0, 1024.0 );
	glScissor(0,splity,split,height-splity);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
	draw_game(false);
	if (shadows) {
		/* Set STENCIL Buffer: */ 
		glStencilMask(1);
		glEnable(GL_STENCIL_TEST);
		glDepthMask(GL_FALSE);
		glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
		glStencilFunc(GL_ALWAYS,1,1);
		glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
		draw_game(true);
		glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);

		/* Draw shadow poligon: */ 
		glDepthFunc(GL_ALWAYS);
		glDisable(GL_CULL_FACE);

		glColor4f(0.0,0.0,0.0,0.4f);
		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		glEnable(GL_BLEND);

		glStencilFunc(GL_NOTEQUAL,0,1);
		glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glBegin(GL_TRIANGLE_STRIP);
		glVertex3f(-1.0, 1.0,0.0);
		glVertex3f(-1.0,-1.0,0.0);
		glVertex3f( 1.0, 1.0,0.0);
		glVertex3f( 1.0,-1.0,0.0);
		glEnd();
		glPopMatrix();

		glDisable(GL_BLEND);

		glDepthMask(GL_TRUE);
		glDepthFunc(GL_LEQUAL);
		glEnable(GL_CULL_FACE);
		glDisable(GL_STENCIL_TEST);
	} /* if */ 

	if (game_started>0) {
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity( );
		gluPerspective( 30.0, ratio, 1.0, 1024.0 );
		gluLookAt(0,0,30,0,0,0,0,1,0);
		glClear(GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		if (game_started>40) glTranslatef(0,0,(game_started-40)*2);
		if (game_started<20) glTranslatef(0,0,(20-game_started)*2);
		message_tile[0]->draw(1.0,1.0,1.0);
	} /* if */ 

	if (game_finished>100) {
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity( );
		gluPerspective( 30.0, ratio, 1.0, 1024.0 );
		gluLookAt(0,0,30,0,0,0,0,1,0);
		glClear(GL_DEPTH_BUFFER_BIT);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		if (game_finished<120) glTranslatef(0,0,(120-game_finished)*2);
		if (game_finished>240) glTranslatef(0,0,(game_finished-240)*2);
		if (statistics[0][0]==0) message_tile[2]->draw(1.0,1.0,1.0);
						    else message_tile[1]->draw(1.0,1.0,1.0);
	} /* if */ 

	/* Draw the RADAR screen: */ 
	if (show_radar && redrawradar<=1) {

		glLightfv(GL_LIGHT0,GL_POSITION,lightpos2);
		glClearColor(0.0,0.0,0,0);
		glViewport(0,0,split,splity);
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity( );
		glOrtho(0,float(split),0,float(splity),-100,100);
		glScissor(0,0,split,splity);
		glScalef(width/640.0,height/480.0,1);
		draw_radar();
	} /* if */ 
	redrawradar--;
	if (redrawradar<0) redrawradar=3;

	/* Draw the STATUS screen: */ 
	if (redrawmenu!=0) {
		redrawmenu--;

		glLightfv(GL_LIGHT0,GL_POSITION,lightpos2);
		glClearColor(0,0,0.2,0);
		glViewport(split,0,width-split,height);
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity( );
		glOrtho(0,float(width-split),0,height,-100,100);
		glScissor(split,0,width-split,height);
		glScalef(width/640.0,height/480.0,1);
		draw_status();

/*
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(70.0,10.0,0);
		glColor3f(1.0f,1.0f,1.0f);
		scaledglprintf(0.1f,0.1f,"FPS: %i",frames_per_sec);
		glPopMatrix();
*/
 
	} /* if */ 
} /* NETHER::draw */