To do this, you need to go through several steps. You will need an image of a bullet, a way to save the location of bullets, a way to create bullets, a way to visualize bullets and a way to update bullets. You seem to already know how to import images, so I will skip this part.
. . bullets=[].
, . bullets.append([event.pos[0]-32, 500]) shot.play() .
, for . screen.blit(background, (0, 0)) :
for bullet in bullets:
screen.blit(bulletpicture, pygame.Rect(bullet[0], bullet[1], 0, 0)
, - , :
for b in range(len(bullets)):
bullets[b][0]-=10
, , . for, :
for bullet in bullets:
if bullet[0]<0:
bullets.remove(bullet)
, :
import sys, pygame, pygame.mixer
from pygame.locals import *
pygame.init()
size = width, height = 800, 600
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()
bullets=[]
background = pygame.image.load("bg.png")
ship = pygame.image.load("ship.png")
ship = pygame.transform.scale(ship,(64,64))
bulletpicture = pygame.image.load("You know what to do")
shot = pygame.mixer.Sound("shot.wav")
soundin = pygame.mixer.Sound("sound.wav")
soundin.play()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == MOUSEBUTTONDOWN:
shot.play()
bullets.append([event.pos[0]-32, 500])
clock.tick(60)
mx,my = pygame.mouse.get_pos()
for b in range(len(bullets)):
bullets[b][0]-=10
for bullet in bullets:
if bullet[0]<0:
bullets.remove(bullet)
screen.blit(background,(0,0))
for bullet in bullets:
screen.blit(bulletpicture, pygame.Rect(bullet[0], bullet[1], 0, 0)
screen.blit(ship,(mx-32,500))
pygame.display.flip()
, . , - , , - .