Python Forum
[PyGame] Issue with item counter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Issue with item counter
#2
Just putting the question aside for a bit, I'd like to extrude more on your code. This is very common to see code like this from people new to pygame, and it's very messy. It makes code hard to read, hard to change, less efficient, and just overall not very good. You should work on splitting the logic up more through creating different functions and classes. Also in the Game_Item function, under random_pos there's a while loop without any event detection. If someone were to try and exit while the loop was running it wouldn't work. Another thing that I see is many parameters for your functions. You should try to reduce that through possibly a list or tuple. For example the x's and y's that correlate can go together in a list or tuple. Now for the problem, from what I understand, the counter decreases when an item is picked up. I'd suggest putting the items in a list, then when an item is picked up, remove it from the list, once the list for example has 1 item left, you can end the loop, though there are various other ways if you decide to do it some other way. Hope that helps you with your problem. I would suggest going to the tutorial on using a State Machine from metulburr - https://python-forum.io/Thread-PyGame-Cr...te-machine - This shows a great way to manage everything efficiently.
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