in my game I have a class to control the player item witch he can throw. the objective is that when the key is pressed the item should be displayed on screen and then using a while loop its position should be updated until either it collided with an enemy or with the world.
class Fight():
def __init__(self):
self.image = pygame.image.load('Wepon.png')
self.pressed = False
self.rect = self.image.get_rect()
self.rect.x = player.rect.x +16
self.rect.y = player.rect.y +14
i = 0
key = pygame.key.get_pressed()
if (key[pygame.K_x] ) and (self.pressed == False):
self.pressed =True
while self.pressed == True:
screen.blit(self.image,(self.rect.x,self.rect.y))
self.rect.y = self.rect.y + 1
self.rect.x = self.rect.x + 1
i = i + 1
if i == 200 :
self.pressed = False
print('I am working')
so the code runs when the key is pressed how ever the item is only displayed on the screen after the i reaches 200 and its on all the positions not just one if that makes sense