Reputation: 1
I'm doing a python coding project for school and I need to code a pygame that shoots bullets from a specific blit.
I tried using this code,
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_SPACE):
screen.blit(projectile,(projectilex,projectiley))
The projectile's x
coordinate is equal to the player's x
coordinate that it shoots from. So like:
projectilex = playerx
It only appears on the screen for 1 second then disappears. I need to it start at the player's x
and increase it's y
value until it hits the top of the screen, then disappears. Any help?
Note: I have to use python 3.2.5 and I cannot upgrade to newer versions.
Upvotes: 0
Views: 91
Reputation: 4050
screen.blit
only displays something for the duration of a single frame. You need to draw the bullet each frame. Use separate variables to track the bullet's X and Y position and whether to display the bullet. E.g.,
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_SPACE):
show_projectile = True
projectile_x = player_x
projectile_y = player_y
# ...
if show_projectile:
screen.blit(projectile, (projectile_x, projectile_y))
Upvotes: 1