Python Forum
[pygame] Inventory items not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pygame] Inventory items not working
#6
I have already stated the issues beforehand in other threads. Fixing those issues would reduce your code.

The first simple one to reduce code is your loading of images. A simple method of loading images since yours are all in one directory is to load all PNG's in that directory. Then use the filename as the dictionary key. A simple for loop would reduce 50 lines of hard coded image loads to just a few.

All your time sleeps everywhere add a single line on every function. It is also slowing your program down and glitching your GUI. During the half second, nothing happens. No logic and no drawing to the screen.

Your drawWeap method is redundant and can be reduced by splitting logic from drawing. This occurs in all of your classes.

Things like this
                if self.direct == 'Left':
                    WeapRect = self.weapType[3]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.rect[0] - round(self.width*.8)
                    WeapRect[1] = self.rect[1] + round(self.height/2)
                elif self.direct == 'Right':
                    WeapRect = self.weapType[1]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.rect[0] + round(self.width*.8)
                    WeapRect[1] = self.rect[1] + round(self.height/2)
                elif self.direct == 'Up':
                    WeapRect = self.weapType[0]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.rect[0] + round(self.width/2)
                    WeapRect[1] = self.rect[1] - round(self.height*.8)
                elif self.direct == 'Down':
                    WeapRect = self.weapType[2]
                    WeapRect = WeapRect.get_rect()
                    WeapRect[0] = self.rect[0] + round(self.width/2)
WeapRect[1] = self.rect[1] + round(self.height*.8)
You are copying code to apply to each direction. With dictionaries, you can do this once instead of copy and pasting for each direction. You do this quite often everywhere. Which would reduce your code by 75%.

I will leave it there. Because you do not have a good track record for applying what people tell you to change. And there is no point in me spending any more time looking at your code if you are not going to apply what i suggest.
Recommended Tutorials:
Reply


Messages In This Thread
[pygame] Inventory items not working - by SheeppOSU - May-12-2019, 12:36 AM
RE: [pygame] Inventory items not working - by metulburr - May-27-2019, 12:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding an inventory and a combat system to a text based adventure game detkitten 2 7,017 Dec-17-2019, 03:40 AM
Last Post: detkitten
  [pygame] Inventory problems. Weapons equipped to wrong slot SheeppOSU 6 4,140 May-07-2019, 02:46 AM
Last Post: SheeppOSU
  [pygame] Blitting armor and weapons with inventory SheeppOSU 3 2,965 Apr-29-2019, 02:31 AM
Last Post: SheeppOSU
  [pygame] Equiping inventory slots with invisible buttons SheeppOSU 6 4,850 Apr-26-2019, 08:45 PM
Last Post: SheeppOSU
  [pyGame] Key Event not Working !... JamieVanCadsand 7 20,911 Sep-29-2017, 08:59 PM
Last Post: Mekire

Forum Jump:

User Panel Messages

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