Core examples (#11)

* Added core_input_keys example

* Added core_basic_window example

* Added core_input_mouse example

* Added core_input_mouse_wheel example
This commit is contained in:
Matt Lebrun 2020-07-30 20:43:39 +08:00 committed by GitHub
parent 8a30502288
commit 76e945e1c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 199 additions and 0 deletions

View file

@ -0,0 +1,47 @@
"""
raylib [core] example - Keyboard input
"""
from raylib.pyray import PyRay
from raylib.colors import (
RAYWHITE,
DARKGRAY,
MAROON,
)
pyray = PyRay()
# Initialization
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT,
'raylib [core] example - keyboard input')
ball_position = pyray.Vector2(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
# Main game loop
while not pyray.window_should_close(): # Detect window close button or ESC key
# Update
if pyray.is_key_down(pyray.KEY_RIGHT): ball_position.x += 2
if pyray.is_key_down(pyray.KEY_LEFT): ball_position.x -= 2
if pyray.is_key_down(pyray.KEY_UP): ball_position.y -= 2
if pyray.is_key_down(pyray.KEY_DOWN): ball_position.y += 2
# Draw
pyray.begin_drawing()
pyray.clear_background(RAYWHITE)
pyray.draw_text('move the ball with arrow keys', 10, 10, 20, DARKGRAY)
pyray.draw_circle_v(ball_position, 50, MAROON)
pyray.end_drawing()
# De-Initialization
pyray.close_window() # Close window and OpenGL context