Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 每次我按多次鼠标按钮时,pygame子弹都会重置_Python_Pygame - Fatal编程技术网

Python 每次我按多次鼠标按钮时,pygame子弹都会重置

Python 每次我按多次鼠标按钮时,pygame子弹都会重置,python,pygame,Python,Pygame,我的游戏有问题,我是初学者。我的子弹不起作用(如果我多次按,我的子弹会消失) 例如,如果我想从鼠标(左_键)射击,我按1次,子弹进入顶部,如果我在1秒内按3次,我的子弹是resst,压缩我的代码,然后看! 求你了 你没有子弹,你只有一颗子弹。创建项目符号列表: bullet_list=[] 按下鼠标按钮时,将新项目符号添加到列表中: 如果event.type==pygame.MOUSEBUTTONDOWN: xa,ya=event.pos bullet_list.append([xa,ya])

我的游戏有问题,我是初学者。我的子弹不起作用(如果我多次按,我的子弹会消失) 例如,如果我想从鼠标(左_键)射击,我按1次,子弹进入顶部,如果我在1秒内按3次,我的子弹是resst,压缩我的代码,然后看! 求你了


你没有子弹,你只有一颗子弹。创建项目符号列表:

bullet_list=[]
按下鼠标按钮时,将新项目符号添加到列表中:

如果event.type==pygame.MOUSEBUTTONDOWN:
xa,ya=event.pos
bullet_list.append([xa,ya])
绘制并移动列表中的所有项目符号:

用于项目符号列表中的项目符号位置[:]:
bullet_位置[1]-=2.15
pygame.draw.rect(屏幕,白色,pygame.rect(*bullet_pos,5,20))
如果项目符号位置[1]<0.0:
项目符号列表。移除(项目符号位置)
import pygame

pygame.init()
red = (189, 87, 87)
white = (230, 230, 230)

xbullet = 150
ybullet = 510

tix = 380
tiy = 50

screen = pygame.display.set_mode((800, 600))
window_title = pygame.display.set_caption("bullets")
xa, ya = pygame.mouse.get_pos()
running = True
bullet = pygame.draw.rect(screen, white, pygame.Rect(xa, ya, 5, 20))
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            xa, ya = pygame.mouse.get_pos()
            click = pygame.mouse.get_pressed()
            if click:
                print(xa, ya)

    screen.fill((94, 94, 94))
    ya -= 2.15
    object = pygame.draw.rect(screen, red, pygame.Rect(tix, tiy, 60 ,60))
    bullet = pygame.draw.rect(screen, white, pygame.Rect(xa, ya, 5, 20))
    pygame.display.flip()
    pygame.display.update()