Reputation: 59
I've tried to run the code as normal, however I was met with a error which looks something like this
Traceback (most recent call last):
File "H:\Coursework assets\gametest1.py", line 85, in <module>
wizard.move(wizard.x)
AttributeError: 'tuple' object has no attribute 'move'
Below is the class for the original player Player class for the main character. Where the error may have originated from
class player:
def __init__(self,x,y):
self.x = x
self.y = y
self.standing = True
self.left = False
self.right = True
self.vel = 15
def move(self,x,y):
if not(self.standing):
if k[pygame.K_LEFT] and self.x > 0 - 150:
self.left = True
self.right = False
self.x -= self.vel
elif k[pygame.K_RIGHT] and self.x < 500 - 150 :
self.right = True
self.left = False
self.x += self.vel
else:
self.standing = True
run = True
Main game loop
wizard = (25,420)
while run:#main game loop
pygame.time.delay(15)
wizard.move(wizard.x,wizard.y)
win.blit(bg,(0,0))
wizard.jump(wizard.y)
wizard.draw(win))
pygame.display.update()
pygame.quit()
Upvotes: 1
Views: 905
Reputation: 14906
Assuming your wizard is meant to be "player" class, the deceleration of the variable wizard
is not correct.
The code has:
wizard = (25,420)
Which just makes the wizard a pair of numbers. ( Known as a "tuple ).
I think this should be an instance of player
, with the x
and y
parameters of 25, 240 ~
wizard = player( 25, 420 )
I assume you left the functions player.jump()
and player.draw()
out of the code, but if they are not written yet, your main loop will break with much the same error you already reported, except for .jump()
first.
Upvotes: 0
Reputation: 1482
In the game loop, the wizard you create is just a tuple. Create it as wizard = player(25, 420)
Also, it is heavily recommended to make class names capital (Player
). See PEP 8 for more coding style recommendations which are generally accepted by Python community.
Moreover, you don't have to put parentheses around the negated statement, just as if not self.standing
. And you probably actually don't want the not
there, you want to move the wizard if he is standing, and raise him when he isn't...
Upvotes: 2