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


Python sdl2.SDL_KEYUP屬性代碼示例

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


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

示例1: orb_turn

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYUP [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

示例2: poll_events

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYUP [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

示例3: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYUP [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

示例4: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYUP [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

示例5: run

# 需要導入模塊: import sdl2 [as 別名]
# 或者: from sdl2 import SDL_KEYUP [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_KEYUP屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。