Beispiel #1
0
// @TODO - this should only set some variables in a global and the drawinbg should be handled my show_scene()
// That way we can move the run_XXX methods into threads to run in paralel
void sceneShow::run_image_scene(CURRENT_FILE_FORMAT::file_scene_show_image scene_image)
{
    std::cout << "** sceneShow::run_image_scene::START" << std::endl;
    float x = scene_image.ini_x;
    float y = scene_image.ini_y;
    graphicsLib_gSurface image;
    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(RES_W, RES_H), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(0, 0, RES_W, RES_H), st_position(0, 0), &bg_image);
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/" + scene_image.filename, &image);

    std::cout << "** sceneShow::run_image_scene::total_dist: " << total_dist << std::endl;

    while (total_dist > 0) {
        input.read_input();
        //std::cout << "total_dist: " << total_dist << std::endl;
        timer.delay(scene_image.move_delay);
        // @TODO - copy background, but should be done in a smarter way as there can be several moving elements
        graphLib.showSurfaceAt(&bg_image, st_position(0, 0), false);
        graphLib.showSurfaceAt(&image, st_position(x, y), false);
        graphLib.updateScreen();
        x += speed_x;
        y += speed_y;
        total_dist--;
    }
    graphLib.showSurfaceAt(&image, st_position(x, y), false);
    graphLib.updateScreen();
}
Beispiel #2
0
void pass2_convert_to_asm(const char* listing_name) {
  FILE* fd;
  int row;

  if (listing_name)
    if (!(fd = fopen(listing_name, "w")))
      err(PASS2, INVALID_LISTNAM, 0, listing_name);

  int sym_tab_size = st_size();
  for (int i = 0; i <= sym_tab_size; i++) {
    int addr_val = 0;
    st_get_row(i, toknam, inst, op, &row);
    if (*op) {
      if (isalpha(*op)) {
        if ((addr_val = st_lookup_tok(op)) == -1)
          err(PASS2, MISSING_TOK, row, op);
      } else {
        addr_val = atoi(op);
      }
    }
    int opcode = st_lookup_inst(inst);
    long code = 1000*opcode + addr_val;
    st_store_code(i, code);
    if (listing_name)
      fprintf(fd, "%5d: %05ld %15s %15s %15s\n",
          i, code, toknam, inst, op);
  }

  if (listing_name)
    fclose(fd);
}
Beispiel #3
0
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode)
{
    int frame_n = 0;
    CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n);
    long frame_timer = timer.getTimer() + scene.frame_delay;
    long started_timer = timer.getTimer();
    int repeat_times = 0;

    graphicsLib_gSurface image;
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image);
    int max_frames = image.width / scene.frame_w;

    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image);

    while (true) {

        std::cout << "sceneShow::show_animation::LOOP" << std::endl;

        //graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);

        int x = frame_n*scene.frame_w;
        std::cout << "origin.x: " << x << ", dest.x: " << scene.x << ", frame.w: " << scene.frame_w << ", frame.h: " << scene.frame_h << std::endl;

        graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y));


        graphLib.updateScreen();

        if (frame_timer < timer.getTimer()) {
            frame_n++;
            if (frame_n > max_frames) {
                frame_n = 0;
                repeat_times++;
            }
            frame_timer = timer.getTimer() + scene.frame_delay;
        }

        // stop condition
        if (repeat_times > 0 && repeat_n <= 1) {
            std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl;
            return;
        } else {
            if (repeat_mode == 0) { // time-mode
                if ((timer.getTimer() - started_timer) > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl;
                    return;
                }
            } else { // repeat number mode
                if (repeat_times > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl;
                    return;
                }
            }
        }
        timer.delay(10);
    }
}
Beispiel #4
0
void class_config::set_player_ref(classPlayer* set_player_ref)
{
	player_ref = set_player_ref;
	if (_player_surface.width == 0) {
		graphLib.initSurface(st_size(player_ref->get_char_frame(ANIM_DIRECTION_RIGHT, ANIM_TYPE_ATTACK, 0)->width, player_ref->get_char_frame(ANIM_DIRECTION_RIGHT, ANIM_TYPE_ATTACK, 0)->height), &_player_surface);
		graphLib.copyArea(st_position(0, 0), player_ref->get_char_frame(ANIM_DIRECTION_RIGHT, ANIM_TYPE_ATTACK, 0), &_player_surface);
	}
}
void draw::show_boss_intro_sprites(short boss_id, bool show_fall)
{
    UNUSED(show_fall);
    unsigned int intro_frames_n = 0;
    //int intro_frames_rollback = 0;
    st_position boss_pos(20, -37);
    st_position sprite_size;
    graphicsLib_gSurface bgCopy, boss_graphics;


    std::string graph_filename = FILEPATH + "data/images/sprites/enemies/" + std::string(game_data.game_npcs[boss_id].graphic_filename);
    sprite_size.x = game_data.game_npcs[boss_id].frame_size.width;
    sprite_size.y = game_data.game_npcs[boss_id].frame_size.height;
    graphLib.surfaceFromFile(graph_filename.c_str(), &boss_graphics);

    graphLib.initSurface(st_size(RES_W, RES_H), &bgCopy);
    graph_filename = FILEPATH + "data/images/backgrounds/stage_boss_intro.png";
    graphLib.surfaceFromFile(graph_filename.c_str(), &bgCopy);
    st_position bg_pos(0, (RES_H/2)-(bgCopy.height/2));
    graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);

    update_screen();

    int sprite_pos_y = RES_H/2 - sprite_size.y/2;

    for (int i=0; i<ANIM_FRAMES_COUNT; i++) {
        if (game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].used == true) {
            intro_frames_n++;
        }
    }

    // fall into position
    while (boss_pos.y < sprite_pos_y) {
        boss_pos.y += 4;
        graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);
        graphLib.copyArea(st_rectangle(0, 0, sprite_size.x, sprite_size.y), st_position(boss_pos.x, boss_pos.y), &boss_graphics, &graphLib.gameScreen);
        graphLib.wait_and_update_screen(5);
    }
    graphLib.wait_and_update_screen(500);


    // show intro sprites
    if (intro_frames_n > 1) {
        for (int i=0; i<ANIM_FRAMES_COUNT; i++) {
            if (game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].used == true) {
                //std::cout << "i: " << i << ", used: " << game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].used << ", duration: " << game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].duration << std::endl;
                graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);
                graphLib.copyArea(st_rectangle(sprite_size.x * game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].sprite_graphic_pos_x, 0, sprite_size.x, sprite_size.y), st_position(boss_pos.x, boss_pos.y), &boss_graphics, &graphLib.gameScreen);
                graphLib.wait_and_update_screen(game_data.game_npcs[boss_id].sprites[ANIM_TYPE_INTRO][i].duration);
            }
        }
    } else { // just frow first sprite
        graphLib.copyArea(bg_pos, &bgCopy, &graphLib.gameScreen);
        graphLib.copyArea(st_rectangle(0, 0, sprite_size.x, sprite_size.y), st_position(boss_pos.x, boss_pos.y), &boss_graphics, &graphLib.gameScreen);
        graphLib.wait_and_update_screen(200);
    }
}
Beispiel #6
0
bool dialogs::show_leave_game_dialog() const
{
    bool res = false;
    bool repeat_menu = true;
    int picked_n = -1;

    timer.pause();

    std::cout << ">>>>>>> show_leave_game_dialog::START" << std::endl;

    graphicsLib_gSurface bgCopy;
    graphLib.initSurface(st_size(RES_W, RES_H), &bgCopy);
    graphLib.copyArea(st_position(0, 0), &graphLib.gameScreen, &bgCopy);

    graphLib.show_dialog(0, false);
    st_position dialog_pos = graphLib.get_dialog_pos();
    graphLib.draw_text(dialog_pos.x+30, dialog_pos.y+16, "QUIT GAME?");
    std::vector<std::string> item_list;
    item_list.push_back("YES");
    item_list.push_back("NO");
    option_picker main_picker(false, st_position(dialog_pos.x+40, dialog_pos.y+16+11), item_list, false);
    draw_lib.update_screen();
    while (repeat_menu == true) {
        picked_n = main_picker.pick();
        std::cout << "picked_n: " << picked_n << std::endl;
        if (picked_n == 0) {
            res = true;
            repeat_menu = false;
        } else if (picked_n == 1) {
            res = false;
            repeat_menu = false;
        } else {
            main_picker.draw();
        }
    }
    input.clean();
    input.waitTime(200);
    graphLib.copyArea(st_position(0, 0), &bgCopy, &graphLib.gameScreen);
    draw_lib.update_screen();
    timer.unpause();

    std::cout << ">>>>>>> show_leave_game_dialog::END" << std::endl;

    return res;
}
void draw::show_credits()
{
    int line_n=0;
    unsigned int scrolled=0;
    int posY = -RES_H;
    st_rectangle dest;
    graphicsLib_gSurface credits_surface;

    graphLib.initSurface(st_size(RES_W, RES_H+12), &credits_surface);
    graphLib.blank_surface(credits_surface);
    graphLib.blank_screen();


    // add the initial lines to screen
    create_credits_text(credits_surface);

    update_screen();

    // scroll the lines
    while (scrolled < (credits_list.size()*12)+RES_H/2+46) {
        graphLib.copyArea(st_rectangle(0, posY, RES_W, RES_H), st_position(0, 0), &credits_surface, &graphLib.gameScreen);
        update_screen();
        timer.delay(60);
        posY++;
        scrolled++;
        if (posY > 12) {
            graphLib.copyArea(st_rectangle(0, posY, credits_surface.width, RES_H), st_position(0, 0), &credits_surface, &credits_surface);
            // scroll the lines
            dest.x = 0;
            dest.y = RES_H;
            dest.w = RES_W;
            dest.h = 12;
            graphLib.blank_area(dest.x, dest.y, dest.w, dest.h, credits_surface);
            draw_credit_line(credits_surface, line_n+21);
            posY = 0;
            line_n++;
        }
    }
    update_screen();
}
Beispiel #8
0
int main(void)
{
    int n = 10;
    int i;
    st_t st;
    st = st_init(n);

    for (i = 0; i < n; i++) {
        st_insert(st, i);
    }

    for (i = 0; i < n; i++) {
        if (st_search(st, i)) {
            printf("Found key %2d\n", i);
        }

        st_delete(st, i);
    }

    printf("The size of the table is: %u\n", st_size(st));
    st_finalize(&st);
    return 0;
}
Beispiel #9
0
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode)
{
    int frame_n = 0;
    CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n);
    long frame_timer = timer.getTimer() + scene.frame_delay;
    long started_timer = timer.getTimer();
    int repeat_times = 0;

    graphicsLib_gSurface image;
    graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image);
    int max_frames = image.width / scene.frame_w;

    graphicsLib_gSurface bg_image;
    graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image);
    graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image);


    std::cout << "max_frames[" << max_frames << "], image.w[" << image.width << "], scene.frame_w[" << scene.frame_w << "]" << std::endl;

    while (true) {
        input.read_input();
        int x = frame_n*scene.frame_w;


        // stop condition
        if (repeat_times > 0 && repeat_n <= 1) {
            std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl;
            break;
        } else {
            if (repeat_mode == 0) { // time-mode
                if ((timer.getTimer() - started_timer) > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl;
                    break;
                }
            } else { // repeat number mode
                if (repeat_times > repeat_n) {
                    std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl;
                    break;
                }
            }
        }
        graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);
        std::cout << "x[" << x << "], img.w[" << image.width << "], frame.w[" << scene.frame_w << "]" << std::endl;
        graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y));
        graphLib.updateScreen();
        timer.delay(scene.frame_delay);


        if (frame_timer < timer.getTimer()) {
            frame_n++;
            if (frame_n >= max_frames) {
                frame_n = 0;
                repeat_times++;
            }
            frame_timer = timer.getTimer() + scene.frame_delay;
        }

    }
    // avoid leaving animation image trail if it is a repeating one
    if (repeat_n > 1) {
        graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false);
        graphLib.updateScreen();
        timer.delay(scene.frame_delay);
    }
}