May-10-2020, 04:17 PM
1. Don't capitalize variables unless they are constant. Game items will never be a constant.
2. Load your images once. Then you pass your images. They should be in your constant section. Don't forget to convert/convert_alpha them.
Can't run code or see the rest of code. So here my best guess. To me when you pick up an item. You need another copy of it. So maybe this example will help you.
2. Load your images once. Then you pass your images. They should be in your constant section. Don't forget to convert/convert_alpha them.
Can't run code or see the rest of code. So here my best guess. To me when you pick up an item. You need another copy of it. So maybe this example will help you.
class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def __iter__(self): yield self.x yield self.y class GameItem: def __init__(self, image, zone, count=3): self.image = image self.zone = zone self.counter = count self.cell = Point() self.visible = True self.position = Point() def draw(self): if self.visible: zone.blit(self.image, tuple(self.position)) def pickup(self, zone, bar_position): if visible: self.counter -= 1 if self.counter <= 0: self.visible = False item = GameItem(zone, self.image, 1) item.position = bar_position return item def pickup_all(self, zone, bar_position): self.zone = zone self.position = bar_position def random_position(self): loop = True while loop: self.cell.x = randint(0, 14) self.cell.y = randint(0, 14) if zone.game_design[self.cell.y][self.cell.x] == "0": self.position.x = self.cell.x * cst.SPRITE_SIZE self.position.y = self.cell.y * cst.SPRITE_SIZE loop = False
99 percent of computer problems exists between chair and keyboard.