SDL之学习1

#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; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值