Пример #1
0
bool run_game(){

   if(!quit){    
    render_board();
    process_input();
    render_board();     
       return true;
   }
    else 
   

    return false; 
    
 
}
Пример #2
0
void render()
{
  if(quit)
    return;
  //clear renderer
  SDL_SetRenderTarget(renderer, NULL);
  SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
  SDL_RenderClear(renderer);

  //clear camera
  SDL_SetRenderTarget(renderer, camera.game_texture.sdl_texture);
  SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
  SDL_RenderClear(renderer);

  render_board(&board);
  render_striker(&striker);
  render_chips();

  if(game_state == PLAY && striker.state == WITH_PLAYER)
  {
    render_orientation(&striker);
  }


  //render camera in viewport
  SDL_SetRenderTarget(renderer, NULL);
  SDL_Rect dest_rect = { VIEWPORT_X, VIEWPORT_Y, VIEWPORT_HEIGHT, VIEWPORT_WIDTH };
  SDL_RenderCopy(renderer, camera.game_texture.sdl_texture, NULL, &dest_rect);
  

  if(game_state == MAIN_MENU)
  {
    render_main_menu();
  }

  if(game_state == INSTRUCTION)
  {
    render_instructions();
  }

  if(game_state == GAME_OVER)
  {
    render_game_over_state();
  }

  if(game_state == PLAY && striker.state == WITH_PLAYER)
  {
    render_speed(&striker);
    // render_orientation_text(&striker);
  }

  if(game_state == PLAY)
  {
    render_main_instruction();
  }

  render_scores();
  SDL_RenderPresent(renderer);
}
Пример #3
0
void new_game(void) {
	char c = 0;
	cancel_software_timer(foodTimerNum);
	cancel_software_timer(ratsTimerNum);
	empty_display();

	//wait for space
	while(c != ' ' && c != 'l' && c != 'L'){
		if(input_available())
			c = fgetc(stdin);

		if(c == 'M' || c == 'm'){
			toggle_sound();
			display_sound_status();
			c = 0;
		}
	}
	
	init_display();
	
	if(c == 'l' || c == 'L'){
		if(load_state())
			render_board();
		else {
			/* Initialise internal representations. */
			init_board();
			init_score();
		}
	}
	else {
		/* Initialise internal representations. */
		init_board();
		init_score();
	}
	clear_terminal();

	//Place scores
	update_score();

	//place sound status
	display_sound_status();

	show_instruction(PLAYING);

	/* Make food blink 5 times a second. We should call blink_food
	** 10 times a second which is 100ms
	*/
	foodTimerNum = execute_function_periodically(BLINKRATE, blink_food);
	ratsTimerNum = execute_function_periodically(RATSPEED, move_rats);

	/* Debug *
	move_cursor(0, TITLEY-1);
	printf_P(PSTR("new_game %u"), get_score());
	wait_for(1000);
	//*/
}
Пример #4
0
void pause_game() {
	/*
	** status = 0, game is running
	** status = 1, game is paused
	*/
	static uint8_t status = 0;
	char c = 0;

	if(status) {
		move_cursor(28, TITLEY);
		clear_to_end_of_line();
		show_instruction(PLAYING);
		render_board();
		foodTimerNum = execute_function_periodically(BLINKRATE, blink_food);
		ratsTimerNum = execute_function_periodically(RATSPEED, move_rats);
		status = 0;
	}
	else {
		show_instruction(PAUSE);
		cancel_software_timer(foodTimerNum);
		cancel_software_timer(ratsTimerNum);
		empty_display();
		status = 1;

		while(c != 'p' && c != 'P'){
			if(input_available())
				c = fgetc(stdin);

			if(c == 's' || c == 'S'){
				save_state();
				//move_cursor(0, TITLEY);
				//clear_to_end_of_line();
				move_cursor(28, TITLEY);
				printf_P(PSTR("State has been saved."));
				c = 0;
			}

		}
		pause_game();

	}
}