Python pygame 模块,K_PLUS 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用pygame.K_PLUS

项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def run(self):
        """The mainloop"""
        #self.playtime = 0
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False 
                elif event.type == pygame.KEYDOWN:
                    #print(event.key)
                    if event.key == pygame.K_ESCAPE:
                        running = False
                    if event.key == pygame.K_PLUS or event.key == pygame.K_KP_PLUS:
                        self.changeTerrain(10)
                    if event.key == pygame.K_MINUS or event.key == pygame.K_KP_MINUS:
                        self.changeTerrain(-10)
                    if event.key == pygame.K_F4:
                        # save into level.txt
                        linenr = 0
                        #with open("level.txt", "w") as f:
                        #    for line in self.tiles:
                        #        linenr += 1
                        #        print(linenr, line)
                        #        f.write(str(line)+"\n")
                        #print("level saved as level.txt")
                        nr = 0
                        for line in self.tiles:
                            nr +=1
                            print(nr, line)



            if pygame.mouse.get_pressed()[0]:
                self.changeTerrain(-1)  # left click
            if pygame.mouse.get_pressed()[2]:
                self.changeTerrain(1) # right click
            # end of event handler
            #milliseconds = self.clock.tick(self.fps) #
            #seconds = milliseconds / 1000
            #self.playtime += seconds
            # delete everything on screen
            self.screen.blit(self.background, (0, 0)) 
            self.changeTerrain()

            pygame.display.flip()
            (x,y,z) = self.get_info()
            pygame.display.set_caption("--- MAP-VIEWER F4=save---x: {} y: {} z: {}".format(x,y,z))

        pygame.quit()
项目:pygame-event-calendar-and-pianobar    作者:scottpcrawford    | 项目源码 | 文件源码
def __init__(self, screen):
        self.done = False
        self.screen = screen
        self.clock = pg.time.Clock()
        self.fps = 60
        self.RADIO_STATION = '39' # or 1591330390268116913
        self.BACKGROUND_IMG = 'img/bg/day_tree.png'
        self.SCREEN_WIDTH = SCREEN_WIDTH
        self.SCREEN_HEIGHT = SCREEN_HEIGHT
        self.RADIO_RUNNING = False
        self.RESTING = False
        self.SHOWGOALS = False
        self.grass = 'img/bg/day_grass.png'
        self.day_clouds = pg.sprite.RenderUpdates()
        self.night_clouds = pg.sprite.RenderUpdates()
        self.all_sprites_list = pg.sprite.RenderUpdates()
        self.quote_list = return_list('quotes.txt')
        self.contributions = return_list('contributions.txt')
        self.goals = return_list('goals.txt')
        self.weather = Weather()
        self.weather_observation = {}
        self.phrase = random.choice(self.quote_list)
        #self.cwd = os.getcwd() #windows
        self.cwd = '/home/pi/.config/pianobar' # linux
        ## DAIYE COLORS ###
        self.HEADER_COLOR = pg.Color('black')
        self.CONTENT_COLOR = pg.Color('indianred4')
        self.BG_COLOR = pg.Color('skyblue')
        self.current_events = []
        self.upcoming_events = []

        # User events:
        self.UPDATECALENDAR = pg.USEREVENT + 1
        self.UPDATEQUOTE = pg.USEREVENT + 2
        self.NIGHTRADIO = pg.USEREVENT + 3
        self.CHANGESTATE = pg.USEREVENT + 4
        self.UPDATEWEATHER = pg.USEREVENT + 5
        #self.SHOWGOALS = pg.USEREVENT + 6
        pg.time.set_timer(self.UPDATECALENDAR, 60000) #update calendar every 60 seconds     
        pg.time.set_timer(self.UPDATEQUOTE, 20000) #update quote every 20 seconds
        pg.time.set_timer(self.NIGHTRADIO,300000) # check for relaxation radio time
        pg.time.set_timer(self.UPDATEWEATHER, 600000)
        pg.time.set_timer(self.CHANGESTATE, 300000)
        #pg.time.set_timer(self.SHOWGOALS, 6000)

        self.DAYGFX = load_gfx(os.path.join("img", "clouds", "day"))
        self.NTGFX = load_gfx(os.path.join("img", "clouds", "night"))
        self.BGIMG  = load_gfx(os.path.join('img', 'bg'))
        self.keymap_dict = {pg.K_n: 'n', pg.K_PLUS: '+', pg.K_KP_PLUS: '+', pg.K_EQUALS: '+', pg.K_MINUS: '-', pg.K_KP_MINUS: '-', 
                            pg.K_p: 'p', pg.K_SPACE: 'p', pg.K_q: 'q', pg.K_r: 'r', pg.K_s: 's', pg.K_1: 's6\n', pg.K_2: 's4\n', 
                            pg.K_3: 's15\n', pg.K_4: 's25\n', pg.K_5: 's48\n', pg.K_6: 's37\n', pg.K_7: 's52\n', pg.K_8: 's16\n'}