0

I'm attempting to write a code in which the user can add as many of a certain object as needed, and blit it on to a pygame window. Essentially a game engine of sorts. I need to make it so that they can add as many of these objects as they need, so that they can create a game world. The only problem I'm encountering is that I cannot create enough names for all of this by hard-coding it, and even then it would not be enough. So is there a way for me to make it so that they can name each class, or so that it would be procedurally generated names for each class? Here is my class:

##My Class
class objectMesh():
    def __init__(self, objectType, color, width, dimensions):   ##Send dimensions depending on what is required for each pygame.draw command. Polygons are
        self.objectType, self.color, self.width, self.dimensions = objectType, color, width, dimensions ##list of vertices, circles are center + radius, etc.
    def drawObject(self):
        if self.objectType == 0:
            drawRect(self.dimensions, self.color, self.width)
2
Contributors
1
Reply
73
Views
6 Months
Discussion Span
Last Post by Gribouillis
2

The only problem I'm encountering is that I cannot create enough names for all of this by hard-coding it

I'm not sure I understand this question very well. It seems to me that you want to create many instances of a certain class but you don't want to create a variable name for each instance. The solution is to store the instances in one of the many container classes that come with python: list, set, dict, deque, etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.