void AnimFrame::Draw(BITMAP* bmp, Vector pos, float scale, bool vertical_flip, float rotation, int alpha) { BITMAP* graphic = (BITMAP*)global_datafile[graphic_id].dat; if (graphic == NULL) { erlog("Graphic ID out of bounds in frame draw", 3); return; } if (bmp == NULL) { erlog("Buffer out of bounds in frame draw", 3); return; } if (scale == 0.0 && vertical_flip == false && rotation == 0.0 && (alpha >= 256 || alpha < 0)) { draw_sprite(bmp, graphic, pos.XInt(), pos.YInt()); return; } if (alpha >= 256 || alpha < 0) { if (vertical_flip == false) { rotate_scaled_sprite(bmp, graphic, pos.XInt(), pos.YInt(), fixmul(ftofix(rotation), radtofix_r), ftofix(scale)); return; } rotate_scaled_sprite_v_flip(bmp, graphic, pos.XInt(), pos.YInt(), fixmul(ftofix(rotation), radtofix_r), ftofix(scale)); return; } float fdiagonal = sqrt(static_cast<float>(graphic->w*graphic->w + graphic->h*graphic->h)); int diagonal = static_cast<int>(fdiagonal + 1); BITMAP* temp_bmp = create_bitmap(diagonal, diagonal); if (vertical_flip == false) { rotate_scaled_sprite(temp_bmp, graphic, 0, 0, fixmul(ftofix(rotation), radtofix_r), ftofix(scale)); } else { rotate_scaled_sprite_v_flip(temp_bmp, graphic, 0, 0, fixmul(ftofix(rotation), radtofix_r), ftofix(scale)); } set_trans_blender(0, 0, 0, alpha); drawing_mode(DRAW_MODE_TRANS, 0, 0, 0); draw_trans_sprite(temp_bmp, bmp, pos.XInt(), pos.YInt()); drawing_mode(DRAW_MODE_SOLID, 0, 0, 0); }
void CPROC SpriteDrawProc( uintptr_t psv, PRENDERER renderer, int32_t x, int32_t y, uint32_t w, uint32_t h ) { int had_one = 0; int n; for( n = 0; n < USE_SPRITES; n++ ) { if( sprite[n].ttl ) { rotate_scaled_sprite( GetDisplayImage( renderer ), sprite[n].sprite, rot, 0x10000, 0x10000 ); had_one = 1; } } if( !had_one ) l.renderer = NULL; }
void draw_a_donkey(BITMAP *bmp, BITMAP *sprite, int x, int y, int color, int flip, fixed angle, fixed scale) { BITMAP *temp = create_bitmap(sprite->w, sprite->h); clear(temp); ((flip)? draw_sprite_h_flip: draw_sprite)(temp, sprite, 0, 0); color_map = tint_map; draw_lit_sprite(temp, temp, 0, 0, color); color_map = NULL; if ((angle == itofix(1)) && (scale == itofix(1))) draw_sprite(bmp, temp, x, y); else rotate_scaled_sprite(bmp, temp, x, y, angle, scale); destroy_bitmap(temp); }
void draw_shells(void) { int i,type; float scale =1; for(i=0;i<MAX_SHELL_NUM;i++) if(shell_data[i].used) { type = shell_data[i].type; if(object_is_in_player_los(shell_data[i].x,shell_data[i].y,get_bitmap_w(particle_info[type].pic[0].dat),get_bitmap_h(particle_info[type].pic[0].dat),0,0)) { rotate_scaled_sprite(virt,particle_info[type].pic[0].dat, shell_data[i].x - get_bitmap_w(particle_info[type].pic[0].dat)/2-map_x, shell_data[i].y - get_bitmap_h(particle_info[type].pic[0].dat)/2-map_y, degree_to_fixed(shell_data[i].angle), degree_to_fixed(shell_data[i].z)); } } }
int CGame::SetupGame(char *argv[]) { int bpp = 32; //bits per pixel (truecolor) //buffers for filename manipulation char fullpath[255]; char filename[10]; int ret; //catches return values for processing int i; //universal loop counter //initialise allegro stuff allegro_init(); install_keyboard(); install_mouse(); install_timer(); set_color_depth(bpp); /* Lets play the color depth game! tries 32, 24, then 16 bit color modes */ // set resolution to play intro movie ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); /* did the video mode set properly? */ if (ret != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error); bpp = 24; set_color_depth(bpp); // set resolution ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); /* did the video mode set properly? */ if (ret != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error setting %d bit graphics mode\n%s\nLets try another color depth!", bpp, allegro_error); bpp = 16; set_color_depth(bpp); // set resolution ret = set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0); /* did the video mode set properly? */ if (ret != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error setting %d bit graphics mode\n%s\nIm all out of options. Exiting", bpp, allegro_error); return 1; } } } // Load data from data.dat into memory textout_centre(screen,font,"NOW LOADING",SCREEN_W/2,SCREEN_H/2,makecol(255,255,255)); sprintf(filename,"data.dat"); replace_filename(fullpath, argv[0], filename, sizeof(fullpath)); data = load_datafile(fullpath); if (!data) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Cant load file %s for some reason.\nIt should be in the same directory as the .exe\n" "If you have deleted the debug directory to mark this then\ncopy all files from the \"required files\"" "directory into the directory with the .exe\n\nThanks. Scarbble will now crash horribly", filename); return 1; } //make smaller copy of all tiles for (i=0;i<27;i++) { smalltiles[i] = create_bitmap(29,29); rotate_scaled_sprite(smalltiles[i], (WINDOWS_BITMAP *)data[i].dat, 0,0, 0, ftofix(0.8)); } PlayIntro(); AddPlayers(); //stuff that cant be done in the players constructor InitialisePlayers(); //set video mode to play game ret = set_gfx_mode(GFX_AUTODETECT, 800, 600, 0, 0); /* did the video mode set properly? */ if (ret != 0) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error setting %d bit graphics mode\n%s\n", bpp, allegro_error); return 1; } //initialise the 'background' screen buffer background = create_bitmap(SCREEN_W, SCREEN_H); clear(background); //clear to black boardcolor = makecol(206,206,90); show_mouse(screen); return 0; }
int main(void) { BITMAP *dbuf; BITMAP *b; BITMAP *b2; int mode = NORMAL; float fangle = 0; float fscale = 1; float inc = 0.002; int dir = -1; if (allegro_init() != 0) { return 1; } set_color_depth(32); install_keyboard(); if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0) { allegro_message("Could not set graphics mode\n"); return 1; } dbuf = create_bitmap(SCREEN_W, SCREEN_H); if (!dbuf) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Could not create double buffer\n"); return 1; } /* Load the alpha bitmap. This is used for alpha and normal modes */ set_color_conversion(COLORCONV_KEEP_ALPHA); b = load_bitmap("inkblot.tga", NULL); if (!b) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Could not load inkblot.tga\n"); return 1; } /* Make a non-alpha copy for drawing lit */ b2 = create_bitmap(b->w, b->h); if (!b2) { set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); allegro_message("Error creating bitmap\n"); return 1; } clear_to_color(b2, makeacol(255, 255, 255, 255)); set_alpha_blender(); draw_trans_sprite(b2, b, 0, 0); while (!key[KEY_ESC]) { fixed angle = ftofix(fangle); fixed scale = ftofix(fscale); float x = (SCREEN_W-(b->w*fscale))/2; float y = (SCREEN_H-(b->h*fscale))/2; /* XXX flickers badly due to no buffering */ clear_to_color(dbuf, makecol(255, 255, 255)); textout_centre_ex(dbuf, font, "Press 'n' for next mode", SCREEN_W/2, SCREEN_H-30, makecol(0, 0, 0), -1); switch (mode) { case NORMAL: rotate_scaled_sprite(dbuf, b, x, y, angle, scale); textout_centre_ex(dbuf, font, "Normal", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1); break; case ALPHA: set_alpha_blender(); rotate_scaled_sprite_trans(dbuf, b, x, y, angle, scale); textout_centre_ex(dbuf, font, "Alpha", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1); break; case LIT: set_trans_blender(255, 0, 0, 0); rotate_scaled_sprite_lit(dbuf, b2, x, y, angle, scale, 128); textout_centre_ex(dbuf, font, "Lit", SCREEN_W/2, SCREEN_H-20, makecol(0, 0, 0), -1); break; } blit(dbuf, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); fangle += 1; fscale += dir*inc; if (fscale < 0.5) { dir = -dir; fscale = 0.5; } else if (fscale > 1) { dir = -dir; fscale = 1; } rest(5); if (keypressed()) { int k = readkey(); switch (k >> 8) { case KEY_N: mode++; mode %= 3; break; } } } destroy_bitmap(b); destroy_bitmap(b2); destroy_bitmap(dbuf); return 0; }