Spelunking-Studios / The-Caverns-Original

An exploration ARPG game made in python with pygame
2 stars 1 forks source link

Worked on the aspects of the player. #2

Closed https123456789 closed 3 years ago

https123456789 commented 3 years ago

Changes:

LGgameLAB commented 3 years ago

I am going to pull and edit the inventory a little but I merged it

LGgameLAB commented 3 years ago

There are a few problems with your code. For now I am just going to have a list store all the items in the inventory and cap off at a certain value. I am just going to store the objects directly because unlike javascript where it is efficient to just store {type:weapon, obj:sword} you can't do that in python without creating strings (The only reason you didn't get an error for putting type instead of 'type' is because type is a method). I am going to have to think about this for while because it is fundamental class for the player. I will still use your code just gonna tweak.

https123456789 commented 3 years ago

Okay. The master index provides the name of the entity that the inventory object belongs to. I figured it might be useful if you added things like chests and such.

LGgameLAB commented 3 years ago

Okay. The master index provides the name of the entity that the inventory object belongs to. I figured it might be useful if you added things like chests and such.

ooh multi use. I like it. I guess for a chest you could have a list of items it stores and then create an inventory based on that for easy interaction but you might have to make a small inventory subclass that has a different init

https123456789 commented 3 years ago

We could also add like a resize method to allow for an inventory to grow-shrink (although it would probably only be called on the creation of the object). Then there would only need to be one Inventory class.

LGgameLAB commented 3 years ago

We could also add like a resize method to allow for an inventory to grow-shrink (although it would probably only be called on the creation of the object). Then there would only need to be one Inventory class.

I just revised the code and this is an example of how my edited version would work. I used dict instead of a list because it felt more manageable and specific (a list can get a bit jumbly). Yea we could totally add a resize method that would be great, it would just edit the maximum slot value and change the slot dictionary.

class Inventory:
    def __init__(self, *args, **kwargs):#sprite, *args, **kwargs):
        self.slotMax = 5
        self.slots = {}
        #self.sprite = sprite
        for k, v in kwargs.items():
            self.__dict__[k] = v

        for x in range(1, self.slotMax+1):
            try:
                self.slots[x] = args[x-1]
            except:
                self.slots[x] = None

        print(self.slots)

    def setSlot(self, index, item=None):
        if not index > self.slotMax:
            self.slots[index] = item

    def getSlot(self, index):
        if not index > self.slotMax:
            return self.slots[index]

inv1 = Inventory("banana", "apple", "strawberry", "coconut", "kiwi", "grape", slotMax = 6)

try this