Python pygame 模块,K_F4 实例源码

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

项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, _):
        for event in pg.event.get():

            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.KEYDOWN:
                if event.key == pg.K_F4:
                    sys.exit()

            if (event.type == self.MENU_EVENT
                    or event.type == pg.KEYDOWN):
                self.menuEngine.handleEvent(event)

            if (event.type == self.SCENE_EVENT
                    or event.type == pg.KEYDOWN
                    or event.type == pg.KEYUP):
                self.sceneEngine.handleEvent(event)

            if (event.type == self.CUTSCENE_EVENT
                    or event.type == pg.KEYDOWN):
                self.cutsceneEngine.handleEvent(event)
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def process_events(self):
        keys = pygame.key.get_pressed()

        self.B1 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5)
        self.B2 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5)
        self.B3 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5)
        self.M1 = Menu(self.width, self.height, I0)

        for event in pygame.event.get():
            if event.type == VIDEORESIZE:
                self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE)
                self.width = event.dict['size'][0]
                self.height = event.dict['size'][1]
            if event.type == pygame.QUIT:
                return True
            if keys[pygame.K_LCTRL] and keys[pygame.K_w]:
                return True
            if keys[pygame.K_LALT] and keys[pygame.K_F4]:
                return True
            if keys[pygame.K_ESCAPE]:
                if self.S0[1] == 1 or self.S0[2] == 1 or self.S0[3] == 1:
                    self.S0 = [1, 0, 0, 0]
            if event.type == pygame.MOUSEBUTTONUP:
                if self.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[1] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[3] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.M1.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    self.S0 = [0, 1, 0, 0]
                if self.M1.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    self.S0 = [0, 0, 1, 0]
                if self.M1.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    self.S0 = [0, 0, 0, 1]
                if self.M1.B4.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    return True

        return False
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def game_loop(self):
        self.screen = pygame.display.get_surface()
        self.clock = pygame.time.Clock()
        self.load_assets()
        self.font_large = pygame.font.Font(self.font_path, 72)
        self.font = pygame.font.Font(self.font_path, 24)
        self.font_small = pygame.font.Font(self.font_path, 14)
        self.bold_font_large = pygame.font.Font(self.bold_font_path, 72)
        self.bold_font = pygame.font.Font(self.bold_font_path, 24)
        self.bold_font_small = pygame.font.Font(self.bold_font_path, 14)
        pygame.display.set_caption(self.title)
        pygame.display.set_icon(self.game_icon)
        self.difficulty = "Easy"
        self.starting_scene = scenes.TitleScene
        self.active_scene = self.starting_scene(self)

        while self.active_scene != None:
            pressed_keys = pygame.key.get_pressed()
            # Event filtering
            filtered_events = []
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.quit_attempt = True
                elif event.type == pygame.KEYDOWN:
                    alt_pressed = pressed_keys[pygame.K_LALT] or \
                                  pressed_keys[pygame.K_RALT]
                    if event.key == pygame.K_ESCAPE:
                        self.quit_attempt = True
                    elif event.key == pygame.K_F4 and alt_pressed:
                        self.quit_attempt = True

                if self.quit_attempt:
                    self.active_scene.Terminate()
                else:
                    filtered_events.append(event)

            self.active_scene.ProcessInput(filtered_events, pressed_keys)
            self.active_scene.Update()
            self.active_scene.Render()

            if not self.active_scene.override_render:
                pygame.display.flip()
            self.active_scene = self.active_scene.next
            self.clock.tick(self.fps)
项目: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()
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def process_events(self):
        keys = pygame.key.get_pressed()

        self.B1 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5)
        self.B2 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5)
        self.B3 = Button(self.width * 0.88, self.height * 0.04, self.width * 0.1, self.height * 0.07, I5)
        self.H1 = Button(self.width * 0.88, self.height * 0.84, self.width * 0.1, self.height * 0.07, I6)
        self.H2 = Button(self.width * 0.77, self.height * 0.84, self.width * 0.1, self.height * 0.07, I7)
        self.M1 = Menu(self.width, self.height, I0)
        self.screen_rect = self.screen.get_rect()

        for event in pygame.event.get():
            if event.type == VIDEORESIZE:
                self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE)
                self.width = event.dict['size'][0]
                self.height = event.dict['size'][1]
            if event.type == pygame.QUIT:
                return True
            if keys[pygame.K_LCTRL] and keys[pygame.K_w]:
                return True
            if keys[pygame.K_LALT] and keys[pygame.K_F4]:
                return True
            if keys[pygame.K_ESCAPE]:
                if self.S0[1] == 1 or self.S0[2] == 1 or self.S0[3] == 1:
                    self.S0 = [1, 0, 0, 0]
            if keys[pygame.K_r]:
                self.D1
                self.D1 = Dice(self.width * 0.5, self.height * 0.5, self.width * 0.1, self.width * 0.1)
            if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and self.D1.rc == 0:
                self.D1.check_click(event.pos)
            if event.type == pygame.MOUSEBUTTONUP and event.button == 1:
                self.D1.click = False
                if self.D1.rc == 1:
                    self.D1.rc = 2
                if self.D1.rc == 3 and self.D1.vcc < 30:
                    self.D1.rc = 0
                    self.D1.vcc = 0
                if self.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[1] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.H1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.H2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[2] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[3] == 1:
                    self.S0 = [1, 0, 0, 0]
                if self.M1.B1.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    self.S0 = [0, 1, 0, 0]
                if self.M1.B2.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    self.S0 = [0, 0, 1, 0]
                if self.M1.B3.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    self.S0 = [0, 0, 0, 1]
                if self.M1.B4.rect.collidepoint(pygame.mouse.get_pos()) and self.S0[0] == 1:
                    return True

        return False