|
3 | 3 | raylib [core] example - Mouse input
|
4 | 4 |
|
5 | 5 | """
|
6 |
| -import pyray |
| 6 | +from pyray import * |
7 | 7 | from raylib.colors import (
|
8 | 8 | RAYWHITE,
|
9 | 9 | DARKGRAY,
|
10 | 10 | MAROON,
|
11 |
| - DARKBLUE, |
12 | 11 | LIME,
|
| 12 | + DARKBLUE, |
| 13 | + PURPLE, |
| 14 | + YELLOW, |
| 15 | + ORANGE, |
| 16 | + BEIGE, |
| 17 | +) |
| 18 | +from raylib import ( |
| 19 | + MOUSE_BUTTON_LEFT, |
| 20 | + MOUSE_BUTTON_MIDDLE, |
| 21 | + MOUSE_BUTTON_RIGHT, |
| 22 | + MOUSE_BUTTON_SIDE, |
| 23 | + MOUSE_BUTTON_EXTRA, |
| 24 | + MOUSE_BUTTON_FORWARD, |
| 25 | + MOUSE_BUTTON_BACK |
13 | 26 | )
|
14 |
| - |
15 |
| - |
16 |
| - |
17 | 27 |
|
18 | 28 | # Initialization
|
19 | 29 | SCREEN_WIDTH = 800
|
20 | 30 | SCREEN_HEIGHT = 450
|
21 | 31 |
|
22 |
| -pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, |
23 |
| - 'raylib [core] example - mouse input') |
| 32 | +init_window(SCREEN_WIDTH, SCREEN_HEIGHT, |
| 33 | + 'raylib [core] example - mouse input') |
24 | 34 |
|
25 |
| -ball_position = pyray.Vector2(-100, -100) |
| 35 | +ball_position = Vector2(-100, -100) |
26 | 36 | ball_color = DARKBLUE
|
27 | 37 |
|
28 |
| -pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second |
29 |
| - |
| 38 | +set_target_fps(60) # Set our game to run at 60 frames-per-second |
30 | 39 |
|
31 | 40 | # Main game loop
|
32 |
| -while not pyray.window_should_close(): # Detect window close button or ESC key |
| 41 | +while not window_should_close(): # Detect window close button or ESC key |
33 | 42 | # Update
|
34 |
| - ball_position = pyray.get_mouse_position() |
| 43 | + ball_position = get_mouse_position() |
35 | 44 |
|
36 |
| - if pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_LEFT): |
| 45 | + if is_mouse_button_pressed(MOUSE_BUTTON_LEFT): |
37 | 46 | ball_color = MAROON
|
38 |
| - elif pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_MIDDLE): |
| 47 | + print("MOUSE_BUTTON_LEFT") |
| 48 | + elif is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE): |
39 | 49 | ball_color = LIME
|
40 |
| - elif pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_RIGHT): |
| 50 | + print("MOUSE_BUTTON_MIDDLE") |
| 51 | + elif is_mouse_button_pressed(MOUSE_BUTTON_RIGHT): |
41 | 52 | ball_color = DARKBLUE
|
42 |
| - |
| 53 | + print("MOUSE_BUTTON_RIGHT") |
| 54 | + elif is_mouse_button_pressed(MOUSE_BUTTON_SIDE): |
| 55 | + ball_color = PURPLE |
| 56 | + print("MOUSE_BUTTON_SIDE") |
| 57 | + elif is_mouse_button_pressed(MOUSE_BUTTON_EXTRA): |
| 58 | + ball_color = YELLOW |
| 59 | + print("MOUSE_BUTTON_EXTRA") |
| 60 | + elif is_mouse_button_pressed(MOUSE_BUTTON_FORWARD): |
| 61 | + ball_color = ORANGE |
| 62 | + print("MOUSE_BUTTON_FORWARD") |
| 63 | + elif is_mouse_button_pressed(MOUSE_BUTTON_BACK): |
| 64 | + ball_color = BEIGE |
| 65 | + print("MOUSE_BUTTON_BACK") |
43 | 66 | # Draw
|
44 |
| - pyray.begin_drawing() |
| 67 | + begin_drawing() |
45 | 68 |
|
46 |
| - pyray.clear_background(RAYWHITE) |
47 |
| - pyray.draw_circle_v(ball_position, 40, ball_color) |
48 |
| - pyray.draw_text( |
| 69 | + clear_background(RAYWHITE) |
| 70 | + draw_circle_v(ball_position, 40, ball_color) |
| 71 | + draw_text( |
49 | 72 | 'move ball with mouse and click mouse button to change color',
|
50 | 73 | 10, 10, 20, DARKGRAY
|
51 | 74 | )
|
52 | 75 |
|
53 |
| - pyray.end_drawing() |
54 |
| - |
| 76 | + end_drawing() |
55 | 77 |
|
56 | 78 | # De-Initialization
|
57 |
| -pyray.close_window() # Close window and OpenGL context |
| 79 | +close_window() # Close window and OpenGL context |
0 commit comments