Skip to content

Commit dead4cf

Browse files
committed
adding the shapes_logo_raylib example.
adding the missing press checks in the core_input_mouse example: I added the missing MOUSE_BUTTON_SIDE,MOUSE_BUTTON_EXTRA,MOUSE_BUTTON_FORWARD,MOUSE_BUTTON_BACK press checks. note: my mouse doesn't have the "forward" and "back" buttons, so I couldn't test if they work
1 parent 50e74a7 commit dead4cf

File tree

3 files changed

+93
-28
lines changed

3 files changed

+93
-28
lines changed

examples/core/core_input_mouse.py

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,77 @@
33
raylib [core] example - Mouse input
44
55
"""
6-
import pyray
6+
from pyray import *
77
from raylib.colors import (
88
RAYWHITE,
99
DARKGRAY,
1010
MAROON,
11-
DARKBLUE,
1211
LIME,
12+
DARKBLUE,
13+
PURPLE,
14+
YELLOW,
15+
ORANGE,
16+
BEIGE,
17+
)
18+
from raylib import (
19+
MOUSE_BUTTON_LEFT,
20+
MOUSE_BUTTON_MIDDLE,
21+
MOUSE_BUTTON_RIGHT,
22+
MOUSE_BUTTON_SIDE,
23+
MOUSE_BUTTON_EXTRA,
24+
MOUSE_BUTTON_FORWARD,
25+
MOUSE_BUTTON_BACK
1326
)
14-
15-
16-
1727

1828
# Initialization
1929
SCREEN_WIDTH = 800
2030
SCREEN_HEIGHT = 450
2131

22-
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT,
23-
'raylib [core] example - mouse input')
32+
init_window(SCREEN_WIDTH, SCREEN_HEIGHT,
33+
'raylib [core] example - mouse input')
2434

25-
ball_position = pyray.Vector2(-100, -100)
35+
ball_position = Vector2(-100, -100)
2636
ball_color = DARKBLUE
2737

28-
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
29-
38+
set_target_fps(60) # Set our game to run at 60 frames-per-second
3039

3140
# Main game loop
32-
while not pyray.window_should_close(): # Detect window close button or ESC key
41+
while not window_should_close(): # Detect window close button or ESC key
3342
# Update
34-
ball_position = pyray.get_mouse_position()
43+
ball_position = get_mouse_position()
3544

36-
if pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_LEFT):
45+
if is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
3746
ball_color = MAROON
38-
elif pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_MIDDLE):
47+
print("MOUSE_BUTTON_LEFT")
48+
elif is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
3949
ball_color = LIME
40-
elif pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_RIGHT):
50+
print("MOUSE_BUTTON_MIDDLE")
51+
elif is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
4152
ball_color = DARKBLUE
42-
53+
print("MOUSE_BUTTON_RIGHT")
54+
elif is_mouse_button_pressed(MOUSE_BUTTON_SIDE):
55+
ball_color = PURPLE
56+
print("MOUSE_BUTTON_SIDE")
57+
elif is_mouse_button_pressed(MOUSE_BUTTON_EXTRA):
58+
ball_color = YELLOW
59+
print("MOUSE_BUTTON_EXTRA")
60+
elif is_mouse_button_pressed(MOUSE_BUTTON_FORWARD):
61+
ball_color = ORANGE
62+
print("MOUSE_BUTTON_FORWARD")
63+
elif is_mouse_button_pressed(MOUSE_BUTTON_BACK):
64+
ball_color = BEIGE
65+
print("MOUSE_BUTTON_BACK")
4366
# Draw
44-
pyray.begin_drawing()
67+
begin_drawing()
4568

46-
pyray.clear_background(RAYWHITE)
47-
pyray.draw_circle_v(ball_position, 40, ball_color)
48-
pyray.draw_text(
69+
clear_background(RAYWHITE)
70+
draw_circle_v(ball_position, 40, ball_color)
71+
draw_text(
4972
'move ball with mouse and click mouse button to change color',
5073
10, 10, 20, DARKGRAY
5174
)
5275

53-
pyray.end_drawing()
54-
76+
end_drawing()
5577

5678
# De-Initialization
57-
pyray.close_window() # Close window and OpenGL context
79+
close_window() # Close window and OpenGL context

examples/core/core_random_values.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
)
1212

1313
# Initialization
14-
SCREEN_WIDTH: int = 800
15-
SCREEN_HEIGHT: int = 450
14+
SCREEN_WIDTH = 800
15+
SCREEN_HEIGHT = 450
1616

1717
init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'raylib [core] example - random values')
1818

1919
# set_random_seed() // Set a custom random seed if desired, by default: "time(NULL)"
2020

21-
randValue: int = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included)
21+
randValue = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included)
2222

23-
framesCounter: int = 0 # Variable used to count frames
23+
framesCounter = 0 # Variable used to count frames
2424

2525
set_target_fps(60) # Set our game to run at 60 frames-per-second
2626

@@ -32,7 +32,7 @@
3232
framesCounter += 1
3333

3434
# Every two seconds (120 frames) a new random value is generated
35-
if ((framesCounter/120)%2) == 1:
35+
if ((framesCounter/120) % 2) == 1:
3636
randValue = get_random_value(-8, 5)
3737
framesCounter = 0
3838

examples/shapes/shapes_logo_raylib.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
3+
raylib [core] example - Logo Raylib
4+
5+
"""
6+
from pyray import *
7+
from raylib.colors import (
8+
RAYWHITE,
9+
BLACK,
10+
GRAY
11+
)
12+
13+
# Initialization
14+
screenWidth = 800
15+
screenHeight = 450
16+
17+
init_window(screenWidth, screenHeight, 'raylib [shapes] example - raylib logo using shapes')
18+
19+
set_target_fps(60) # Set our game to run at 60 frames-per-second
20+
21+
# Main game loop
22+
while not window_should_close(): # Detect window close button or ESC key
23+
# Update
24+
# ----------------------------------------------------------------------------------
25+
# TODO: Update your variables here
26+
# ----------------------------------------------------------------------------------
27+
28+
# Draw
29+
# ----------------------------------------------------------------------------------
30+
begin_drawing()
31+
32+
clear_background(RAYWHITE)
33+
34+
draw_rectangle(int(screenWidth/2 - 128), int(screenHeight/2 - 128), 256, 256, BLACK)
35+
draw_rectangle(int(screenWidth/2 - 112), int(screenHeight/2 - 112), 224, 224, RAYWHITE)
36+
draw_text("raylib", int(screenWidth/2 - 44), int(screenHeight/2 + 48), 50, BLACK)
37+
38+
draw_text("this is NOT a texture!", 350, 370, 10, GRAY)
39+
40+
end_drawing()
41+
42+
# De-Initialization
43+
close_window() # Close window and OpenGL context

0 commit comments

Comments
 (0)