-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.py
109 lines (90 loc) · 3.23 KB
/
factory.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from config import *
from utils import *
import attack
import gameObjects
import particles
class Factory(object):
# generic factory class
def __init__(self, creator):
self.creator = creator
self.values = {}
def create(self, **kwargs):
self.values.update(kwargs)
created = self.creator(**self.values)
return created
class Factory2(object):
# generic factory class
def __init__(self, creator):
self.creator = creator
self.values = {}
def create(self):
created = self.creator()
# set the values
for key in self.values:
try:
setattr(created, key, self.values[key]) #equivalent to self.{key} = value
except:
pdb.set_trace()
return created
class GameObjectFactory(Factory):
# factory class for creating game objects
def __init__(self):
super().__init__(gameObjects.GameObject) #check syntax
def create(self, x, y):
kwargs = {}
kwargs["x"] = x
kwargs['y'] = y
kwargs['old_x'] = x
kwargs['old_y'] = y
created = super().create(**kwargs)
return created
class DamageObjFactory(Factory):
# factory class for creating damage objects
def __init__(self):
super().__init__(attack.DamageObj) #check syntax
class ParticleObjFactory(Factory):
# factory class for creating damage objects
def __init__(self):
super().__init__(particles.ParticleObj) #check syntax
def create(self, x, y, **kwargs):
kwargs["x"] = x
kwargs['y'] = y
kwargs['old_x'] = x
kwargs['old_y'] = y
created = super().create(**kwargs)
return created
class GhostParticleFactory(ParticleObjFactory):
def __init__(self):
super().__init__()
self.values['objectType'] = 'Ghost1' # for drawing purposes
self.values['update_rate'] = 0.25
self.values['duration'] = 7.0 * self.values['update_rate'] + 0.1
self.values['width'] = 1.0
self.values['height'] = 1.0
self.values['artWidth'] = 1.0
self.values['artHeight'] = 1.0
self.values['pixelWidth'] = 16 # size of the sprite image, depends on image size, shouldn't change
self.values['pixelHeight'] = 16 # size of the sprite image, depends on image size, shouldn't change
self.values['collideable'] = False
def create(self, x, y):
object = super().create(x, y)
# setup
object.setSpriteStatus(visible=True, has_sprite=True)
object.animation.update_rate = self.values['update_rate']
object.animation.passive = True # will update even when still
object.animation.register_indices(0, range(7))
# start the thread
object.start()
return object
class BloodParticleFactory(GhostParticleFactory):
def __init__(self):
super().__init__()
self.values['objectType'] = 'Blood1' # for drawing purposes
self.values['update_rate'] = 0.15
self.values['duration'] = 6.0 * self.values['update_rate'] + 0.1
self.values['width'] = 1.0
self.values['height'] = 1.0
self.values['artWidth'] = 1.0
self.values['artHeight'] = 1.0
self.values['pixelWidth'] = 16 # size of the sprite image, depends on image size, shouldn't change
self.values['pixelHeight'] = 16 # size of the sprite image, depends on image size, shouldn't change