Im not saying this is the cause of your issue. But it illustrates the problem of people helping you.
Quote: def drawWeap(self, i):
gearBool = i.itemReturn()
if self.direct == 'Left':
if gearBool['armor'] == None:
self.character = gD.blit(Character[3], (self.x, self.y))
if gearBool['armor'] != None:
self.character = gD.blit(Character[3], (self.x, self.y))
self.armor = gD.blit(self.color[3], (self.x, self.y))
if gearBool['weapon'] != None:
self.weapon = gD.blit(self.weapType[3], (self.x - round(self.width*.8), self.y + round(self.height/2)))
This entire drawWeap() function is massively redundant. First of all there should be
if
and
elif
, not only
if
. Secondly you should split the logic of armor and weapons from the draw method. This alone would reduce the number of lines in your code as well make your code much more readable to new people looking at it. If you copy and paste a lot of code, then you are doing something wrong. And you are doing that.
Another example:
def move(self, p):
if not self.dead:
plrPos = p.getPos()
plrX = plrPos[0]
plrY = plrPos[1]
self.collision(p)
DownRight = ['Down', 'Right']
UpRight = ['Right', 'Up']
UpLeft = ['Up', 'Left']
DownLeft = ['Down', 'Left']
AnyDirect = ['Down', 'Up', 'Left', 'Right']
if plrX > self.x and plrY > self.y:
self.x += .2
self.y += .2
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = random.choice(DownRight)
elif plrX > self.x and plrY < self.y:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = random.choice(UpRight)
self.x += .2
self.y -= .2
elif plrX < self.x and plrY < self.y:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = random.choice(UpLeft)
self.x -= .2
self.y -= .2
elif plrX < self.x and plrY > self.y:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = random.choice(DownLeft)
self.x -= .2
self.y += .2
elif plrX == self.x and plrY > self.y:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = 'Down'
self.y += .2
elif plrX == self.x and plrY < self.y:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = 'Up'
self.y -= .2
elif plrY == self.y and plrX > self.x:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = 'Right'
self.x += .2
elif plrY == self.y and plrX < self.x:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = 'Left'
self.x -= .2
elif plrX == self.x and plrY == self.y:
if self.diff == 'noob':
num = random.randint(1, 200)
elif self.diff == 'easy':
num = random.randint(1, 100)
if num < 3:
self.direct = random.choice(AnyDirect)
Sure of course it works, but it makes it a nightmare to help fix bugs. As an example...when i look at this i dont know if your issue is a draw issue or a logic issue. You do not use docstrings. You do not use modules. You are not using the builtin pygame rects (You should never have to do self.x/self.y in pygame with rects). You are using time.sleep (Which is always bad in GUI).
Im sure if i wanted to devote the time i could make your 1200 line code into 300~ lines. But i dont have the time or patience. Reducing it by that much would make it much more easy to work on. Less bugs. Easier to find bugs that do come along.
My suggestion would be to rework your code better. If your asking yourself "how do i do that?". I would read (or reread)
the series of tutorials and follow along through part 1 through part 8. If you do that you should be thinking your code is in bad shape. And you would know tips on how to fix it. By doing all that more people would be willing to help. No one is ever going to look through thousands of lines of code, devote time in understanding your spaghetti code...without at least pay.
If you want to look at a good structure of RPG in python/pygame, check out Mekire's RPG
Cabbages and kings. Check out how loading sprites are separated into a tools module. check out the
player module. You never have redundant code, he labels every single method on what it does, each method does ONE thing.
EDIT:
Another suggestion is dont make us wait. Get us straight to the problem. Dont make use type username/passwords in. Dont make us kill the first guy. Put us straight at the shop. Programmers always have cheat arguments in development to progress users to the point of the problem....eliminating the need to start at the beginning.