Beispiel #1
0
ball_position = pyray.Vector2(-100, -100)
ball_color = DARKBLUE

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
    ball_position = pyray.get_mouse_position()

    if pyray.is_mouse_button_pressed(pyray.MOUSE_LEFT_BUTTON):
        ball_color = MAROON
    elif pyray.is_mouse_button_pressed(pyray.MOUSE_MIDDLE_BUTTON):
        ball_color = LIME
    elif pyray.is_mouse_button_pressed(pyray.MOUSE_RIGHT_BUTTON):
        ball_color = DARKBLUE

    # Draw
    pyray.begin_drawing()

    pyray.clear_background(RAYWHITE)
    pyray.draw_circle_v(ball_position, 40, ball_color)
    pyray.draw_text(
        'move ball with mouse and click mouse button to change color', 10, 10,
        20, DARKGRAY)

    pyray.end_drawing()

# De-Initialization
pyray.close_window()  # Close window and OpenGL context
Beispiel #2
0
texture = pyray.load_texture_from_image(image)
mesh = pyray.gen_mesh_heightmap(image, (16, 8, 16))
model = pyray.load_model_from_mesh(mesh)
model.materials.maps[pyray.MAP_DIFFUSE].texture = texture

pyray.unload_image(image)
pyray.set_camera_mode(camera, pyray.CAMERA_ORBITAL)

pos = pyray.get_mouse_position()
ray = pyray.get_mouse_ray(pos, camera)
rayhit = pyray.get_collision_ray_ground(ray, 0)
print(str(rayhit.position.x))

while not pyray.window_should_close():
    pyray.update_camera(pyray.pointer(camera))
    pyray.begin_drawing()
    pyray.clear_background(RAYWHITE)
    pyray.begin_mode_3d(camera)
    pyray.draw_model(model, (-8.0, 0.0, -8.0), 1.0, RED)
    pyray.draw_grid(20, 1.0)
    pyray.end_mode_3d()
    pyray.draw_text("This mesh should be textured", 190, 200, 20, VIOLET)
    pyray.end_drawing()

    pos = pyray.get_mouse_position()
    ray = pyray.get_mouse_ray(pos, camera)
    rayhit = pyray.get_collision_ray_ground(ray, 0)
    print(str(rayhit.position.x))

pyray.close_window()