示例#1
0
int main(int argc, wchar* argv[])
{
    //if (argc==2)
        //ndcid=atoi(argv[1]);

    if (setup_curses() < 0) die("failed to setup curses!\n");
#ifdef TARGET_PANDORA
    signal(SIGSEGV, clean_exit);
    signal(SIGKILL, clean_exit);
#endif

#if defined(USES_HOMEDIR) && HOST_OS != OS_DARWIN
    string home = (string)getenv("HOME");
    if(home.c_str())
    {
        home += "/.reicast";
        mkdir(home.c_str(), 0755); // create the directory if missing
        SetHomeDir(home);
    }
    else
        SetHomeDir(".");
#else
    SetHomeDir(".");
#endif

 /* #if defined(SUPPORT_X11)
        x11_keymap[113] = DPad_Left;
        x11_keymap[114] = DPad_Right;

        x11_keymap[111] = DPad_Up;
        x11_keymap[116] = DPad_Down;

        x11_keymap[52] = Btn_Y;
        x11_keymap[53] = Btn_X;
        x11_keymap[54] = Btn_B;
        x11_keymap[55] = Btn_A;

        x11_keymap[36] = Btn_Start;
    #endif */

    printf("Home dir is: %s\n",GetPath("/").c_str());

    common_linux_setup();

    SetupInput();

    settings.profile.run_counts=0;

    dc_init(argc,argv);

    dc_run();

#ifdef TARGET_PANDORA
    clean_exit(0);
#endif

    return 0;
}
示例#2
0
void Engine::main_loop() {
    setup_curses();

    map->update_visibility_from(player->get_pos());
    render();

    main_loop_done = false;
    while(!main_loop_done) {

        switch (state) {
            case NEUTRAL:
                if (detect_player_and_mob_turns())
                    break;

                if (detect_modal_messages())
                    break;

                tick();

                break;
            case PLAYER_TURN:
                render();
                if(handle_keypress(getch())) {
                    state = NEUTRAL;
                    player->turn_taken();
                }
                map->update_visibility_from(player->get_pos());
                break;

            case MOB_TURN:
                do_ai();
                state = NEUTRAL;
                break;

            case VIEW_INVENTORY:
                render();
                render_inv();
                doupdate();
                getch();
                state = NEUTRAL;
                break;
            case WIELD:
                do_wield();
                state = NEUTRAL;
                player->turn_taken();
                break;
            case FIRE:
                if (fire_weapon()) {
                    player->turn_taken();
                }
                state = NEUTRAL;
                break;
            case MODAL_MSG:
                render();
                render_modal_messages();
                doupdate();
                while(getch() != ' ') {}
                state = NEUTRAL;
                break;

        }

        if (player->is_dead()) {
            game_over_lost();
        }


    }

    teardown_curses();
}
示例#3
0
int main(int argc, char*argv[])
{
	int m;
	FILE* landscape;
	for (m = 0; m<argc; m++)
	{
		if (argv[m][0] == '-')
		{
			if(strlen(argv[m])==2)
			{
				switch (argv[m][1])
				{
					case 'g':
						acceleration = atof(argv[m+1]);
					case 't':
						thrust = atof(argv[m+1]);
					case 'f':
						landscape = fopen(argv[m+1],"r");
				}
			}
			else if (strlen((argv[m]))>2)
			{
				switch (argv[m][1])

				{
					case 'g':
						acceleration = atof(argv[m]+2);
					case 't':
						thrust = atof(argv[m]+2);
					case 'f':
						landscape = fopen(argv[m]+2,"r");
				}
				if (thrust < (double)(-20) && thrust > (double)(0))
				{
					printf("Thrust should not be less than -20 or over 0.\n");
					exit(1);
				}
			}
		}
	}
	
	velocity[0].x = 0;
	velocity[0].y = 0;
		

	shuttle[0].x = 315;
	shuttle[0].y = 10;
	shuttle[1].x = 310;
	shuttle[1].y = 30;
	shuttle[2].x = 330;
	shuttle[2].y = 30;
	shuttle[3].x = 325;
	shuttle[3].y = 10;
	
	angle = 90.0;
	
	startengine = 0;
	opensketch();
	
	setup_curses();
  	move(5, 10);
  	printw("Press any key to start.\n");
	printw("          (Then press arrow keys to rotate,space of thrust,'q' to quit.)");
  	refresh();
  	int c = getch();

	drawlandscape(landscape);
	fflush(executable);
	drawshuttle();
	fflush(executable);

  	nodelay(stdscr, true);
  	erase();


  	move(5, 10);
  	printw("Press arrow keys, 'q' to quit.\n");
  	printw("        Press left key to rotate cc, press right key to rotate c,space to thrust");
  	refresh();
  	c = getch();

	sigemptyset(&block_mask_g); 
  	sigaddset(&block_mask_g, SIGALRM); 

  	struct sigaction handler;
  	handler.sa_handler = handle_timeout;
  	sigemptyset(&handler.sa_mask);
  	handler.sa_flags = 0;

 	if (sigaction(SIGALRM, &handler, NULL) == -1)
    		exit(EXIT_FAILURE);

  	struct itimerval timer;
    		struct timeval time_delay;
    		time_delay.tv_sec = 0;
    		time_delay.tv_usec = 0;
    		time_delay.tv_usec = 50000;

    		timer.it_interval = time_delay;

    
    		struct timeval start;
    		start.tv_sec = 0;
    		start.tv_usec = 0;
    		start.tv_usec = 50000;

    		timer.it_value = start;

  
  	if (setitimer(ITIMER_REAL, &timer, NULL) == -1)
    		exit(EXIT_FAILURE);

  	while(1)
  	{
    		if (c != ERR)
    		{
      			erase();
      			move(5,10);
      			printw("left arrow key rotates counter-clockwise,right clockwise,space for thrust,'q' to quit");
      			move(6, 10);
      			if (c == KEY_LEFT)
			{	
				changeangle = -5.0;
				angle += changeangle;
				block_and_left();
			}
      			else if (c == KEY_RIGHT)
			{
				changeangle = 5.0;
				angle += changeangle;
				block_and_right();
			}
      			else if (c == ' ')
			{
				getthrust();
        			printw("    space key pressed");
			}
      			else if (c == 'q')
        			break;
      			refresh();
    		}
    		c = getch();
  	}

	fprintf(executable, "end\n");
  	unset_curses();
	pclose(executable);
	fclose(landscape);
  	exit(EXIT_SUCCESS);
}	
示例#4
0
int main(int argc,char *argv[]){
    I=0;
    int argv_index=1;
    for(argv_index=1;argv_index<argc;argv_index++){
	if(argv[argv_index][0]=='-'){
		if(strlen(argv[argv_index])==2){
			if((argv[argv_index][1])=='g'){
				gravity=atof(argv[argv_index+1]);
			}
			else if((argv[argv_index][1])=='t'){
				thrust=atof(argv[argv_index+1]);
			}
			else if((argv[argv_index][1])=='f'){
				landscape=fopen(argv[argv_index+1],"r");
			}
                        else if((argv[argv_index][1])=='i'){
                                I=1;
                        }
		}
		else if(strlen(argv[argv_index])>2){
			if((argv[argv_index][1])=='g'){
				gravity=atof(argv[argv_index]+2);
			}
			else if((argv[argv_index][1])=='t'){
				thrust=atof(argv[argv_index]+2);
			}
			else if((argv[argv_index][1])=='f'){
				landscape=fopen(argv[argv_index]+2,"r");
			}
		}
	}
    }
    fuel=10;
    ship_degree=90;
    // curses set up------------------------------------------
    setup_curses();
    open_pipe(exec_name);
    move(5, 10);
    printw("Press any key to start.\n");
    printw("          (Then press arrow keys to rotate, space for thust, 'q' to quit)");
    refresh();
    int cmd = getch();
	
    nodelay(stdscr, true);
    erase();
    move(5, 0);
    printw("left arrow key rotate counter-clockwise, right clockwise, space for thust, q to quit.");
	
    //set initial location of the ship-----------------
	
    //left_up point
    ship[0].x=315;
    ship[0].y=20;
    
    //right_up point
    ship[1].x=325;
    ship[1].y=20;
    
    //left_down point
    ship[2].x=305;
    ship[2].y=50;
    
    //right_down point
    ship[3].x=335;
    ship[3].y=50;
    
    //thrust point
    ship[4].x=320;
    ship[4].y=60;

    // set all switches-----------------------------
    over=0;
    thrust_sw=0;
    //set_velocity--------------------------------------
    xV=0;yV=0;
    //draw the landscape
    draw_landscape(landscape);
    if(I==1){
        draw_fuel_rec();
    }
    //set_timer-------------------------------------
    sigemptyset(&block_mask_g);
    sigaddset(&block_mask_g, SIGALRM);
    struct sigaction handler;
    handler.sa_handler = handle_timeout;
    sigemptyset(&handler.sa_mask);
    handler.sa_flags = 0;
    if (sigaction(SIGALRM, &handler, NULL) == -1){
        exit(EXIT_FAILURE);
    }
    struct itimerval timer;
        struct timeval time_delay;
        time_delay.tv_sec = 0;
        time_delay.tv_usec = 50000;
        timer.it_interval = time_delay;
        struct timeval start;
        start.tv_sec = 0;
        start.tv_usec = 50000;
        timer.it_value = start;
    if (setitimer(ITIMER_REAL, &timer, NULL) == -1){
        exit(EXIT_FAILURE);
    }
    while(1){
        cmd = getch();
        if (cmd != ERR){
            if (cmd == KEY_LEFT){
                if(over==0){
                    blocking_signal_for_rotate(1);  //rotate left
                }
            }
            else if(cmd == KEY_RIGHT){
                if(over==0){
                    blocking_signal_for_rotate(0);  //rotate right
                }
            }
            else if(cmd == ' '){
                if(I==0){
                    thrust_sw=1;
                }
                else if(I==1){
                    if(fuel<=0){
                        move(8,10);
                        refresh();
                        printw("Empty fuel tank ! ! ! !");
                    }
                    else if(fuel>0){
                        thrust_sw=1;
                    }
                }
            }
            else if(cmd == 'q'){
                // block the signal
                sigset_t old_mask;
                if (sigprocmask(SIG_BLOCK, &block_mask_g, &old_mask) < 0){
                    exit(EXIT_FAILURE);
                }
                break;
            }
        }
    }
    if(executable!=NULL&&over==0){
        fprintf(executable,"end\n");
    }
    unset_curses();
    //-----------------------------------------------------------
    fclose(landscape);
    close_pipe();
    exit(EXIT_SUCCESS);
}
示例#5
0
int main(int argc, wchar* argv[])
{
  if (setup_curses() < 0)
  {
    printf("failed to setup curses!\n");
  }
  #ifdef TARGET_PANDORA
    signal(SIGSEGV, clean_exit);
    signal(SIGKILL, clean_exit);
  #endif

  /* Set home dir */
  string home = ".";
  #if defined(USES_HOMEDIR)
    if(getenv("HOME") != NULL)
    {
      home = (string)getenv("HOME") + "/.reicast";
      mkdir(home.c_str(), 0755); // create the directory if missing
    }
  #endif
  SetHomeDir(home);
  printf("Home dir is: %s\n", GetPath("/").c_str());

  #if defined(SUPPORT_X11)
    x11_keymap[113] = DPad_Left;
    x11_keymap[114] = DPad_Right;

    x11_keymap[111] = DPad_Up;
    x11_keymap[116] = DPad_Down;

    x11_keymap[52] = Btn_Y;
    x11_keymap[53] = Btn_X;
    x11_keymap[54] = Btn_B;
    x11_keymap[55] = Btn_A;

    /*
      //TODO: Fix sliders
      x11_keymap[38] = DPad_Down;
      x11_keymap[39] = DPad_Down;
    */

    x11_keymap[36] = Btn_Start;
  #endif

  common_linux_setup();

  SetupInput();

  settings.profile.run_counts=0;

  dc_init(argc,argv);

  #if !defined(TARGET_EMSCRIPTEN)
    dc_run();
  #else
    emscripten_set_main_loop(&dc_run, 100, false);
  #endif


  #ifdef TARGET_PANDORA
    clean_exit(0);
  #endif

  return 0;
}