接上篇。完美解决。
单键单击有效,双键单击有效,双键同时按住有效,同时松开有效,分别松开有效……,总之 解决了游戏控制键和发射键按键的所有状态。
import pygame
from sys import exit #用到exit() 省的每次退出都有红字提示
class Keycontral(object):
def __init__(self):
pygame.init()
scene = pygame.display.set_mode((400,600))
pygame.display.set_caption('按键测试')
#记录 a 键 按下的次数
self.key_a_count = 0
#记录 j 键 按下的次数
self.key_j_count = 0
# pygame.key.set_repeat(1,50)
#储存键盘的'a s d w'键,控制飞机移动
self.key_down_list = []
#存储键盘的 j 键,用来射击fire
self.fire_key_list = []
self.rightcount = 1
self.fiercount = 1
self.leftcount = 1
def move(self,direction):
if direction == "RIGHT":
self.rightcount += 1
print('right ' + str(self.rightcount))
elif direction =&#