Пример #1
0
static gboolean
controls_timeout_cb (gpointer data)
{
  UserInterface *ui = data;

  ui->controls_timeout = -1;

  clutter_stage_hide_cursor (CLUTTER_STAGE (ui->stage));
  if (!ui->keep_showing_controls) {
    show_controls (ui, FALSE);
  }

  return FALSE;
}
Пример #2
0
int main(int argc, char* argv[])
{
#if defined PDCURSES
    putenv("PDC_COLS=" macro_str(MIN_W));
    putenv("PDC_LINES=" macro_str(MIN_H));
    resize_term(MIN_H, MIN_W);
#endif

    srand(time(NULL));

    initscr();
    clear();
    noecho();
    cbreak();

    if(!has_colors()) {
        endwin();
        fprintf(stderr, "Error: Your terminal does not support color output.\nThis application must have color output to run.\n");
        return 1;
    }

    start_color();

#ifdef Linux
    if(COLORS < MIN_COLS || COLOR_PAIRS < MIN_PAIRS) {
        endwin();
        fprintf(stderr, "Warning: Your terminal lacks sufficient color support to run this game (Expected %d colors and %d pairs, got %d colors and %d pairs).\n", MIN_COLS, MIN_PAIRS, COLORS, COLOR_PAIRS);
    }
#endif

#if !defined PDCURSES
    if(COLORS < BEST_COLS || COLOR_PAIRS < BEST_PAIRS) {
        endwin();
        fprintf(stderr, "Warning: Your terminal lacks sufficient color support to use the game's full range of color (Expected %d colors and %d pairs, got %d colors and %d pairs).\nThis may impact the game's graphics.\nPress any key to continue.\n", BEST_COLS, BEST_PAIRS, COLORS, COLOR_PAIRS);
        getch();
        set_hicolor(false);
    } else {
        if(!can_change_color()) {
            endwin();
            fprintf(stderr, "Warning: Your terminal cannot change color definitions.\nThis will negatively impact the game's graphics.\nPress any key to continue.\n");
            getch();
            refresh();
            set_hicolor(false);
        } else {
            set_hicolor(true);
        }
    }
#else
    set_hicolor(false);
#endif

    int rows, cols;
    max_size(stdscr, rows, cols);
    if(rows < MIN_H || cols < MIN_W) {
        endwin();
        fprintf(stderr, "This terminal is too small to play this game!\nRequired dimensions are %dx%d, but got %dx%d\n", MIN_W, MIN_H, cols, rows);
        return 1;
    }

    init_input();

    bool should_continue = true;


    if(!init_menu())
    {
        endwin();
        fprintf(stderr, "Failed to create menu!\n");
        return 1;
    }

    while(should_continue) {
        switch(game_state) {
            case STATE_MENU: {
                int val;
                if((val = update_menu()))
                {
                    switch(val) {
                        case SELECTION_PLAY:
                            hide_menu();
                            game_state = STATE_GAME;
                            init_game();
                            break;
                        case SELECTION_CONTROLS:
                            show_controls();
                            break;
                        case SELECTION_QUIT:
                            should_continue = false;
                            break;
                        default:
                            endwin();
                            fprintf(stderr, "If you see this message, something has gone terribly wrong in the menu code!\n");
                            return 1;
                    }
                }
            } break;
            case STATE_GAME:
                if(!update_game()) {
                    end_game();
                    game_state = STATE_MENU;
                    show_menu();
                }
                break;
            default:
                endwin();
                fprintf(stderr, "If you see this message, something has gone terribly wrong in general!\n");
                return 1;
        }
    }

    endwin();
    delwin(stdscr);
    return 0;
}
Пример #3
0
static gboolean
event_cb (ClutterStage * stage, ClutterEvent * event, UserInterface * ui)
{
  gboolean handled = FALSE;

  switch (event->type) {
    case CLUTTER_KEY_PRESS:
    {
      /* Clutter key codes based on */
      /* http://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h */

      ClutterVertex center = { 0, };
      ClutterAnimation *animation = NULL;

      center.x - clutter_actor_get_width (ui->texture) / 2;
      guint keyval = clutter_event_get_key_symbol (event);
      switch (keyval) {
        case CLUTTER_q:
        case CLUTTER_Escape:
        {
          clutter_main_quit ();

	  handled = TRUE;
          break;
        }

        case CLUTTER_f:
        {
          // Fullscreen button
          toggle_fullscreen (ui);

          handled = TRUE;
          break;
        }

        case CLUTTER_space:
        {
          // Spacebar
          toggle_playing (ui);

          handled = TRUE;
          break;
        }

        case CLUTTER_l:
        {
          ui->engine->loop = !ui->engine->loop;

	  handled = TRUE;
          break;
        }

        case CLUTTER_8:
        {
          // Mute button
          gdouble volume;
          gboolean muteval;

          g_object_get (G_OBJECT (ui->engine->player), "mute", &muteval, NULL);
          g_object_set (G_OBJECT (ui->engine->player), "mute", !muteval, NULL);
          update_volume (ui, volume);

          handled = TRUE;
          break;
        }

        case CLUTTER_9:
        case CLUTTER_0:
        {
          gdouble volume;
          g_object_get (G_OBJECT (ui->engine->player), "volume", &volume, NULL);
          // Volume Down
          if (keyval == CLUTTER_9 && volume > 0.0) {
            volume -= 0.05;
            if (volume < 0.01)
              volume = 0;
            g_object_set (G_OBJECT (ui->engine->player), "volume",
                volume, NULL);

            // Volume Up
          } else if (keyval == CLUTTER_0 && volume < 1.0) {
            volume += 0.05;
            if (volume > 1)
              volume = 1;
            g_object_set (G_OBJECT (ui->engine->player), "volume",
                volume, NULL);
          }

          update_volume (ui, volume);

          handled = TRUE;
          break;
        }

        case CLUTTER_Up:
        case CLUTTER_Down:
        case CLUTTER_Left:
        case CLUTTER_Right:
        case CLUTTER_Page_Up:
        case CLUTTER_Page_Down:
        {
          gint64 pos, second;
          gfloat progress;

          pos = query_position (ui->engine);
          second = ui->engine->second;

          if (keyval == CLUTTER_Up) {
            // Seek 1 minute foward
            pos += 60 * second;

          } else if (keyval == CLUTTER_Down) {
            // Seek 1 minute back
            pos -= 60 * second;

          } else if (keyval == CLUTTER_Right) {
            // Seek 10 seconds foward
            pos += 10 * second;

          } else if (keyval == CLUTTER_Left) {
            // Seek 10 seconds back
            pos -= 10 * second;

          } else if (keyval == CLUTTER_Page_Up) {
            // Seek 10 minutes foward
            pos += 600 * second;

          } else if (keyval == CLUTTER_Page_Down) {
            // Seek 10 minutes back
            pos -= 600 * second;
          }

          /* clamp the timestamp to be within the media */
          pos = CLAMP (pos, 0, ui->engine->media_duration);

          engine_seek (ui->engine, pos, TRUE);

          progress = (float) pos / ui->engine->media_duration;
          clutter_actor_set_size (ui->control_seekbar,
              progress * ui->seek_width, ui->seek_height);
          progress_update_text (ui);

          handled = TRUE;
          break;
        }

        case CLUTTER_i:
        {
	  // set in point for segment
	  gint64 in_point;

	  in_point = query_position (ui->engine);
	  ui->engine->in_point = in_point;
	  engine_seek (ui->engine, in_point, TRUE);

	  handled = TRUE;
	  break;
        }

        case CLUTTER_o:
        {
	  // set out point for segment
	  gint64 out_point;

	  out_point = query_position (ui->engine);
	  ui->engine->out_point = out_point;
	  engine_seek (ui->engine, out_point, FALSE);

	  handled = TRUE;
	  break;
        }

        case CLUTTER_r:
        {
          // rotate texture 90 degrees.
          rotate_video (ui);

          handled = TRUE;
          break;
        }

        case CLUTTER_c:
        {
          // show or hide controls
          penalty_box (ui);
          ui->keep_showing_controls = !ui->controls_showing;
          show_controls (ui, !ui->controls_showing);

          handled = TRUE;
          break;
        }

        case CLUTTER_period:
        {
          frame_stepping (ui->engine, TRUE);

          handled = TRUE;
          break;
        }

        case CLUTTER_comma:
        {
          frame_stepping (ui->engine, FALSE);

          handled = TRUE;
          break;
        }

        default:
        {
          handled = FALSE;
          break;
        }
      }

      break;
    }

    case CLUTTER_BUTTON_PRESS:
    {
      if (ui->controls_showing) {
        ClutterActor *actor;
        ClutterButtonEvent *bev = (ClutterButtonEvent *) event;

        actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL,
            bev->x, bev->y);
        if (actor == ui->control_play_toggle) {
          toggle_playing (ui);

        } else if (actor == ui->control_seek1 ||
            actor == ui->control_seek2 || actor == ui->control_seekbar) {
          gfloat x, y, dist;
          gint64 progress;

          clutter_actor_get_transformed_position (ui->control_seekbar, &x, &y);
          dist = bev->x - x;
          dist = CLAMP (dist, 0, ui->seek_width);

          if (ui->engine->media_duration == -1) {
            update_media_duration (ui->engine);
          }

          progress = ui->engine->media_duration * (dist / ui->seek_width);
          engine_seek (ui->engine, progress, TRUE);
          clutter_actor_set_size (ui->control_seekbar, dist, ui->seek_height);
          progress_update_text (ui);

        } else if (actor == ui->vol_int || actor == ui->vol_int_bg) {
          gfloat x, y, dist;
          gdouble volume;

          clutter_actor_get_transformed_position (ui->vol_int_bg, &x, &y);
          dist = bev->x - x;
          dist = CLAMP (dist, 0, ui->volume_width);

          volume = dist / ui->volume_width;
          g_object_set (G_OBJECT (ui->engine->player), "volume", volume, NULL);
          clutter_actor_set_size (ui->vol_int, dist, ui->volume_height);

        } else if (actor == ui->control_bg || actor == ui->control_title
            || actor == ui->control_pos) {
          ui->keep_showing_controls = !ui->keep_showing_controls;

          if (ui->keep_showing_controls) {
            clutter_stage_hide_cursor (CLUTTER_STAGE (ui->stage));
          } else {
            penalty_box (ui);
            show_controls (ui, FALSE);
          }
        } else if (actor == ui->texture || actor == ui->stage) {
          if (!ui->penalty_box_active) {
            penalty_box (ui);
            show_controls (ui, FALSE);
          }
        }
      }

      handled = TRUE;
      break;
    }

    case CLUTTER_MOTION:
    {
      if (!ui->penalty_box_active)
        show_controls (ui, TRUE);

      handled = TRUE;
      break;
    }
  }

  return handled;
}
Пример #4
0
void player_act()
{
    switch(get_last_action()) {
        case ACTION_TILL:
            till(x, y, current_map);
            break;
        case ACTION_PICKUP: {
            item* it = get_item(items_at(x, y, current_map), item_count_at(x, y, current_map), PURPOSE_PICKUP, true);
            if(!it)
                break;
            printf_message(COLOR_DEFAULT, "Picked up %d %s", it->count, it->name);
            callback("picked_up", it->script_state);
            take_item(x, y, it, current_map);
            add_item(it);
        } break;
        case ACTION_DROP: {
            item* it = get_item(inventory, item_count, PURPOSE_DROP, false);
            if(!it)
                break;
            if(it->can_equip && equipment[it->slot] == it) {
                equipment[it->slot] = 0;
                printf_message(COLOR_DEFAULT, "You unequip the %s, and drop it on the ground.", it->name);
                callback("removed", it->script_state);
            }
            item* clone = clone_item(it);
            callback("dropped", clone->script_state);
            place_item(x, y, clone, current_map);
            remove_item(it, -1);
        } break;
        case ACTION_APPLY: {
            item* it = get_item(inventory, item_count, PURPOSE_APPLY, false);
            if(!it)
                break;
            callback("apply", it->script_state);
            remove_item(it, 1);
        } break;
        case ACTION_EQUIP: {
            item* it = get_item(inventory, item_count, PURPOSE_EQUIP, false);
            if(!it || it->slot == SLOT_INVALID)
                break;
            callback("equip", it->script_state);
            printf_message(COLOR_DEFAULT, "You equip the %s.", it->name);
            equipment[it->slot] = it;
        break; }
        case ACTION_REMOVE: {
            item* it = get_item(equipment, 3, PURPOSE_REMOVE, false);
            if(!it)
                break;
            callback("remove", it->script_state);
            equipment[it->slot] = 0;
            printf_message(COLOR_DEFAULT, "You unequip the %s.", it->name);
        break; }
        case ACTION_PLANT: {
            if(!can_plant(x, y, current_map, true))
                break;
            item* it = get_item(inventory, item_count, PURPOSE_PLANT, false);
            if(!it)
                break;
            if(spawn_plant(x, y, it->plant_id, current_map)) {
                printf_message(COLOR_DEFAULT, "You plant the %s in the tilled soil.", it->name);
                remove_item(it, 1);
            }
        break; }
        case ACTION_HARVEST: {
            add_item(harvest_plant(x, y, current_map));
        break; }
        case ACTION_HELP:
            show_controls();
            break;
        case ACTION_INVENTORY:
            get_item(inventory, item_count, PURPOSE_NONE, false);
            break;
        case ACTION_WATER:
            water_tile(x, y, current_map);
            break;
        case ACTION_EXAMINE: {
            int mx, my;
            get_last_mouse_position(&mx, &my);
            int xdiff = mx - pres_x;
            int ydiff = my - pres_y;
            if(mx < 1 || my < 1 || mx > 78 || my > 78)
                break;
            examine(x + xdiff, y +ydiff, current_map);
        } break;
    }
    if(ep_current <= 0)
        add_message(COLOR_EP_CRIT, "Out of energy, you fall to the ground.");
}