From aa921e71bd1a551ced19d29051439e88d2330975 Mon Sep 17 00:00:00 2001 From: Japa Illo Date: Mon, 13 Feb 2012 22:59:56 +0530 Subject: [PATCH] Zoom and enhance! Signed-off-by: Japa Illo --- Block.cpp | 24 +++++++++++-- Config.cpp | 2 +- SpriteObjects.cpp | 70 ++++++++++++++++++++++++++++++++------ SpriteObjects.h | 2 ++ UserInput.cpp | 23 ++----------- WorldSegment.cpp | 43 +++-------------------- main.cpp | 2 +- resources/Sprite Guide.txt | 5 +++ 8 files changed, 98 insertions(+), 73 deletions(-) diff --git a/Block.cpp b/Block.cpp index 99a5bb4a..f4a7162c 100644 --- a/Block.cpp +++ b/Block.cpp @@ -677,8 +677,28 @@ void drawFloorBlood ( Block *b, int32_t drawx, int32_t drawy ) int sheetOffsetX = TILEWIDTH * (sprite.sheetIndex % SHEET_OBJECTSWIDE), sheetOffsetY = 0; - al_draw_tinted_bitmap_region( IMGBloodSheet, premultiply(b->bloodcolor), sheetOffsetX, sheetOffsetY, TILEWIDTH, TILEHEIGHT+FLOORHEIGHT, drawx, drawy, 0); - al_draw_bitmap_region( IMGBloodSheet, sheetOffsetX, sheetOffsetY+TILEHEIGHT+FLOORHEIGHT, TILEWIDTH, TILEHEIGHT+FLOORHEIGHT, drawx, drawy, 0); + al_draw_tinted_scaled_bitmap( IMGBloodSheet, + premultiply(b->bloodcolor), + sheetOffsetX, + sheetOffsetY, + TILEWIDTH, + TILEHEIGHT+FLOORHEIGHT, + drawx, + drawy, + TILEWIDTH*config.scale, + (TILEHEIGHT+FLOORHEIGHT)*config.scale, + 0); + al_draw_scaled_bitmap( + IMGBloodSheet, + sheetOffsetX, + sheetOffsetY+TILEHEIGHT+FLOORHEIGHT, + TILEWIDTH, + TILEHEIGHT+FLOORHEIGHT, + drawx, + drawy, + TILEWIDTH*config.scale, + (TILEHEIGHT+FLOORHEIGHT)*config.scale, + 0); } } diff --git a/Config.cpp b/Config.cpp index 3c8b6690..3143be36 100644 --- a/Config.cpp +++ b/Config.cpp @@ -174,7 +174,7 @@ void parseConfigLine( string line ){ } if( line.find("[FOG_ALPHA") != -1){ int value = parseIntFromLine( "FOG_ALPHA", line); - config.foga = value; + config.foga = value / 255.0; } if( line.find("[SHOW_FOG") != -1){ string result = parseStrFromLine( "SHOW_FOG", line ); diff --git a/SpriteObjects.cpp b/SpriteObjects.cpp index 183e466c..8001920f 100644 --- a/SpriteObjects.cpp +++ b/SpriteObjects.cpp @@ -188,6 +188,7 @@ void c_sprite::reset(void) randomanimation = 0; animate = 1; bloodsprite = 0; + spritescale=1.0f; { for(int i = 0; i < subsprites.size(); i++) { @@ -232,6 +233,13 @@ void c_sprite::set_by_xml(TiXmlElement *elemSprite) { randomanimation=atoi(animoffStr); } + const char* scaleStr; + scaleStr = elemSprite->Attribute("zoom"); + if (scaleStr != NULL && scaleStr[0] != 0) + { + int scalev=atoi(scaleStr); + spritescale=pow(2.0f,(float)scalev); + } //load files, if any const char* filename = elemSprite->Attribute("file"); if (filename != NULL && filename[0] != 0) @@ -544,14 +552,14 @@ void c_sprite::draw_screen(int x, int y) if(config.block_count) config.drawcount ++; - al_draw_bitmap_region(IMGObjectSheet, sheetx * spritewidth, sheety * spriteheight, spritewidth, spriteheight, x + offset_x, y + offset_y, 0); + al_draw_bitmap_region(IMGObjectSheet, sheetx * spritewidth * spritescale, sheety * spriteheight * spritescale, spritewidth * spritescale, spriteheight * spritescale, x + offset_x, y + offset_y, 0); } else { if(config.block_count) config.drawcount ++; - al_draw_bitmap_region(getImgFile(fileindex), sheetx * spritewidth, sheety * spriteheight, spritewidth, spriteheight, x + offset_x, y + (offset_y - WALLHEIGHT), 0); + al_draw_bitmap_region(getImgFile(fileindex), sheetx * spritewidth * spritescale, sheety * spriteheight * spritescale, spritewidth * spritescale, spriteheight * spritescale, x + offset_x, y + (offset_y - WALLHEIGHT * spritescale), 0); } if(!subsprites.empty()) { @@ -692,13 +700,13 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, } else if(tilelayout == RAMPBOTTOMTILE) { - sheetx = sheetx = SPRITEWIDTH * b->ramp.index; - sheety = sheety = ((TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset))+(TILEHEIGHT + FLOORHEIGHT); + sheetx = SPRITEWIDTH * b->ramp.index; + sheety = ((TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset))+(TILEHEIGHT + FLOORHEIGHT); } else if(tilelayout == RAMPTOPTILE) { - sheetx = sheetx = SPRITEWIDTH * b->ramp.index; - sheety = sheety = (TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset); + sheetx = SPRITEWIDTH * b->ramp.index; + sheety = (TILEHEIGHT + FLOORHEIGHT + SPRITEHEIGHT) * (sheetindex+tileoffset+randoffset); } else { @@ -718,14 +726,35 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, { if(config.block_count) config.drawcount ++; - al_draw_tinted_scaled_bitmap(defaultsheet, premultiply(shade_color), sheetx, sheety+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT)*config.scale, spritewidth*config.scale, (spriteheight-WALL_CUTOFF_HEIGHT)*config.scale, 0); + al_draw_tinted_scaled_bitmap( + defaultsheet, premultiply(shade_color), + sheetx * spritescale, + (sheety+WALL_CUTOFF_HEIGHT) * spritescale, + spritewidth * spritescale, + (spriteheight-WALL_CUTOFF_HEIGHT) * spritescale, + drawx + (offset_x + offset_user_x)*config.scale, + drawy + (offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT)*config.scale, + spritewidth*config.scale, + (spriteheight-WALL_CUTOFF_HEIGHT)*config.scale, + 0); } else { if(config.block_count) config.drawcount ++; - al_draw_tinted_scaled_bitmap(getImgFile(fileindex), premultiply(shade_color), sheetx, (sheety)+WALL_CUTOFF_HEIGHT, spritewidth, spriteheight-WALL_CUTOFF_HEIGHT, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT)*config.scale, spritewidth*config.scale, (spriteheight-WALL_CUTOFF_HEIGHT)*config.scale, 0); + al_draw_tinted_scaled_bitmap( + getImgFile(fileindex), + premultiply(shade_color), + sheetx * spritescale, + (sheety+WALL_CUTOFF_HEIGHT) * spritescale, + spritewidth * spritescale, + (spriteheight-WALL_CUTOFF_HEIGHT) * spritescale, + drawx + (offset_x + offset_user_x)*config.scale, + drawy + (offset_user_y + (offset_y - WALLHEIGHT)+WALL_CUTOFF_HEIGHT)*config.scale, + spritewidth*config.scale, + (spriteheight-WALL_CUTOFF_HEIGHT)*config.scale, + 0); } //draw cut-off floor thing if(config.block_count) @@ -746,14 +775,35 @@ void c_sprite::draw_world_offset(int x, int y, int z, Block * b, int tileoffset, if(config.block_count) config.drawcount ++; - al_draw_tinted_scaled_bitmap(defaultsheet, premultiply(shade_color), sheetx, sheety, spritewidth, spriteheight, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT))*config.scale,spritewidth*config.scale, spriteheight*config.scale, 0); + al_draw_tinted_scaled_bitmap( + defaultsheet, premultiply(shade_color), + sheetx * spritescale, + sheety * spritescale, + spritewidth * spritescale, + spriteheight * spritescale, + drawx + (offset_x + offset_user_x)*config.scale, + drawy + (offset_user_y + (offset_y - WALLHEIGHT))*config.scale, + spritewidth*config.scale, + spriteheight*config.scale, + 0); } else { if(config.block_count) config.drawcount ++; - al_draw_tinted_scaled_bitmap(getImgFile(fileindex), premultiply(shade_color), sheetx, sheety, spritewidth, spriteheight, drawx + (offset_x + offset_user_x)*config.scale, drawy + (offset_user_y + (offset_y - WALLHEIGHT))*config.scale,spritewidth*config.scale, spriteheight*config.scale, 0); + al_draw_tinted_scaled_bitmap( + getImgFile(fileindex), + premultiply(shade_color), + sheetx * spritescale, + sheety * spritescale, + spritewidth * spritescale, + spriteheight * spritescale, + drawx + (offset_x + offset_user_x)*config.scale, + drawy + (offset_user_y + (offset_y - WALLHEIGHT))*config.scale, + spritewidth*config.scale, + spriteheight*config.scale, + 0); } } if(needoutline) diff --git a/SpriteObjects.h b/SpriteObjects.h index b532b113..4cfa51ae 100644 --- a/SpriteObjects.h +++ b/SpriteObjects.h @@ -84,6 +84,8 @@ class c_sprite unsigned char light : 2; + float spritescale; + ALLEGRO_BITMAP * defaultsheet; uint8_t tilelayout; diff --git a/UserInput.cpp b/UserInput.cpp index 456ec817..45a83c6b 100644 --- a/UserInput.cpp +++ b/UserInput.cpp @@ -4,6 +4,7 @@ #include "ContentLoader.h" #include "GameBuildings.h" #include "Creatures.h" +#include extern int mouse_x, mouse_y, mouse_z; extern unsigned int mouse_b; ALLEGRO_MOUSE_STATE mouse; @@ -275,29 +276,11 @@ void doKeys(int Key) } if(Key == ALLEGRO_KEY_FULLSTOP){ config.zoom++; - if (config.zoom == -1) - config.zoom = 1; - if(config.zoom > 0) - { - config.scale = 1.0f * config.zoom; - } - if(config.zoom < 0) - { - config.scale = 1.0f / abs((float)config.zoom); - } + config.scale = pow(2.0f, config.zoom); } if(Key == ALLEGRO_KEY_COMMA){ config.zoom--; - if (config.zoom == 0) - config.zoom = -2; - if(config.zoom > 0) - { - config.scale = 1.0f * config.zoom; - } - if(config.zoom < 0) - { - config.scale = 1.0f / abs((float)config.zoom); - } + config.scale = pow(2.0f, config.zoom); } if(Key == ALLEGRO_KEY_F5){ if (al_key_down(&keyboard,ALLEGRO_KEY_LCTRL) || al_key_down(&keyboard,ALLEGRO_KEY_RCTRL)) diff --git a/WorldSegment.cpp b/WorldSegment.cpp index b6f616c4..a1a3197d 100644 --- a/WorldSegment.cpp +++ b/WorldSegment.cpp @@ -4,7 +4,6 @@ #include "ContentLoader.h" -ALLEGRO_BITMAP * level = 0; ALLEGRO_BITMAP * fog = 0; Block* WorldSegment::getBlock(int32_t x, int32_t y, int32_t z){ @@ -209,45 +208,26 @@ void WorldSegment::drawAllBlocks(){ if(!fog) { fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); - level = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); al_set_target_bitmap(fog); - al_clear_to_color(premultiply(al_map_rgba_f(config.fogr, config.fogg, config.fogb, 1))); - al_set_target_bitmap(level); - int op, src, dst, alpha_op, alpha_src, alpha_dst; - al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst); - al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO,ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); - al_clear_to_color(al_map_rgba(0,0,0,0)); - al_set_separate_blender(op, src, dst, alpha_op, alpha_src, alpha_dst); + al_clear_to_color(premultiply(al_map_rgba_f(config.fogr, config.fogg, config.fogb, config.foga))); al_set_target_bitmap(temp); } if(!((al_get_bitmap_width(fog) == al_get_bitmap_width(temp)) && (al_get_bitmap_height(fog) == al_get_bitmap_height(temp)))) { + al_destroy_bitmap(fog); fog = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); - level = al_create_bitmap(al_get_bitmap_width(temp), al_get_bitmap_height(temp)); al_set_target_bitmap(fog); - al_clear_to_color(premultiply(al_map_rgba_f(config.fogr, config.fogg, config.fogb, 1))); - al_set_target_bitmap(level); - int op, src, dst, alpha_op, alpha_src, alpha_dst; - al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst); - al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO,ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); - al_clear_to_color(al_map_rgba(0,0,0,0)); - al_set_separate_blender(op, src, dst, alpha_op, alpha_src, alpha_dst); + al_clear_to_color(al_map_rgba_f(config.fogr*config.foga, config.fogg*config.foga, config.fogb*config.foga, config.foga)); al_set_target_bitmap(temp); } - al_set_target_bitmap(level); + al_draw_bitmap(fog, 0, 0, 0); } - int op, src, dst, alpha_op, alpha_src, alpha_dst; - al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst); - al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO,ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); - al_clear_to_color(al_map_rgba(0,0,0,0)); - al_set_separate_blender(op, src, dst, alpha_op, alpha_src, alpha_dst); if(vsz == vszmax-1) { if (config.show_osd) DrawCurrentLevelOutline(true); } if(config.dayNightCycle) al_hold_bitmap_drawing(true); - al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); for(int32_t vsx=1; vsx < vsxmax; vsx++) { for(int32_t vsy=1; vsy < vsymax; vsy++) @@ -285,21 +265,6 @@ void WorldSegment::drawAllBlocks(){ } } al_hold_bitmap_drawing(false); - - if(config.fogenable && config.foga) - { - float actual_alpha = vszmax - vsz; //distance from the top - actual_alpha/=config.foga; - if(actual_alpha > 1.0) actual_alpha = 1.0; - al_set_target_bitmap(level); - int op, src, dst, alpha_op, alpha_src, alpha_dst; - al_get_separate_blender(&op, &src, &dst, &alpha_op, &alpha_src, &alpha_dst); - al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); - al_draw_tinted_bitmap(fog, al_map_rgba_f(actual_alpha,actual_alpha,actual_alpha,actual_alpha), 0,0,0); - al_set_separate_blender(op, src, dst, alpha_op, alpha_src, alpha_dst); - al_set_target_bitmap(temp); - al_draw_bitmap(level, 0,0,0); - } } if(config.showRenderStatus) SetTitle("Stonesense"); diff --git a/main.cpp b/main.cpp index c26a7f9a..f9e95538 100644 --- a/main.cpp +++ b/main.cpp @@ -453,7 +453,7 @@ static void * stonesense_thread(ALLEGRO_THREAD * thred, void * parms) config.fog_of_war = 1; config.occlusion = 1; contentLoader = new ContentLoader(); - config.zoom = 1; + config.zoom = 0; config.scale = 1.0f; initRandomCube(); loadConfigFile(); diff --git a/resources/Sprite Guide.txt b/resources/Sprite Guide.txt index 11b10db9..ff400102 100644 --- a/resources/Sprite Guide.txt +++ b/resources/Sprite Guide.txt @@ -155,6 +155,11 @@ Useful for adding blood pools. This over-rides 'variations' so they cannot be us Additional sprites can be layered on top using the subsprite tag, like so: +Attriibute: zoom +Valid Values: any number +Default Value: "0" +Description: Sets the scale of the sprite, in the form of 2^x. this means 0 is normal sized, -1 is half sized, 1 is double, 2 is quadruple, etc. + blah blah