void sceneShow::run_viewpoint_scene(CURRENT_FILE_FORMAT::file_scene_show_viewpoint viewpoint) { std::cout << "** sceneShow::run_image_scene::START" << std::endl; float x = viewpoint.ini_x; float y = viewpoint.ini_y; graphicsLib_gSurface image; graphLib.surfaceFromFile(FILEPATH + "images/scenes/" + viewpoint.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(viewpoint.move_delay); std::cout << "rect - x[" << x << "], .y[" << y << "], w[" << viewpoint.w << "], h[" << viewpoint.h << "]" << std::endl; //void graphicsLib::showSurfacePortion(graphicsLib_gSurface *surfaceOrigin, const st_rectangle origin_rect, st_rectangle destiny_rect) graphLib.showSurfacePortion(&image, st_rectangle(x, y, viewpoint.w, viewpoint.h), st_rectangle(viewpoint.pos_x, viewpoint.pos_y, viewpoint.w, viewpoint.h)); graphLib.updateScreen(); x += speed_x; y += speed_y; total_dist--; } graphLib.showSurfacePortion(&image, st_rectangle(x, y, viewpoint.w, viewpoint.h), st_rectangle(viewpoint.pos_x, viewpoint.pos_y, viewpoint.w, image.height)); timer.delay(viewpoint.move_delay); graphLib.updateScreen(); }
// @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(); }
/// @TODO: fix animation. investigate a better way for drawing it (code is way too confusing) void classMap::redraw_boss_door(bool is_close, int nTiles, int tileX, short player_number) { int k, tileCount; //is_close = false; // THIS IS A TEMPORARY FIX //std::cout << "classMap::redraw_boss_door - is_close: " << is_close << std::endl; input.waitTime(10); //for (k=0; k<tilePieces; k++) { for (k=0; k<nTiles; k++) { tileCount = nTiles; //if (is_close == false) { std::cout << "classMap::redraw_boss_door - nTiles: " << nTiles << ", tilePieces: " << tilePieces << ", tileCount: " << tileCount << std::endl; } // redraw screen showMap(); graphLib.updateScreen(); int tiles_showed; if (is_close == false) { tiles_showed = k; } else { tiles_showed = 0; } for (int i=0; i<MAP_W; i++) { for (int j=0; j<MAP_H; j++) { if (map_tiles.tiles[i][j].tile3.x != -1 && map_tiles.tiles[i][j].tile3.y != -1) { if (i == tileX && map_tiles.tiles[i][j].locked == TERRAIN_DOOR) { //std::cout << "****** redraw_boss_door - k: " << k << ", tiles_showed: " << tiles_showed << ", nTiles: " << nTiles << std::endl; if (is_close == false) { if (tiles_showed < nTiles) { graphLib.placeTile(st_position(map_tiles.tiles[i][j].tile3.x, map_tiles.tiles[i][j].tile3.y), st_position((i*TILESIZE)-scroll.x, (j*TILESIZE)-scroll.y), &graphLib.gameScreen); graphLib.updateScreen(); tiles_showed++; } } else { if (tiles_showed < k) { graphLib.placeTile(st_position(map_tiles.tiles[i][j].tile3.x, map_tiles.tiles[i][j].tile3.y), st_position((i*TILESIZE)-scroll.x, (j*TILESIZE)-scroll.y), &graphLib.gameScreen); graphLib.updateScreen(); tiles_showed++; } } } else { graphLib.placeTile(st_position(map_tiles.tiles[i][j].tile3.x, map_tiles.tiles[i][j].tile3.y), st_position((i*TILESIZE)+scroll.x, (j*TILESIZE)-scroll.y), &graphLib.gameScreen); } } } } _player_list.at(0)->show(); graphLib.draw_hp_bar(_player_list.at(0)->get_current_hp(), player_number, WEAPON_DEFAULT); //show_sprite(p1Obj->sprite, game_screen); //draw_hp_bar(p1Obj); graphLib.updateScreen(); input.waitTime(100); } input.waitTime(100); }
void draw::update_screen() { if (_rain_enabled == true) { show_rain(); } graphLib.updateScreen(); }
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); } }
void sceneShow::clear_area(int n) { if (cleararea_list.size() <= n) { std::cout << "ERROR: Scene ClearArea[" << n << "] invalid. List size is " << image_scenes.size() << "." << std::endl; exit(-1); } graphLib.clear_area(cleararea_list.at(n).x, cleararea_list.at(n).y, cleararea_list.at(n).w, cleararea_list.at(n).h, cleararea_list.at(n).r, cleararea_list.at(n).g, cleararea_list.at(n).b); graphLib.updateScreen(); }
void inputLib::wait_keypress() { bool fim = false; while (!fim) { readInput(); if (p1_input[BTN_START] == 1 || p2_input[BTN_JUMP] == 1 || p1_input[BTN_JUMP] == 1 || p2_input[BTN_JUMP]) { fim = true; } graphLib.updateScreen(); waitTime(50); } clean(); }
int main(int argc, char *argv[]) { quick_load = false; UNUSED(argc); gameControl.currentStage = TECHNOBOT; game_config.selected_player = 1; //strncpy (FILEPATH, argv[0], strlen(argv[0])-11); string argvString = string(argv[0]); FILEPATH = argvString.substr(0, argvString.size()-EXEC_NAME.size()); //std::cout << "main - FILEPATH: " << FILEPATH << std::endl; format_v_2_0_1::file_io fio; fio.read_game(game_data); // INIT GRAPHICS if (graphLib.initGraphics() != true) { exit(-1); } // INIT GAME if (quick_load == false) { if (gameControl.showIntro() == false) { return 0; } } else { gameControl.quick_load_game(); //ending game_ending; //game_ending.start(); } input.clean(); input.p1_input[BTN_START] = 0; input.waitTime(200); input.clean(); while (true) { input.readInput(); if (input.p1_input[BTN_QUIT] == 1) { exit(-1); } gameControl.showGame(); graphLib.updateScreen(); } /// @TODO: sdl quit sub-systems SDL_Quit(); return 1; }
void gfx_sin_wave::show(int x, int y) { float angle_max = 3.14 * SIN_STEPS; float angle_step = angle_max / surface->width; float angle = 0; for (int j=0; j<max_amplitude; j++) { graphLib.clear_area(x, y, surface->width, surface->height, 0, 0, 0); for (int i=0; i<surface->height; i++) { float pos_x = (sin(angle) + x)*amplitude; int pos_y = i + y; angle += angle_step; //std::cout << "i[" << i << "], pos_x[" << pos_x << "], pos_y[" << pos_y << "]" << std::endl; graphLib.showSurfacePortion(surface, st_rectangle(0, i, surface->width, 1), st_rectangle(pos_x, pos_y, surface->width, 1)); } amplitude--; graphLib.updateScreen(); timer.delay(40); } }
// ********************************************************************************************** // // // // ********************************************************************************************** // void inputLib::waitTime(int wait_period) const { /* #ifdef PLAYSTATION2 if (wait_period < 20) { return; } #endif */ int now_time=0; now_time = timer.getTimer(); wait_period = now_time + wait_period; while (now_time < wait_period) { now_time = timer.getTimer(); SDL_Delay(1); #ifdef PLAYSTATION RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY); #endif graphLib.updateScreen(); } }
void sceneShow::clear_screen() { graphLib.clear_area(0, 0, RES_W, RES_H, 0, 0, 0); graphLib.updateScreen(); }
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); } }
void draw::show_ready() { st_position dest_pos((RES_W/2)-26, (RES_H/2)-6); graphLib.copyArea(dest_pos, &ready_message, &graphLib.gameScreen); graphLib.updateScreen(); }