/* * * (c) 2019 Sollia 3 */ PROGRAM texturemaps; global rgb; struct quad[2] x,y,s; struct point[3]; x,y; handle; end end quads = 1; struct texture[2] x,y, s, map, w,h; struct coord[3] x,y; end end w,h; tx[3]; ty[3]; tl[3]; qx[3]; qy[3]; ql[3]; vmx; vmy; oldmx; oldmy; local i,j; pressing; private texture_id[2]; begin set_mode(m1024x768); set_fps(60,0); write_int(0,10,700,0,&fps); rgb = load_fpg("rgb.fpg"); mouse.graph = 4; mouse.x = 700; define_region(1,0,0,512,512); draw(3,114,15,1,0,0,512,512); draw(5,1,15,1,255-52,255-52,255+52,255+52); for(i = 255; i>24; i-=22) draw(4,1,15,1,255-i,255-i,255+i,255+i); end draw(5,114,15,1,255-11,255-11,255+11,255+11); draw(4,114,15,1,255-33,255-33,255+33,255+33); frame; texture.map = new_map(512,512,0,0,114); screen_copy(1,0,texture.map,0,0,512,512); delete_draw(all_drawing); put(rgb,texture.map,0,0); w = graphic_info(rgb,texture.map,g_wide); h = graphic_info(rgb,texture.map,g_height); for(i = 0; iw-32) texture.x = 32; end texture.y+=4*(key(_down)-key(_up)); if(texture.y<32) texture.y = h-32; end if(texture.y>h-32) texture.y = 32; end //end pressing = key(_right) or key(_left) or key(_up) or key(_down); texture.coord[0].x = texture.x-texture.w/2; texture.coord[0].y = texture.y-texture.h/2; texture.coord[1].x = texture.x+texture.w/2; texture.coord[1].y = texture.y-texture.h/2; texture.coord[2].x = texture.x+texture.w/2; texture.coord[2].y = texture.y+texture.h/2; texture.coord[3].x = texture.x-texture.w/2; texture.coord[3].y = texture.y+texture.h/2; texture_id[0] = paintTexture(0); // texture_id[1] = paintTexture(1); // texture_id[2] = paintTexture(2); tex(0,texture_id); // tex(1,texture_id[1]); // tex(2,texture_id[2]); drawTextureArea(0); frame; unload_map(texture_id); unload_map(texture_id[1]); unload_map(texture_id[2]); delete_draw(all_drawing); vmx = mouse.x-oldmx; vmy = mouse.y-oldmy; oldmx = mouse.x; oldmy = mouse.y; end exit(0,0); end process tex(q,graph) begin x =quad[q].x; y =quad[q].y; xput(rgb,graph,quad[q].x,quad[q].y+200,0,200,0,0); frame; end process handle(idq,idp) private got; begin graph = 2 ; z = -10; flags = 4; loop size = 100; x =quad[idq].x+quad[idq].point[idp].x; y =quad[idq].y+quad[idq].point[idp].y; if(collision(type mouse)) got = mouse.left; end if(got) quad[idq].point[idp].x+=vmx; if(quad[idq].point[idp].x<-quad[idq].s) quad[idq].point[idp].x = -quad[idq].s; end if(quad[idq].point[idp].x>quad[idq].s) quad[idq].point[idp].x = quad[idq].s; end quad[idq].point[idp].y+=vmy; if(quad[idq].point[idp].y<-quad[idq].s) quad[idq].point[idp].y = -quad[idq].s; end if(quad[idq].point[idp].y>quad[idq].s) quad[idq].point[idp].y = quad[idq].s; end if (not mouse.left) got =0; end end frame; end end function paintTexture(t) private pix; px,py; rpx[2]; rpy[2]; image; begin image =new_map(64,64,31,31,10); for(i = 0; i<4; i+=1) tx[i] =texture[t].coord[i].x; ty[i] =texture[t].coord[i].y; qx[i] =quad[t].point[i].x; qy[i] =quad[t].point[i].y; end for(i = 0; i<4; i+=1) tl[i] = fget_dist(tx[i],ty[i],tx[(i+1)%4],ty[(i+1)%4]); ql[i] = fget_dist(qx[i],qy[i],qx[(i+1)%4],qy[(i+1)%4]); end for(i = 0; i