Skip to content

Commit a33f4fc

Browse files
update examples
1 parent 4071263 commit a33f4fc

40 files changed

+232
-321
lines changed

examples/audio/audio_module_playing.py

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,18 @@
66
import dataclasses
77
import pyray
88
import raylib as rl
9-
from raylib.colors import (
10-
RAYWHITE,
11-
ORANGE,
12-
RED,
13-
GOLD,
14-
LIME,
15-
BLUE,
16-
VIOLET,
17-
BROWN,
18-
LIGHTGRAY,
19-
PINK,
20-
YELLOW,
21-
GREEN,
22-
SKYBLUE,
23-
PURPLE,
24-
BEIGE,
25-
MAROON,
26-
GRAY,
27-
BLACK
28-
)
299

3010

3111
MAX_CIRCLES=64
3212

3313

3414
@dataclasses.dataclass
3515
class CircleWave:
36-
position: 'rl.Vector2'
16+
position: pyray.Vector2
3717
radius: float
3818
alpha: float
3919
speed: float
40-
color: 'rl.Color'
41-
20+
color: pyray.Color
4221

4322
screenWidth = 800
4423
screenHeight = 450
@@ -49,8 +28,8 @@ class CircleWave:
4928

5029
rl.InitAudioDevice() # Initialize audio device
5130

52-
colors = [ ORANGE, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK,
53-
YELLOW, GREEN, SKYBLUE, PURPLE, BEIGE ]
31+
colors = [pyray.ORANGE, pyray.RED, pyray.GOLD, pyray.LIME, pyray.BLUE, pyray.VIOLET, pyray.BROWN, pyray.LIGHTGRAY, pyray.PINK,
32+
pyray.YELLOW, pyray.GREEN, pyray.SKYBLUE, pyray.PURPLE, pyray.BEIGE]
5433

5534
# Creates some circles for visual effect
5635
circles = []
@@ -141,23 +120,23 @@ class CircleWave:
141120
#----------------------------------------------------------------------------------
142121
pyray.begin_drawing()
143122

144-
pyray.clear_background(RAYWHITE)
123+
pyray.clear_background(pyray.RAYWHITE)
145124

146125
for i in range(MAX_CIRCLES):
147-
pyray.draw_circle_v(circles[i].position, circles[i].radius, rl.Fade(circles[i].color, circles[i].alpha))
126+
pyray.draw_circle_v(circles[i].position, circles[i].radius, pyray.fade(circles[i].color, circles[i].alpha))
148127

149128
# Draw time bar
150-
pyray.draw_rectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, LIGHTGRAY)
151-
pyray.draw_rectangle(20, screenHeight - 20 - 12, int(timePlayed), 12, MAROON)
152-
pyray.draw_rectangle_lines(20, screenHeight - 20 - 12, screenWidth - 40, 12, GRAY)
129+
pyray.draw_rectangle(20, screenHeight - 20 - 12, screenWidth - 40, 12, pyray.LIGHTGRAY)
130+
pyray.draw_rectangle(20, screenHeight - 20 - 12, int(timePlayed), 12, pyray.MAROON)
131+
pyray.draw_rectangle_lines(20, screenHeight - 20 - 12, screenWidth - 40, 12, pyray.GRAY)
153132

154133
# Draw help instructions
155-
pyray.draw_rectangle(20, 20, 425, 145, RAYWHITE)
156-
pyray.draw_rectangle_lines(20, 20, 425, 145, GRAY)
157-
pyray.draw_text("PRESS SPACE TO RESTART MUSIC", 40, 40, 20, BLACK)
158-
pyray.draw_text("PRESS P TO PAUSE/RESUME", 40, 70, 20, BLACK)
159-
pyray.draw_text("PRESS UP/DOWN TO CHANGE SPEED", 40, 100, 20, BLACK)
160-
pyray.draw_text(f"SPEED: {pitch}", 40, 130, 20, MAROON)
134+
pyray.draw_rectangle(20, 20, 425, 145, pyray.RAYWHITE)
135+
pyray.draw_rectangle_lines(20, 20, 425, 145, pyray.GRAY)
136+
pyray.draw_text("PRESS SPACE TO RESTART MUSIC", 40, 40, 20, pyray.BLACK)
137+
pyray.draw_text("PRESS P TO PAUSE/RESUME", 40, 70, 20, pyray.BLACK)
138+
pyray.draw_text("PRESS UP/DOWN TO CHANGE SPEED", 40, 100, 20, pyray.BLACK)
139+
pyray.draw_text(f"SPEED: {pitch}", 40, 130, 20, pyray.MAROON)
161140

162141
pyray.end_drawing()
163142
#----------------------------------------------------------------------------------

examples/core/core_2d_camera.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@
5757
# Update
5858

5959
# Player movement
60-
if pyray.is_key_down(pyray.KEY_RIGHT):
60+
if pyray.is_key_down(pyray.KeyboardKey.KEY_RIGHT):
6161
player.x += 2
62-
elif pyray.is_key_down(pyray.KEY_LEFT):
62+
elif pyray.is_key_down(pyray.KeyboardKey.KEY_LEFT):
6363
player.x -= 2
6464

6565
# Camera target follows player
6666
camera.target = pyray.Vector2(player.x + 20, player.y + 20)
6767

6868
# Camera rotation controls
69-
if pyray.is_key_down(pyray.KEY_A):
69+
if pyray.is_key_down(pyray.KeyboardKey.KEY_A):
7070
camera.rotation -= 1
71-
elif pyray.is_key_down(pyray.KEY_S):
71+
elif pyray.is_key_down(pyray.KeyboardKey.KEY_S):
7272
camera.rotation += 1
7373

7474
# Limit camera rotation to 80 degrees (-40 to 40)
@@ -86,7 +86,7 @@
8686
camera.zoom = 0.1
8787

8888
# Camera reset (zoom and rotation)
89-
if pyray.is_key_pressed(pyray.KEY_R):
89+
if pyray.is_key_pressed(pyray.KeyboardKey.KEY_R):
9090
camera.zoom = 1.0
9191
camera.rotation = 0.0
9292

examples/core/core_2d_camera_mouse_zoom.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414
camera = pyray.Camera2D()
1515

16-
camera = pyray.Camera2D()
1716
camera.zoom = 1.0
1817

19-
pyray.set_target_fps(60);
18+
pyray.set_target_fps(60)
2019

2120
# main game loop
2221
while not pyray.window_should_close():
2322
# update
24-
if pyray.is_mouse_button_down(pyray.MOUSE_BUTTON_RIGHT):
23+
if pyray.is_mouse_button_down(pyray.MouseButton.MOUSE_BUTTON_RIGHT):
2524
delta = pyray.get_mouse_delta()
2625
delta = pyray.vector2_scale(delta, -1.0 / camera.zoom)
2726
camera.target = pyray.vector2_add(camera.target, delta)
@@ -58,7 +57,7 @@
5857

5958
pyray.end_mode_2d()
6059

61-
pyray.draw_text("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, pyray.WHITE);
60+
pyray.draw_text("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, pyray.WHITE)
6261

6362
pyray.end_drawing()
6463

examples/core/core_2d_camera_platformer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def __init__(self, rect, blocking, color):
6262

6363

6464
def update_player(player, env_items, delta):
65-
if pyray.is_key_down(pyray.KEY_LEFT):
65+
if pyray.is_key_down(pyray.KeyboardKey.KEY_LEFT):
6666
player.position.x -= PLAYER_HOR_SPD * delta
67-
if pyray.is_key_down(pyray.KEY_RIGHT):
67+
if pyray.is_key_down(pyray.KeyboardKey.KEY_RIGHT):
6868
player.position.x += PLAYER_HOR_SPD * delta
69-
if pyray.is_key_down(pyray.KEY_SPACE) and player.can_jump:
69+
if pyray.is_key_down(pyray.KeyboardKey.KEY_SPACE) and player.can_jump:
7070
player.speed = -PLAYER_JUMP_SPD
7171
player.can_jump = False
7272

@@ -264,11 +264,11 @@ def update_camera_player_bounds_push(
264264
elif camera.zoom < 0.25:
265265
camera.zoom = 0.25
266266

267-
if pyray.is_key_pressed(pyray.KEY_R):
267+
if pyray.is_key_pressed(pyray.KeyboardKey.KEY_R):
268268
camera.zoom = 1.0
269269
player.position = pyray.Vector2(400, 280)
270270

271-
if pyray.is_key_pressed(pyray.KEY_C):
271+
if pyray.is_key_pressed(pyray.KeyboardKey.KEY_C):
272272
camera_option = (camera_option + 1) % camera_updaters_length
273273

274274
# Call update camera function by its pointer

examples/core/core_3d_camera_first_person_incomplete.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010
SCREEN_WIDTH = 800
1111
SCREEN_HEIGHT = 450
1212

13-
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, b"raylib [core] example - 3d camera first person")
13+
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - 3d camera first person")
1414

1515
# Define the camera to look into our 3d world (position, target, up vector)
1616
camera = pyray.Camera3D()
1717
camera.position = pyray.Vector3(4.0, 2.0, 4.0)
1818
camera.target = pyray.Vector3(0.0, 1.8, 0.0)
1919
camera.up = pyray.Vector3(0.0, 1.0, 0.0)
2020
camera.fovy = 60.0
21-
camera.projection = pyray.CAMERA_PERSPECTIVE
21+
camera.projection = pyray.CameraProjection.CAMERA_PERSPECTIVE
2222

2323
# Generates some random columns
24-
heights = [None] * MAX_COLUMNS
25-
positions = [None] * MAX_COLUMNS
26-
colors = [None] * MAX_COLUMNS
24+
heights = []
25+
positions = []
26+
colors = []
2727

2828
for i in range(MAX_COLUMNS):
29-
heights[i] = pyray.get_random_value(1, 12) * 1.0
30-
positions[i] = pyray.Vector3(pyray.get_random_value(-15, 15) * 1.0, heights[i]/2.0 * 1.0, pyray.get_random_value(-15, 15) * 1.0)
31-
colors[i] = pyray.Color(pyray.get_random_value(20, 255), pyray.get_random_value(10, 55), 30, 255)
29+
heights.append(pyray.get_random_value(1, 12) * 1.0)
30+
positions.append(pyray.Vector3(pyray.get_random_value(-15, 15) * 1.0, heights[i]/2.0 * 1.0, pyray.get_random_value(-15, 15) * 1.0))
31+
colors.append(pyray.Color(pyray.get_random_value(20, 255), pyray.get_random_value(10, 55), 30, 255))
3232

3333

3434
pyray.set_target_fps(60)
3535

3636
while not pyray.window_should_close():
3737

38-
pyray.update_camera(camera, pyray.CAMERA_FIRST_PERSON)
38+
pyray.update_camera(camera, pyray.CameraMode.CAMERA_FIRST_PERSON)
3939

4040
pyray.begin_drawing()
4141

examples/core/core_3d_camera_free_incomplete.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# Update
2626
update_camera(camera, CameraMode.CAMERA_FREE)
2727

28-
if is_key_pressed(KEY_Z):
28+
if is_key_pressed(KeyboardKey.KEY_Z):
2929
camera.target = Vector3(0.0, 0.0, 0.0)
3030

3131
# Draw

examples/core/core_3d_camera_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
pyray.end_mode_3d()
4242

43-
pyray.draw_text("Welcome to the third dimension!", 10, 40, 20, pyray.DARKGRAY);
43+
pyray.draw_text("Welcome to the third dimension!", 10, 40, 20, pyray.DARKGRAY)
4444

4545
pyray.draw_fps(10, 10)
4646

examples/core/core_basic_screen_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def main():
2727
if frame_count > 120:
2828
current_screen = GameScreen.TITLE
2929
elif current_screen == GameScreen.TITLE:
30-
if is_key_pressed(KEY_ENTER) or is_gesture_detected(GESTURE_TAP):
30+
if is_key_pressed(KeyboardKey.KEY_ENTER) or is_gesture_detected(Gesture.GESTURE_TAP):
3131
current_screen = GameScreen.GAMEPLAY
3232
elif current_screen == GameScreen.GAMEPLAY:
33-
if is_key_pressed(KEY_ENTER) or is_gesture_detected(GESTURE_TAP):
33+
if is_key_pressed(KeyboardKey.KEY_ENTER) or is_gesture_detected(Gesture.GESTURE_TAP):
3434
current_screen = GameScreen.ENDING
3535
elif current_screen == GameScreen.ENDING:
36-
if is_key_pressed(KEY_ENTER) or is_gesture_detected(GESTURE_TAP):
36+
if is_key_pressed(KeyboardKey.KEY_ENTER) or is_gesture_detected(Gesture.GESTURE_TAP):
3737
current_screen = GameScreen.TITLE
3838

3939
begin_drawing()

examples/core/core_drop_files.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
1212
"""
1313
import pyray
14-
from raylib.colors import (
15-
RAYWHITE,
16-
DARKGRAY,
17-
LIGHTGRAY,
18-
GRAY
19-
)
2014

2115
screenWidth = 800
2216
screenHeight = 450
@@ -36,21 +30,21 @@
3630

3731
pyray.begin_drawing()
3832

39-
pyray.clear_background(RAYWHITE)
33+
pyray.clear_background(pyray.RAYWHITE)
4034

4135
if droppedFiles.count == 0:
42-
pyray.draw_text("Drop your files to this window!", 100, 40, 20, DARKGRAY)
36+
pyray.draw_text("Drop your files to this window!", 100, 40, 20, pyray.DARKGRAY)
4337
else:
44-
pyray.draw_text("Dropped files:", 100, 40, 20, DARKGRAY)
38+
pyray.draw_text("Dropped files:", 100, 40, 20, pyray.DARKGRAY)
4539

4640
for i in range(0, droppedFiles.count):
4741
if i % 2 == 0:
48-
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.5))
42+
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(pyray.LIGHTGRAY, 0.5))
4943
else:
50-
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.3))
51-
pyray.draw_text(droppedFiles.paths[i], 120, 100 + 40*i, 10, GRAY)
44+
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(pyray.LIGHTGRAY, 0.3))
45+
pyray.draw_text(droppedFiles.paths[i], 120, 100 + 40*i, 10, pyray.GRAY)
5246

53-
pyray.draw_text("Drop new files...", 100, 110 + 40*droppedFiles.count, 20, DARKGRAY)
47+
pyray.draw_text("Drop new files...", 100, 110 + 40*droppedFiles.count, 20, pyray.DARKGRAY)
5448
pyray.end_drawing()
5549

5650
# De-Initialization

examples/core/core_input_gestures.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
55
"""
66
import pyray
7-
from raylib.colors import (
8-
RAYWHITE,
9-
LIGHTGRAY,
10-
DARKGRAY,
11-
MAROON,
12-
GRAY,
13-
)
147

158

169

@@ -26,20 +19,20 @@
2619

2720
gesture_strings = []
2821

29-
current_gesture = pyray.GESTURE_NONE
30-
last_gesture = pyray.GESTURE_NONE
22+
current_gesture = pyray.Gesture.GESTURE_NONE
23+
last_gesture = pyray.Gesture.GESTURE_NONE
3124

3225
GESTURE_LABELS = {
33-
pyray.GESTURE_TAP: 'GESTURE TAP',
34-
pyray.GESTURE_DOUBLETAP: 'GESTURE DOUBLETAP',
35-
pyray.GESTURE_HOLD: 'GESTURE HOLD',
36-
pyray.GESTURE_DRAG: 'GESTURE DRAG',
37-
pyray.GESTURE_SWIPE_RIGHT: 'GESTURE SWIPE RIGHT',
38-
pyray.GESTURE_SWIPE_LEFT: 'GESTURE SWIPE LEFT',
39-
pyray.GESTURE_SWIPE_UP: 'GESTURE SWIPE UP',
40-
pyray.GESTURE_SWIPE_DOWN: 'GESTURE SWIPE DOWN',
41-
pyray.GESTURE_PINCH_IN: 'GESTURE PINCH IN',
42-
pyray.GESTURE_PINCH_OUT: 'GESTURE PINCH OUT',
26+
pyray.Gesture.GESTURE_TAP: 'GESTURE TAP',
27+
pyray.Gesture.GESTURE_DOUBLETAP: 'GESTURE DOUBLETAP',
28+
pyray.Gesture.GESTURE_HOLD: 'GESTURE HOLD',
29+
pyray.Gesture.GESTURE_DRAG: 'GESTURE DRAG',
30+
pyray.Gesture.GESTURE_SWIPE_RIGHT: 'GESTURE SWIPE RIGHT',
31+
pyray.Gesture.GESTURE_SWIPE_LEFT: 'GESTURE SWIPE LEFT',
32+
pyray.Gesture.GESTURE_SWIPE_UP: 'GESTURE SWIPE UP',
33+
pyray.Gesture.GESTURE_SWIPE_DOWN: 'GESTURE SWIPE DOWN',
34+
pyray.Gesture.GESTURE_PINCH_IN: 'GESTURE PINCH IN',
35+
pyray.Gesture.GESTURE_PINCH_OUT: 'GESTURE PINCH OUT',
4336
}
4437

4538
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
@@ -54,7 +47,7 @@
5447

5548
if (
5649
pyray.check_collision_point_rec(touch_position, touch_area)
57-
and current_gesture != pyray.GESTURE_NONE
50+
and current_gesture != pyray.Gesture.GESTURE_NONE
5851
):
5952
if current_gesture != last_gesture:
6053
gesture_strings.append(GESTURE_LABELS[current_gesture])
@@ -66,34 +59,34 @@
6659
# Draw
6760
pyray.begin_drawing()
6861

69-
pyray.clear_background(RAYWHITE)
62+
pyray.clear_background(pyray.RAYWHITE)
7063

71-
pyray.draw_rectangle_rec(touch_area, GRAY)
64+
pyray.draw_rectangle_rec(touch_area, pyray.GRAY)
7265
pyray.draw_rectangle(225, 15, SCREEN_WIDTH - 240, SCREEN_HEIGHT - 30,
73-
RAYWHITE)
66+
pyray.RAYWHITE)
7467
pyray.draw_text(
7568
'GESTURES TEST AREA',
76-
SCREEN_WIDTH - 270, SCREEN_HEIGHT - 40, 20, pyray.fade(GRAY, 0.5)
69+
SCREEN_WIDTH - 270, SCREEN_HEIGHT - 40, 20, pyray.fade(pyray.GRAY, 0.5)
7770
)
7871

7972
for i, val in enumerate(gesture_strings):
8073
if i % 2 == 0:
8174
pyray.draw_rectangle(
82-
10, 30 + 20 * i, 200, 20, pyray.fade(LIGHTGRAY, 0.5))
75+
10, 30 + 20 * i, 200, 20, pyray.fade(pyray.LIGHTGRAY, 0.5))
8376
else:
8477
pyray.draw_rectangle(
85-
10, 30 + 20 * i, 200, 20, pyray.fade(LIGHTGRAY, 0.3))
78+
10, 30 + 20 * i, 200, 20, pyray.fade(pyray.LIGHTGRAY, 0.3))
8679

8780
if i < len(gesture_strings) - 1:
88-
pyray.draw_text(val, 35, 36 + 20 * i, 10, DARKGRAY)
81+
pyray.draw_text(val, 35, 36 + 20 * i, 10, pyray.DARKGRAY)
8982
else:
90-
pyray.draw_text(val, 35, 36 + 20 * i, 10, MAROON)
83+
pyray.draw_text(val, 35, 36 + 20 * i, 10, pyray.MAROON)
9184

92-
pyray.draw_rectangle_lines(10, 29, 200, SCREEN_HEIGHT - 50, GRAY)
93-
pyray.draw_text('DETECTED GESTURES', 50, 15, 10, GRAY)
85+
pyray.draw_rectangle_lines(10, 29, 200, SCREEN_HEIGHT - 50, pyray.GRAY)
86+
pyray.draw_text('DETECTED GESTURES', 50, 15, 10, pyray.GRAY)
9487

95-
if current_gesture != pyray.GESTURE_NONE:
96-
pyray.draw_circle_v(touch_position, 30, MAROON)
88+
if current_gesture != pyray.Gesture.GESTURE_NONE:
89+
pyray.draw_circle_v(touch_position, 30, pyray.MAROON)
9790

9891
pyray.end_drawing()
9992

0 commit comments

Comments
 (0)