當前位置: 首頁>>代碼示例>>Python>>正文


Python sdl2.SDL_KEYDOWN屬性代碼示例

本文整理匯總了Python中sdl2.SDL_KEYDOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Python sdl2.SDL_KEYDOWN屬性的具體用法?Python sdl2.SDL_KEYDOWN怎麽用?Python sdl2.SDL_KEYDOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在sdl2的用法示例。


在下文中一共展示了sdl2.SDL_KEYDOWN屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_event

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def handle_event(self):
        """Busywait until SDL_Event in keyhandlers is received.
        Then the corresponding value is returned."""
        event = sdl2.SDL_Event()
        while True:
            if sdl2.SDL_WaitEvent(ctypes.byref(event)) == 0:
                raise Exception(sdl2.SDL_GetError())
            if event.type == sdl2.SDL_QUIT:
                self.quit_handler()
                return True
            elif event.type == sdl2.SDL_KEYDOWN:
                key = event.key.keysym.sym
                mod = event.key.keysym.mod
                if mod in (sdl2.KMOD_NUM, sdl2.KMOD_NUM + sdl2.KMOD_LSHIFT,
                           sdl2.KMOD_NUM + sdl2.KMOD_RSHIFT):  # ignore numlock
                    mod -= sdl2.KMOD_NUM
                if (key, mod) in self.key_handlers:
                    return self.key_handlers[(key, mod)] 
開發者ID:kampffrosch94,項目名稱:pyAoEM,代碼行數:20,代碼來源:input_.py

示例2: orb_turn

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def orb_turn(self, activity):
        events = sdl2.ext.get_events()
        if events:
            activity.mark(
                l=self,
                s='sdl2 event(s)')
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                raise SolentQuitException()
            elif event.type == sdl2.SDL_KEYDOWN:
                if event.key.keysym.sym == sdl2.SDLK_UP:
                    self.ent_player_b.velocity.vy = -3
                elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                    self.ent_player_b.velocity.vy = 3
                elif event.key.keysym.sym == ord('\\'):
                    raise SolentQuitException()
            elif event.type == sdl2.SDL_KEYUP:
                if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
                    self.ent_player_b.velocity.vy = 0
        self.sdl_world.process() 
開發者ID:solent-eng,項目名稱:solent,代碼行數:22,代碼來源:sdl.py

示例3: handle_events

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def handle_events():
	global CLICKEDBUTTON
	for event in sdl2.ext.get_events():
		if event.type == sdl2.SDL_QUIT:
			shutdown()
		elif event.type == sdl2.SDL_MOUSEBUTTONUP:
			mousex, mousey = event.button.x, event.button.y
			button = getButtonClicked(mousex, mousey)
			if button:
			    CLICKEDBUTTON.append(button)
		elif event.type == sdl2.SDL_KEYDOWN:
			sym = event.key.keysym.sym
			if sym == sdl2.SDLK_ESCAPE:
				shutdown()
			elif sym == sdl2.SDLK_q:
				CLICKEDBUTTON.append(YELLOW)
			elif sym == sdl2.SDLK_w:
				CLICKEDBUTTON.append(BLUE)
			elif sym == sdl2.SDLK_a:
				CLICKEDBUTTON.append(RED)
			elif sym == sdl2.SDLK_s:
				CLICKEDBUTTON.append(GREEN) 
開發者ID:rswinkle,項目名稱:inventwithpython_pysdl2,代碼行數:24,代碼來源:simulate_pysdl2.py

示例4: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def run():
    # Initialize the video subsystem, create a window and make it visible.
    sdl2.ext.init()
    window = sdl2.ext.Window("Sprite Transformations", size=(800, 600))
    window.show()

    # Create a hardware-accelerated sprite factory. The sprite factory requires
    # a rendering context, which enables it to create the underlying textures
    # that serve as the visual parts for the sprites.
    renderer = sdl2.ext.Renderer(window)
    factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)

    # Create a simple rendering system for the window. We will use it to
    # display the sprites.
    rendersystem = factory.create_sprite_render_system(window)

    # Create the sprite to display.
    sprite = factory.from_image(RESOURCES.get_path("hello.bmp"))

    # Use the sprite.center tuple to change the center of the sprite for
    # rotation. You can reset a changed center simply by assinging None to it.
    #
    # sprite.center = 10, 30    # Changes the center
    # sprite.center = None      # Resets the center

    running = True
    while running:
        events = sdl2.ext.get_events()
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            elif event.type == sdl2.SDL_KEYDOWN:
                # Flip the sprite over its vertical axis on pressing down or up
                if event.key.keysym.sym in (sdl2.SDLK_DOWN, sdl2.SDLK_UP):
                    sprite.flip ^= sdl2.SDL_FLIP_VERTICAL
                # Flip the sprite over its horizontal axis on pressing left or
                # right
                elif event.key.keysym.sym in (sdl2.SDLK_LEFT, sdl2.SDLK_RIGHT):
                    sprite.flip ^= sdl2.SDL_FLIP_HORIZONTAL
                # Rotate the sprite around its center on pressing plus or
                # minus. The center can be changed via sprite.center.
                elif event.key.keysym.sym == sdl2.SDLK_PLUS:
                    sprite.angle += 1.0
                    if sprite.angle >= 360.0:
                        sprite.angle = 0.0
                elif event.key.keysym.sym == sdl2.SDLK_MINUS:
                    sprite.angle -= 1.0
                    if sprite.angle <= 0.0:
                        sprite.angle = 360.0
        renderer.clear()
        rendersystem.render(sprite, 100, 75)
        sdl2.SDL_Delay(10)
    sdl2.ext.quit()
    return 0 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:57,代碼來源:transfomations.py

示例5: poll_events

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def poll_events(self, scene_state, data=None):
        """Process each event in the queue.

        Parameters
        ----------
        scene_state : hienoi.renderer.SceneState
            Scene state.
        data : object
            Data to pass back and forth between the caller and the function set
            for the 'on event' callback.
        """
        self._has_view_changed = False

        event = sdl2.SDL_Event()
        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
            event_type = event.type
            if event_type == sdl2.SDL_QUIT:
                self._on_quit_event(event.quit)
            elif event_type == sdl2.SDL_WINDOWEVENT:
                self._on_window_event(event.window)
            elif event_type == sdl2.SDL_KEYDOWN:
                self._on_key_down_event(event.key, scene_state)
            elif event_type == sdl2.SDL_KEYUP:
                self._on_key_up_event(event.key)
            elif event_type == sdl2.SDL_MOUSEBUTTONDOWN:
                self._on_mouse_button_down_event(event.button)
            elif event_type == sdl2.SDL_MOUSEBUTTONUP:
                self._on_mouse_button_up_event(event.button)
            elif event_type == sdl2.SDL_MOUSEWHEEL:
                self._on_mouse_wheel_event(event.wheel)
            elif event_type == sdl2.SDL_MOUSEMOTION:
                self._on_mouse_motion_event(event.motion)

            if self._on_event_callback:
                self._on_event_callback(self, data, event)

            if self.quit:
                break 
開發者ID:christophercrouzet,項目名稱:hienoi,代碼行數:40,代碼來源:gui.py

示例6: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def run(self):
        self.window.show()

        grid = self.renderer.grid

        running = True
        while running:
            events = sdl2.ext.get_events()
            for event in events:
                if event.type == sdl2.SDL_QUIT:
                    running = False
                    break
                if event.type == sdl2.SDL_KEYDOWN:
                    if event.key.keysym.sym == sdl2.SDLK_UP:
                        grid.velocity[1] = -6
                    elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                        grid.velocity[1] = 6
                    elif event.key.keysym.sym == sdl2.SDLK_LEFT:
                        grid.velocity[0] = -6
                    elif event.key.keysym.sym == sdl2.SDLK_RIGHT:
                        grid.velocity[0] = 6
                elif event.type == sdl2.SDL_KEYUP:
                    if event.key.keysym.sym in \
                            (sdl2.SDLK_UP, sdl2.SDLK_DOWN,
                             sdl2.SDLK_LEFT, sdl2.SDLK_RIGHT):
                        grid.velocity = [0,0]
                    elif event.key.keysym.sym == sdl2.SDLK_z:
                        grid.scale += 10
                    elif event.key.keysym.sym == sdl2.SDLK_x:
                        grid.scale -= 10
            self.world.process()
        return 0 
開發者ID:udiboy1209,項目名稱:fractal-creator,代碼行數:34,代碼來源:__init__.py

示例7: process

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def process(self, event):
        """Process the current event and update the keyboard state."""
        down = True if event.type == sdl2.SDL_KEYDOWN else False
        self._process_mods(event.key.keysym.sym, down)
        if not down:
            self._process_locks(event.key.keysym.sym)
        return self 
開發者ID:LukeMS,項目名稱:pysdl2-roguelike-tutorial,代碼行數:9,代碼來源:manager.py

示例8: main

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def main():
	global ren, window, sprite_factory, sprite_renderer
	sdl2.ext.init()

	window = sdl2.ext.Window("testing", size=(WIDTH, HEIGHT))
	window.show()

	ren = sdl2.ext.Renderer(window, flags=sdl2.SDL_RENDERER_SOFTWARE)
	font_file = sysfont.get_font("freesans")
	print(font_file)
	font_manager = sdl2.ext.FontManager(font_file, size=24)

	#fontmanager=font_manager will be default_args passed to every sprite creation method
	sprite_factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE, renderer=ren, fontmanager=font_manager, free=True)
	sprite_renderer = sprite_factory.create_sprite_render_system(window)

	#test1(1000)
	#test_surface_drawing()
	#sdl2.SDL_Delay(1000)
	#test_surface_sprites()

	ren.present()

	while True:
		for event in get_events():
			if event.type == sdl2.SDL_QUIT:
				shutdown()
			elif event.type == sdl2.SDL_MOUSEBUTTONUP:
				mousex, mousey = event.button.x, event.button.y
			elif event.type == sdl2.SDL_KEYDOWN:
				sym = event.key.keysym.sym
				if sym == sdl2.SDLK_ESCAPE:
					shutdown()

		test_surface_sprites() 
開發者ID:rswinkle,項目名稱:inventwithpython_pysdl2,代碼行數:37,代碼來源:myfunctions.py

示例9: check_for_key_press

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def check_for_key_press():
	ret = False
	for event in sdl2.ext.get_events():
		if event.type == sdl2.SDL_QUIT:
			shutdown()
		elif event.type == sdl2.SDL_MOUSEBUTTONUP:
			mousex, mousey = event.button.x, event.button.y
		elif event.type == sdl2.SDL_KEYDOWN:
			sym = event.key.keysym.sym
			ret = True
			if sym == sdl2.SDLK_ESCAPE:
				shutdown()
	return ret 
開發者ID:rswinkle,項目名稱:inventwithpython_pysdl2,代碼行數:15,代碼來源:wormy_pysdl2.py

示例10: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def run(self):
		next(self.model.tick)
		self.keydict = { #key mapped here
			sdl2.SDLK_a:[False,False, 0, -1], #left
			sdl2.SDLK_d:[False,False, 0, 1], #right
			sdl2.SDLK_w:[False,False, 1, -1], #up
			sdl2.SDLK_s:[False,False, 1, 1], #down
			sdl2.SDLK_l:[False,False, 2, 1], #A
			sdl2.SDLK_j:[False,False, 2, -1], #B
			sdl2.SDLK_i:[False,False, 3, 1]} #Hold
		self.intup = [0,0,0,0] #(left/right), (up/down), (b/a), (hold)
		running = True
		d = sdl2.timer.SDL_GetTicks()
		t = d
		tick = 0
		while running:
			tick += 1
			events = sdl2.ext.get_events()
			for event in events:
				if event.type == sdl2.SDL_QUIT:
					running=False
					break
				if event.type == sdl2.SDL_KEYDOWN:
					if event.key.keysym.sym in self.keydict.keys():
						self.keydict[event.key.keysym.sym][0] = True
				if event.type == sdl2.SDL_KEYUP:
					if event.key.keysym.sym in self.keydict.keys():
						self.keydict[event.key.keysym.sym][0] = False
			for i, d in enumerate(self.intup):
				if d != 0:
					self.intup[i] += ( 1 if d > 0 else -1 )
			for key in self.keydict.keys():
				if self.keydict[key][0] != self.keydict[key][1]:
					if self.keydict[key][0]:
						self.intup[self.keydict[key][2]] = self.keydict[key][3]
					elif self.intup[self.keydict[key][2]] * self.keydict[key][3] > 0:
						self.intup[self.keydict[key][2]] = 0
					self.keydict[key][1] = self.keydict[key][0]
			self.model.tick.send(self.intup)
			next(self.view.render)
			next(self.audio.player)
			d = sdl2.timer.SDL_GetTicks()
			sdl2.timer.SDL_Delay(max((tick*1000)//self.framerate-d+t, 0))
		return 
開發者ID:ruby3141,項目名稱:PyTGM,代碼行數:46,代碼來源:ctrl.py

示例11: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYDOWN [as 別名]
def run():
    sdl2.ext.init()
    window = sdl2.ext.Window("The Pong Game", size=(800, 600))
    window.show()

    if "-hardware" in sys.argv:
        print("Using hardware acceleration")
        renderer = sdl2.ext.Renderer(window)
        factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
    else:
        print("Using software rendering")
        factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)

    # Create the paddles - we want white ones. To keep it easy enough for us,
    # we create a set of surfaces that can be used for Texture- and
    # Software-based sprites.
    sp_paddle1 = factory.from_color(WHITE, size=(20, 100))
    sp_paddle2 = factory.from_color(WHITE, size=(20, 100))
    sp_ball = factory.from_color(WHITE, size=(20, 20))

    world = sdl2.ext.World()

    movement = MovementSystem(0, 0, 800, 600)
    collision = CollisionSystem(0, 0, 800, 600)
    aicontroller = TrackingAIController(0, 600)
    if factory.sprite_type == sdl2.ext.SOFTWARE:
        spriterenderer = SoftwareRenderSystem(window)
    else:
        spriterenderer = TextureRenderSystem(renderer)

    world.add_system(aicontroller)
    world.add_system(movement)
    world.add_system(collision)
    world.add_system(spriterenderer)

    player1 = Player(world, sp_paddle1, 0, 250)
    player2 = Player(world, sp_paddle2, 780, 250, True)
    ball = Ball(world, sp_ball, 390, 290)
    ball.velocity.vx = -BALL_SPEED
    collision.ball = ball
    aicontroller.ball = ball

    running = True
    while running:
        for event in sdl2.ext.get_events():
            if event.type == sdl2.SDL_QUIT:
                running = False
                break
            if event.type == sdl2.SDL_KEYDOWN:
                if event.key.keysym.sym == sdl2.SDLK_UP:
                    player1.velocity.vy = -PADDLE_SPEED
                elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                    player1.velocity.vy = PADDLE_SPEED
            elif event.type == sdl2.SDL_KEYUP:
                if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
                    player1.velocity.vy = 0
        sdl2.SDL_Delay(10)
        world.process() 
開發者ID:marcusva,項目名稱:py-sdl2,代碼行數:60,代碼來源:pong.py


注:本文中的sdl2.SDL_KEYDOWN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。