Beispiel #1
0
void help_menu(WINDOW* screen, struct Ball* ball, struct Paddle* paddle, int max_x, int max_y)
{
    clear();
    refresh();

    Timer* timer = sgl_timer_new();

    move_ball_xy(ball, ball->x, max_y / 2);

    int key;

    while ((key = getch()) != 'q'){

        //Move and bound ball
        if (sgl_timer_elapsed_milliseconds(timer) > 20){
            sgl_timer_reset(timer);
            update_background(ball, paddle, max_x, max_y - 4);
            draw_background(screen, ball, paddle);
        }

        draw_strings(screen, 1, max_x / 2 - strlen(help_title[0]), help_title, 6);
        draw_strings(screen, 8, 3, help_text, 6);

        wrefresh(screen);
    }
    clear();
}
Beispiel #2
0
void D3D12GSRender::render_overlay()
{
	D2D1_SIZE_F rtSize = g_d2d_render_targets[m_swap_chain->GetCurrentBackBufferIndex()]->GetSize();
	std::wstring duration = L"Draw duration : " + std::to_wstring(m_timers.draw_calls_duration) + L" us";
	float vtxIdxPercent = (float)m_timers.vertex_index_duration / (float)m_timers.draw_calls_duration;
	std::wstring vertexIndexDuration = L"Vtx/Idx upload : " + std::to_wstring(m_timers.vertex_index_duration) + L" us (" + std::to_wstring(100.f * vtxIdxPercent) + L" %)";
	std::wstring size = L"Upload size : " + std::to_wstring(m_timers.buffer_upload_size) + L" Bytes";
	float texPercent = (float)m_timers.texture_duration / (float)m_timers.draw_calls_duration;
	std::wstring texDuration = L"Textures : " + std::to_wstring(m_timers.texture_duration) + L" us (" + std::to_wstring(100.f * texPercent) + L" %)";
	float programPercent = (float)m_timers.program_load_duration / (float)m_timers.draw_calls_duration;
	std::wstring programDuration = L"Program : " + std::to_wstring(m_timers.program_load_duration) + L" us (" + std::to_wstring(100.f * programPercent) + L" %)";
	float constantsPercent = (float)m_timers.constants_duration / (float)m_timers.draw_calls_duration;
	std::wstring constantDuration = L"Constants : " + std::to_wstring(m_timers.constants_duration) + L" us (" + std::to_wstring(100.f * constantsPercent) + L" %)";
	float rttPercent = (float)m_timers.prepare_rtt_duration / (float)m_timers.draw_calls_duration;
	std::wstring rttDuration = L"RTT : " + std::to_wstring(m_timers.prepare_rtt_duration) + L" us (" + std::to_wstring(100.f * rttPercent) + L" %)";
	std::wstring flipDuration = L"Flip : " + std::to_wstring(m_timers.flip_duration) + L" us";

	std::wstring count = L"Draw count : " + std::to_wstring(m_timers.draw_calls_count);
	draw_strings(rtSize, m_swap_chain->GetCurrentBackBufferIndex(),
		{
			duration,
			count,
			rttDuration,
			vertexIndexDuration,
			size,
			programDuration,
			constantDuration,
			texDuration,
			flipDuration
		});
}
Beispiel #3
0
void QPlot::paintEvent(QPaintEvent* /*event*/)
{
    QPainter painter(this);
    draw_coordinate_system(painter);
    if(draw_ByteArray_flag)
    {
        draw_ByteArray(painter);
    }
    if(draw_Data_flag)
    {
        draw_Data(painter);
    }
    draw_caption(painter);
    draw_strings(painter);
}
Beispiel #4
0
int user_select_string(char **strings, int n)
{
    int cursor = 0;
    int display_start = 0;
    int n_display = 20;

    while (1)
    {
	if (cursor>=display_start+n_display)
	    display_start = cursor-n_display+1;
	if (cursor<display_start)
	    display_start = cursor;

	int x = 10;
	int y = 5;
	
	clear_screen();
	clear_text_area(x,y,60-2*x,n_display+4);
	y+=2;
	
	pgPrintCenter(29,red,"X = Select");
	pgPrintCenter(30,red,"O = Abort");
	
	draw_strings(strings, n, x, 7,
		     display_start, n_display, cursor);
	
	int key = get_buttons();

	if (key & PSP_CTRL_DOWN)
	    cursor ++;
	if (key & PSP_CTRL_UP)
	    cursor --;
	if (key & PSP_CTRL_RIGHT)
	    cursor += n_display;
	if (key & PSP_CTRL_LEFT)
	    cursor -= n_display;
	if (key & PSP_CTRL_CIRCLE)
	    return -1;
	if (key & PSP_CTRL_CROSS)
	    return cursor;
	
	if (cursor>=n)
	    cursor = n-1;
	if (cursor<0)
	    cursor = 0;
    }
}
Beispiel #5
0
struct Game* options_menu(WINDOW* screen, struct Game* game, struct Ball* ball, struct Paddle* paddle, int max_x, int max_y)
{
    clear();
    refresh();

    move_ball_xy(ball, ball->x, max_y / 2);

    char* opts_menu_l[8] = {"Difficulty", "Sound", "Paddle Sensitivity",\
        "Screen Size", "Left Control", "Right Control",\
        "Play to", "Save & Return"};

    struct Menu* opts_menu = new_menu(max_x / 8, 8, 8, opts_menu_l, BLUE_ON_BLACK, GREEN_ON_BLACK);

    WINDOW* info_win = newwin(3, max_x, max_y - 3, 0);

    Timer* timer = sgl_timer_new();

    char* tmp_str = malloc(sizeof(char) * MAX_STRING_LENGTH);

    int key;

    while (key != 'q'){
        switch (key = getch()){
            case KEY_DOWN:
                move_selected(opts_menu, DOWN);
                wclear(info_win);
                break;

            case KEY_UP:
                wclear(info_win);
                move_selected(opts_menu, UP);
                break;

            case KEY_LEFT:
                switch (opts_menu->selected){
                    case 0: //Difficulty
                        if (game->difficulty == 0) game->difficulty = 2;
                        else game->difficulty--;
                        break;
                    case 1: //Sound
                        if (game->sound) game->sound = 0;
                        else game->sound = 1;
                        break;
                    case 2: //Paddle sensitivity
                        if (game->sensitivity == 1) game->sensitivity = 4;//DEHARDCODE THE 4
                        else game->sensitivity--;
                        break;
                    case 4: //Left control selection...
                        game->p1_aictrl = (game->p1_aictrl ? 0 : 1); break;
                    case 5: //Right control selection
                        game->p2_aictrl = (game->p2_aictrl ? 0 : 1); break;
                    case 6: //Change maximum score...
                        game->max_score--;
                        if (game->max_score < 1) game->max_score = MAX_SCORE;
                        break;
                }
                break;

            case KEY_RIGHT:
            case KEY_ENTER:
                switch (opts_menu->selected){
                    case 0: //Difficulty
                        if (game->difficulty == 2) game->difficulty = 0;
                        else game->difficulty++;
                        break;
                    case 1: //Sound
                        if (game->sound) game->sound = 0;
                        else game->sound = 1;
                        break;
                    case 2: //Paddle sensitivity
                        if (game->sensitivity == 4) game->sensitivity = 1;
                        else game->sensitivity++;
                        break;
                    case 3: //Change Resolution
                        change_resolution(screen, game);
                        break;
                    case 4: //Left control selection...
                        if (game->p1_aictrl) game->p1_aictrl = 0;
                        else game->p1_aictrl = 1;
                        break;
                    case 5: //Right control selection
                        if (game->p2_aictrl) game->p2_aictrl = 0;
                        else game->p2_aictrl = 1;
                        break;
                    case 6: //Change maximum score...
                        game->max_score++;
                        if (game->max_score > MAX_SCORE) game->max_score = 1;
                        break;
                    case 7: //Quit
                        return game;
                        break;
                }
                break;
        }

        //Move and bound ball
        if (sgl_timer_elapsed_milliseconds(timer) > 20){
            sgl_timer_reset(timer);
            update_background(ball, paddle, max_x, max_y - 4);
            draw_background(screen, ball, paddle);
            box(info_win, 0, 0);
        }

        draw_strings(screen, 1, max_x / 2 - strlen(options_title[0]), options_title, 6);
        draw_menu(opts_menu);

        /************************************************************
         * NOTE: The spaces in strings below are there for a purpose!
         * They erase double digits. eg. "1 " erases "10"
         */
        snprintf(tmp_str, MAX_STRING_LENGTH, "%d ", game->difficulty + 1);//+1 so we don't get a difficulty of '0'
        mvwaddstr(screen, opts_menu->y, opts_menu->x + opts_menu->width + 1, tmp_str);//print difficulty

        mvwaddstr(screen, opts_menu->y + 1, opts_menu->x + opts_menu->width + 1, game->sound ? "On " : "Off");//print sound

        snprintf(tmp_str, MAX_STRING_LENGTH, "%d ", game->sensitivity);
        mvwaddstr(screen, opts_menu->y + 2, opts_menu->x + opts_menu->width + 1, tmp_str);//print sensitivity

        snprintf(tmp_str, MAX_STRING_LENGTH, "%dx%d", game->width, game->height); //Print the resolution
        mvwaddstr(screen, opts_menu->y + 3, opts_menu->x + opts_menu->width + 1, tmp_str);

        mvwaddstr(screen, opts_menu->y + 4, opts_menu->x + opts_menu->width + 1, game->p1_aictrl ? "Computer" : "Human   ");

        mvwaddstr(screen, opts_menu->y + 5, opts_menu->x + opts_menu->width + 1, game->p2_aictrl ? "Computer" : "Human   ");

        snprintf(tmp_str, MAX_STRING_LENGTH, "%d ", game->max_score);
        mvwaddstr(screen, opts_menu->y + 6, opts_menu->x + opts_menu->width + 1, tmp_str);

        //Write a helpful hint in the info_win
        switch (opts_menu->selected){
            case 0:
                mvwaddstr(info_win, 1, 1, "Change the difficulty, higher numbers are more difficult"); break;
            case 1:
                mvwaddstr(info_win, 1, 1, "Toggle sound on or off"); break;
            case 2:
                mvwaddstr(info_win, 1, 1, "Adjust paddle sensitivity, higher numbers are less sensitive"); break;
            case 3:
                mvwaddstr(info_win, 1, 1, "Change the playing screen size"); break;
            case 4:
                mvwaddstr(info_win, 1, 1, "Toggle control between Computer and Human for the left paddle"); break;
            case 5:
                mvwaddstr(info_win, 1, 1, "Toggle control between Computer and Human for the right paddle"); break;
            case 6:
                mvwaddstr(info_win, 1, 1, "Change the maximum score needed to win"); break;
            case 7:
                mvwaddstr(info_win, 1, 1, "Save changes and go back to main menu"); break;
        }

        wrefresh(opts_menu->win);
        wrefresh(info_win);
    }

    clear();
    refresh();
    return game;
}
Beispiel #6
0
int main_menu(WINDOW* screen)
{
    int max_x, max_y;
    getmaxyx(screen, max_y, max_x);

    char* title_menu_l[4] = {"Play!", "Options", "Help", "Quit"};
    struct Menu* title_menu = new_menu(max_x / 8, 8, 4, title_menu_l, BLUE_ON_BLACK, GREEN_ON_BLACK);

    //For the moving background...
    struct Ball* ball = make_ball(max_x / 2, max_y / 4, HARD_BALL_VX, HARD_BALL_VY);
    struct Paddle* paddle = make_paddle(0, max_y / 2, 5, 2);

    Timer* timer = sgl_timer_new();

    //Default settings...
    int difficulty = EASY;
    int sound = SOUND_OFF;

    char* random_name = ai_names[randint(ai_names_c)];
    struct Game* game = make_game(max_x, max_y, difficulty, sound, PADDLE_SENSITIVITY, random_name, getenv("USER"), 1, 0, DEFAULT_SCORE);
    int key;
    while (key != 'q'){
        switch (key = getch()){
            case KEY_DOWN:
                move_selected(title_menu, DOWN);
                break;
            case KEY_UP:
                move_selected(title_menu, UP);
                break;

            case KEY_RIGHT:
            case KEY_ENTER:
                switch (title_menu->selected){
                    case 0: //Play game
                        play_game(game);
                        break;
                    case 1: //Options
                        game = options_menu(screen, game, ball, paddle, max_x, max_y);
                        clear();
                        break;
                    case 2: //Help
                        help_menu(screen, ball, paddle, max_x, max_y);
                        break;
                    case 3: //Quit
                        return 0;
                        break;
                }
                break;
        }

        //Render the background
        if (sgl_timer_elapsed_milliseconds(timer) > 20){
            sgl_timer_reset(timer);
            update_background(ball, paddle, max_x, max_y);
            draw_background(screen, ball, paddle);
            refresh();
        }

        draw_strings(screen, 1, max_x / 2 - strlen(game_title[0]), game_title, 6);

        draw_menu(title_menu);
        wrefresh(title_menu->win);
    }

    clear();
    refresh();
    return 0;
}