本文整理汇总了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)]
示例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()
示例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)
示例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
示例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
示例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
示例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
示例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()
示例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
示例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
示例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()