6cb93f087dd54045393acc971a5e04e5e0067ee2
[butaba-adventures.git] / gameobjects.py
1 # object classes - classes for game interactive objects
2 import pygame
3 import os.path
4
5 import utility
6
7 # base class for all objects
8 class GameObject:
9 # initialization routine
10 def __init__ (self, row, col, text, image = None, can_pickup = True):
11 self.row = row
12 self.col = col
13 self.image = image
14 self.text = text
15 self.can_pickup = can_pickup
16
17 # override this for interaction, i.e. when character walks into the item
18 def interact (self):
19 # always return True if the object is interacted with
20 # return False to make the object block the player from
21 # moving over it
22 return True
23
24 # use the object on another object
25 def use (self, otherobject):
26 pass
27
28
29 class HealthPotion (GameObject):
30 # initialize
31 def __init__ (self, row, col, image):
32 text = "health potion"
33 GameObject.__init__ (self, row, col, text, image, True)
34
35 # no interaction with this object
36 def interact (self):
37 return True
38
39 # using the potion
40 def use (self, butaba):
41 pass
42
43 class Key (GameObject):
44 def __init__ (self, row, col, text, image, key_id):
45 self.key_id = key_id
46 GameObject.__init__ (self, row, col, text, image, True)
47
48 # no interaction with this object
49 def interact (self):
50 # key is not a solid object so return True
51 return True
52
53 # using the key
54 def use (self, lockitem):
55 if type (lockitem) == Chest or type (lockitem) == Door:
56 if self.key_id == lockitem.key_id:
57 if lockitem.unlocked is False:
58 lockitem.unlocked = True
59 else:
60 lockitem.unlocked = True