Example #1
0
    pyray.draw_rectangle_rec(touch_area, GRAY)
    pyray.draw_rectangle(225, 15, SCREEN_WIDTH - 240, SCREEN_HEIGHT - 30,
                         RAYWHITE)
    pyray.draw_text('GESTURES TEST AREA', SCREEN_WIDTH - 270,
                    SCREEN_HEIGHT - 40, 20, pyray.fade(GRAY, 0.5))

    for i, val in enumerate(gesture_strings):
        if i % 2 == 0:
            pyray.draw_rectangle(10, 30 + 20 * i, 200, 20,
                                 pyray.fade(LIGHTGRAY, 0.5))
        else:
            pyray.draw_rectangle(10, 30 + 20 * i, 200, 20,
                                 pyray.fade(LIGHTGRAY, 0.3))

        if i < len(gesture_strings) - 1:
            pyray.draw_text(val, 35, 36 + 20 * i, 10, DARKGRAY)
        else:
            pyray.draw_text(val, 35, 36 + 20 * i, 10, MAROON)

    pyray.draw_rectangle_lines(10, 29, 200, SCREEN_HEIGHT - 50, GRAY)
    pyray.draw_text('DETECTED GESTURES', 50, 15, 10, GRAY)

    if current_gesture != pyray.GESTURE_NONE:
        pyray.draw_circle_v(touch_position, 30, MAROON)

    pyray.end_drawing()

# De-Initialization
pyray.close_window()  # Close window and OpenGL context
Example #2
0
ball_position = pyray.Vector2(-100, -100)
ball_color = DARKBLUE

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
    ball_position = pyray.get_mouse_position()

    if pyray.is_mouse_button_pressed(pyray.MOUSE_LEFT_BUTTON):
        ball_color = MAROON
    elif pyray.is_mouse_button_pressed(pyray.MOUSE_MIDDLE_BUTTON):
        ball_color = LIME
    elif pyray.is_mouse_button_pressed(pyray.MOUSE_RIGHT_BUTTON):
        ball_color = DARKBLUE

    # Draw
    pyray.begin_drawing()

    pyray.clear_background(RAYWHITE)
    pyray.draw_circle_v(ball_position, 40, ball_color)
    pyray.draw_text(
        'move ball with mouse and click mouse button to change color', 10, 10,
        20, DARKGRAY)

    pyray.end_drawing()

# De-Initialization
pyray.close_window()  # Close window and OpenGL context
Example #3
0
# 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