Esempio n. 1
0
void die ()
{
	int r;
	freeze (1);
	sp_base_idle (1, "");
	sp_brain (1, "none");
	sp_seq (1, "die");
	sp_frame (1, 1);
	sp_nohit (1, 1);
	wait (3000);
	while (1)
	{
		r = choice ("Load", "Restart", "Quit");
		if (r == 1)
			escape.load ();
		else if (r == 2)
			restart_game ();
		else if (r == 3)
			kill_game ();
	}
}
Esempio n. 2
0
void client_shutdown()
{
	console_print("Shutting down...\n");
	
	kill_servers();
	kill_download();
	kill_key();
	kill_openssl();
	kill_sound();
	kill_game();
	kill_network();
	kill_render();
//	kill_input();
	dump_console();
	kill_console();
	kill_control();
	write_config_file();
	
	SDL_Quit();

	terminate_process();
}
Esempio n. 3
0
void die( void )
{
freeze(1);
&update_status = 0;
int &mholdx = sp_x(1,-1);
int &mholdy = sp_y(1,-1)

//int &crap = create_sprite(&mholdx,&mholdy,5,436,1);

sp_seq(1, 436);
sp_base_idle(1, -1);
wait(3000);
sp_nohit(1, 1);
sp_brain(1, 0);
again:
        choice_start();
"Load a previously saved game"
"Restart game"
"Quit to system"
        choice_end();

if (&result == 1)
{
load();
kill_this_task();
}
   if (&result == 2)
   {
   sp_nohit(1, 0);
   restart_game();
   }

   if (&result == 3)
   {
   kill_game();
   }


}
Esempio n. 4
0
File: game.c Progetto: posva/msnake
void run() {
  int ch = 0, ich, i, current_columns, current_rows, success = 1;

  // some variables for the timer (inclusive the interval)
  struct timespec last_time              = {};
  struct timespec current_time           = {};
  long long default_interval             = 40000000;
  long long interval                     = default_interval;
  long long res;
  char playername[HIGHSCORE_NAME_LENGTH] = {};

  int range_counter = 0;

  // create the game struct
  GAME game = {};

  // set the eat range to 1
  game.snake.eat_range = 1;

  // helper variable to keep track of how long we've paused
  time_t pause_start;

  // get the dimensions of the terminal and store them in the GAME struct
  getmaxyx(stdscr, game.rows, game.columns);

  // clear the whole screen
  clear();

  // draw the walls
  draw_border(&game);

  // show the newly created walls
  refresh();

  // place the snake in the middle of the game field
  grow_snake(&game.snake, game.rows / 2, game.columns / 2);
  game.snake.dir = DIR_LEFT;

  // create some fruits on the screen
  // NOM, NOM, NOM
  for(i = 0; i < 50; i++) {
    grow_fruit(&game);
  }
  
  // get the time when the game started
  time(&game.started);
  // get the current time
  current_utc_time(&last_time);

  // start the event loop
  while((ich = getch()) && success) {
    // key typed?
    if(ich == ERR) {
    } else if(ich == '0') {
      // reset the speed
      interval = default_interval;
    } else if(ich == '8') {
      // speed up
      interval *= 1.1;
    } else if(ich == '9') {
      // slow down
      interval *= 0.9;
    } else {
      // use this key as a direction
      ch = ich;
    }
    // check if we have an overrun
    current_utc_time(&current_time);

    // calculate the dirrence between the last snake move and the current time
    res = timeval_diff(&last_time, &current_time);

    // is the interval over?
    if(res > interval) {
      // has an effect on the eat_range ?
      if(game.snake.eat_range > 1) {
        // every 200th field, decrease the range
        range_counter = (range_counter + 1) % 150;
        // it turns to 0 after the 200th field
        if(range_counter == 0) {
          game.snake.eat_range--; // so, decrease it!
        }
      }
      // new direction? 
      if((ch == KEY_UP || ch == 'w') && game.snake.dir != DIR_DOWN) {
        game.snake.dir = DIR_UP;
      } else if((ch == KEY_LEFT || ch == 'a') && game.snake.dir != DIR_RIGHT) {
        game.snake.dir = DIR_LEFT;
      } else if((ch == KEY_RIGHT || ch == 'd') && game.snake.dir != DIR_LEFT) {
        game.snake.dir = DIR_RIGHT;
      } else if((ch == KEY_DOWN || ch == 's') && game.snake.dir != DIR_UP) {
        game.snake.dir = DIR_DOWN;
      }
      // move the snake
      success = move_snake(&game);

      // refresh the screen
      refresh();

      // display the status bar (top-right)
      status_display(&game);

      // update the time when we last moved the snake
      last_time = current_time;
    }
    
    getmaxyx(stdscr, current_rows, current_columns);
    // 'p' pressed || size of the terminal changed
    if(ich == 'p' || (current_rows != game.rows || current_columns != game.columns)) {
      // use the terminal new size
      game.rows = current_rows;
      game.columns = current_columns;

      // get the time
      time(&pause_start);

      // show the pause dialog
      switch(pause_dialog()) {
        case 2:
          // leave the game if '2' is pressed
          success = 0;
        default:
          // redraw the screen on resume
          game.paused += time(NULL) - pause_start;
          redraw_game(&game);
          break;
      }
    }
  }

  // get the time when the game has ended
  time(&game.ended);

  // display the highscore dialog & let the player enter his name
  display_highscore(&game, playername, HIGHSCORE_NAME_LENGTH);

  // has a name been entered? if not don't create a highscore entry
  if(playername[0]) {
    add_highscore(playername, game.highscore, game.ended - game.started - game.paused);
  }

  // free all the resources reserved in the game struct
  kill_game(&game);
}