X-Git-Url: https://harishankar.org/repos/?p=butaba-adventures.git;a=blobdiff_plain;f=gameobjects.py;fp=gameobjects.py;h=6cb93f087dd54045393acc971a5e04e5e0067ee2;hp=0000000000000000000000000000000000000000;hb=4b6e952b476861c8979dc395781964099285a4c6;hpb=7dbb8e9b6766b7c0c17433bea3c88a321036b837 diff --git a/gameobjects.py b/gameobjects.py new file mode 100644 index 0000000..6cb93f0 --- /dev/null +++ b/gameobjects.py @@ -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