本文整理汇总了C++中graphicsLib::surfaceFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ graphicsLib::surfaceFromFile方法的具体用法?C++ graphicsLib::surfaceFromFile怎么用?C++ graphicsLib::surfaceFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphicsLib
的用法示例。
在下文中一共展示了graphicsLib::surfaceFromFile方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: show_boss_intro_sprites
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);
}
}
示例2: run_viewpoint_scene
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();
}
示例3: run_image_scene
// @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();
}
示例4: show_animation
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);
}
}
示例5: show_bubble
void draw::show_bubble(int x, int y)
{
if (_bubble_gfx.gSurface == NULL) {
std::string filename = FILEPATH + "/data/images/tilesets/bubble.png";
graphLib.surfaceFromFile(filename, &_bubble_gfx);
}
graphLib.showSurfaceAt(&_bubble_gfx, st_position(x, y), false);
}
示例6: preload
void draw::preload()
{
std::string filename = FILEPATH + "data/images/tilesets/ready.png";
graphLib.surfaceFromFile(filename, &ready_message);
filename = FILEPATH + "data/images/sprites/teleport_small.png";
graphLib.surfaceFromFile(filename, &_teleport_small_gfx);
// DROPABLE OBJECT GRAPHICS
for (int i=0; i<GAME_MAX_OBJS; i++) {
for (int j=0; j<DROP_ITEM_COUNT; j++) {
short obj_type_n = gameControl.get_drop_item_id(j);
if (obj_type_n != -1) {
get_object_graphic(obj_type_n);
}
}
}
}
示例7: graphic_filename
graphicsLib_gSurface *draw::get_object_graphic(int obj_id)
{
std::map<unsigned int, graphicsLib_gSurface>::iterator it;
graphicsLib_gSurface temp_sprite;
it = objects_sprite_list.find(obj_id);
if (it == objects_sprite_list.end()) { // there is no graphic with this key yet, add it
std::string graphic_filename(game_data.objects[obj_id].graphic_filename);
std::string complete_filename(FILEPATH + "data/images/sprites/objects/" + graphic_filename);
graphLib.surfaceFromFile(complete_filename, &temp_sprite);
objects_sprite_list.insert(std::pair<unsigned int, graphicsLib_gSurface>(obj_id, temp_sprite));
} else {
return &(*it).second;
}
}
示例8: show_rain
void draw::show_rain()
{
if (rain_obj.gSurface == NULL) {
// load rain
std::string filename = FILEPATH + "/data/images/tilesets/rain.png";
graphLib.surfaceFromFile(filename, &rain_obj);
}
for (int i=0; i<MAP_W; i++) {
for (int j=0; j<MAP_H; j++) {
graphLib.showSurfaceRegionAt(&rain_obj, st_rectangle(_rain_pos*TILESIZE, 0, TILESIZE, TILESIZE), st_position(i*TILESIZE, j*TILESIZE));
}
}
if (timer.getTimer() > _rain_timer) {
_rain_pos++;
if (_rain_pos > 2) {
_rain_pos = 0;
}
_rain_timer = timer.getTimer() + RAIN_DELAY;
}
}
示例9: loadMap
// ********************************************************************************************** //
// //
// ********************************************************************************************** //
void classMap::loadMap(std::map<std::string, object> &game_object_list)
{
if (stage_number == -1) {
cout << "ERROR::map::loadMap - stage number was not set, can't load it before setting the number.\n";
return;
}
if (number == -1) {
cout << "ERROR::map::loadMap - map number was not set, can't load it before setting the number.\n";
return;
}
game_data.stages[stage_number].maps[number].backgrounds[0].speed = 0.0; // background #1 is ALWAYS static
/*
//#ifdef DINGUX
game_data.stages[stage_number].maps[number].backgrounds[0].speed = 0.0;
game_data.stages[stage_number].maps[number].backgrounds[1].speed = 0.0;
//#endif
*/
clean_map();
//std::cout << "loading map[" << number << "] from stage[" << stage_number << "]" << std::endl;
for (int i=0; i<MAP_W; i++) {
for (int j=0; j<MAP_H; j++) {
map_tiles.tiles[i][j].locked = game_data.stages[stage_number].maps[number].tiles[i][j].locked;
map_tiles.tiles[i][j].tile1.x = game_data.stages[stage_number].maps[number].tiles[i][j].tile1.x;
map_tiles.tiles[i][j].tile1.y = game_data.stages[stage_number].maps[number].tiles[i][j].tile1.y;
map_tiles.tiles[i][j].tile2.x = game_data.stages[stage_number].maps[number].tiles[i][j].tile2.x;
map_tiles.tiles[i][j].tile2.y = game_data.stages[stage_number].maps[number].tiles[i][j].tile2.y;
map_tiles.tiles[i][j].tile3.x = game_data.stages[stage_number].maps[number].tiles[i][j].tile3.x;
map_tiles.tiles[i][j].tile3.y = game_data.stages[stage_number].maps[number].tiles[i][j].tile3.y;
}
}
bool column_locked = true;
for (int i=0; i<MAP_W; i++) {
column_locked = true;
for (int j=0; j<MAP_H; j++) {
if (map_tiles.tiles[i][j].locked != 1 && map_tiles.tiles[i][j].locked != TERRAIN_DOOR && map_tiles.tiles[i][j].locked != TERRAIN_SCROLL_LOCK) {
column_locked = false;
break;
}
}
wall_scroll_lock[i] = column_locked;
}
load_map_npcs();
load_map_objects(game_object_list);
if (strlen(game_data.stages[stage_number].maps[number].backgrounds[0].filename) > 0) {
std::string bg1_filename(FILEPATH+"data/images/map_backgrounds/" + game_data.stages[stage_number].maps[number].backgrounds[0].filename);
//std::cout << "stage_number: " << stage_number << ", map_number: " << number << ", bg1_filename: " << bg1_filename.c_str() << std::endl;
graphLib.surfaceFromFile(bg1_filename, &bg1_surface);
}
if (strlen(game_data.stages[stage_number].maps[number].backgrounds[1].filename) > 0) {
std::string bg2_filename(FILEPATH+"data/images/map_backgrounds/"+ game_data.stages[stage_number].maps[number].backgrounds[1].filename);
std::cout << "classmap::loadMap - loading bg2: '" << bg2_filename << std::endl;
std::cout << "bg2_filename: " << bg2_filename.c_str() << std::endl;
graphLib.surfaceFromFile(bg2_filename, &bg2_surface);
}
drawMap();
}
示例10: show_animation
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);
}
}