void VL_SetPalette(const byte *palette) { SDL_Color colors[256]; int i; VL_WaitVBL(1); for (i = 0; i < 256; i++) { colors[i].r = ((int)palette[i*3+0] * 255) / 63; colors[i].g = ((int)palette[i*3+1] * 255) / 63; colors[i].b = ((int)palette[i*3+2] * 255) / 63; } SDL_SetPalette(surface, sdl_palettemode, colors, 0, 256); }
void SDLVideo::UpdateScreen (DCanvas *canvas) { if(palettechanged) { // m_Private may or may not be the primary surface (sdlScreen) SDL_SetPalette((SDL_Surface*)canvas->m_Private, SDL_LOGPAL|SDL_PHYSPAL, newPalette, 0, 256); palettechanged = false; } // If not writing directly to the screen blit to the primary surface if(canvas->m_Private != sdlScreen) SDL_BlitSurface((SDL_Surface*)canvas->m_Private, NULL, sdlScreen, NULL); SDL_Flip(sdlScreen); }
/** ** Color Cycle for particular surface */ static void ColorCycleSurface(SDL_Surface &surface) { SDL_Color *palcolors = surface.format->palette->colors; SDL_Color colors[256]; CColorCycling &colorCycling = CColorCycling::GetInstance(); memcpy(colors, palcolors, sizeof(colors)); for (std::vector<ColorIndexRange>::const_iterator it = colorCycling.ColorIndexRanges.begin(); it != colorCycling.ColorIndexRanges.end(); ++it) { const ColorIndexRange &range = *it; memcpy(colors + range.begin, palcolors + range.begin + 1, (range.end - range.begin) * sizeof(SDL_Color)); colors[range.end] = palcolors[range.begin]; } SDL_SetPalette(&surface, SDL_LOGPAL | SDL_PHYSPAL, colors, 0, 256); }
void SaveLevel() { int x, y, i; SDL_Surface *map_surf; char cs[2] = "."; char rnum[5] = "0000"; unsigned char ch; unsigned char *map_p; SDL_Color cpalette[4]; Uint8 cl; map_surf = SDL_CreateRGBSurface(0, 4096, 4096, 8, 0, 0, 0, 0); map_p = map.m; cpalette[0].r = cpalette[0].g = cpalette[0].b = 0; cpalette[1].r = cpalette[1].g = cpalette[1].b = 255; cpalette[2].r = 255; cpalette[2].g = 0; cpalette[2].b = 255; cpalette[3].r = 0; cpalette[3].g = 255; cpalette[3].b = 128; SDL_SetPalette(map_surf, SDL_LOGPAL | SDL_PHYSPAL, cpalette, 0, 4); for (y = 0; y < map.h; y++) { for (x = 0; x < map.w; x++) { ch = *(map_p++); if (IsSolid(ch)) *cs = 4; else *cs = 5; if (ch == 17) *cs = 0; cl = 1; if (map.rooms[GetRoom(x, y)].room_type == 2) cl = 2; if (map.rooms[GetRoom(x, y)].room_type == 3) cl = 3; draw_map_text (x * 8, y * 8, cs, cl, map_surf); } } for (i = 0; i < NUM_ROOMS; i++) { sprintf(rnum, "%d", i); draw_map_text (map.rooms[i].x * 8, map.rooms[i].y * 8, rnum, 0, map_surf); } SDL_SaveBMP(map_surf, "map.bmp"); }
static VOID PAL_LoadBattleBackground( VOID ) /*++ Purpose: Load the screen background picture of the battle. Parameters: None. Return value: None. --*/ { PAL_LARGE BYTE buf[320 * 200]; // // Create the surface // g_Battle.lpBackground = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8, gpScreen->format->Rmask, gpScreen->format->Gmask, gpScreen->format->Bmask, gpScreen->format->Amask); if (g_Battle.lpBackground == NULL) { TerminateOnError("PAL_LoadBattleBackground(): failed to create surface!"); } #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetSurfacePalette(g_Battle.lpBackground, gpScreen->format->palette); #else SDL_SetPalette(g_Battle.lpBackground, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256); #endif // // Load the picture // PAL_MKFDecompressChunk(buf, 320 * 200, gpGlobals->wNumBattleField, gpGlobals->f.fpFBP); // // Draw the picture to the surface. // PAL_FBPBlitToSurface(buf, g_Battle.lpBackground); }
static SDL_Surface * create_surface_from_data(void *data, int width, int height, int transparent) { int r; /* Create sprite surface */ SDL_Surface *surf8 = SDL_CreateRGBSurfaceFrom(data, (int)width, (int)height, 8, (int)(width*sizeof(uint8_t)), 0, 0, 0, 0); if (surf8 == NULL) { LOGE("sdl-video", "Unable to create sprite surface: %s.", SDL_GetError()); exit(EXIT_FAILURE); } /* Set sprite palette */ r = SDL_SetPalette(surf8, SDL_LOGPAL | SDL_PHYSPAL, pal_colors, 0, 256); if (r == 0) { LOGE("sdl-video", "Unable to set palette for sprite."); exit(EXIT_FAILURE); } /* Covert to screen format */ SDL_Surface *surf = NULL; if (transparent) { /* Set color key */ r = SDL_SetColorKey(surf8, SDL_SRCCOLORKEY | SDL_RLEACCEL, 0); if (r < 0) { LOGE("sdl-video", "Unable to set color key for sprite."); exit(EXIT_FAILURE); } surf = SDL_DisplayFormatAlpha(surf8); } else { surf = SDL_DisplayFormat(surf8); } if (surf == NULL) { LOGE("sdl-video", "Unable to convert sprite surface: %s.", SDL_GetError()); exit(EXIT_FAILURE); } SDL_FreeSurface(surf8); return surf; }
void InitCollisions(int n) { SDL_Color colors[256]; for (int p=0;p<256;p++) { colors[p].r=p; colors[p].g=p; colors[p].b=p; } if (n>MAX_LAYERS) n=MAX_LAYERS; for (int z=0;z<n;z++) { collision_layer[z]=SDL_CreateRGBSurface(SDL_SWSURFACE,640,480,8,0,0,0,0); SDL_SetPalette(collision_layer[z],SDL_LOGPAL | SDL_PHYSPAL,colors,0,256); } ResetCollisions(0); }
void blit_image(CameraImage *img, int x, int y) { int bpp = img->bits_per_pixel; SDL_Surface *image = NULL; if (bpp == 8) { image = SDL_CreateRGBSurfaceFrom((void*)img->ptr, WIDTH, HEIGHT, 8, WIDTH, 0, 0, 0, 0); SDL_SetPalette(image, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); } else { image = SDL_CreateRGBSurfaceFrom((void*)img->ptr, WIDTH, HEIGHT, bpp, WIDTH*bpp/8, 0x0000ff, 0x00ff00, 0xff0000, 0); } SDL_Rect offset; offset.x = x; offset.y = y; SDL_BlitSurface(image, NULL, screen, &offset); SDL_Flip(screen); SDL_FreeSurface(image); }
Uint32 update_screen(Uint32 intvl, void *param) { (void)intvl; (void)param; SDL_Rect rcDest = {0, 0, 9, 16}; SDL_Rect rcSrc = {0, 0, 9, 16}; uint8_t *buf = (uint8_t *)adr_p2h(0xb8000); for (int y = 0; y < 25; y++) { rcDest.y = y * 16; for (int x = 0; x < 80; x++) { rcSrc.x = (buf[0] % 32) * 9; rcSrc.y = ((int)(buf[0] / 32)) * 16; rcDest.x = x * 9; SDL_FillRect(screen, &rcDest, SDL_MapRGB(screen->format, colors[buf[1] >> 4][0], colors[buf[1] >> 4][1], colors[buf[1] >> 4][2])); SDL_SetPalette(font, SDL_LOGPAL, &(SDL_Color){ colors[buf[1] & 0xF][0], colors[buf[1] & 0xF][1], colors[buf[1] & 0xF][2] }, 1, 1); SDL_BlitSurface(font, &rcSrc, screen, &rcDest); buf += 2; } } SDL_UpdateRect(screen, 0, 0, 0, 0); SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: exit(EXIT_SUCCESS); } } return 10; }
void colorcyclinghandler() { int s,e,d; SDL_Color colors[256]; int i,c; s=colorcycling_s; e=colorcycling_e; d=colorcycling_d; if(d==0){ c=Palette[s]; for(i=s;i<=e;i++){ //color(i,Palette[i+1]); colors[i].b = Palette[i+1] & 255; colors[i].g =( Palette[i+1] / 256) & 255 ; colors[i].r =( Palette[i+1] / (256*256)) & 255; Palette[i]= Palette[i+1]; } //color(e,c); colors[e].b = c & 255; colors[e].g =( c / 256) & 255 ; colors[e].r =( c / (256*256)) & 255; Palette[e]=c; } else{ c=Palette[e]; for(i=e;i>=s;i--){ //color(i,Palette[i-1]); colors[i].b = Palette[i-1] & 255; colors[i].g =( Palette[i-1] / 256) & 255 ; colors[i].r =( Palette[i-1] / (256*256)) & 255; Palette[i]= Palette[i-1]; } //color(s,c); colors[s].b = c & 255; colors[s].g =( c / 256) & 255 ; colors[s].r =( c / (256*256)) & 255; Palette[s]=c; } /* Set palette */ SDL_SetPalette(SDLdisplay, SDL_LOGPAL|SDL_PHYSPAL, &colors[s], s, e-s); colorcycling_next=colorcycling_delay+chrono(); }
static mrb_value mrb_sdl_video_set_palette (mrb_state *mrb, mrb_value self) { mrb_value arg_surface = mrb_nil_value(); mrb_int flags; mrb_value arg_colors = mrb_nil_value(); mrb_int first_color; mrb_int n_colors; mrb_get_args(mrb, "|o", &arg_surface); mrb_get_args(mrb, "|i", &flags); mrb_get_args(mrb, "|o", &arg_colors); mrb_get_args(mrb, "|i", &first_color); mrb_get_args(mrb, "|i", &n_colors); SDL_Surface* surface = mrb_value_to_sdl_surface(mrb, arg_surface); SDL_Color* colors = mrb_value_to_sdl_color(mrb, arg_colors); return mrb_fixnum_value(SDL_SetPalette(surface, flags, colors, first_color, n_colors)); }
/** * Change the palette with the palette supplied. * @param palette The palette to replace the current with. * @param from From which colour. * @param length The length of the palette (in colours). */ void Video_SetPalette(void *palette, int from, int length) { SDL_Color paletteRGB[256]; uint8 *p = palette; int i; s_video_lock = true; for (i = from; i < from + length; i++) { paletteRGB[i].r = ((*p++) & 0x3F) * 4; paletteRGB[i].g = ((*p++) & 0x3F) * 4; paletteRGB[i].b = ((*p++) & 0x3F) * 4; } SDL_SetPalette(s_gfx_surface, SDL_LOGPAL | SDL_PHYSPAL, paletteRGB, from, length); s_video_lock = false; }
/* -------------------------------------------------------------------------- * * Rendert eine Surface mit dem Hintergrund-Muster * * -------------------------------------------------------------------------- */ SDL_Surface *client_render(void) { SDL_Surface *pattern; sgColor *palette; pattern = SDL_CreateRGBSurface(SDL_SWSURFACE, client_rect.w, client_rect.h, 8, 0, 0, 0, 0); palette = sgCreatePalette(client_bgcolor); SDL_SetPalette(pattern, SDL_LOGPAL, (SDL_Color *)palette, 0, 256); sgFillPattern(pattern, client_bgnd, client_config.contrast); free(palette); return pattern; }
/** * Change the palette with the palette supplied. * @param palette The palette to replace the current with. * @param from From which colour. * @param length The length of the palette (in colours). */ void Video_SetPalette(void *palette, int from, int length) { SDL_Color paletteRGB[256]; uint8 *p = palette; int i; s_video_lock = true; /* convert from 6bit to 8bit per component */ for (i = from; i < from + length; i++) { paletteRGB[i].r = (((*p++) & 0x3F) * 0x41) >> 4; paletteRGB[i].g = (((*p++) & 0x3F) * 0x41) >> 4; paletteRGB[i].b = (((*p++) & 0x3F) * 0x41) >> 4; } SDL_SetPalette(s_gfx_surface, SDL_LOGPAL | SDL_PHYSPAL, paletteRGB, from, length); s_video_lock = false; }
void SWimp_SetPalette( const unsigned char *palette ) { SDL_Color colors[256]; int i; if (!X11_active) return; if ( !palette ) palette = ( const unsigned char * ) sw_state.currentpalette; for (i = 0; i < 256; i++) { colors[i].r = palette[i*4+0]; colors[i].g = palette[i*4+1]; colors[i].b = palette[i*4+2]; } SDL_SetPalette(surface, sdl_palettemode, colors, 0, 256); }
Surface Surface::subsection(const Rect& rect) const { SDL_Surface* new_surface; new_surface = Blitter::create_surface_from_format(impl->surface, rect.get_width(), rect.get_height()); SDL_Rect dst_rect; dst_rect.x = static_cast<Sint16>(rect.left); dst_rect.y = static_cast<Sint16>(rect.top); if (impl->surface->format->palette) SDL_SetPalette(new_surface, SDL_LOGPAL, impl->surface->format->palette->colors, 0, impl->surface->format->palette->ncolors); if (impl->surface->flags & SDL_SRCCOLORKEY) SDL_SetColorKey(new_surface, SDL_SRCCOLORKEY, impl->surface->format->colorkey); SDL_BlitSurface(impl->surface, NULL, new_surface, &dst_rect); return Surface(std::shared_ptr<SurfaceImpl>(new SurfaceImpl(new_surface))); }
// set 8-bit palette void vid_palette_set(PCOLOUR *palette, u8 num) { SDL_Color sdl_palette[num]; int i; SDL_Surface *surface; surface = SDL_GetVideoSurface(); assert(surface); for (i=0; i<num; i++) { sdl_palette[i].r = palette[i].r; sdl_palette[i].g = palette[i].g; sdl_palette[i].b = palette[i].b; sdl_palette[i].unused = 0; } SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, sdl_palette, 0, num); }
static int sdl_convert_icon( SDL_Surface *source, SDL_Surface **icon, int red ) { SDL_Surface *copy; /* Copy with altered palette */ int i; SDL_Color colors[ source->format->palette->ncolors ]; copy = SDL_ConvertSurface( source, source->format, SDL_SWSURFACE ); for( i = 0; i < copy->format->palette->ncolors; i++ ) { colors[i].r = red ? copy->format->palette->colors[i].r : 0; colors[i].g = red ? 0 : copy->format->palette->colors[i].g; colors[i].b = 0; } SDL_SetPalette( copy, SDL_LOGPAL, colors, 0, i ); icon[0] = SDL_ConvertSurface( copy, tmp_screen->format, SDL_SWSURFACE ); SDL_FreeSurface( copy ); icon[1] = SDL_CreateRGBSurface( SDL_SWSURFACE, (icon[0]->w)<<1, (icon[0]->h)<<1, icon[0]->format->BitsPerPixel, icon[0]->format->Rmask, icon[0]->format->Gmask, icon[0]->format->Bmask, icon[0]->format->Amask ); ( scaler_get_proc16( SCALER_DOUBLESIZE ) )( (libspectrum_byte*)icon[0]->pixels, icon[0]->pitch, (libspectrum_byte*)icon[1]->pixels, icon[1]->pitch, icon[0]->w, icon[0]->h ); return 0; }
/** * Wrapper around various software and OpenGL screen buffer pushing functions which zoom. * Basically called just from Screen::flip() * * @param src The surface to zoom (input). * @param dst The zoomed surface (output). * @param topBlackBand Size of top black band in pixels (letterboxing). * @param bottomBlackBand Size of bottom black band in pixels (letterboxing). * @param leftBlackBand Size of left black band in pixels (letterboxing). * @param rightBlackBand Size of right black band in pixels (letterboxing). * @param glOut OpenGL output. */ void Zoom::flipWithZoom(SDL_Surface *src, SDL_Surface *dst, int topBlackBand, int bottomBlackBand, int leftBlackBand, int rightBlackBand, OpenGL *glOut) { assert (0 && "not implemented"); #if 0 if (Screen::isOpenGLEnabled()) { #ifndef __NO_OPENGL if (glOut->buffer_surface) { SDL_BlitSurface(src, 0, glOut->buffer_surface->getSurface(), 0); // TODO; this is less than ideal... glOut->refresh(glOut->linear, glOut->iwidth, glOut->iheight, dst->w, dst->h, topBlackBand, bottomBlackBand, leftBlackBand, rightBlackBand); SDL_GL_SwapBuffers(); } #endif } else if (topBlackBand <= 0 && bottomBlackBand <= 0 && leftBlackBand <= 0 && rightBlackBand <= 0) { _zoomSurfaceY(src, dst, 0, 0); } else if (dst->w - leftBlackBand - rightBlackBand == src->w && dst->h - topBlackBand - bottomBlackBand == src->h) { SDL_Rect dstrect = {(Sint16)leftBlackBand, (Sint16)topBlackBand, (Uint16)src->w, (Uint16)src->h}; SDL_BlitSurface(src, NULL, dst, &dstrect); } else { SDL_Surface *tmp = SDL_CreateRGBSurface(dst->flags, dst->w - leftBlackBand - rightBlackBand, dst->h - topBlackBand - bottomBlackBand, dst->format->BitsPerPixel, 0, 0, 0, 0); _zoomSurfaceY(src, tmp, 0, 0); if (src->format->palette != NULL) { SDL_SetPalette(tmp, SDL_LOGPAL|SDL_PHYSPAL, src->format->palette->colors, 0, src->format->palette->ncolors); } SDL_Rect dstrect = {(Sint16)leftBlackBand, (Sint16)topBlackBand, (Uint16)tmp->w, (Uint16)tmp->h}; SDL_BlitSurface(tmp, NULL, dst, &dstrect); SDL_FreeSurface(tmp); } #endif }
//color (c,optional v) : set palette color c with value v se missing return the current color c int color(int c,int v) { SDL_Color c_color; if (v !=-1 ){ if (c<0)return -1; if (c>255)return -1; Palette[c]=v; if (enablePalette!=0){ c_color.b = v & 255; c_color.g =( v / 256) & 255 ; c_color.r =( v / (256*256)) & 255; /* Set palette */ SDL_SetPalette(SDLdisplay, SDL_LOGPAL|SDL_PHYSPAL, &c_color, c, 1); } return 0; } else{ return Palette[c]; } }
// // ISDL12Window::finishRefresh // void ISDL12Window::finishRefresh() { assert(mLocks == 0); // window surface shouldn't be locked when blitting SDL_Surface* sdlsurface = SDL_GetVideoSurface(); if (mNeedPaletteRefresh) { Uint32 flags = SDL_LOGPAL | SDL_PHYSPAL; if (sdlsurface->format->BitsPerPixel == 8) SDL_SetPalette(sdlsurface, flags, sdlsurface->format->palette->colors, 0, 256); // if (mSDLSoftwareSurface && mSDLSoftwareSurface->format->BitsPerPixel == 8) // SDL_SetPalette(mSDLSoftwareSurface, flags, mSDLSoftwareSurface->format->palette->colors, 0, 256); } mNeedPaletteRefresh = false; if (mBlit) { mSurfaceManager->finishRefresh(); } }
static void blit_to_screen (void) { int j; SDL_LockSurface (screen); /* FIXME: add scaling support */ SDL_SetPalette (screen, SDL_LOGPAL|SDL_PHYSPAL, (SDL_Color*)pn_image_data->cmap, 0, 256); SDL_SetAlpha (screen, 0, 255); for (j=0; j<pn_image_data->height; j++) memcpy (screen->pixels + j*screen->pitch, pn_image_data->surface[0] + j*pn_image_data->width, pn_image_data->width); SDL_UnlockSurface (screen); SDL_UpdateRect (screen, 0, 0, 0, 0); }
int main(int argc, char* argv[]) { SDL_Surface* screen = SDL_SetVideoMode(640, 480, 8, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_HWPALETTE); SDL_Surface* refpal = SDL_LoadBMP("pic.bmp"); SDL_Surface* bnwpal = SDL_LoadBMP("bnw.bmp"); /* Normal blit */ SDL_SetPalette(screen, SDL_LOGPAL, refpal->format->palette->colors, 0, 256); SDL_SetPalette(screen, SDL_PHYSPAL, refpal->format->palette->colors, 0, 256); SDL_BlitSurface(refpal, NULL, screen, NULL); SDL_Flip(screen); SDL_Delay(1000); /* Blit on B&W physical palette: everything is B&W */ SDL_SetPalette(screen, SDL_PHYSPAL, bnwpal->format->palette->colors, 0, 256); SDL_BlitSurface(refpal, NULL, screen, NULL); SDL_Flip(screen); SDL_Delay(1000); /* Dither (DisplayFormat) when screen physical palette is changed: screen logical palette (same as pic.bmp) is used, no change */ SDL_Surface* testorig = SDL_LoadBMP("pic.bmp"); SDL_SetPalette(screen, SDL_PHYSPAL, bnwpal->format->palette->colors, 0, 256); SDL_Surface* testblit = SDL_DisplayFormat(testorig); SDL_SetPalette(screen, SDL_PHYSPAL, refpal->format->palette->colors, 0, 256); SDL_BlitSurface(testblit, NULL, screen, NULL); SDL_Flip(screen); SDL_Delay(1000); SDL_FreeSurface(testblit); /* Dither (DisplayFormat) when screen logical palette is changed: screen logical palette (same as bnw.bmp) is used, the heart is B&W, rest of the screen unchanged */ SDL_SetPalette(screen, SDL_LOGPAL, bnwpal->format->palette->colors, 0, 256); testblit = SDL_DisplayFormat(testorig); SDL_SetPalette(screen, SDL_PHYSPAL, refpal->format->palette->colors, 0, 256); SDL_BlitSurface(testblit, NULL, screen, NULL); SDL_Flip(screen); SDL_Delay(1000); SDL_FreeSurface(testblit); }
void init() { int i; /* load the background image */ tile = IMG_Load("../GFX/tile.png"); if (!tile) { fprintf(stderr, "Cannot open file tile.png: %s\n", SDL_GetError()); quit(3); } if (tile->w != 256 || tile->h != 256) { fprintf(stderr, "Tile dimensions must be 256x256!\n"); quit(3); } SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, tile->format->palette->colors, 0, 256); for (i = 0; i < 256; i++) { float rad = (float)i * 1.41176 * 0.0174532; float c = sin(rad); roto[i] = (c + 0.8) * 4096.0; roto2[i] = (2.0 * c) * 4096.0; } /*disable events */ for (i = 0; i < SDL_NUMEVENTS; ++i) { if (i != SDL_KEYDOWN && i != SDL_QUIT) { SDL_EventState(i, SDL_IGNORE); } } SDL_LockSurface(tile); SDL_LockSurface(screen); SDL_ShowCursor(SDL_DISABLE); }
void init_video(int w,int h,int xoff,int yoff,int scale) { SDL_Color palette[2]; init_sdl(w,h,8); SDL_WM_SetCaption("AnimText",NULL); buffer_len=(h-8*scale)*screen->pitch; scroll_buffer=(char*)malloc(buffer_len); if(!scroll_buffer) { printf("Error ! Couldn't initialize scroll buffer !\n"); } font=load_font("font.fot"); palette[0].r=0; palette[0].g=0; palette[0].b=0; palette[1].r=200; palette[1].g=200; palette[1].b=200; SDL_SetPalette(screen, SDL_LOGPAL|SDL_PHYSPAL, palette, 0, 2); cursorX=0; cursorY=0; frame=0; font_scale=scale; xoffset=xoff; yoffset=yoff; }
int SDL_COMPAT_SetPalette(SDL_Surface *surface, int flags, SDL_Color *colors, int firstcolor, int ncolors) { return SDL_SetPalette(surface, flags, colors, firstcolor, ncolors); }
VOID PAL_EndingAnimation( VOID ) /*++ Purpose: Show the ending animation.//就是灵儿独自面对合体水魔兽的动画 Parameters: None. Return value: None. --*/ { LPBYTE buf; LPBYTE bufGirl; SDL_Surface *pUpper; SDL_Surface *pLower; SDL_Rect srcrect, dstrect; int yPosGirl = 180; int i; buf = (LPBYTE)UTIL_calloc(1, 64000); bufGirl = (LPBYTE)UTIL_calloc(1, 6000); pUpper = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8, gpScreen->format->Rmask, gpScreen->format->Gmask, gpScreen->format->Bmask, gpScreen->format->Amask); pLower = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8, gpScreen->format->Rmask, gpScreen->format->Gmask, gpScreen->format->Bmask, gpScreen->format->Amask); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetSurfacePalette(pUpper, gpScreen->format->palette); SDL_SetSurfacePalette(pLower, gpScreen->format->palette); #else SDL_SetPalette(pUpper, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256); SDL_SetPalette(pLower, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256); #endif #ifdef PAL_WIN95 PAL_MKFDecompressChunk(buf, 64000, 69, gpGlobals->f.fpFBP); PAL_FBPBlitToSurface(buf, pUpper); PAL_MKFDecompressChunk(buf, 64000, 70, gpGlobals->f.fpFBP); PAL_FBPBlitToSurface(buf, pLower); #else PAL_MKFDecompressChunk(buf, 64000, 61, gpGlobals->f.fpFBP); PAL_FBPBlitToSurface(buf, pUpper); PAL_MKFDecompressChunk(buf, 64000, 62, gpGlobals->f.fpFBP); PAL_FBPBlitToSurface(buf, pLower); #endif PAL_MKFDecompressChunk(buf, 64000, 571, gpGlobals->f.fpMGO); PAL_MKFDecompressChunk(bufGirl, 6000, 572, gpGlobals->f.fpMGO); srcrect.x = 0; dstrect.x = 0; srcrect.w = 320; dstrect.w = 320; gpGlobals->wScreenWave = 2; for (i = 0; i < 400; i++) { // // Draw the background // srcrect.y = 0; srcrect.h = 200 - i / 2; dstrect.y = i / 2; dstrect.h = 200 - i / 2; SDL_BlitSurface(pLower, &srcrect, gpScreen, &dstrect); srcrect.y = 200 - i / 2; srcrect.h = i / 2; dstrect.y = 0; dstrect.h = i / 2; SDL_BlitSurface(pUpper, &srcrect, gpScreen, &dstrect); PAL_ApplyWave(gpScreen); // // Draw the beast // PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 0), gpScreen, PAL_XY(0, -400 + i)); PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i)); #ifdef PAL_WIN95 PAL_RLEBlitToSurface(buf + 0x8444, gpScreen, PAL_XY(0, -200 + i)); #else PAL_RLEBlitToSurface(PAL_SpriteGetFrame(buf, 1), gpScreen, PAL_XY(0, -200 + i)); #endif // // Draw the girl // yPosGirl -= i & 1; if (yPosGirl < 80) { yPosGirl = 80; } PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufGirl, (SDL_GetTicks() / 50) % 4), gpScreen, PAL_XY(220, yPosGirl)); // // Update the screen // VIDEO_UpdateScreen(NULL); if (gpGlobals->fNeedToFadeIn) { PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1); gpGlobals->fNeedToFadeIn = FALSE; #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetSurfacePalette(pUpper, gpScreen->format->palette); SDL_SetSurfacePalette(pLower, gpScreen->format->palette); #else SDL_SetPalette(pUpper, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256); SDL_SetPalette(pLower, SDL_LOGPAL | SDL_PHYSPAL, VIDEO_GetPalette(), 0, 256); #endif } UTIL_Delay(50); } gpGlobals->wScreenWave = 0; SDL_FreeSurface(pUpper); SDL_FreeSurface(pLower); free(buf); free(bufGirl); }
void init() { Uint16 i; short x, y; float rad; heightmap = IMG_Load("../GFX/tuxblackbg.png"); if (!heightmap) { fprintf(stderr, "Cannot open file tuxblackbg.png: %s\n", SDL_GetError()); quit(3); } TDEC_create_heightmap(heightmap); SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, heightmap->format->palette->colors, 0, heightmap->format->palette->ncolors); /*create sin lookup table */ for (i = 0; i < 512; i++) { rad = (float)i * 0.0174532 * 0.703125; aSin[i] = (short)((sin(rad) * 100.0) + 256.0); } /* create reflection map */ for (x = 0; x < 256; ++x) { for (y = 0; y < 256; ++y) { float X = (x - 128) / 128.0; float Y = (y - 128) / 128.0; float Z = 1.0 - sqrt(X * X + Y * Y); Z *= 255.0; if (Z < 0.0) Z = 0.0; reflectionmap[x][y] = Z; } } /* create bump map */ for (x = 1; x < SCREEN_WIDTH - 1; ++x) { for (y = 1; y < SCREEN_HEIGHT - 1; ++y) { bumpmap[x][y].x = *((Uint8*)heightmap->pixels + y * heightmap->pitch + x + 1) - *((Uint8*)heightmap->pixels + y * heightmap->pitch + x); bumpmap[x][y].y = *((Uint8*)heightmap->pixels + y * heightmap->pitch + x) - *((Uint8*)heightmap->pixels + ((y - 1) * heightmap->pitch) + x); } } /*disable events */ for (i = 0; i < SDL_NUMEVENTS; ++i) { if (i != SDL_KEYDOWN && i != SDL_QUIT) { SDL_EventState(i, SDL_IGNORE); } } SDL_ShowCursor(SDL_DISABLE); }
/*++ Start a battle. Parameters: [IN] wEnemyTeam - the number of the enemy team. [IN] fIsBoss - TRUE for boss fight (not allowed to flee). Return value: The result of the battle. --*/ BATTLERESULT PAL_StartBattle(WORD wEnemyTeam, BOOL fIsBoss) { int i; WORD w, wPrevWaveLevel; SHORT sPrevWaveProgression; // // Set the screen waving effects // wPrevWaveLevel = gpGlobals->wScreenWave; sPrevWaveProgression = gpGlobals->sWaveProgression; gpGlobals->sWaveProgression = 0; gpGlobals->wScreenWave = gpGlobals->g.lprgBattleField[gpGlobals->wNumBattleField].wScreenWave; // // Make sure everyone in the party is alive, also clear all hidden // EXP count records // for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++) { w = gpGlobals->rgParty[i].wPlayerRole; if (gpGlobals->g.PlayerRoles.rgwHP[w] == 0) { gpGlobals->g.PlayerRoles.rgwHP[w] = 1; gpGlobals->rgPlayerStatus[w][kStatusPuppet] = 0; } gpGlobals->Exp.rgHealthExp[w].wCount = 0; gpGlobals->Exp.rgMagicExp[w].wCount = 0; gpGlobals->Exp.rgAttackExp[w].wCount = 0; gpGlobals->Exp.rgMagicPowerExp[w].wCount = 0; gpGlobals->Exp.rgDefenseExp[w].wCount = 0; gpGlobals->Exp.rgDexterityExp[w].wCount = 0; gpGlobals->Exp.rgFleeExp[w].wCount = 0; } // // Clear all item-using records // for (i = 0; i < MAX_INVENTORY; i++) { gpGlobals->rgInventory[i].nAmountInUse = 0; } // // Store all enemies // for (i = 0; i < MAX_ENEMIES_IN_TEAM; i++) { memset(&(g_Battle.rgEnemy[i]), 0, sizeof(BATTLEENEMY)); w = gpGlobals->g.lprgEnemyTeam[wEnemyTeam].rgwEnemy[i]; if (w == 0xFFFF) { break; } if (w != 0) { g_Battle.rgEnemy[i].e = gpGlobals->g.lprgEnemy[gpGlobals->g.rgObject[w].enemy.wEnemyID]; g_Battle.rgEnemy[i].wObjectID = w; g_Battle.rgEnemy[i].state = kFighterWait; g_Battle.rgEnemy[i].wScriptOnTurnStart = gpGlobals->g.rgObject[w].enemy.wScriptOnTurnStart; g_Battle.rgEnemy[i].wScriptOnBattleEnd = gpGlobals->g.rgObject[w].enemy.wScriptOnBattleEnd; g_Battle.rgEnemy[i].wScriptOnReady = gpGlobals->g.rgObject[w].enemy.wScriptOnReady; g_Battle.rgEnemy[i].iColorShift = 0; g_Battle.rgEnemy[i].dwMaxHealth = g_Battle.rgEnemy[i].e.wHealth; #ifndef PAL_CLASSIC g_Battle.rgEnemy[i].flTimeMeter = 50; // // HACK: Otherwise the black thief lady will be too hard to beat // if (g_Battle.rgEnemy[i].e.wDexterity == 164) { g_Battle.rgEnemy[i].e.wDexterity /= ((gpGlobals->wMaxPartyMemberIndex == 0) ? 6 : 3); } // // HACK: Heal up automatically for final boss // if (g_Battle.rgEnemy[i].e.wHealth == 32760) { for (w = 0; w < MAX_PLAYER_ROLES; w++) { gpGlobals->g.PlayerRoles.rgwHP[w] = gpGlobals->g.PlayerRoles.rgwMaxHP[w]; gpGlobals->g.PlayerRoles.rgwMP[w] = gpGlobals->g.PlayerRoles.rgwMaxMP[w]; } } // // Yet another HACKs // if ((SHORT)g_Battle.rgEnemy[i].e.wDexterity == -32) { g_Battle.rgEnemy[i].e.wDexterity = 0; // for Grandma Knife } else if (g_Battle.rgEnemy[i].e.wDexterity == 20) { // // for Fox Demon // if (gpGlobals->g.PlayerRoles.rgwLevel[0] < 15) { g_Battle.rgEnemy[i].e.wDexterity = 8; } else if (gpGlobals->g.PlayerRoles.rgwLevel[4] > 28 || gpGlobals->Exp.rgPrimaryExp[4].wExp > 0) { g_Battle.rgEnemy[i].e.wDexterity = 60; } } else if (g_Battle.rgEnemy[i].e.wExp == 250 && g_Battle.rgEnemy[i].e.wCash == 1100) { g_Battle.rgEnemy[i].e.wDexterity += 12; // for Snake Demon } else if ((SHORT)g_Battle.rgEnemy[i].e.wDexterity == -60) { g_Battle.rgEnemy[i].e.wDexterity = 15; // for Spider } else if ((SHORT)g_Battle.rgEnemy[i].e.wDexterity == -30) { g_Battle.rgEnemy[i].e.wDexterity = (WORD)-10; // for Stone Head } else if ((SHORT)g_Battle.rgEnemy[i].e.wDexterity == -16) { g_Battle.rgEnemy[i].e.wDexterity = 0; // for Zombie } else if ((SHORT)g_Battle.rgEnemy[i].e.wDexterity == -20) { g_Battle.rgEnemy[i].e.wDexterity = -8; // for Flower Demon } else if (g_Battle.rgEnemy[i].e.wLevel < 20 && gpGlobals->wNumScene >= 0xD8 && gpGlobals->wNumScene <= 0xE2) { // // for low-level monsters in the Cave of Trial // g_Battle.rgEnemy[i].e.wLevel += 15; g_Battle.rgEnemy[i].e.wDexterity += 25; } else if (gpGlobals->wNumScene == 0x90) { g_Battle.rgEnemy[i].e.wDexterity += 25; // for Tower Dragons } else if (g_Battle.rgEnemy[i].e.wLevel == 2 && g_Battle.rgEnemy[i].e.wCash == 48) { g_Battle.rgEnemy[i].e.wDexterity += 8; // for Miao Fists } else if (g_Battle.rgEnemy[i].e.wLevel == 4 && g_Battle.rgEnemy[i].e.wCash == 240) { g_Battle.rgEnemy[i].e.wDexterity += 18; // for Fat Miao } else if (g_Battle.rgEnemy[i].e.wLevel == 16 && g_Battle.rgEnemy[i].e.wMagicRate == 4 && g_Battle.rgEnemy[i].e.wAttackEquivItemRate == 4) { g_Battle.rgEnemy[i].e.wDexterity += 50; // for Black Spider } #endif } } g_Battle.wMaxEnemyIndex = i - 1; // // Store all players // for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++) { g_Battle.rgPlayer[i].flTimeMeter = 15.0f; #ifndef PAL_CLASSIC g_Battle.rgPlayer[i].flTimeSpeedModifier = 2.0f; g_Battle.rgPlayer[i].sTurnOrder = -1; #endif g_Battle.rgPlayer[i].wHidingTime = 0; g_Battle.rgPlayer[i].state = kFighterWait; g_Battle.rgPlayer[i].action.sTarget = -1; g_Battle.rgPlayer[i].fDefending = FALSE; g_Battle.rgPlayer[i].wCurrentFrame = 0; g_Battle.rgPlayer[i].iColorShift = FALSE; } // // Load sprites and background // PAL_LoadBattleSprites(); PAL_LoadBattleBackground(); // // Create the surface for scene buffer // g_Battle.lpSceneBuf = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8, gpScreen->format->Rmask, gpScreen->format->Gmask, gpScreen->format->Bmask, gpScreen->format->Amask); if (g_Battle.lpSceneBuf == NULL) { TerminateOnError("PAL_StartBattle(): creating surface for scene buffer failed!"); } #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetSurfacePalette(g_Battle.lpSceneBuf, gpScreen->format->palette); #else SDL_SetPalette(g_Battle.lpSceneBuf, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256); #endif PAL_UpdateEquipments(); g_Battle.iExpGained = 0; g_Battle.iCashGained = 0; g_Battle.fIsBoss = fIsBoss; g_Battle.fEnemyCleared = FALSE; g_Battle.fEnemyMoving = FALSE; g_Battle.iHidingTime = 0; g_Battle.wMovingPlayerIndex = 0; g_Battle.UI.szMsg[0] = '\0'; g_Battle.UI.szNextMsg[0] = '\0'; g_Battle.UI.dwMsgShowTime = 0; g_Battle.UI.state = kBattleUIWait; g_Battle.UI.fAutoAttack = FALSE; g_Battle.UI.wSelectedIndex = 0; g_Battle.UI.wPrevEnemyTarget = 0; memset(g_Battle.UI.rgShowNum, 0, sizeof(g_Battle.UI.rgShowNum)); g_Battle.lpSummonSprite = NULL; g_Battle.sBackgroundColorShift = 0; gpGlobals->fInBattle = TRUE; g_Battle.BattleResult = kBattleResultPreBattle; PAL_BattleUpdateFighters(); // // Load the battle effect sprite. // i = PAL_MKFGetChunkSize(10, gpGlobals->f.fpDATA); g_Battle.lpEffectSprite = UTIL_malloc(i); PAL_MKFReadChunk(g_Battle.lpEffectSprite, i, 10, gpGlobals->f.fpDATA); #ifdef PAL_CLASSIC g_Battle.Phase = kBattlePhaseSelectAction; g_Battle.fRepeat = FALSE; g_Battle.fForce = FALSE; g_Battle.fFlee = FALSE; #endif #ifdef PAL_ALLOW_KEYREPEAT SDL_EnableKeyRepeat(120, 75); #endif // // Run the main battle routine. // i = PAL_BattleMain(); #ifdef PAL_ALLOW_KEYREPEAT SDL_EnableKeyRepeat(0, 0); PAL_ClearKeyState(); g_InputState.prevdir = kDirUnknown; #endif if (i == kBattleResultWon) { // // Player won the battle. Add the Experience points. // PAL_BattleWon(); } // // Clear all item-using records // for (w = 0; w < MAX_INVENTORY; w++) { gpGlobals->rgInventory[w].nAmountInUse = 0; } // // Clear all player status, poisons and temporary effects // PAL_ClearAllPlayerStatus(); for (w = 0; w < MAX_PLAYER_ROLES; w++) { PAL_CurePoisonByLevel(w, 3); PAL_RemoveEquipmentEffect(w, kBodyPartExtra); } // // Free all the battle sprites // PAL_FreeBattleSprites(); free(g_Battle.lpEffectSprite); // // Free the surfaces for the background picture and scene buffer // SDL_FreeSurface(g_Battle.lpBackground); SDL_FreeSurface(g_Battle.lpSceneBuf); g_Battle.lpBackground = NULL; g_Battle.lpSceneBuf = NULL; gpGlobals->fInBattle = FALSE; PAL_PlayMUS(gpGlobals->wNumMusic, TRUE, 1); // // Restore the screen waving effects // gpGlobals->sWaveProgression = sPrevWaveProgression; gpGlobals->wScreenWave = wPrevWaveLevel; return i; }
VOID PAL_ShowFBP( WORD wChunkNum, WORD wFade ) /*++ Purpose: Draw an FBP picture to the screen. Parameters: [IN] wChunkNum - number of chunk in fbp.mkf file. [IN] wFade - fading speed of showing the picture. Return value: None. --*/ { PAL_LARGE BYTE buf[320 * 200]; PAL_LARGE BYTE bufSprite[320 * 200]; const int rgIndex[6] = {0, 3, 1, 5, 2, 4}; SDL_Surface *p; int i, j, k; BYTE a, b; if (PAL_MKFDecompressChunk(buf, 320 * 200, wChunkNum, gpGlobals->f.fpFBP) <= 0) { memset(buf, 0, sizeof(buf)); } if (g_wCurEffectSprite != 0) { PAL_MKFDecompressChunk(bufSprite, 320 * 200, g_wCurEffectSprite, gpGlobals->f.fpMGO); } if (wFade) { wFade++; wFade *= 10; p = SDL_CreateRGBSurface(gpScreen->flags & ~SDL_HWSURFACE, 320, 200, 8, gpScreen->format->Rmask, gpScreen->format->Gmask, gpScreen->format->Bmask, gpScreen->format->Amask); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_SetSurfacePalette(p, gpScreen->format->palette); #else SDL_SetPalette(p, SDL_PHYSPAL | SDL_LOGPAL, VIDEO_GetPalette(), 0, 256); #endif PAL_FBPBlitToSurface(buf, p); VIDEO_BackupScreen(); for (i = 0; i < 16; i++) { for (j = 0; j < 6; j++) { // // Blend the pixels in the 2 buffers, and put the result into the // backup buffer // for (k = rgIndex[j]; k < gpScreen->pitch * gpScreen->h; k += 6) { a = ((LPBYTE)(p->pixels))[k]; b = ((LPBYTE)(gpScreenBak->pixels))[k]; if (i > 0) { if ((a & 0x0F) > (b & 0x0F)) { b++; } else if ((a & 0x0F) < (b & 0x0F)) { b--; } } ((LPBYTE)(gpScreenBak->pixels))[k] = ((a & 0xF0) | (b & 0x0F)); } SDL_BlitSurface(gpScreenBak, NULL, gpScreen, NULL); if (g_wCurEffectSprite != 0) { int f = SDL_GetTicks() / 150; PAL_RLEBlitToSurface(PAL_SpriteGetFrame(bufSprite, f % PAL_SpriteGetNumFrames(bufSprite)), gpScreen, PAL_XY(0, 0)); } VIDEO_UpdateScreen(NULL); UTIL_Delay(wFade); } } SDL_FreeSurface(p); } // // HACKHACK: to make the ending show correctly // #ifdef PAL_WIN95 if (wChunkNum != 68) #else if (wChunkNum != 49) #endif { PAL_FBPBlitToSurface(buf, gpScreen); } VIDEO_UpdateScreen(NULL); }