-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_objects.py
109 lines (90 loc) · 3.36 KB
/
item_objects.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 utils
import factory
import attack
import weapons
import AI
import inventory
import gameObjects
# defaultAI = AI.DmgAvoiderAttacker
defaultAI = AI.Basic
class ItemFactory(factory.GameObjectFactory):
def __init__(self):
super().__init__()
self.values['type'] = "item"
self.values['moveable'] = False
self.ai_class = defaultAI
self.item = inventory.Item
def item_maker(self, item_object, go):
# fcn to make the item
pass
def create(self, x, y):
object = super().create(x, y)
# set the item maker
object.item_maker = self.item_maker
# set AI type
object.AI = self.ai_class(object)
# object.AI = AI.Basic(object)
# setup
object.setSpriteStatus(visible=True, has_sprite=True)
return object
class PotionFactory(ItemFactory):
def __init__(self):
super().__init__()
self.values['objectType'] = 'Potion'
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
def item_maker(self, item_object, go):
# item depends on which game object picks it up
return inventory.Potion(50.0)
class KeyFactory(ItemFactory):
def __init__(self):
super().__init__()
self.values['objectType'] = 'GoldKey'
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
def item_maker(self, item_object, go):
# connect key to door
return inventory.GoldKey(item_object.door_id)
class Gate(gameObjects.GameObject):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.collide_cooldown = utils.Cooldown(5.0, self.print_fcn)
self.door_id = -1
def collide_callback(self, other):
# check if other has key
if hasattr(other, "inventory") and other.inventory.has_item("GoldKey") and other.inventory.items["GoldKey"].door_id == self.door_id:
other.inventory.use_item("GoldKey")
else:
# if not, print message
self.collide_cooldown.start()
def print_fcn(self, **kwargs):
print("Gate requires a key.")
return True
class GateFactory(ItemFactory):
def __init__(self):
super().__init__()
self.creator = Gate
self.values['type'] = "game_object"
self.values['objectType'] = 'Gate'
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['moveable'] = False # if the object can be moved
self.values['collideable'] = True # if the object can be collided with
self.values['mass'] = 500.0
potionFactory = PotionFactory()
goldKeyFactory = KeyFactory()
gateFactory = GateFactory()