update examples

This commit is contained in:
Richard Smith 2024-11-16 20:11:08 +00:00 committed by Richard Smith
parent 4071263a59
commit a33f4fcc9a
40 changed files with 232 additions and 321 deletions

View file

@ -57,18 +57,18 @@ while not pyray.window_should_close(): # Detect window close button or ESC key
# Update
# Player movement
if pyray.is_key_down(pyray.KEY_RIGHT):
if pyray.is_key_down(pyray.KeyboardKey.KEY_RIGHT):
player.x += 2
elif pyray.is_key_down(pyray.KEY_LEFT):
elif pyray.is_key_down(pyray.KeyboardKey.KEY_LEFT):
player.x -= 2
# Camera target follows player
camera.target = pyray.Vector2(player.x + 20, player.y + 20)
# Camera rotation controls
if pyray.is_key_down(pyray.KEY_A):
if pyray.is_key_down(pyray.KeyboardKey.KEY_A):
camera.rotation -= 1
elif pyray.is_key_down(pyray.KEY_S):
elif pyray.is_key_down(pyray.KeyboardKey.KEY_S):
camera.rotation += 1
# Limit camera rotation to 80 degrees (-40 to 40)
@ -86,7 +86,7 @@ while not pyray.window_should_close(): # Detect window close button or ESC key
camera.zoom = 0.1
# Camera reset (zoom and rotation)
if pyray.is_key_pressed(pyray.KEY_R):
if pyray.is_key_pressed(pyray.KeyboardKey.KEY_R):
camera.zoom = 1.0
camera.rotation = 0.0

View file

@ -13,15 +13,14 @@ pyray.set_target_fps(60)
camera = pyray.Camera2D()
camera = pyray.Camera2D()
camera.zoom = 1.0
pyray.set_target_fps(60);
pyray.set_target_fps(60)
# main game loop
while not pyray.window_should_close():
# update
if pyray.is_mouse_button_down(pyray.MOUSE_BUTTON_RIGHT):
if pyray.is_mouse_button_down(pyray.MouseButton.MOUSE_BUTTON_RIGHT):
delta = pyray.get_mouse_delta()
delta = pyray.vector2_scale(delta, -1.0 / camera.zoom)
camera.target = pyray.vector2_add(camera.target, delta)
@ -58,7 +57,7 @@ while not pyray.window_should_close():
pyray.end_mode_2d()
pyray.draw_text("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, pyray.WHITE);
pyray.draw_text("Mouse right button drag to move, mouse wheel to zoom", 10, 10, 20, pyray.WHITE)
pyray.end_drawing()

View file

@ -62,11 +62,11 @@ class EnvItem:
def update_player(player, env_items, delta):
if pyray.is_key_down(pyray.KEY_LEFT):
if pyray.is_key_down(pyray.KeyboardKey.KEY_LEFT):
player.position.x -= PLAYER_HOR_SPD * delta
if pyray.is_key_down(pyray.KEY_RIGHT):
if pyray.is_key_down(pyray.KeyboardKey.KEY_RIGHT):
player.position.x += PLAYER_HOR_SPD * delta
if pyray.is_key_down(pyray.KEY_SPACE) and player.can_jump:
if pyray.is_key_down(pyray.KeyboardKey.KEY_SPACE) and player.can_jump:
player.speed = -PLAYER_JUMP_SPD
player.can_jump = False
@ -264,11 +264,11 @@ while not pyray.window_should_close(): # Detect window close button or ESC key
elif camera.zoom < 0.25:
camera.zoom = 0.25
if pyray.is_key_pressed(pyray.KEY_R):
if pyray.is_key_pressed(pyray.KeyboardKey.KEY_R):
camera.zoom = 1.0
player.position = pyray.Vector2(400, 280)
if pyray.is_key_pressed(pyray.KEY_C):
if pyray.is_key_pressed(pyray.KeyboardKey.KEY_C):
camera_option = (camera_option + 1) % camera_updaters_length
# Call update camera function by its pointer

View file

@ -10,7 +10,7 @@ MAX_COLUMNS = 20
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, b"raylib [core] example - 3d camera first person")
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - 3d camera first person")
# Define the camera to look into our 3d world (position, target, up vector)
camera = pyray.Camera3D()
@ -18,24 +18,24 @@ camera.position = pyray.Vector3(4.0, 2.0, 4.0)
camera.target = pyray.Vector3(0.0, 1.8, 0.0)
camera.up = pyray.Vector3(0.0, 1.0, 0.0)
camera.fovy = 60.0
camera.projection = pyray.CAMERA_PERSPECTIVE
camera.projection = pyray.CameraProjection.CAMERA_PERSPECTIVE
# Generates some random columns
heights = [None] * MAX_COLUMNS
positions = [None] * MAX_COLUMNS
colors = [None] * MAX_COLUMNS
heights = []
positions = []
colors = []
for i in range(MAX_COLUMNS):
heights[i] = pyray.get_random_value(1, 12) * 1.0
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)
colors[i] = pyray.Color(pyray.get_random_value(20, 255), pyray.get_random_value(10, 55), 30, 255)
heights.append(pyray.get_random_value(1, 12) * 1.0)
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))
colors.append(pyray.Color(pyray.get_random_value(20, 255), pyray.get_random_value(10, 55), 30, 255))
pyray.set_target_fps(60)
while not pyray.window_should_close():
pyray.update_camera(camera, pyray.CAMERA_FIRST_PERSON)
pyray.update_camera(camera, pyray.CameraMode.CAMERA_FIRST_PERSON)
pyray.begin_drawing()

View file

@ -25,7 +25,7 @@ while not window_should_close(): # Detect window close button or ESC key
# Update
update_camera(camera, CameraMode.CAMERA_FREE)
if is_key_pressed(KEY_Z):
if is_key_pressed(KeyboardKey.KEY_Z):
camera.target = Vector3(0.0, 0.0, 0.0)
# Draw

View file

@ -40,7 +40,7 @@ while not pyray.window_should_close():
pyray.end_mode_3d()
pyray.draw_text("Welcome to the third dimension!", 10, 40, 20, pyray.DARKGRAY);
pyray.draw_text("Welcome to the third dimension!", 10, 40, 20, pyray.DARKGRAY)
pyray.draw_fps(10, 10)

View file

@ -27,13 +27,13 @@ def main():
if frame_count > 120:
current_screen = GameScreen.TITLE
elif current_screen == GameScreen.TITLE:
if is_key_pressed(KEY_ENTER) or is_gesture_detected(GESTURE_TAP):
if is_key_pressed(KeyboardKey.KEY_ENTER) or is_gesture_detected(Gesture.GESTURE_TAP):
current_screen = GameScreen.GAMEPLAY
elif current_screen == GameScreen.GAMEPLAY:
if is_key_pressed(KEY_ENTER) or is_gesture_detected(GESTURE_TAP):
if is_key_pressed(KeyboardKey.KEY_ENTER) or is_gesture_detected(Gesture.GESTURE_TAP):
current_screen = GameScreen.ENDING
elif current_screen == GameScreen.ENDING:
if is_key_pressed(KEY_ENTER) or is_gesture_detected(GESTURE_TAP):
if is_key_pressed(KeyboardKey.KEY_ENTER) or is_gesture_detected(Gesture.GESTURE_TAP):
current_screen = GameScreen.TITLE
begin_drawing()

View file

@ -11,12 +11,6 @@
"""
import pyray
from raylib.colors import (
RAYWHITE,
DARKGRAY,
LIGHTGRAY,
GRAY
)
screenWidth = 800
screenHeight = 450
@ -36,21 +30,21 @@ while not pyray.window_should_close():
pyray.begin_drawing()
pyray.clear_background(RAYWHITE)
pyray.clear_background(pyray.RAYWHITE)
if droppedFiles.count == 0:
pyray.draw_text("Drop your files to this window!", 100, 40, 20, DARKGRAY)
pyray.draw_text("Drop your files to this window!", 100, 40, 20, pyray.DARKGRAY)
else:
pyray.draw_text("Dropped files:", 100, 40, 20, DARKGRAY)
pyray.draw_text("Dropped files:", 100, 40, 20, pyray.DARKGRAY)
for i in range(0, droppedFiles.count):
if i % 2 == 0:
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.5))
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(pyray.LIGHTGRAY, 0.5))
else:
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(LIGHTGRAY, 0.3))
pyray.draw_text(droppedFiles.paths[i], 120, 100 + 40*i, 10, GRAY)
pyray.draw_rectangle(0, 85 + 40*i, screenWidth, 40, pyray.fade(pyray.LIGHTGRAY, 0.3))
pyray.draw_text(droppedFiles.paths[i], 120, 100 + 40*i, 10, pyray.GRAY)
pyray.draw_text("Drop new files...", 100, 110 + 40*droppedFiles.count, 20, DARKGRAY)
pyray.draw_text("Drop new files...", 100, 110 + 40*droppedFiles.count, 20, pyray.DARKGRAY)
pyray.end_drawing()
# De-Initialization

View file

@ -4,13 +4,6 @@ raylib [core] example - Input Gestures Detection
"""
import pyray
from raylib.colors import (
RAYWHITE,
LIGHTGRAY,
DARKGRAY,
MAROON,
GRAY,
)
@ -26,20 +19,20 @@ touch_area = pyray.Rectangle(220, 10, SCREEN_WIDTH - 230, SCREEN_HEIGHT - 20)
gesture_strings = []
current_gesture = pyray.GESTURE_NONE
last_gesture = pyray.GESTURE_NONE
current_gesture = pyray.Gesture.GESTURE_NONE
last_gesture = pyray.Gesture.GESTURE_NONE
GESTURE_LABELS = {
pyray.GESTURE_TAP: 'GESTURE TAP',
pyray.GESTURE_DOUBLETAP: 'GESTURE DOUBLETAP',
pyray.GESTURE_HOLD: 'GESTURE HOLD',
pyray.GESTURE_DRAG: 'GESTURE DRAG',
pyray.GESTURE_SWIPE_RIGHT: 'GESTURE SWIPE RIGHT',
pyray.GESTURE_SWIPE_LEFT: 'GESTURE SWIPE LEFT',
pyray.GESTURE_SWIPE_UP: 'GESTURE SWIPE UP',
pyray.GESTURE_SWIPE_DOWN: 'GESTURE SWIPE DOWN',
pyray.GESTURE_PINCH_IN: 'GESTURE PINCH IN',
pyray.GESTURE_PINCH_OUT: 'GESTURE PINCH OUT',
pyray.Gesture.GESTURE_TAP: 'GESTURE TAP',
pyray.Gesture.GESTURE_DOUBLETAP: 'GESTURE DOUBLETAP',
pyray.Gesture.GESTURE_HOLD: 'GESTURE HOLD',
pyray.Gesture.GESTURE_DRAG: 'GESTURE DRAG',
pyray.Gesture.GESTURE_SWIPE_RIGHT: 'GESTURE SWIPE RIGHT',
pyray.Gesture.GESTURE_SWIPE_LEFT: 'GESTURE SWIPE LEFT',
pyray.Gesture.GESTURE_SWIPE_UP: 'GESTURE SWIPE UP',
pyray.Gesture.GESTURE_SWIPE_DOWN: 'GESTURE SWIPE DOWN',
pyray.Gesture.GESTURE_PINCH_IN: 'GESTURE PINCH IN',
pyray.Gesture.GESTURE_PINCH_OUT: 'GESTURE PINCH OUT',
}
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
@ -54,7 +47,7 @@ while not pyray.window_should_close(): # Detect window close button or ESC key
if (
pyray.check_collision_point_rec(touch_position, touch_area)
and current_gesture != pyray.GESTURE_NONE
and current_gesture != pyray.Gesture.GESTURE_NONE
):
if current_gesture != last_gesture:
gesture_strings.append(GESTURE_LABELS[current_gesture])
@ -66,34 +59,34 @@ while not pyray.window_should_close(): # Detect window close button or ESC key
# Draw
pyray.begin_drawing()
pyray.clear_background(RAYWHITE)
pyray.clear_background(pyray.RAYWHITE)
pyray.draw_rectangle_rec(touch_area, GRAY)
pyray.draw_rectangle_rec(touch_area, pyray.GRAY)
pyray.draw_rectangle(225, 15, SCREEN_WIDTH - 240, SCREEN_HEIGHT - 30,
RAYWHITE)
pyray.RAYWHITE)
pyray.draw_text(
'GESTURES TEST AREA',
SCREEN_WIDTH - 270, SCREEN_HEIGHT - 40, 20, pyray.fade(GRAY, 0.5)
SCREEN_WIDTH - 270, SCREEN_HEIGHT - 40, 20, pyray.fade(pyray.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))
10, 30 + 20 * i, 200, 20, pyray.fade(pyray.LIGHTGRAY, 0.5))
else:
pyray.draw_rectangle(
10, 30 + 20 * i, 200, 20, pyray.fade(LIGHTGRAY, 0.3))
10, 30 + 20 * i, 200, 20, pyray.fade(pyray.LIGHTGRAY, 0.3))
if i < len(gesture_strings) - 1:
pyray.draw_text(val, 35, 36 + 20 * i, 10, DARKGRAY)
pyray.draw_text(val, 35, 36 + 20 * i, 10, pyray.DARKGRAY)
else:
pyray.draw_text(val, 35, 36 + 20 * i, 10, MAROON)
pyray.draw_text(val, 35, 36 + 20 * i, 10, pyray.MAROON)
pyray.draw_rectangle_lines(10, 29, 200, SCREEN_HEIGHT - 50, GRAY)
pyray.draw_text('DETECTED GESTURES', 50, 15, 10, GRAY)
pyray.draw_rectangle_lines(10, 29, 200, SCREEN_HEIGHT - 50, pyray.GRAY)
pyray.draw_text('DETECTED GESTURES', 50, 15, 10, pyray.GRAY)
if current_gesture != pyray.GESTURE_NONE:
pyray.draw_circle_v(touch_position, 30, MAROON)
if current_gesture != pyray.Gesture.GESTURE_NONE:
pyray.draw_circle_v(touch_position, 30, pyray.MAROON)
pyray.end_drawing()

View file

@ -19,13 +19,13 @@ 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):
if pyray.is_key_down(pyray.KeyboardKey.KEY_RIGHT):
ball_position.x += 2
if pyray.is_key_down(pyray.KEY_LEFT):
if pyray.is_key_down(pyray.KeyboardKey.KEY_LEFT):
ball_position.x -= 2
if pyray.is_key_down(pyray.KEY_UP):
if pyray.is_key_down(pyray.KeyboardKey.KEY_UP):
ball_position.y -= 2
if pyray.is_key_down(pyray.KEY_DOWN):
if pyray.is_key_down(pyray.KeyboardKey.KEY_DOWN):
ball_position.y += 2
# Draw

View file

@ -22,19 +22,19 @@ while not window_should_close(): # Detect window close button or ESC key
# Update
ball_position = get_mouse_position()
if is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
if is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_LEFT):
ball_color = MAROON
elif is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
elif is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_MIDDLE):
ball_color = LIME
elif is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
elif is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_RIGHT):
ball_color = DARKBLUE
elif is_mouse_button_pressed(MOUSE_BUTTON_SIDE):
elif is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_SIDE):
ball_color = PURPLE
elif is_mouse_button_pressed(MOUSE_BUTTON_EXTRA):
elif is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_EXTRA):
ball_color = YELLOW
elif is_mouse_button_pressed(MOUSE_BUTTON_FORWARD):
elif is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_FORWARD):
ball_color = ORANGE
elif is_mouse_button_pressed(MOUSE_BUTTON_BACK):
elif is_mouse_button_pressed(MouseButton.MOUSE_BUTTON_BACK):
ball_color = BEIGE
# Draw
begin_drawing()

View file

@ -23,7 +23,7 @@ set_target_fps(60) # Set our game to run at 60 frames-per-second
while not window_should_close(): # Detect window close button or ESC key
# Update
# ----------------------------------------------------------------------------------
if is_key_pressed(KEY_S):
if is_key_pressed(KeyboardKey.KEY_S):
scissorMode = not scissorMode
# Centre the scissor area around the mouse position

View file

@ -18,7 +18,7 @@ worldSpaceCamera.zoom = 1.0
screenSpaceCamera = Camera2D([0]) # Smoothing camera
screenSpaceCamera.zoom = 1.0
target = load_render_texture(virtualScreenWidth, virtualScreenHeight); # This is where we'll draw all our objects.
target = load_render_texture(virtualScreenWidth, virtualScreenHeight) # This is where we'll draw all our objects.
rec01 = Rectangle(70.0, 35.0, 20.0, 20.0)
rec02 = Rectangle(90.0, 55.0, 30.0, 10.0)
@ -42,7 +42,7 @@ while not window_should_close(): # Detect window close button or ESC key
# Update
rotation += 60.0 *get_frame_time(); # Rotate the rectangles, 60 degrees per second
rotation += 60.0 *get_frame_time() # Rotate the rectangles, 60 degrees per second
# Make the camera move to demonstrate the effect
cameraX = (math.sin(get_time())*50.0) - 10.0

View file

@ -66,21 +66,21 @@ while not window_should_close(): # Detect window close button or ESC key
# Move Player1 forward and backwards (no turning)
if is_key_down(KEY_W):
if is_key_down(KeyboardKey.KEY_W):
cameraPlayer1.position.z += offsetThisFrame
cameraPlayer1.target.z += offsetThisFrame
elif is_key_down(KEY_S):
elif is_key_down(KeyboardKey.KEY_S):
cameraPlayer1.position.z -= offsetThisFrame
cameraPlayer1.target.z -= offsetThisFrame
# Move Player2 forward and backwards (no turning)
if is_key_down(KEY_UP):
if is_key_down(KeyboardKey.KEY_UP):
cameraPlayer2.position.x += offsetThisFrame
cameraPlayer2.target.x += offsetThisFrame
elif is_key_down(KEY_DOWN):
elif is_key_down(KeyboardKey.KEY_DOWN):
cameraPlayer2.position
cameraPlayer2.position.x -= offsetThisFrame
cameraPlayer2.target.x -= offsetThisFrame

View file

@ -17,7 +17,6 @@ device = pyray.VrDeviceInfo(
1200, # Vertical resolution in pixels
0.133793, # Horizontal size in meters
0.0669, # Vertical size in meters
0.04678, # Screen center in meters
0.041, # Distance between eye and display in meters
0.07, # Lens separation distance in meters
0.07, # IPD (distance between pupils) in meters
@ -35,15 +34,15 @@ config = pyray.load_vr_stereo_config(device)
distortion = pyray.load_shader(pyray.ffi.NULL, f"resources/distortion{GLSL_VERSION}.fs")
# Update distortion shader with lens and distortion-scale parameters
pyray.set_shader_value(distortion, 2, pyray.ffi.new('char []', b"leftLensCenter"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"rightLensCenter"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"leftScreenCenter"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"rightScreenCenter"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2, pyray.ffi.new('char []', b"leftLensCenter"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"rightLensCenter"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"leftScreenCenter"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"rightScreenCenter"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"scale"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"scaleIn"), pyray.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"deviceWarpParam"), pyray.SHADER_UNIFORM_VEC4)
pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"chromaAbParam"), pyray.SHADER_UNIFORM_VEC4)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"scale"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 2,pyray.ffi.new('char []', b"scaleIn"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC2)
pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"deviceWarpParam"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC4)
pyray.set_shader_value(distortion, 4,pyray.ffi.new('char []', b"chromaAbParam"), pyray.ShaderUniformDataType.SHADER_UNIFORM_VEC4)
# Initialize framebuffer for stereo rendering
# NOTE: Screen size should match HMD aspect ratio
@ -59,7 +58,7 @@ camera = pyray.Camera3D(
pyray.Vector3(0.0, 2.0, 0.0), # Camera looking at point
pyray.Vector3(0.0, 1.0, 0.0), # Camera up vector
60.0, # Camera field-of-view Y
pyray.CAMERA_PERSPECTIVE # Camera projection type
pyray.CameraProjection.CAMERA_PERSPECTIVE # Camera projection type
)
cubePosition = pyray.Vector3(0.0, 0.0, 0.0)
@ -71,7 +70,7 @@ pyray.set_target_fps(90) # Set our game to run at 90 frames-per-sec
# Main game loop
while not pyray.window_should_close(): # Detect window close button or ESC key
# Update
pyray.update_camera(camera, pyray.CAMERA_FIRST_PERSON)
pyray.update_camera(camera, pyray.CameraMode.CAMERA_FIRST_PERSON)
# Draw
pyray.begin_texture_mode(target)

View file

@ -6,7 +6,7 @@ import pyray
screen_width = 800
screen_height = 450
init_window(screen_width, screen_height, b"raylib [core] example - window flags")
init_window(screen_width, screen_height, "raylib [core] example - window flags")
ball_position = Vector2(get_screen_width() / 2.0, get_screen_height() / 2.0)
ball_speed = Vector2(5.0, 4.0)
@ -18,71 +18,71 @@ frames_counter = 0
while not window_should_close(): # Detect window close button or ESC key
# Update
# -----------------------------------------------------
if is_key_pressed(pyray.KEY_F):
if is_key_pressed(pyray.KeyboardKey.KEY_F):
toggle_fullscreen()
if is_key_pressed(pyray.KEY_R):
if is_window_state(pyray.FLAG_WINDOW_RESIZABLE):
clear_window_state(pyray.FLAG_WINDOW_RESIZABLE)
if is_key_pressed(pyray.KeyboardKey.KEY_R):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_RESIZABLE):
clear_window_state(pyray.ConfigFlags.FLAG_WINDOW_RESIZABLE)
else:
set_window_state(pyray.FLAG_WINDOW_RESIZABLE)
set_window_state(pyray.ConfigFlags.FLAG_WINDOW_RESIZABLE)
if is_key_pressed(pyray.KEY_D):
if is_window_state(pyray.FLAG_WINDOW_UNDECORATED):
clear_window_state(pyray.FLAG_WINDOW_UNDECORATED)
if is_key_pressed(pyray.KeyboardKey.KEY_D):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_UNDECORATED):
clear_window_state(pyray.ConfigFlags.FLAG_WINDOW_UNDECORATED)
else:
set_window_state(pyray.FLAG_WINDOW_UNDECORATED)
set_window_state(pyray.ConfigFlags.FLAG_WINDOW_UNDECORATED)
if is_key_pressed(pyray.KEY_H):
if not is_window_state(pyray.FLAG_WINDOW_HIDDEN):
set_window_state(pyray.FLAG_WINDOW_HIDDEN)
if is_key_pressed(pyray.KeyboardKey.KEY_H):
if not is_window_state(pyray.ConfigFlags.FLAG_WINDOW_HIDDEN):
set_window_state(pyray.ConfigFlags.FLAG_WINDOW_HIDDEN)
frames_counter = 0
if is_window_state(pyray.FLAG_WINDOW_HIDDEN):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_HIDDEN):
frames_counter += 1
if frames_counter >= 240:
clear_window_state(pyray.FLAG_WINDOW_HIDDEN) # Show window after 3 seconds
clear_window_state(pyray.ConfigFlags.FLAG_WINDOW_HIDDEN) # Show window after 3 seconds
if is_key_pressed(pyray.KEY_N):
if not is_window_state(pyray.FLAG_WINDOW_MINIMIZED):
if is_key_pressed(pyray.KeyboardKey.KEY_N):
if not is_window_state(pyray.ConfigFlags.FLAG_WINDOW_MINIMIZED):
minimize_window()
frames_counter = 0
if is_window_state(pyray.FLAG_WINDOW_MINIMIZED):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_MINIMIZED):
frames_counter += 1
if frames_counter >= 240:
restore_window() # Restore window after 3 seconds
if is_key_pressed(pyray.KEY_M):
if is_window_state(pyray.FLAG_WINDOW_RESIZABLE):
if is_window_state(pyray.FLAG_WINDOW_MAXIMIZED):
if is_key_pressed(pyray.KeyboardKey.KEY_M):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_RESIZABLE):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_MAXIMIZED):
restore_window()
else:
maximize_window()
if is_key_pressed(pyray.KEY_U):
if is_window_state(pyray.FLAG_WINDOW_UNFOCUSED):
clear_window_state(pyray.FLAG_WINDOW_UNFOCUSED)
if is_key_pressed(pyray.KeyboardKey.KEY_U):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_UNFOCUSED):
clear_window_state(pyray.ConfigFlags.FLAG_WINDOW_UNFOCUSED)
else:
set_window_state(pyray.FLAG_WINDOW_UNFOCUSED)
set_window_state(pyray.ConfigFlags.FLAG_WINDOW_UNFOCUSED)
if is_key_pressed(pyray.KEY_T):
if is_window_state(pyray.FLAG_WINDOW_TOPMOST):
clear_window_state(pyray.FLAG_WINDOW_TOPMOST)
if is_key_pressed(pyray.KeyboardKey.KEY_T):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_TOPMOST):
clear_window_state(pyray.ConfigFlags.FLAG_WINDOW_TOPMOST)
else:
set_window_state(pyray.FLAG_WINDOW_TOPMOST)
set_window_state(pyray.ConfigFlags.FLAG_WINDOW_TOPMOST)
if is_key_pressed(pyray.KEY_A):
if is_window_state(pyray.FLAG_WINDOW_ALWAYS_RUN):
clear_window_state(pyray.FLAG_WINDOW_ALWAYS_RUN)
if is_key_pressed(pyray.KeyboardKey.KEY_A):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_ALWAYS_RUN):
clear_window_state(pyray.ConfigFlags.FLAG_WINDOW_ALWAYS_RUN)
else:
set_window_state(pyray.FLAG_WINDOW_ALWAYS_RUN)
set_window_state(pyray.ConfigFlags.FLAG_WINDOW_ALWAYS_RUN)
if is_key_pressed(pyray.KEY_V):
if is_window_state(pyray.FLAG_VSYNC_HINT):
clear_window_state(pyray.FLAG_VSYNC_HINT)
if is_key_pressed(pyray.KeyboardKey.KEY_V):
if is_window_state(pyray.ConfigFlags.FLAG_VSYNC_HINT):
clear_window_state(pyray.ConfigFlags.FLAG_VSYNC_HINT)
else:
set_window_state(pyray.FLAG_VSYNC_HINT)
set_window_state(pyray.ConfigFlags.FLAG_VSYNC_HINT)
# Bouncing ball logic
ball_position.x += ball_speed.x
@ -96,7 +96,7 @@ while not window_should_close(): # Detect window close button or ESC key
# -----------------------------------------------------
begin_drawing()
if is_window_state(pyray.FLAG_WINDOW_TRANSPARENT):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_TRANSPARENT):
clear_background(BLANK)
else:
clear_background(RAYWHITE)
@ -113,16 +113,16 @@ while not window_should_close(): # Detect window close button or ESC key
# Draw window state info
draw_text("Following flags can be set after window creation:", 10, 60, 10, GRAY)
flag_texts = [
("FLAG_FULLSCREEN_MODE", pyray.FLAG_FULLSCREEN_MODE),
("FLAG_WINDOW_RESIZABLE", pyray.FLAG_WINDOW_RESIZABLE),
("FLAG_WINDOW_UNDECORATED", pyray.FLAG_WINDOW_UNDECORATED),
("FLAG_WINDOW_HIDDEN", pyray.FLAG_WINDOW_HIDDEN),
("FLAG_WINDOW_MINIMIZED", pyray.FLAG_WINDOW_MINIMIZED),
("FLAG_WINDOW_MAXIMIZED", pyray.FLAG_WINDOW_MAXIMIZED),
("FLAG_WINDOW_UNFOCUSED", pyray.FLAG_WINDOW_UNFOCUSED),
("FLAG_WINDOW_TOPMOST", pyray.FLAG_WINDOW_TOPMOST),
("FLAG_WINDOW_ALWAYS_RUN", pyray.FLAG_WINDOW_ALWAYS_RUN),
("FLAG_VSYNC_HINT", pyray.FLAG_VSYNC_HINT),
("FLAG_FULLSCREEN_MODE", pyray.ConfigFlags.FLAG_FULLSCREEN_MODE),
("FLAG_WINDOW_RESIZABLE", pyray.ConfigFlags.FLAG_WINDOW_RESIZABLE),
("FLAG_WINDOW_UNDECORATED", pyray.ConfigFlags.FLAG_WINDOW_UNDECORATED),
("FLAG_WINDOW_HIDDEN", pyray.ConfigFlags.FLAG_WINDOW_HIDDEN),
("FLAG_WINDOW_MINIMIZED", pyray.ConfigFlags.FLAG_WINDOW_MINIMIZED),
("FLAG_WINDOW_MAXIMIZED", pyray.ConfigFlags.FLAG_WINDOW_MAXIMIZED),
("FLAG_WINDOW_UNFOCUSED", pyray.ConfigFlags.FLAG_WINDOW_UNFOCUSED),
("FLAG_WINDOW_TOPMOST", pyray.ConfigFlags.FLAG_WINDOW_TOPMOST),
("FLAG_WINDOW_ALWAYS_RUN", pyray.ConfigFlags.FLAG_WINDOW_ALWAYS_RUN),
("FLAG_VSYNC_HINT", pyray.ConfigFlags.FLAG_VSYNC_HINT),
]
y_offset = 80
for text, flag in flag_texts:
@ -133,15 +133,15 @@ while not window_should_close(): # Detect window close button or ESC key
y_offset += 20
draw_text("Following flags can only be set before window creation:", 10, 300, 10, GRAY)
if is_window_state(pyray.FLAG_WINDOW_HIGHDPI):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_HIGHDPI):
draw_text("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, LIME)
else:
draw_text("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, MAROON)
if is_window_state(pyray.FLAG_WINDOW_TRANSPARENT):
if is_window_state(pyray.ConfigFlags.FLAG_WINDOW_TRANSPARENT):
draw_text("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, LIME)
else:
draw_text("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, MAROON)
if is_window_state(pyray.FLAG_MSAA_4X_HINT):
if is_window_state(pyray.ConfigFlags.FLAG_MSAA_4X_HINT):
draw_text("FLAG_MSAA_4X_HINT: on", 10, 360, 10, LIME)
else:
draw_text("FLAG_MSAA_4X_HINT: off", 10, 360, 10, MAROON)

View file

@ -12,7 +12,7 @@ SCREEN_HEIGHT = 450
init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [core] example - window should close")
set_exit_key(KEY_NULL) # Disable KEY_ESCAPE to close window, X-button still works
set_exit_key(KeyboardKey.KEY_NULL) # Disable KEY_ESCAPE to close window, X-button still works
exitWindowRequested = False # Flag to request window to exit
exitWindow = False # Flag to set window to exit
@ -26,7 +26,7 @@ while not exitWindow:
# Update
# ----------------------------------------------------------------------------------
# Detect if X-button or KEY_ESCAPE have been pressed to close window
if window_should_close() or is_key_pressed(KEY_ESCAPE):
if window_should_close() or is_key_pressed(KeyboardKey.KEY_ESCAPE):
exitWindowRequested = True
if exitWindowRequested:
@ -34,9 +34,9 @@ while not exitWindow:
# A request for close window has been issued, we can save data before closing
# or just show a message asking for confirmation
if is_key_pressed(KEY_Y):
if is_key_pressed(KeyboardKey.KEY_Y):
exitWindow = True
elif is_key_pressed(KEY_N):
elif is_key_pressed(KeyboardKey.KEY_N):
exitWindowRequested = False
# ----------------------------------------------------------------------------------