Python pygame 模块,K_e() 实例源码

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

项目:ice-mud-game    作者:PyBargain    | 项目源码 | 文件源码
def update(self, is_key_pressed, time, display):
        """
        ?????????????????????????????
        is_key_pressed      ?????????????ascii????????????
        time                ????
        display             ????????Display??
        """
        if (is_key_pressed(pygame.K_e)):
            if self.theme_changed:
                display.theme_index = (display.theme_index + 1) % len(self.themes)
                display.theme = self.themes[display.theme_index]
                self.theme_changed = False
        elif not self.theme_changed:
            self.theme_changed = True

        flag = False
        if (is_key_pressed(pygame.K_UP)):
            self._up(display, time)
            flag = True
        if (is_key_pressed(pygame.K_DOWN)):
            self._down(display, time)
            flag = True
        if (is_key_pressed(pygame.K_LEFT)):
            self._left(display, time)
            flag = True
        if (is_key_pressed(pygame.K_RIGHT)):
            self._right(display, time)
            flag = True
        if self.counter >= 3:
            self.counter = 0
            return flag
        else:
            self.counter += 1
            return False
项目:Write-Chinese-Calligraphy-with-Palletizing-Robot-and-SVG-Files    作者:amjltc295    | 项目源码 | 文件源码
def generate_path(self, pointList, up_Z=-1, down_Z=-1):
        """ Generate path for a line of the image. """
        count = 0
        toEnd = NOT_ADJUST_THICKNESS
        start_point = self.robotCoorToPygameCoor( pointList[0] )
        for (x, y) in pointList:
            upZ = self.up_z if up_Z == -1 else up_Z
            downZ = self.down_z if down_Z == -1 else down_Z
            if_draw = True

            end_point = self.robotCoorToPygameCoor( (x, y) )
            pygame.draw.line(self.screen, BLACK, start_point, end_point, PYGAME_LINE_WIDTH)
            pygame.display.update()
            if not toEnd:
                pressed_key = self.pygame_wait()
                if (pressed_key == pygame.K_a):
                    downZ -= Z_THICK_ADJUST
                    pygame.draw.line(self.screen, BLACK, start_point, end_point, PYGAME_THICK_LINE_WIDTH)
                    pygame.display.update()
                elif (pressed_key == pygame.K_d):
                    downZ += Z_THIN_ADJUST
                    pygame.draw.line(self.screen, WHITE, start_point, end_point, PYGAME_LINE_WIDTH)
                    pygame.draw.line(self.screen, BLACK, start_point, end_point, PYGAME_THIN_LINE_WIDTH)
                elif (pressed_key == pygame.K_e):
                    toEnd = True
                elif (pressed_key == pygame.K_p):
                    pygame.draw.line(self.screen, WHITE, start_point, end_point, PYGAME_LINE_WIDTH)
                    if_draw = False
            start_point = end_point

            if if_draw:
                """ Move to the stating point. """
                if count == 0:
                    self.create_robot_point(x, y, upZ)
                self.create_robot_point(x, y, downZ)
                """ Move to the last point. """
                if count == len(pointList) -1:
                    self.create_robot_point(x, y, upZ)
            count += 1
项目:CritterEvolution    作者:apockill    | 项目源码 | 文件源码
def updateKeys(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == K_r:
                keys["r"] = True
            elif event.key == pygame.K_e:
                keys["e"] = True
            elif event.key == pygame.K_p:
                keys["p"] = True
            elif event.key == pygame.K_n:
                keys["n"] = True

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_r:
                keys["r"] = False
            elif event.key == pygame.K_e:
                keys["e"] = False
            elif event.key == pygame.K_p:
                keys["p"] = False
            elif event.key == pygame.K_n:
                keys["n"] = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = True
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = True

        if event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = False
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = False

        keys["mousePos"] =  pygame.mouse.get_pos()
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def init():
    add_key(pygame.K_w)
    add_key(pygame.K_s)
    add_key(pygame.K_a)
    add_key(pygame.K_d)
    add_key(pygame.K_c)
    add_key(pygame.K_r)
    add_key(pygame.K_q)
    add_key(pygame.K_e)
    add_key(pygame.K_g)
    add_key(pygame.K_t)


# Adds a new key to be tracked for input
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def init():
    add_key(pygame.K_w)
    add_key(pygame.K_s)
    add_key(pygame.K_a)
    add_key(pygame.K_d)
    add_key(pygame.K_c)
    add_key(pygame.K_r)
    add_key(pygame.K_q)
    add_key(pygame.K_e)
    add_key(pygame.K_g)
    add_key(pygame.K_t)


# Adds a new key to be tracked for input
项目:jackit    作者:vix597    | 项目源码 | 文件源码
def __init__(self):
        super(JackitConfigControls, self).__init__()
        self.up = pygame.K_w
        self.down = pygame.K_s
        self.left = pygame.K_a
        self.right = pygame.K_d
        self.jump = pygame.K_SPACE
        self.interact = pygame.K_e
        self.push = pygame.K_LSHIFT
        self.reset_code = pygame.K_q
        self.toggle_sound = pygame.K_m
        self.kill_self = pygame.K_k
        self.reset_game = pygame.K_n
项目:jackit    作者:vix597    | 项目源码 | 文件源码
def from_json(self, raw):
        '''
        Load the object from JSON loaded from config file
        '''

        # First pass make sure all are valid
        for key in raw:
            if isinstance(raw[key], str):
                if not hasattr(pygame, raw[key]):
                    raise ConfigError(
                        "Invalid control for {}. Must be a valid pygame key constant".format(key)
                    )
                else:
                    raw[key] = getattr(pygame, raw[key])
            elif isinstance(raw[key], int):
                pass
            else:
                raise ConfigError(
                    "Controls must be a valid pygame key constant as a string or integer"
                )

        # Check for duplicates
        values = list(raw.values())
        values_set = set(values)

        if len(values) != len(values_set):
            raise ConfigError("Cannot have duplicate controls")

        self.up = raw.get('up', getattr(pygame, 'K_w'))
        self.down = raw.get('down', getattr(pygame, 'K_s'))
        self.left = raw.get('left', getattr(pygame, 'K_a'))
        self.right = raw.get('right', getattr(pygame, 'K_d'))
        self.jump = raw.get('jump', getattr(pygame, 'K_SPACE'))
        self.interact = raw.get('interact', getattr(pygame, 'K_e'))
        self.push = raw.get("push", getattr(pygame, "K_LSHIFT"))
        self.reset_code = raw.get("reset_code", getattr(pygame, "K_q"))
        self.toggle_sound = raw.get("toggle_sound", getattr(pygame, "K_m"))
        self.kill_self = raw.get("kill_self", getattr(pygame, "K_k"))
        self.reset_game = raw.get("reset_game", getattr(pygame, "K_n"))
项目:Python-Platformer---Map-editor    作者:billy-yoyo    | 项目源码 | 文件源码
def update(self, button):
        keys = pygame.key.get_pressed()
        if focus == main:
            elapsed = min(1, self.cds.elapsed("move_keys"))
            if keys[pygame.K_LEFT] or keys[pygame.K_a]:
                self.offset[0] = self.offset[0] - (self.key_velocity[0] * elapsed)
                self.change = True
            if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
                self.offset[0] = self.offset[0] + (self.key_velocity[0] * elapsed)
                self.change = True
            if keys[pygame.K_UP] or keys[pygame.K_w]:
                self.offset[1] = self.offset[1] - (self.key_velocity[1] * elapsed)
                self.change = True
            if keys[pygame.K_DOWN] or keys[pygame.K_s]:
                self.offset[1] = self.offset[1] + (self.key_velocity[1] * elapsed)
                self.change = True
            self.cds.start()

            if self.cds.check("save_load"):
                if keys[pygame.K_q]:
                    save(fnbox.text)
                    self.cds.start()
                if keys[pygame.K_e]:
                    load(fnbox.text)
                    self.cds.start()
                if keys[pygame.K_r]:
                    self.new()

        if self.mmb_down and self.cds.check("navigate"):
            mpos = pygame.mouse.get_pos()
            diffx = (mpos[0] - self.mmb_start[0]) / 10
            diffy = (mpos[1] - self.mmb_start[1]) / 10
            self.offset = [ self.offset[0] + diffx, self.offset[1] + diffy ]
            self.cds.start()
            self.change = True
项目:python-game-dev    作者:arindam-modak    | 项目源码 | 文件源码
def process(bug,FPS,total_frames):

    # processing
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_e:
                classes.BugAttack.fire = not classes.BugAttack.fire

    keys = pygame.key.get_pressed()

    if keys[pygame.K_d]:
        classes.Bug.going_right = True
        bug.image = pygame.image.load("images/bug2right.png")
        bug.velx = 5
    elif keys[pygame.K_a]:
        classes.Bug.going_right = False
        bug.image = pygame.image.load("images/bug2left.png")
        bug.velx = -5
    else:
        bug.velx = 0

    if keys[pygame.K_w]:
        bug.jumping = True

    if keys[pygame.K_SPACE]:
        if classes.Game.end == True:
            classes.Game.end = False
        if classes.Game.start == False:
            classes.Game.start = True
            for fly in classes.Fly.List:
                fly.destroy(classes.Fly)
            for attack in classes.BugAttack.List:
                attack.destroy()
            classes.Fly.count = 0

        else:
            def direction():
                if classes.Bug.going_right:
                    p.velx = 6
                else:
                    p.image = pygame.transform.flip(p.image, True, False)
                    p.velx = -6
            if (classes.BugAttack.fire):
                p = classes.BugAttack(bug.rect.x,bug.rect.y, "images/fire2.gif")
                direction()
                p.velx = p.velx/3.0
            else:
                p = classes.BugAttack(bug.rect.x,bug.rect.y, "images/bolt.gif")
                direction()
    if classes.Game.start == True:        
        spawn(FPS,total_frames)
        collisions(bug)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def handle_mouse_input(tileset):
    tile = None

    if tileset.is_at_mouse_pos():
        tile = tileset.tile_at_mouse_pos()

    # Add column to Tileset
    if Input.key_typed(pygame.K_c):
        tileset.add_columns(1)

    # Add row to Tileset
    if Input.key_typed(pygame.K_r):
        tileset.add_rows(1)

    # Make Tile at mouse position not passable
    if Input.left_mouse_down:
        if tileset.is_at_mouse_pos():
            tile.passable = False
            tile.color = Renderer.COLOR_BLACK

    # Make Tile at mouse position passable
    if Input.right_mouse_down:
        if tileset.is_at_mouse_pos():
            tile.passable = True
            tile.color = (128, 128, 128)

    if Input.key_typed(pygame.K_q):
        if tileset.is_at(Input.mouse_x(), Input.mouse_y()):
            tile.passable = True
            tile.color = Renderer.COLOR_GREEN
            GenAlg.start_node = tile
            TileInteractor.start_node = tile

    if Input.key_typed(pygame.K_e):
        if tileset.is_at_mouse_pos():
            tile.passable = True
            tile.color = Renderer.COLOR_RED
            GenAlg.end_node = tile
            TileInteractor.end_node = tile

    if Input.key_typed(pygame.K_g):
        GenAlg.init()


# This is used for framerate