Пример #1
0
Файл: ball.c Проект: shiftky/GBA
void ball_step(void)
{
  int x, y;
  switch ( game_get_state() ) {
    case START:
      remaining = 3;
      init_ball();
      break;

    case NEXTSTAGE:
      init_ball();
      break;

    case REMAINING:
      break;

    case RUNNING:
      x = old_x + dx; y = old_y + dy;

      if ( x != old_x && ( x <= 0 || LCD_WIDTH-ball.width < x )) {
        dx = dx > 0 ? -1*BALL_DX : BALL_DX;
        return;
      }

      if ( y != old_y && y <= 0 ) {
        dy = dy > 0 ? -1*BALL_DY : BALL_DY;
        return;
      } else if ( y!= old_y && LCD_HEIGHT-ball.width < y ) {
        if ( remaining <= 1 ) {
          game_set_state(DEAD);
        } else {
          draw_box(&ball, ball.x, ball.y, COLOR_BLACK);
          remaining--;
          init_ball();
          game_set_state(REMAINING);
        }
        return;
      }

      move_box(&ball, x, y, BALL_COLOR);
      old_x = x; old_y = y;
      break;

    case CLEAR:
      draw_box(&ball, old_x, old_y, BALL_COLOR);
      break;

    case DEAD:
      break;

    case RESTART:
      remaining = 3;
      init_ball();
      break;
  }
}
static void 
state_changed(Game * game,
	      GameNetworkPlayerManager * manager) 
{


    g_print("STATE changed \n");
    if( game_get_state( game ) == GAME_FINISHED ) {
	g_print("GAME finished\n");
	PRIVATE(manager)->current_score = game_network_player_get_score( GAME_NETWORK_PLAYER(game));

	//	PRIVATE(manager)->playing = FALSE;
      
    }
				
}
Пример #3
0
void hp_step(){
  
  hword color = COLOR_WHITE;
  
  switch (game_get_state()) {
  case START:
    hp_initialize();
    stock_initialize();
    break;
    
  case RUNNING:
    draw_box(&hpbar, hpbar.x, hpbar.y, COLOR_RED);
    if(hp == 0){
      stock_lose();
      if(stock_count == 0){
	game_set_state(DEAD);
	break;
      }
      game_set_state(MISS);
    }
    break;
    
  case MISS:    
    if(stock_count == 0)
      game_set_state(DEAD);
    hp = 50;
    hpbar.width = hp;   
    break;
    
  case DEAD:
    break;
    
  case RESTART:
    hp_initialize();
    stock_initialize();
    break;
    
  case CLEAR:
    break;
    
  }
  
}
Пример #4
0
void game_step(void)
{
  int key = gba_register(KEY_STATUS);
  
  switch (game_get_state()) {
  case START:

    if (! (key & KEY_START))  //STARTキーが押された
      game_set_state(RUNNING);
    break;

  case RUNNING:
    if (! (key & KEY_R))  //Rキーが押された(デバッグ用)
      game_set_state(CLEAR);
    if (! (key & KEY_L))  //Lキーが押された(デバッグ用)
      game_set_state(MISS);
    break;

  case MISS:
    if (! (key & KEY_START))  //STARTキーが押された
      game_set_state(RUNNING);
    break;
    
  case DEAD:
    if (! (key & KEY_START))  //STARTキーが押された
      game_set_state(RESTART);
    break;
    
  case RESTART:
    /* 次のティックはRUNNING状態にする.*/
    game_set_state(RUNNING);
    break;

  case CLEAR:
    if (! (key & KEY_SELECT))  //SELECTキーが押された(STARTの場合1tickだけボタン押さないとRUNNINGに移動してしまうため)
      game_set_state(START);
    break;
  }
}
Пример #5
0
Файл: game.c Проект: shiftky/GBA
void game_step(void)
{
  switch ( game_get_state() ) {
    case START:
      current_stage = 0;
      draw_string("Press START key to start.", 23, 85, COLOR_WHITE);
      if ( get_key_state(KEY_START) ) {
        draw_string("Press START key to start.", 23, 85, COLOR_BLACK);
        game_set_state(REMAINING);
      }
      break;

    case NEXTSTAGE:
      game_set_state(REMAINING);
      break;

    case REMAINING:
      draw_string("stage ", 95, 75, COLOR_WHITE);
      draw_num(current_stage+1, 140, 75, COLOR_WHITE);
      draw_string("ball x", 90, 85, COLOR_YELLOW);
      draw_num(ball_get_remaining(), 145, 85, COLOR_YELLOW);
      delay(30000);
      draw_string("stage ", 95, 75, COLOR_BLACK);
      draw_num(current_stage+1, 140, 75, COLOR_BLACK);
      draw_string("ball x", 90, 85, COLOR_BLACK);
      draw_num(ball_get_remaining(), 145, 85, COLOR_BLACK);
      game_set_state(RUNNING);
      break;

    case RUNNING:
      // for Debug
      if ( get_key_state(KEY_SELECT) ) {
        game_set_state(CLEAR);
      }
      break;

    case DEAD:
      draw_string("GAME OVER", 85, 70, COLOR_RED);
      draw_string("Press START key to restart.", 16, 85, COLOR_WHITE);
      if ( get_key_state(KEY_START) ) {
        init_screen();
        game_set_state(RESTART);
      }
      break;

    case CLEAR:
      if ( current_stage < 2 ) {
        draw_string("CLEAR!!", 95, 70, COLOR_ITF);
        draw_string("Press A key to", 65, 85, COLOR_WHITE);
        draw_string("next stage!", 80, 95, COLOR_WHITE);
        if ( get_key_state(KEY_A) ) {
          init_screen();
          current_stage++;
          game_set_state(NEXTSTAGE);
        }
      } else {
        draw_string("CLEAR!!", 95, 70, COLOR_ITF);
        draw_string("Press START key to restart.", 16, 85, COLOR_WHITE);
        if ( get_key_state(KEY_START) ) {
          init_screen();
          game_set_state(RESTART);
        }
      }
      break;

    case RESTART:
      current_stage = 0;
      game_set_state(START);
      break;
  }
}
Пример #6
0
void multi_change_state(struct game* game, game_state_t state_to) {
	switch(game_get_state(game)) {
	case PLAYING:
	case PAUSED:
		switch(state_to) {
		case SCORE:
#ifdef USE_WIIMOTE
		//= 0)
			//wiimote_set_rumble(player->id, 0);
#endif
			game_set_state(game, SCORE);
			if(player_get_nb_player_alive(game) == 1)
				game_inc_score(game, player_get_id_player_alive(game));

			break;
		case CHOOSE_MAP:
			game_set_state(game, CHOOSE_MAP);
			game_reset_lvl_map(game);
			game_reset_scores(game);

			break;
		default:
			break;
		}
		break;

	case CHOOSE_MAP:
		switch(state_to) {
		case PLAYING:
			game_set_state(game, PLAYING);
			window_resize(map_get_width(level_get_curr_map(game_get_curr_level(game))) * SIZE_BLOC, map_get_height(level_get_curr_map(game_get_curr_level(game))) * SIZE_BLOC + BANNER_HEIGHT + LINE_HEIGHT);
			players_from_map(game, level_get_curr_map(game_get_curr_level(game)));
			player_reset(game, 1, 1, 2, 4, 0);

			break;
		default:
			break;
		}
		break;

	case SCORE:
		switch(state_to) {
		case PLAYING:
			game_set_state(game, PLAYING);
			game_reset_lvl_map(game);
			level_set_cur_map(game_get_curr_level(game), game_get_pos(game));
			players_from_map(game, level_get_curr_map(game_get_curr_level(game)));
			player_reset(game, 1, 1, 2, 4, 0);


			break;
		case CHOOSE_MAP:
			game_set_state(game, CHOOSE_MAP);
			game_reset_lvl_map(game);
			game_reset_scores(game);

			break;
		default:
			break;
		}

		break;
	default:
		break;
	}
}
Пример #7
0
void multi_display(struct game* game) {
	assert(game);
	struct map* map = NULL;
	int w, h;
	int* scores;

	switch(game_get_state(game)) {
	case PLAYING:
	case PAUSED:
		game_display(game);
		if(player_get_nb_player_alive(game) == 1)
			multi_change_state(game, SCORE);

		break;
	case CHOOSE_MAP:

		map = level_get_curr_map(game_get_curr_level(game));

		w = 10 + 15 + sprite_get_max_width() + 50 + SIZE_BLOC * map_get_width(map);
		h = max(30 * (sprite_get_nb_map_multi() + 1), SIZE_BLOC * map_get_height(map));

		window_resize( w, h);
		window_clear();

		for(int i = 0; i < sprite_get_nb_map_multi(); i++) {
			window_display_image(	sprite_get_map_multi(i),
									10 + 15,
									15 + 30 * i);
		}

		window_display_image(sprite_get_menu(M_S_SELECT_BLACK), 10, 15 + 30 * game_get_pos(game));

		map_display(	map,
						10 + 15 + sprite_get_max_width() + 50,
						(h-(SIZE_BLOC * map_get_height(map))) / 2);
		window_refresh();

		break;
	case SCORE:

		window_clear();
		level_display(game_get_curr_level(game));
		bomb_display(game, level_get_curr_map(game_get_curr_level(game)));
		for(int i = 0; i < game_get_nb_player(game); i++)
			player_display(game_get_player(game, i+1));

		int map_w = map_get_width(level_get_curr_map(game_get_curr_level(game)));
		int map_h = map_get_height(level_get_curr_map(game_get_curr_level(game)));
		int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2;
		int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2;

		window_display_image(	sprite_get_menu(M_BG_GREY),
								mid_w - 240,
								mid_h - 262);

		window_display_image(	sprite_get_score(player_get_id_player_alive(game)),
								mid_w - 200,
								mid_h - 222);

		scores = game_get_scores(game);
		for(int i = 0; i < game_get_nb_player(game); i++) {
			window_display_sprite(	sprite_get_players(i+1),
									sprite_get_rect_player_anim(0, i+1, SOUTH),
									mid_w - 200,
									mid_h - 222 + 80 + 80 * i);

			window_display_image(	sprite_get_number_white(scores[i]),
									mid_w - 140,
									mid_h - 222 + 100 + 80 * i);
		}

		window_refresh();

		break;
	}
}