Skip to content

Commit

Permalink
Zoom and enhance!
Browse files Browse the repository at this point in the history
Signed-off-by: Japa Illo <[email protected]>
  • Loading branch information
RosaryMala committed Feb 13, 2012
1 parent 78f13e7 commit aa921e7
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 73 deletions.
24 changes: 22 additions & 2 deletions Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

2 changes: 1 addition & 1 deletion Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
70 changes: 60 additions & 10 deletions SpriteObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions SpriteObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class c_sprite

unsigned char light : 2;

float spritescale;

ALLEGRO_BITMAP * defaultsheet;

uint8_t tilelayout;
Expand Down
23 changes: 3 additions & 20 deletions UserInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ContentLoader.h"
#include "GameBuildings.h"
#include "Creatures.h"
#include <math.h>
extern int mouse_x, mouse_y, mouse_z;
extern unsigned int mouse_b;
ALLEGRO_MOUSE_STATE mouse;
Expand Down Expand Up @@ -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))
Expand Down
43 changes: 4 additions & 39 deletions WorldSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions resources/Sprite Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<floors>
<floor sheetindex="1">
blah blah
Expand Down

0 comments on commit aa921e7

Please sign in to comment.