Objects added to game rendering
[butaba-adventures.git] / object.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, image = None):
11 self.row = row
12 self.col = col
13 self.image = image
14
15 # override this for interaction
16 def interact (self):
17 pass
18
19 # use the object on another object
20 def use (self, otherobject):
21 pass
22
23
24 class Key (GameObject):
25 def __init__ (self, row, col, image, key_id):
26 self.key_id = key_id
27 GameObject.__init__ (self, row, col, image)
28
29 # ask whether to pick up the key
30 def interact (self, surface):
31 ans = utility.ask_question (surface, "You found a key.", ["Pick it up", "Leave it"])
32 return ans
33
34 # using the key
35 def use (self, lockitem):
36 if type (lockitem) == Chest or type (lockitem) == Door:
37 if self.key_id == lockitem.key_id:
38 if lockitem.unlocked is False:
39 lockitem.unlocked = True
40 else:
41 lockitem.unlocked = True