Skip to content

Commit db84739

Browse files
committed
Replaced bytes strings with unicode in examples.
Added models_billboard.py and model_box_collision.py examples.
1 parent a09bef3 commit db84739

9 files changed

+218
-36
lines changed

examples/core/core_2d_camera.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
# core_2d_camera.py
22

33
from raylibpy import *
4-
# from raylibpy.structures import *
5-
# from raylibpy.constants import *
6-
# from raylibpy.colors import *
7-
# from raylibpy.core import *
8-
# from raylibpy.text import *
9-
# from raylibpy.shapes import *
4+
105

116
MAX_BUILDINGS = 100
127

@@ -17,7 +12,7 @@ def main():
1712
screen_width = 800
1813
screen_height = 450
1914

20-
init_window(screen_width, screen_height, b"raylib [core] example - 2d camera")
15+
init_window(screen_width, screen_height, "raylib [core] example - 2d camera")
2116

2217
player = Rectangle(400, 280, 40, 40)
2318
buildings = []
@@ -111,7 +106,7 @@ def main():
111106

112107
end_mode2d()
113108

114-
draw_text(b"SCREEN AREA", 640, 10, 20, RED)
109+
draw_text("SCREEN AREA", 640, 10, 20, RED)
115110

116111
draw_rectangle(0, 0, screen_width, 5, RED)
117112
draw_rectangle(0, 5, 5, screen_height - 10, RED)
@@ -121,11 +116,11 @@ def main():
121116
draw_rectangle( 10, 10, 250, 113, fade(SKYBLUE, 0.5))
122117
draw_rectangle_lines( 10, 10, 250, 113, BLUE)
123118

124-
draw_text(b"Free 2d camera controls:", 20, 20, 10, BLACK)
125-
draw_text(b"- Right/Left to move Offset", 40, 40, 10, DARKGRAY)
126-
draw_text(b"- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY)
127-
draw_text(b"- A / S to Rotate", 40, 80, 10, DARKGRAY)
128-
draw_text(b"- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY)
119+
draw_text("Free 2d camera controls:", 20, 20, 10, BLACK)
120+
draw_text("- Right/Left to move Offset", 40, 40, 10, DARKGRAY)
121+
draw_text("- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY)
122+
draw_text("- A / S to Rotate", 40, 80, 10, DARKGRAY)
123+
draw_text("- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY)
129124

130125
end_drawing()
131126
# -----------------------------------------------------------

examples/core/core_3d_camera_first_person.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main():
1313
screen_width = 800
1414
screen_height = 450
1515

16-
rl.init_window(screen_width, screen_height, b"raylib [core] example - 3d camera 1st person")
16+
rl.init_window(screen_width, screen_height, "raylib [core] example - 3d camera 1st person")
1717

1818
# Define the camera to look into our 3d world (position, target, up vector)
1919
camera = rl.Camera(
@@ -76,8 +76,8 @@ def main():
7676
rl.draw_cube(position, 2.0, heights[i], 2.0, colors[i])
7777
rl.draw_cube_wires(position, 2.0, heights[i], 2.0, rl.MAROON)
7878

79-
rl.draw_rectangle(int(camera.target.x), int(-500), 1, screen_height * 4, rl.GREEN)
80-
rl.draw_rectangle(int(-500), int(camera.target.y), screen_width * 4, 1, rl.GREEN)
79+
rl.draw_rectangle(camera.target.x, -500, 1, screen_height * 4, rl.GREEN)
80+
rl.draw_rectangle(-500, camera.target.y, screen_width * 4, 1, rl.GREEN)
8181

8282
rl.end_mode3d()
8383

@@ -86,9 +86,9 @@ def main():
8686
rl.draw_rectangle(10, 10, 220, 70, rl.fade(rl.SKYBLUE, 0.5))
8787
rl.draw_rectangle_lines(10, 10, 220, 70, rl.BLUE)
8888

89-
rl.draw_text(b"First person camera default controls:", 20, 20, 10, rl.BLACK)
90-
rl.draw_text(b"- Move with keys: W, A, S, D", 40, 40, 10, rl.DARKGRAY)
91-
rl.draw_text(b"- Mouse move to look around", 40, 60, 10, rl.DARKGRAY)
89+
rl.draw_text("First person camera default controls:", 20, 20, 10, rl.BLACK)
90+
rl.draw_text("- Move with keys: W, A, S, D", 40, 40, 10, rl.DARKGRAY)
91+
rl.draw_text("- Mouse move to look around", 40, 60, 10, rl.DARKGRAY)
9292

9393
rl.end_drawing()
9494
# -----------------------------------------------------------

examples/core/core_3d_camera_free.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main():
1313
screen_width = 800
1414
screen_height = 450
1515

16-
rl.init_window(screen_width, screen_height, b"raylib [core] example - 3d camera free")
16+
rl.init_window(screen_width, screen_height, "raylib [core] example - 3d camera free")
1717

1818
# Define the camera to look into our 3d world
1919
camera = rl.Camera(
@@ -59,12 +59,12 @@ def main():
5959
rl.draw_rectangle(10, 10, 320, 133, rl.fade(rl.SKYBLUE, 0.5))
6060
rl.draw_rectangle_lines(10, 10, 320, 133, rl.BLUE)
6161

62-
rl.draw_text(b"Free camera default controls:", 20, 20, 10, rl.BLACK)
63-
rl.draw_text(b"- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DARKGRAY)
64-
rl.draw_text(b"- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DARKGRAY)
65-
rl.draw_text(b"- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, rl.DARKGRAY)
66-
rl.draw_text(b"- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, rl.DARKGRAY)
67-
rl.draw_text(b"- Z to Zoom to (0, 0, 0)", 40, 120, 10, rl.DARKGRAY)
62+
rl.draw_text("Free camera default controls:", 20, 20, 10, rl.BLACK)
63+
rl.draw_text("- Mouse Wheel to Zoom in-out", 40, 40, 10, rl.DARKGRAY)
64+
rl.draw_text("- Mouse Wheel Pressed to Pan", 40, 60, 10, rl.DARKGRAY)
65+
rl.draw_text("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, rl.DARKGRAY)
66+
rl.draw_text("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, rl.DARKGRAY)
67+
rl.draw_text("- Z to Zoom to (0, 0, 0)", 40, 120, 10, rl.DARKGRAY)
6868

6969
rl.end_drawing()
7070
# -----------------------------------------------------------

examples/core/core_3d_picking.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def main() -> int:
99
screen_width: int = 800
1010
screen_height: int = 450
1111

12-
init_window(screen_width, screen_height, b"raylib [core] example - 3d picking")
12+
init_window(screen_width, screen_height, "raylib [core] example - 3d picking")
1313

1414
# Define the camera to look into our 3d world
1515
camera: Camera = Camera()
@@ -80,10 +80,10 @@ def main() -> int:
8080

8181
end_mode3d()
8282

83-
draw_text(b"Try Selecting the box with mouse!", 240, 10, 20, DARKGRAY)
83+
draw_text("Try Selecting the box with mouse!", 240, 10, 20, DARKGRAY)
8484

8585
if collision:
86-
draw_text(b"BOX SELECTED", (screen_width - measure_text(b"BOX SELECTED", 30)) // 2, int(screen_height * .1), 30, GREEN)
86+
draw_text("BOX SELECTED", (screen_width - measure_text("BOX SELECTED", 30)) // 2, int(screen_height * .1), 30, GREEN)
8787

8888
end_drawing()
8989
# ---------------------------------------------------------------------------------

examples/core/core_basic_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
def main():
66

7-
rl.init_window(800, 450, b"raylib [core] example - basic window")
7+
rl.init_window(800, 450, "raylib [core] example - basic window")
88

99
rl.set_target_fps(60)
1010

1111
while not rl.window_should_close():
1212

1313
rl.begin_drawing()
1414
rl.clear_background(rl.RAYWHITE)
15-
rl.draw_text(b"Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
15+
rl.draw_text("Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
1616
rl.end_drawing()
1717

1818
rl.close_window()

examples/core/core_drop_files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def main() -> int:
99
screen_width: int = 800
1010
screen_height: int = 450
1111

12-
init_window(screen_width, screen_height, b"raylibpy [core] example - drop files")
12+
init_window(screen_width, screen_height, "raylibpy [core] example - drop files")
1313

1414
dropped_files: list = []
1515

@@ -30,9 +30,9 @@ def main() -> int:
3030
clear_background(RAYWHITE)
3131

3232
if len(dropped_files) == 0:
33-
draw_text(b"Drop your files to this window!", 100, 40, 20, DARKGRAY)
33+
draw_text("Drop your files to this window!", 100, 40, 20, DARKGRAY)
3434
else:
35-
draw_text(b"Dropped files:", 100, 40, 20, DARKGRAY)
35+
draw_text("Dropped files:", 100, 40, 20, DARKGRAY)
3636

3737
for i, drop_file in enumerate(dropped_files):
3838
if i % 2 == 0:
@@ -42,7 +42,7 @@ def main() -> int:
4242

4343
draw_text(drop_file, 120, 100 + 40 * i, 10, GRAY)
4444

45-
draw_text(b"Drop new files...", 100, 110 + 40 * len(dropped_files), 20, DARKGRAY)
45+
draw_text("Drop new files...", 100, 110 + 40 * len(dropped_files), 20, DARKGRAY)
4646

4747
end_drawing()
4848
# ---------------------------------------------------------------------------------

examples/models/models_billboard.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# models_billboard.py
2+
3+
from raylibpy import *
4+
5+
def main() -> int:
6+
7+
# Initialization
8+
# -------------------------------------------------------------------------------------
9+
screen_width: int = 800
10+
screen_height: int = 450
11+
12+
init_window(screen_width, screen_height, "raylibpy [models] example - drawing billboard")
13+
14+
# Define the camera to look into our 3d world
15+
camera: Camera = Camera()
16+
camera.position = Vector3(5., 4., 5.)
17+
camera.target = Vector3(0., 2., 0.)
18+
camera.up = Vector3(0., 1., 0.)
19+
camera.fovy = 45.0
20+
camera.type = CAMERA_PERSPECTIVE
21+
22+
23+
bill: Texture2D = load_texture("resources/billboard.png")
24+
bill_position = Vector3(0., 2., 0.)
25+
26+
set_camera_mode(camera, CAMERA_ORBITAL)
27+
28+
set_target_fps(60)
29+
30+
# Main game loop
31+
while not window_should_close():
32+
# Update
33+
# ---------------------------------------------------------------------------------
34+
update_camera(byref(camera))
35+
# ----------------------------------------------------------------------------------
36+
37+
# Draw
38+
# ---------------------------------------------------------------------------------
39+
begin_drawing()
40+
41+
clear_background(RAYWHITE)
42+
43+
begin_mode3d(camera)
44+
45+
draw_billboard(camera, bill, bill_position, 2., WHITE)
46+
47+
draw_grid(10, 1.0)
48+
49+
end_mode3d()
50+
51+
draw_fps(10, 10)
52+
53+
end_drawing()
54+
# ---------------------------------------------------------------------------------
55+
56+
# De-Initialization
57+
# -------------------------------------------------------------------------------------
58+
unload_texture(bill)
59+
60+
close_window()
61+
# -------------------------------------------------------------------------------------
62+
63+
return 0
64+
65+
66+
if __name__ == '__main__':
67+
main()
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# models_box_collisions.py
2+
3+
from raylibpy import *
4+
5+
def main() -> int:
6+
7+
# Initialization
8+
# -------------------------------------------------------------------------------------
9+
screen_width: int = 800
10+
screen_height: int = 450
11+
12+
init_window(screen_width, screen_height, "raylib [models] example - box collision")
13+
14+
# Define the camera to look into our 3d world
15+
camera: Camera = Camera()
16+
camera.position = Vector3(0., 10., 10.)
17+
camera.target = Vector3(0., 0., 0.)
18+
camera.up = Vector3(0., 1., 0.)
19+
camera.fovy = 45.0
20+
camera.type = CAMERA_PERSPECTIVE
21+
22+
player_position: Vector3 = Vector3(0., 1., 2.)
23+
player_size: Vector3 = Vector3(1., 2., 1.)
24+
player_color: Color = GREEN
25+
26+
enemy_box_pos: Vector3 = Vector3(-4, 1., 0.)
27+
enemy_box_size: Vector3 = Vector3(2., 2., 2.)
28+
29+
enemy_sphere_pos: Vector3 = Vector3(4, 1.5, 0.)
30+
enemy_sphere_size: float = 1.5
31+
32+
collision: bool = False
33+
34+
set_target_fps(60)
35+
36+
# Main game loop
37+
while not window_should_close():
38+
# Update
39+
# ---------------------------------------------------------------------------------
40+
41+
# Mode player
42+
if is_key_down(KEY_RIGHT):
43+
player_position.x += 0.2
44+
elif is_key_down(KEY_LEFT):
45+
player_position.x -= 0.2
46+
elif is_key_down(KEY_DOWN):
47+
player_position.z += 0.2
48+
elif is_key_down(KEY_UP):
49+
player_position.z -= 0.2
50+
51+
collision = False
52+
53+
#
54+
player_bbox = BoundingBox(
55+
Vector3(player_position.x - player_size.x / 2,
56+
player_position.y - player_size.y / 2,
57+
player_position.z - player_size.z / 2),
58+
Vector3(player_position.x + player_size.x / 2,
59+
player_position.y + player_size.y / 2,
60+
player_position.z + player_size.z / 2),
61+
)
62+
if check_collision_boxes(
63+
player_bbox,
64+
BoundingBox(
65+
Vector3(enemy_box_pos.x - enemy_box_size.x / 2,
66+
enemy_box_pos.y - enemy_box_size.y / 2,
67+
enemy_box_pos.z - enemy_box_size.z / 2),
68+
Vector3(enemy_box_pos.x + enemy_box_size.x / 2,
69+
enemy_box_pos.y + enemy_box_size.y / 2,
70+
enemy_box_pos.z + enemy_box_size.z / 2))):
71+
collision = True
72+
73+
if check_collision_box_sphere(player_bbox, enemy_sphere_pos, enemy_sphere_size):
74+
collision = True
75+
76+
if collision:
77+
player_color = RED
78+
else:
79+
player_color = GREEN
80+
81+
update_camera(byref(camera))
82+
# ----------------------------------------------------------------------------------
83+
84+
# Draw
85+
# ---------------------------------------------------------------------------------
86+
begin_drawing()
87+
88+
clear_background(RAYWHITE)
89+
90+
begin_mode3d(camera)
91+
92+
draw_cube(enemy_box_pos, enemy_box_size.x, enemy_box_size.y, enemy_box_size.z, GRAY)
93+
draw_cube_wires(enemy_box_pos, enemy_box_size.x, enemy_box_size.y, enemy_box_size.z, DARKGRAY)
94+
95+
draw_sphere(enemy_sphere_pos, enemy_sphere_size, GRAY)
96+
draw_sphere_wires(enemy_sphere_pos, enemy_sphere_size, 16, 16, DARKGRAY)
97+
98+
draw_cube_v(player_position, player_size, player_color)
99+
100+
draw_grid(10, 1.0)
101+
102+
end_mode3d()
103+
104+
draw_text("Move player with cursors to collide", 220, 40, 20, GRAY)
105+
106+
draw_fps(10, 10)
107+
108+
end_drawing()
109+
# ---------------------------------------------------------------------------------
110+
111+
# De-Initialization
112+
# -------------------------------------------------------------------------------------
113+
close_window()
114+
# -------------------------------------------------------------------------------------
115+
116+
return 0
117+
118+
119+
if __name__ == '__main__':
120+
main()

raylibpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ class VrDeviceInfo(Structure):
21262126
_rl.InitWindow.restype = None
21272127
def init_window(width: int, height: int, title: AnyStr) -> None:
21282128
"""Initialize window and OpenGL context"""
2129-
return _rl.InitWindow(_int(width), _int(width), _str_in(title))
2129+
return _rl.InitWindow(_int(width), _int(height), _str_in(title))
21302130

21312131

21322132
_rl.CloseWindow.argtypes = _NOARGS

0 commit comments

Comments
 (0)