1 """animation loading and manipulating functions.
3 Please note that this file is alpha, and is subject to modification in
4 future versions of pgu!
7 print ('pgu.ani - This module is alpha, and is subject to change.')
12 def _ani_load(tv,name,parts,frames,shape):
18 _ani_load(tv,name + ".%d"%i,parts[:],frames[s*i:s*(i+1)],shape)
22 tv.images[name+".%d"%i] = frames[i],shape
24 def ani_load(tv,name,img,size,shape,parts):
25 """Load an animation from an image
28 tv -- vid to load into
29 name -- prefix name to give the images
30 image -- image to load anis from
31 size -- w,h size of image
32 shape -- shape of image (usually a subset of 0,0,w,h) used for collision detection
33 parts -- list of parts to divide the animation into
34 for example parts = [4,5] would yield 4 animations 5 frames long, 20 total
35 for example parts = [a,b,c] would yield ... images['name.a.b.c'] ..., a*b*c total
42 for y in xrange(0,img.get_height(),h):
43 for x in xrange(0,img.get_width(),w):
44 frames.append(img.subsurface(x,y,w,h))
45 _ani_load(tv,name,parts,frames,shape)
48 def image_rotate(tv,name,img,shape,angles,diff=0):
49 """Rotate an image and put it into tv.images
52 tv -- vid to load into
53 name -- prefix name to give the images
54 image -- image to load anis from
55 shape -- shape fimage (usually a subset of 0,0,w,h) used for collision detection
56 angles -- a list of angles to render in degrees
57 diff -- a number to add to the angles, to correct for source image not actually being at 0 degrees
60 w1,h1 = img.get_width(),img.get_height()
61 shape = pygame.Rect(shape)
62 ps = shape.topleft,shape.topright,shape.bottomleft,shape.bottomright
64 img2 = pygame.transform.rotate(img,a+diff)
65 w2,h2 = img2.get_width(),img2.get_height()
66 minx,miny,maxx,maxy = 1024,1024,0,0
69 a2 = math.radians(a+diff)
70 #NOTE: the + and - are switched from the normal formula because of
71 #the weird way that pygame does the angle...
72 x2 = x*math.cos(a2) + y*math.sin(a2)
73 y2 = y*math.cos(a2) - x*math.sin(a2)
74 x2,y2 = x2+w2/2,y2+h2/2
79 r = pygame.Rect(minx,miny,maxx-minx,maxy-miny)
80 #((ww-w)/2,(hh-h)/2,w,h)
81 tv.images["%s.%d"%(name,a)] = img2,r