Skip to content

Commit ace2ee2

Browse files
committed
Initial commit, from personal computer to GitHub
0 parents  commit ace2ee2

24 files changed

+6086
-0
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/raylibpy.iml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/core/core_2d_camera.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# core_2d_camera.py
2+
3+
from raylibpy.structures import *
4+
from raylibpy.constants import *
5+
from raylibpy.colors import *
6+
from raylibpy.core import *
7+
from raylibpy.text import *
8+
from raylibpy.shapes import *
9+
10+
MAX_BUILDINGS = 100
11+
12+
def main():
13+
14+
# Initialization
15+
# ---------------------------------------------------------------
16+
screen_width = 800
17+
screen_height = 450
18+
19+
init_window(screen_width, screen_height, b"raylib [core] example - 2d camera")
20+
21+
player = Rectangle(400, 280, 40, 40)
22+
buildings = []
23+
build_colors = []
24+
25+
spacing = 0
26+
27+
for i in range(MAX_BUILDINGS):
28+
width = get_random_value(50, 200)
29+
height = get_random_value(100, 800)
30+
y = screen_height - 130 - height
31+
x = -6000 + spacing
32+
33+
buildings.append(Rectangle(x, y, width, height))
34+
35+
spacing += width
36+
37+
build_colors.append(Color(
38+
get_random_value(200, 240),
39+
get_random_value(200, 240),
40+
get_random_value(200, 250),
41+
255
42+
)
43+
)
44+
45+
camera = Camera2D(
46+
Vector2(0, 0),
47+
Vector2(player.x + 20, player.y + 20),
48+
0.0,
49+
1.0
50+
)
51+
52+
set_target_fps(60)
53+
# ---------------------------------------------------------------
54+
55+
# Main game loop
56+
while not window_should_close():
57+
58+
# Update
59+
# -----------------------------------------------------------
60+
if is_key_down(KEY_RIGHT):
61+
player.x += 2 # player movement
62+
camera.offset.x -= 2 # camera displacement with player movement
63+
64+
elif is_key_down(KEY_LEFT):
65+
player.x -= 2
66+
camera.offset.x += 2
67+
68+
# camera follows player
69+
camera.target = Vector2(player.x + 20, player.y + 20)
70+
71+
# camera rotation controls
72+
if is_key_down(KEY_A):
73+
camera.rotation -= 1
74+
elif is_key_down(KEY_S):
75+
camera.rotation += 1
76+
77+
# limit camera rotation to 80 degrees (-40 to 40)
78+
camera.rotation = max(-40, min(camera.rotation, 40))
79+
80+
# camera zoom controls
81+
camera.zoom += get_mouse_wheel_move() * 0.05
82+
83+
camera.zoom = max(0.1, min(camera.zoom, 3.0))
84+
85+
# camera reset (zoom and rotation)
86+
if is_key_pressed(KEY_R):
87+
camera.zoom = 1.0
88+
camera.rotation = 0.0
89+
# -----------------------------------------------------------
90+
91+
# Draw
92+
# -----------------------------------------------------------
93+
begin_drawing()
94+
95+
clear_background(RAYWHITE)
96+
97+
begin_mode2d(camera)
98+
99+
draw_rectangle(-6000, 300, 13000, 8000, DARKGRAY)
100+
101+
for i, rec in enumerate(buildings):
102+
draw_rectangle_rec(rec, build_colors[i])
103+
104+
draw_rectangle_rec(player, RED)
105+
106+
draw_rectangle(int(camera.target.x), int(-500), 1, screen_height * 4, GREEN)
107+
draw_rectangle(int(-500), int(camera.target.y), screen_width * 4, 1, GREEN)
108+
109+
end_mode2d()
110+
111+
draw_text(b"SCREEN AREA", 640, 10, 20, RED)
112+
113+
draw_rectangle(0, 0, screen_width, 5, RED)
114+
draw_rectangle(0, 5, 5, screen_height - 10, RED)
115+
draw_rectangle(screen_width - 5, 5, 5, screen_height - 10, RED)
116+
draw_rectangle(0, screen_height - 5, screen_width, 5, RED)
117+
118+
draw_rectangle( 10, 10, 250, 113, fade(SKYBLUE, 0.5))
119+
draw_rectangle_lines( 10, 10, 250, 113, BLUE)
120+
121+
draw_text(b"Free 2d camera controls:", 20, 20, 10, BLACK)
122+
draw_text(b"- Right/Left to move Offset", 40, 40, 10, DARKGRAY)
123+
draw_text(b"- Mouse Wheel to Zoom in-out", 40, 60, 10, DARKGRAY)
124+
draw_text(b"- A / S to Rotate", 40, 80, 10, DARKGRAY)
125+
draw_text(b"- R to reset Zoom and Rotation", 40, 100, 10, DARKGRAY)
126+
127+
end_drawing()
128+
# -----------------------------------------------------------
129+
130+
# De-Initialization
131+
# ---------------------------------------------------------------
132+
close_window() # Close window and OpenGL context
133+
# ---------------------------------------------------------------
134+
135+
136+
if __name__ == '__main__':
137+
main()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# core_3d_camera_first_person.py
2+
3+
import raylibpy as rl
4+
from ctypes import byref
5+
6+
MAX_COLUMNS = 20
7+
8+
9+
def main():
10+
11+
# Initialization
12+
# ---------------------------------------------------------------
13+
screen_width = 800
14+
screen_height = 450
15+
16+
rl.init_window(screen_width, screen_height, b"raylib [core] example - 3d camera 1st person")
17+
18+
# Define the camera to look into our 3d world (position, target, up vector)
19+
camera = rl.Camera(
20+
rl.Vector3(4.0, 2.0, 4.0),
21+
rl.Vector3(0.0, 1.8, 0.0),
22+
rl.Vector3(0.0, 1.0, 0.0),
23+
60.0,
24+
rl.CAMERA_PERSPECTIVE
25+
)
26+
27+
# Generates some random columns
28+
heights = []
29+
positions = []
30+
colors = []
31+
32+
for i in range(MAX_COLUMNS):
33+
heights.append(rl.get_random_value(1, 12))
34+
positions.append(rl.Vector3(
35+
rl.get_random_value(-15, 15),
36+
heights[-1] / 2,
37+
rl.get_random_value(-15, 15)
38+
)
39+
)
40+
colors.append(rl.Color(
41+
rl.get_random_value(20, 255),
42+
rl.get_random_value(10, 55),
43+
30,
44+
255
45+
)
46+
)
47+
48+
rl.set_camera_mode(camera, rl.CAMERA_FIRST_PERSON)
49+
50+
rl.set_target_fps(60)
51+
# ---------------------------------------------------------------
52+
53+
# Main game loop
54+
while not rl.window_should_close():
55+
56+
# Update
57+
# -----------------------------------------------------------
58+
rl.update_camera(byref(camera))
59+
# -----------------------------------------------------------
60+
61+
# Draw
62+
# -----------------------------------------------------------
63+
rl.begin_drawing()
64+
65+
rl.clear_background(rl.RAYWHITE)
66+
67+
rl.begin_mode3D(camera)
68+
69+
rl.draw_plane(rl.Vector3(0.0, 0.0, 0.0), rl.Vector2(32.0, 32.0), rl.LIGHTGRAY)
70+
rl.draw_cube(rl.Vector3(-16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.BLUE)
71+
rl.draw_cube(rl.Vector3(16.0, 2.5, 0.0), 1.0, 5.0, 32.0, rl.LIME)
72+
rl.draw_cube(rl.Vector3(0.0, 2.5, 16.0), 32.0, 5.0, 1.0, rl.GOLD)
73+
74+
# Draw some cubes around
75+
for i, position in enumerate(positions):
76+
rl.draw_cube(position, 2.0, heights[i], 2.0, colors[i])
77+
rl.draw_cube_wires(position, 2.0, heights[i], 2.0, rl.MAROON)
78+
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)
81+
82+
rl.end_mode3D()
83+
84+
# rl.draw_text(b"SCREEN AREA", 640, 10, 20, rl.RED)
85+
86+
rl.draw_rectangle(10, 10, 220, 70, rl.fade(rl.SKYBLUE, 0.5))
87+
rl.draw_rectangle_lines(10, 10, 220, 70, rl.BLUE)
88+
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)
92+
93+
rl.end_drawing()
94+
# -----------------------------------------------------------
95+
96+
# De-Initialization
97+
# ---------------------------------------------------------------
98+
rl.close_window() # Close window and OpenGL context
99+
# ---------------------------------------------------------------
100+
101+
102+
if __name__ == '__main__':
103+
main()

examples/core/core_3d_camera_free.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# core_3d_camera_free.py
2+
3+
import raylibpy as rl
4+
from ctypes import byref
5+
6+
MAX_COLUMNS = 20
7+
8+
9+
def main():
10+
11+
# Initialization
12+
# ---------------------------------------------------------------
13+
screen_width = 800
14+
screen_height = 450
15+
16+
rl.init_window(screen_width, screen_height, b"raylib [core] example - 3d camera free")
17+
18+
# Define the camera to look into our 3d world
19+
camera = rl.Camera(
20+
rl.Vector3(4.0, 2.0, 4.0),
21+
rl.Vector3(0.0, 0.0, 0.0),
22+
rl.Vector3(0.0, 1.0, 0.0),
23+
45.0,
24+
rl.CAMERA_PERSPECTIVE
25+
)
26+
27+
cube_position = rl.Vector3(0.0, 0.0, 0.0)
28+
29+
rl.set_camera_mode(camera, rl.CAMERA_FREE)
30+
31+
rl.set_target_fps(60)
32+
# ---------------------------------------------------------------
33+
34+
# Main game loop
35+
while not rl.window_should_close():
36+
37+
# Update
38+
# -----------------------------------------------------------
39+
rl.update_camera(byref(camera))
40+
if rl.is_key_down(rl.KEY_Z):
41+
camera.target = rl.Vector3(0.0, 0.0, 0.0)
42+
# -----------------------------------------------------------
43+
44+
# Draw
45+
# -----------------------------------------------------------
46+
rl.begin_drawing()
47+
48+
rl.clear_background(rl.RAYWHITE)
49+
50+
rl.begin_mode3D(camera)
51+
52+
rl.draw_cube(cube_position, 2.0, 2.0, 2.0, rl.RED)
53+
rl.draw_cube_wires(cube_position, 2.0, 2.0, 2.0, rl.MAROON)
54+
55+
rl.draw_grid(10, 1.0)
56+
57+
rl.end_mode3D()
58+
59+
rl.draw_rectangle(10, 10, 320, 133, rl.fade(rl.SKYBLUE, 0.5))
60+
rl.draw_rectangle_lines(10, 10, 320, 133, rl.BLUE)
61+
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)
68+
69+
rl.end_drawing()
70+
# -----------------------------------------------------------
71+
72+
# De-Initialization
73+
# ---------------------------------------------------------------
74+
rl.close_window() # Close window and OpenGL context
75+
# ---------------------------------------------------------------
76+
77+
78+
if __name__ == '__main__':
79+
main()

examples/core/core_basic_window.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# core_basic_window.py
2+
import raylibpy as rl
3+
4+
5+
def main():
6+
7+
rl.init_window(800, 450, b"raylib [core] example - basic window")
8+
9+
rl.set_target_fps(60)
10+
11+
while not rl.window_should_close():
12+
13+
rl.begin_drawing()
14+
rl.clear_background(rl.RAYWHITE)
15+
rl.draw_text(b"Congrats! You created your first window!", 190, 200, 20, rl.LIGHTGRAY)
16+
rl.end_drawing()
17+
18+
rl.close_window()
19+
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)