Exemplo n.º 1
0
void init_player(Player* player)
{
	player->hull = 100;
	player->power = 100;
	player->angle = 45;
	place_player(player, player->pos.x); //TODO random position
}
Exemplo n.º 2
0
Arquivo: game.c Projeto: phoboz/edom
void play(int start_level)
{
  coord opx, opy;
  BOOL quit = 0;
  
  /*
   * Build the current level.
   *
   * XXXX: Once it is possible to save/restore the map this no longer
   *       must be done if the game was started by restoring a save file.
   */
  d.dl = start_level;
  build_map();
  create_population();
  build_monster_map();
  d.visited[0] = TRUE;
  
  /* Initial player position. */
  place_player(d.stxu[d.dl], d.styu[d.dl]);

  /* Initial panel position. */
  d.psx = d.psy = 0;

  /*
   * Standard stuff.
   */
  
  do
  {
    /* Print all the new things. */
    update_screen(d.px, d.py);

    /* The message line should be cleared in any case. */
    clear_messages();
    
    /* Memorize the old PC position. */
    opx = d.px;
    opy = d.py;

    SDL_Event event;

    while (SDL_PollEvent(&event))
    {
      if (event.type == SDL_QUIT)
        quit = TRUE;

      if (event.type == SDL_KEYDOWN)
        game_keydown(event.key.keysym.sym);
    }

    int input = get_input();

    if (input & PRESS_ESC)
      quit = TRUE;

    BOOL player_turn = move_monsters();

    if (player_turn && d.pa.act == IDLE)
    {
      if (input & PRESS_LEFT)
      {
        set_dir_actor(&d.pa, LEFT);
        if (is_open(d.px - 1, d.py) &&
            !is_monster_at(d.px - 1, d.py))
          move_player(LEFT);
      }
      else if (input & PRESS_RIGHT)
      {
        set_dir_actor(&d.pa, RIGHT);
        if (is_open(d.px + 1, d.py) &&
            !is_monster_at(d.px + 1, d.py))
          move_player(RIGHT);
      }
      else if (input & PRESS_UP)
      {
        set_dir_actor(&d.pa, UP);
        if (is_open(d.px, d.py - 1) &&
            !is_monster_at(d.px, d.py - 1))
          move_player(UP);
      }
      else if (input & PRESS_DOWN)
      {
        set_dir_actor(&d.pa, DOWN);
        if (is_open(d.px, d.py + 1) &&
            !is_monster_at(d.px, d.py + 1))
          move_player(DOWN);
      }
    }
    else if (d.pa.act == MOVE)
    {
      animate_move_actor(&d.pa);
    }
    else if (d.pa.act == CHARGE)
    {
      animate_charge_actor(&d.pa);
    }
    else if (d.pa.act == ATTACK)
    {
      if (animate_attack_actor(&d.pa))
        attack_monster_at(d.pa.tx, d.pa.ty);
    }

    d.opx = opx;
    d.opy = opy;
  }
  while (quit == FALSE);
}