void fimg::setfademap(wchar_t *name) { if(!nt) { nt = new NextTex; g_pd3dD->CreateVertexBuffer(sizeof(VertexThree)*4, 0, VertexThreeFVF, D3DPOOL_MANAGED, &nt->lpVB_change, NULL); } nt->lpt_map = gettex(name); }
bool fimg::load(wchar_t *name) { lpt = gettex(name); if(lpt) { D3DXMatrixIdentity(&scale); D3DXMatrixIdentity(&trans); D3DXMatrixIdentity(&rot); setsize(lpt->width,lpt->height); } return bool(lpt); }
/*=========================================================== aimg的读取相关函数 ===========================================================*/ bool LoadaImgFromImgs(unsigned int img_number,wchar_t **imgsname,unsigned int *delay,wchar_t *name) { if(!imgsname) return false; frames *tempf = new frames; tempf->frame_number = img_number; frame *f = new frame[img_number]; for(unsigned int i=0;i<img_number;i++) { if(delay) f[i].delay = delay[i]; f[i].tex = gettex(imgsname[i]); } tempf->f = f; framelist *temp = new framelist; int namelen = wcslen(name); temp->name = new wchar_t[namelen]; wcscpy(temp->name,name); temp->fs = tempf; temp->next = 0; unsigned int i = BKDRHash(name); if(!framelist_headp[i]) { framelist_headp[i] = temp; framelist_nowp[i] = framelist_headp[i]; } else { framelist_nowp[i]->next = temp; framelist_nowp[i] = temp; } return true; }
void fimg::fade(wchar_t *name,float fadestep,float nowx2,float nowy2,unsigned int width2,unsigned int height2,float alpha2) { if(!nt) { nt = new NextTex; nt->lpt_map = 0; g_pd3dD->CreateVertexBuffer(sizeof(VertexThree)*4, 0, VertexThreeFVF, D3DPOOL_MANAGED, &nt->lpVB_change, NULL); } if(!(nt->lpt_next=gettex(name))) return; nt->fade_alpha = 0.0f; nt->fadestep = fadestep; nt->next_x = nowx2; nt->next_y = nowy2; nt->next_alpha = alpha2; if((width2)||(height2)) { nt->next_width = width2; nt->next_height = height2; } else { nt->next_width = nt->lpt_next->width; nt->next_height = nt->lpt_next->height; width2 = nt->next_width; height2 = nt->next_height; } // 储存新图的长宽 float w,h; float x0,y0; float x1[4],x2[4],y1[4],y2[4]; // 储存两张图各点坐标 if((!width2)||(!height2)) {width2=nt->next_width; height2=nt->next_height;} x1[0]=*nowx;y1[0]=*nowy; x1[1]=*nowx;y1[1]=*nowy+*height; x1[2]=*nowx+*width;y1[2]=*nowy; //x1[3]=nowx+height;y1[3]=nowy+width; x2[0]=nowx2;y2[0]=nowy2; x2[1]=nowx2;y2[1]=nowy2+height2; x2[2]=nowx2+width2;y2[2]=nowy2; //x2[3]=nowx2+height2;y2[3]=nowy2+width2; x0= (x1[0]<x2[0]?x1[0]:x2[0]); y0= (y1[0]<y2[0]?y1[0]:y2[0]); w = (x1[2]>x2[2]?x1[2]:x2[2])-x0; h = (y1[1]>y2[1]?y1[1]:y2[1])-y0; x1[0] = (x0 -*nowx)/ *width; y1[0] = (y0 -*nowy)/ *height; x1[1] = (x0 -*nowx)/ *width; y1[1] = (y0+h-*nowy)/ *height; x1[2] = (x0+w-*nowx)/ *width; y1[2] = (y0 -*nowy)/ *height; x1[3] = (x0+w-*nowx)/ *width; y1[3] = (y0+h-*nowy)/ *height; x2[0] = (x0 -nowx2)/ width2; y2[0] = (y0 -nowy2)/ height2; x2[1] = (x0 -nowx2)/ width2; y2[1] = (y0+h-nowy2)/ height2; x2[2] = (x0+w-nowx2)/ width2; y2[2] = (y0 -nowy2)/ height2; x2[3] = (x0+w-nowx2)/ width2; y2[3] = (y0+h-nowy2)/ height2; //修改顶点缓存,重写转换纹理坐标,过渡图采用原图的大小 VertexThree* pVtemp; nt->lpVB_change->Lock( 0, 0, (void**)&pVtemp, 0 ); pVtemp[0] = VertexThree(0.0f, 0.0f , x1[0], y1[0],x2[0], y2[0],x1[0], y1[0]); pVtemp[1] = VertexThree(0.0f, 1.0f , x1[1], y1[1],x2[1], y2[1],x1[1], y1[1]); pVtemp[2] = VertexThree(1.0f, 0.0f , x1[2], y1[2],x2[2], y2[2],x1[2], y1[2]); pVtemp[3] = VertexThree(1.0f, 1.0f , x1[3], y1[3],x2[3], y2[3],x1[3], y1[3]); nt->lpVB_change->Unlock(); setsize(w,h); setpos(x0,y0); }
int run() { int result = EXIT_FAILURE; loadatlas(&texmap, "../atlas/target.atlas", "../atlas/target.png"); Texture *tex = gettex(&texmap, "ball.png"); Texture *streettex = gettex(&texmap, "street.png"); if(!tex || !streettex) goto out_texmap; Object mouse = { tformidentity, { 12, 12 } }; Object street = { tformidentity, { 400, 250 } }; Tform offset = tformidentity; offset.pos.x = -100; real scale = 1.0; Tform zoom = tformidentity; Tform camera = tformidentity; Vec2 worldabs = vec2zero; Tform angle = tformidentity; Vec2 pos = vec2zero; Tform player = tformidentity; while(running) { beginframe(); if(input.keyboard.pressed[SDLK_ESCAPE]) running = false; if(PRESSING_KEY(SDLK_f)) setfullscreen(Diagonal); if(input.keyboard.pressed[SDLK_LSHIFT] && PRESSING_KEY(SDLK_f)) setwindowed(Diagonal); if(input.keyboard.pressed[SDLK_d] || input.keyboard.pressed[SDLK_RIGHT]) pos.x++; if(input.keyboard.pressed[SDLK_a] || input.keyboard.pressed[SDLK_LEFT]) pos.x--; if(input.keyboard.pressed[SDLK_w] || input.keyboard.pressed[SDLK_UP]) pos.y++; if(input.keyboard.pressed[SDLK_s] || input.keyboard.pressed[SDLK_DOWN]) pos.y--; player = tformidentity; player.pos = pos; tformsetangle(&angle, LIMIT(input.mouse.screenabs.y * 0.02f, -M_PI_2, M_PI_2)); player = TFORMMUL(player, angle); tformsetscale(&zoom, (Vec2) { scale, scale }); camera = TFORMMUL( offset, TFORMMUL(zoom, TFORMT(tforminv(player))) ); worldabs = TFORMVEC2(TFORMT(tforminv(camera)), input.mouse.screenabs); beginscene(); batch_bind_texture(streettex->handle); batch.texcoords = streettex->coords; batch.tform = TFORMMUL(camera, street.t); batch_draw_rect(&street.s, 0); batch_bind_texture(tex->handle); batch.texcoords = tex->coords; mouse.t.pos = input.mouse.screenabs; batch.tform = mouse.t; batch_draw_rect(&mouse.s, 0); endscene(); endframe(); } result = EXIT_SUCCESS; out_texmap: freetexmap(&texmap); return result; }