c33d380bca7a101b9352d85c67dbc48f0fdc4c30
1 """animation loading and manipulating functions.
3 <p>please note that this file is alpha, and is subject to modification in
4 future versions of pgu!</p>
7 print 'pgu.ani','This module is alpha, and is subject to change.'
12 def _ani_load(tv
,name
,parts
,frames
,shape
):
19 _ani_load(tv
,name
+ ".%d"%i,parts
[:],frames
[s
*i
:s
*(i
+1)],shape
)
23 tv
.images
[name
+".%d"%i] = frames
[i
],shape
25 def ani_load(tv
,name
,img
,size
,shape
,parts
):
26 """load an animation from an image
28 <pre>ani_load(tv,name,image,size,shape,parts)</pre>
31 <dt>tv<dd>vid to load into
32 <dt>name <dd>prefix name to give the images
33 <dt>image <dd>image to load anis from
34 <dt>size <dd>w,h size of image
35 <dt>shape <dd>shape of image (usually a subset of 0,0,w,h) used for collision detection
36 <dt>parts <dd>list of parts to divide the animation into
37 <br>for example parts = [4,5] would yield 4 animations 5 frames long, 20 total
38 <br>for example parts = [a,b,c] would yield ... images['name.a.b.c'] ..., a*b*c total
46 for y
in xrange(0,img
.get_height(),h
):
47 for x
in xrange(0,img
.get_width(),w
):
48 frames
.append(img
.subsurface(x
,y
,w
,h
))
49 _ani_load(tv
,name
,parts
,frames
,shape
)
52 def image_rotate(tv
,name
,img
,shape
,angles
,diff
=0):
53 """rotate an image and put it into tv.images
55 <pre>image_rotate(tv,name,image,shape,angles,diff=0)</pre>
58 <dt>tv <dd>vid to load into
59 <dt>name <dd>prefix name to give the images
60 <dt>image <dd>image to load anis from
61 <dt>shape <dd>shape fimage (usually a subset of 0,0,w,h) used for collision detection
62 <dt>angles <dd>a list of angles to render in degrees
63 <dt>diff <dd>a number to add to the angles, to correct for source image not actually being at 0 degrees
66 w1
,h1
= img
.get_width(),img
.get_height()
67 shape
= pygame
.Rect(shape
)
68 ps
= shape
.topleft
,shape
.topright
,shape
.bottomleft
,shape
.bottomright
70 img2
= pygame
.transform
.rotate(img
,a
+diff
)
71 w2
,h2
= img2
.get_width(),img2
.get_height()
72 minx
,miny
,maxx
,maxy
= 1024,1024,0,0
75 a2
= math
.radians(a
+diff
)
76 #NOTE: the + and - are switched from the normal formula because of
77 #the weird way that pygame does the angle...
78 x2
= x
*math
.cos(a2
) + y
*math
.sin(a2
)
79 y2
= y
*math
.cos(a2
) - x
*math
.sin(a2
)
80 x2
,y2
= x2
+w2
/2,y2
+h2
/2
85 r
= pygame
.Rect(minx
,miny
,maxx
-minx
,maxy
-miny
)
87 #((ww-w)/2,(hh-h)/2,w,h)
88 tv
.images
["%s.%d"%(name
,a
)] = img2
,r