Added the inventory system (basic)
[butaba-adventures.git] / gameobjects.py
diff --git a/gameobjects.py b/gameobjects.py
new file mode 100644 (file)
index 0000000..6cb93f0
--- /dev/null
@@ -0,0 +1,60 @@
+# object classes - classes for game interactive objects
+import pygame
+import os.path
+
+import utility
+
+# base class for all objects
+class GameObject:
+       # initialization routine
+       def __init__ (self, row, col, text, image = None, can_pickup = True):
+               self.row = row
+               self.col = col
+               self.image = image
+               self.text = text
+               self.can_pickup = can_pickup
+
+       # override this for interaction, i.e. when character walks into the item
+       def interact (self):
+               # always return True if the object is interacted with
+               # return False to make the object block the player from
+               # moving over it
+               return True
+
+       # use the object on another object
+       def use (self, otherobject):
+               pass
+
+
+class HealthPotion (GameObject):
+       # initialize
+       def __init__ (self, row, col, image):
+               text = "health potion"
+               GameObject.__init__ (self, row, col, text, image, True)
+
+       # no interaction with this object
+       def interact (self):
+               return True
+
+       # using the potion
+       def use (self, butaba):
+               pass
+
+class Key (GameObject):
+       def __init__ (self, row, col, text, image, key_id):
+               self.key_id = key_id
+               GameObject.__init__ (self, row, col, text, image, True)
+
+       # no interaction with this object
+       def interact (self):
+               # key is not a solid object so return True
+               return True
+
+       # using the key
+       def use (self, lockitem):
+               if type (lockitem) == Chest or type (lockitem) == Door:
+                       if self.key_id == lockitem.key_id:
+                               if lockitem.unlocked is False:
+                                       lockitem.unlocked = True
+                               else:
+                                       lockitem.unlocked = True