#include
#include
#include
#include
#include
#include
#include "Tunnel.h" // SDL Stuff SDL_Surface *screen; SDL_Surface *bBuffer; SDL_Surface *Image; SDL_Rect rScreen; SDL_Rect rBuffer; static __int64 timerstart; static __int64 timerfrq; static void Tunnel_Timer() { QueryPerformanceCounter((LARGE_INTEGER *)&timerstart); QueryPerformanceFrequency((LARGE_INTEGER *)&timerfrq); } static double Tunnel_GetTime() { __int64 a; QueryPerformanceCounter((LARGE_INTEGER *)&a); return (double)(a - timerstart)/(double)(timerfrq); } // --------------------------------------------------------------------------------- int main (int argc, char **argv) { int flag = SDL_SWSURFACE; //初始化时间 Tunnel_Timer(); //初始化SDL SDL_Init( SDL_INIT_VIDEO ); //设置表面显示模式 screen = SDL_SetVideoMode( 400, 300, 32, flag); //创建一个交换用的空表面 bBuffer = SDL_CreateRGBSurface( SDL_HWSURFACE, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); //装载一个位图到操作页面 Image = SDL_LoadBMP("tunnel_map.bmp");//alpha1.bmp tunnel_map.bmp if (!bBuffer || !Image) { printf("Error: I can't load or create bmp !!!/n/n"); return -1; } //转换操作页面的格式screen->format Image = SDL_ConvertSurface(Image, screen->format, SDL_HWSURFACE); //设置矩形大小 rBuffer.x = 0; rBuffer.y = 0; rBuffer.w = bBuffer->w;//320 rBuffer.h = bBuffer->h;//240 SDL_EventState(SDL_ACTIVEEVENT, SDL_IGNORE); SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); SDL_ShowCursor( SDL_DISABLE ); Tunnel.Set( 400, 300 ); // Dimension du tunnel Tunnel.Precalc( 32 ); // Diametre du tunnel while (SDL_PollEvent(NULL)==0) { float fTime = Tunnel_GetTime(); SDL_LockSurface(bBuffer); SDL_LockSurface(Image); Tunnel.Draw(bBuffer, Image, 180*sin(fTime), fTime*100); SDL_UnlockSurface(bBuffer); SDL_UnlockSurface(Image); SDL_BlitSurface( bBuffer, NULL, screen, &rBuffer ); SDL_UpdateRect( screen, 0, 0, 0, 0 ); } Tunnel.Free(); return 0; } // #include
#include
#include
#include
#include
#include
#ifdef WIN32 #include
#endif #include
#define PI 3.1415926535f // une petite class tunnel class CTunnel { public: int w; // hauteur int h; // Largeur int speed; // vitesse, mais ca sert pas int *TAngle; // lookup des angles int *TDepth; // lookup des profondeur void Set(int, int); void Precalc(int); void Draw(SDL_Surface *buffer,SDL_Surface *map, int, int); void Free(void); }Tunnel; // sert a allouer la memoire pour les lookups .... void CTunnel::Set(int width, int height) { w = width; h = height; TAngle = new int[w * h]; TDepth = new int[w * h]; } // Precalcul des tables void CTunnel::Precalc(int diametre) // diameter = 8, 16, 32, 64 ..... { int cx = w/2; int cy = h/2; for (int x=0; x
pixels; map_dat = (Uint32*)map->pixels; // on boucle sur l'ecran for (int x=0; x
w]; } } } void CTunnel::Free(void) { // on libere les lookups.... delete [] TAngle; delete [] TDepth; }
SDL之学习1
最新推荐文章于 2020-05-19 18:27:47 发布