forked from kxtells/pykurin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cAnimSpriteFactory.py
56 lines (46 loc) · 1.65 KB
/
cAnimSpriteFactory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import functions as BF
from cAnimSprite import cAnimSprite
import random
class cAnimSpriteFactory():
explosions = []
boings = []
ouchs = []
livesup = []
all_sprites = [explosions,boings,ouchs,livesup]
sprite_fps = [20,10,10,10]
# Sprite id definitions
EXPLOSION = 0
BOING = 1
OUCH = 2
LIVES = 3
def __init__(self):
"""
Load all the possible sprites at the beginning :-)
"""
for x in range(6):
explosion_imgset = BF.load_and_slice_sprite(32,32,'explosion'+str(x)+'.png');
self.explosions.append(explosion_imgset)
for x in range(4):
boing_imgset = BF.load_and_slice_sprite(100,50,'boing'+str(x)+'.png');
self.boings.append(boing_imgset)
for x in range(3):
imgset = BF.load_and_slice_sprite(100,50,'ouch'+str(x)+'.png');
self.ouchs.append(imgset)
for x in range(1):
imgset = BF.load_and_slice_sprite(100,50,'livesup'+str(x)+'.png');
self.livesup.append(imgset)
def create_sprite(self,x=-5000,y=-5000,spritetype=0):
"""
Get a random imageset for a spritetype
create a Animation Sprite and return it
"""
rand = random.randint(0,len(self.all_sprites[spritetype])-1)
tsprite = cAnimSprite(self.all_sprites[spritetype][rand],self.sprite_fps[spritetype])
tsprite.move(x,y) #out of view
tsprite.draw = True
return tsprite
def get_sprite_by_id(self,x=-5000,y=-5000,id=0):
"""
Function to call from outside
"""
return self.create_sprite(x,y,id)