Esempio n. 1
0
void		key_handler(unsigned int key, t_entlist *l, int *running)
{
	if (key == K_ENT)
	{
		clean_screen(l);
		*running = 0;
	}
	else
	{
		if (key == K_ESC)
			quit(l);
		else if (key == K_DOWN)
			go_down(l);
		else if (key == K_UP)
			go_up(l);
		else if (key == K_RIGHT)
			go_right(l);
		else if (key == K_LEFT)
			go_left(l);
		else if (key == K_DEL || key == K_BKSPC)
			delete_key(l);
		else
			special_keys(key, l);
	}
}
Esempio n. 2
0
/**
 * The main loop of game
 * @return TRUE if it completed successfully or FALSE otherwise
 */
bool
update_frame (void)
{
  spaceship_struct *ship = spaceship_get ();
#ifdef DEVELOPPEMENT
  /* 1 = phase grid editor enable (don't work) */
  static bool grid_editor = FALSE;
#endif
  /* global frame counter */
  global_counter++;

  /* play start and congratulations animations files
   * ("movie_congratulation.gca" and "movie_introduction.gca") */
  if (movie_playing_switch != MOVIE_NOT_PLAYED)
    {
      if (!movie_player ())
        {
          LOG_ERR ("movie_player() failed!");
          return FALSE;
        }
      else
        {
          return TRUE;
        }
    }

  display_clear_offscreen ();

#ifdef __EMSCRIPTEN__
  lock_surface_game ();
  lock_surface_options ();
  lock_surface_scores ();
#endif

  /* restores the level of energy of the player spaceship */
  spaceship_energy_restore ();

  /* phase grid and curve phase editor (don't work) */
#ifdef DEVELOPPEMENT
  if (grid_editor || curve_editor_enable)
    {
      if (grid_editor)
        {
          Grid_Edit ();
        }
      else
        {
          courbe_editeur ();
        }
    }
  else
#endif

    /* pause or main menu enable */
  if (!player_pause && menu_status == MENU_OFF &&
        menu_section == NO_SECTION_SELECTED)
    {
      /* 
       * handle the phases of the game 
       */
      /* phase 2: grids (enemy wave like Space Invaders) */
      grid_handle ();
      /* phase 1: curves (little skirmish) */
      curve_phase ();
      /* phase 3: meteor storm */
      meteors_handle ();
    }

  /* draw the starfield background */
  starfield_handle ();

  /* handle bonus: green, red, yellow, blue and purple gems */
  bonus_handle ();

  /* handle protection satellites and extra gun of the player spaceship  */
  if (!gameover_enable && menu_section == NO_SECTION_SELECTED)
    {
      /* orbital protection satellites gravitate around player's spaceship */
      satellites_handle ();
      /* extra gun positioned on the sides */
      guns_handle ();
    }

  /* handle enemies */
  if (!is_congratulations_enabled)
    {
      /* handling of all the possible types of enemies */
      enemies_handle ();
    }
  else
    {
      /* congratulations, end of the game */
      congratulations ();
    }

  /* spaceship temporary invincibility  */
  spaceship_invincibility ();

  /* handle the powerful electrical shocks */
  electrical_shock ();

  /* draw the player's spaceship */
  spaceship_draw ();

  /* handle explosions */
  explosions_handle ();

  /* handle shots */
  shots_handle ();

  /* wait until all enemies are dead before jumping on next phase */
  if (num_of_enemies == 0 && !player_pause && menu_status == MENU_OFF
      && menu_section == NO_SECTION_SELECTED)
    {
      /* end of a guardian phase? */
      if (!guardian_finished ())
        {
          LOG_ERR ("guardian_finished() failed!");
          return FALSE;
        }
      /* check if curve phase is finished */
      curve_finished ();
      /* check if grid phase is finished */
      grid_finished ();
      /* check if meteors phase is finished */
      if (!meteors_finished ())
        {
          LOG_ERR ("meteors_finished failed!");
          return FALSE;
        }
    }

  /* display pixel mouse pointer */
#ifdef DEVELOPPEMENT
  if (mouse_here)
    {
      put_pixel (game_offscreen, mouse_x, mouse_y, 5);
    }
#endif

  /* draw powerful circular shock wave propagated by the player spaceship */
  shockwave_draw ();

  /* animations of the options box on the right options panel */
  option_execution ();

  /* handle high score table, game over, about and order sections */
  menu_sections_run ();

  /* display "PAUSE" chars sprites */
  if (is_pause_draw)
    {
      text_pause_draw ();
    }

  /* player's spaceship come */
  if (spaceship_appears_count > 0)
    {
      spaceship_appears_count--;
      /* accelerate the speed of the starfield */
      starfield_speed += 0.028f;
      if (starfield_speed > 2.0)
        {
          starfield_speed = 2.0;
        }
      /* invincibility time */
      spaceship_set_invincibility (SPACESHIP_INVINCIBILITY_TIME / 3);
    }

  /* player's spaceship disappearing to the bottom of the screen. */
  if (spaceship_disappears && is_congratulations_enabled == 0)
    {
      /* decelerate the speed of the starfield */
      starfield_speed -= 0.02f;
      if (starfield_speed <= 0.0)
        {
          starfield_speed = 0.0;
          ship->y_speed = 0.0;
        }
      else
        {
          /* accelerate the speed of the spaceship */
          ship->y_speed += -0.15f;
        }
    }

  /* display number level */
  text_level_draw ();

  /* display scrolltext in the main menu */
  scrolltext_handle ();

  /* handle the main menu of Powermanga */
  menu_handle ();

  /* [F1] spaceship_appears / [F2] spaceship disappears */
#ifdef DEVELOPPEMENT
  if (keys_down[K_F1])
    {
      spaceship_disappears = 1;
    }
  if (keys_down[K_F2] && starfield_speed == 0.0)
    {
      spaceship_show ();
    }
#endif

  /* handle "TLK Games" sprite logo */
  if (tlk_logo_is_move)
    {
      draw_bitmap (&logotlk[tlk_logo_image_index], tlk_logo_xcoord,
                   tlk_logo_ycoord);
      if (tlk_logo_is_next_image)
        {
          tlk_logo_image_index++;
          if (tlk_logo_image_index >= TLKLOGO_MAXOF_IMAGES)
            {
              tlk_logo_image_index = 0;
            }
          tlk_logo_is_next_image = FALSE;
          tlk_logo_ycoord--;
        }
      else
        {
          tlk_logo_is_next_image = TRUE;
        }
      if (tlk_logo_ycoord <= 32)
        {
          tlk_logo_is_move = FALSE;
        }
    }

  /* display text overlay (about, cheats menu and variables) */
  text_overlay_draw ();

  /* handle the loss and the regression of the spaceship or cause game over */
  spaceship_downgrading ();

  /* handle spaceship's energy level */
  energy_gauge_spaceship_update ();

  /* handle guardian's energy level */
  energy_gauge_guardian_update ();

  /* draw player's score into the top panel */
  text_draw_score ();

#ifdef DEVELOPPEMENT
  if (keys_down[K_E] && keys_down[K_G])
    {
      /* [e]+[g] = enable the grid editor */
      grid_editor = 1;
    }
  if (keys_down[K_E] && keys_down[K_C])
    {
      /* [e]+[c] enable the curve editor */
      curve_editor_enable = 1;
    }
  /* [p]+[g] back to the game */
  if (keys_down[K_P] && keys_down[K_G])
    {
      grid_editor = 0;
      curve_editor_enable = 0;
    }
#endif

  /* control the spaceship movements */
  if (!player_pause && !gameover_enable && menu_status == MENU_OFF
      && menu_section == NO_SECTION_SELECTED)
    {
      spaceship_control_movements ();
    }

  /* [P] or [Pause] enable/disable pause */
  if (!keys_down[K_CTRL] && (keys_down[K_P] || keys_down[K_PAUSE]))
    {
      toggle_pause ();
    }
  keys_down[K_P] = FALSE;
  keys_down[K_PAUSE] = FALSE;   /* clear flag pause key */


  /* switch between full screen and windowed mode */
#ifdef POWERMANGA_SDL
  if ((keys_down[K_F] && !is_playername_input ()
       && menu_section != SECTION_ORDER) || keys_down[K_F11])
    {
      if (power_conf->fullscreen)
        {
          power_conf->fullscreen = FALSE;
        }
      else
        {
          power_conf->fullscreen = TRUE;
        }
      init_video_mode ();
    }
  keys_down[K_F] = FALSE;
  keys_down[K_F11] = FALSE;
#endif

  /* control the speed of the spaceship */
  spaceship_speed_control ();

  /* cheat code keys */
#ifdef UNDER_DEVELOPMENT
  special_keys ();
#endif

  /* handle weapon's player spaceship */
#ifdef DEVELOPPEMENT
  if (!grid_editor && !curve_editor_enable && !spaceship_is_dead
      && !player_pause && menu_status == MENU_OFF
      && menu_section == NO_SECTION_SELECTED)
#else
  if (!spaceship_is_dead && !player_pause && menu_status == MENU_OFF
      && menu_section == NO_SECTION_SELECTED)
#endif
    {
      spaceship_weapons ();
    }

#ifdef __EMSCRIPTEN__
  unlock_surface_scores ();
  unlock_surface_options ();
  unlock_surface_game ();
#endif

  return TRUE;
}