萌新求助,怎么让鼠标每隔一段时间判定一次输入
pygame吧
全部回复
仅看楼主
level 10
想做一个打飞机的游戏,鼠标左键点击开火,但是出现的一个情况是按住鼠标后会一直开火,我想弄成按住鼠标后隔一段时间开火一次,比方说每隔10毫秒开火一次(每10毫秒读取一次鼠标操作),请问怎么弄?
我现在的代码关于鼠标的部分是这样的。只看过《python游戏编程入门》的前6章,写的不好还多包涵
这里是读取鼠标输入的地方
这里是开火判定的地方
2018年10月25日 12点10分 1
level 1
你们有飞机大战素材吗?
2019年04月28日 04点04分 5
level 5
加个延迟delay就行啊,比如if not delay%6
2019年05月06日 08点05分 6
level 1
有哪位大佬帮我看看这段代码,帮我让飞船发射子弹,谢谢了!
import pygame,sys,random
pygame.init()
plane1 = pygame.image.load("./png/plane 1.png")
plane2 = pygame.image.load("./png/plane 2.png")
ball = pygame.image.load("./png/子弹.png")
Gball = pygame.image.load("./png/粘液弹.png")
buckground = pygame.image.load("./png/star.png")
font = pygame.font.Font("C:/Windows/Fonts/MSYH.TTF",32)
screen = pygame.display.set_mode((600,900))
screen.fill((255,255,255))
pygame.display.set_caption("太空大战")
plane_x = 236
MSM = 100
MySM = font.render("生命:"+str(MSM),1,(255,0,0))
while True:
key = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if key[pygame.K_LEFT] and plane_x > 0:
plane_x -= 10
print("Plane at",y,",",plane_x,".")
if key[pygame.K_RIGHT] and plane_x < 536:
plane_x += 10
print("Plane at",y,",",plane_x,".")
screen.blit(buckground,(0,0))
screen.blit(MySM,(10,750))
screen.blit(plane1,(plane_x,800))
pygame.display.flip()
pygame.time.wait(26)
screen.blit(plane2,(plane_x,800))
pygame.time.wait(26)
pygame.display.flip()
2019年05月13日 04点05分 7
这个缩进打不出来,对不起了哈
2019年05月13日 04点05分
1