Python Forum
[PyGame] Issue with item counter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Issue with item counter
#4
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.
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.
Reply


Messages In This Thread
Issue with item counter - by Ayckinn - May-08-2020, 09:10 PM
RE: Issue with item counter - by SheeppOSU - May-10-2020, 02:50 AM
RE: Issue with item counter - by Ayckinn - May-10-2020, 08:26 AM
RE: Issue with item counter - by Windspar - May-10-2020, 04:17 PM
RE: Issue with item counter - by Ayckinn - May-10-2020, 07:05 PM
RE: Issue with item counter - by Ayckinn - May-11-2020, 02:09 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020