Merge pull request #74 from sDos280/master
adding the shapes_logo_raylib example and adding the missing press checks in the core_input_mouse example
This commit is contained in:
commit
a115b9bffd
3 changed files with 86 additions and 28 deletions
|
@ -3,55 +3,70 @@
|
||||||
raylib [core] example - Mouse input
|
raylib [core] example - Mouse input
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import pyray
|
from pyray import *
|
||||||
from raylib.colors import (
|
from raylib.colors import (
|
||||||
RAYWHITE,
|
RAYWHITE,
|
||||||
DARKGRAY,
|
DARKGRAY,
|
||||||
MAROON,
|
MAROON,
|
||||||
DARKBLUE,
|
|
||||||
LIME,
|
LIME,
|
||||||
|
DARKBLUE,
|
||||||
|
PURPLE,
|
||||||
|
YELLOW,
|
||||||
|
ORANGE,
|
||||||
|
BEIGE,
|
||||||
|
)
|
||||||
|
from raylib import (
|
||||||
|
MOUSE_BUTTON_LEFT,
|
||||||
|
MOUSE_BUTTON_MIDDLE,
|
||||||
|
MOUSE_BUTTON_RIGHT,
|
||||||
|
MOUSE_BUTTON_SIDE,
|
||||||
|
MOUSE_BUTTON_EXTRA,
|
||||||
|
MOUSE_BUTTON_FORWARD,
|
||||||
|
MOUSE_BUTTON_BACK
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Initialization
|
# Initialization
|
||||||
SCREEN_WIDTH = 800
|
SCREEN_WIDTH = 800
|
||||||
SCREEN_HEIGHT = 450
|
SCREEN_HEIGHT = 450
|
||||||
|
|
||||||
pyray.init_window(SCREEN_WIDTH, SCREEN_HEIGHT,
|
init_window(SCREEN_WIDTH, SCREEN_HEIGHT,
|
||||||
'raylib [core] example - mouse input')
|
'raylib [core] example - mouse input')
|
||||||
|
|
||||||
ball_position = pyray.Vector2(-100, -100)
|
ball_position = Vector2(-100, -100)
|
||||||
ball_color = DARKBLUE
|
ball_color = DARKBLUE
|
||||||
|
|
||||||
pyray.set_target_fps(60) # Set our game to run at 60 frames-per-second
|
set_target_fps(60) # Set our game to run at 60 frames-per-second
|
||||||
|
|
||||||
|
|
||||||
# Main game loop
|
# Main game loop
|
||||||
while not pyray.window_should_close(): # Detect window close button or ESC key
|
while not window_should_close(): # Detect window close button or ESC key
|
||||||
# Update
|
# Update
|
||||||
ball_position = pyray.get_mouse_position()
|
ball_position = get_mouse_position()
|
||||||
|
|
||||||
if pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_LEFT):
|
if is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
|
||||||
ball_color = MAROON
|
ball_color = MAROON
|
||||||
elif pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_MIDDLE):
|
elif is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE):
|
||||||
ball_color = LIME
|
ball_color = LIME
|
||||||
elif pyray.is_mouse_button_pressed(pyray.MOUSE_BUTTON_RIGHT):
|
elif is_mouse_button_pressed(MOUSE_BUTTON_RIGHT):
|
||||||
ball_color = DARKBLUE
|
ball_color = DARKBLUE
|
||||||
|
elif is_mouse_button_pressed(MOUSE_BUTTON_SIDE):
|
||||||
|
ball_color = PURPLE
|
||||||
|
elif is_mouse_button_pressed(MOUSE_BUTTON_EXTRA):
|
||||||
|
ball_color = YELLOW
|
||||||
|
elif is_mouse_button_pressed(MOUSE_BUTTON_FORWARD):
|
||||||
|
ball_color = ORANGE
|
||||||
|
elif is_mouse_button_pressed(MOUSE_BUTTON_BACK):
|
||||||
|
ball_color = BEIGE
|
||||||
# Draw
|
# Draw
|
||||||
pyray.begin_drawing()
|
begin_drawing()
|
||||||
|
|
||||||
pyray.clear_background(RAYWHITE)
|
clear_background(RAYWHITE)
|
||||||
pyray.draw_circle_v(ball_position, 40, ball_color)
|
draw_circle_v(ball_position, 40, ball_color)
|
||||||
pyray.draw_text(
|
draw_text(
|
||||||
'move ball with mouse and click mouse button to change color',
|
'move ball with mouse and click mouse button to change color',
|
||||||
10, 10, 20, DARKGRAY
|
10, 10, 20, DARKGRAY
|
||||||
)
|
)
|
||||||
|
|
||||||
pyray.end_drawing()
|
end_drawing()
|
||||||
|
|
||||||
|
|
||||||
# De-Initialization
|
# De-Initialization
|
||||||
pyray.close_window() # Close window and OpenGL context
|
close_window() # Close window and OpenGL context
|
||||||
|
|
|
@ -11,16 +11,16 @@ from raylib.colors import (
|
||||||
)
|
)
|
||||||
|
|
||||||
# Initialization
|
# Initialization
|
||||||
SCREEN_WIDTH: int = 800
|
SCREEN_WIDTH = 800
|
||||||
SCREEN_HEIGHT: int = 450
|
SCREEN_HEIGHT = 450
|
||||||
|
|
||||||
init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'raylib [core] example - random values')
|
init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'raylib [core] example - random values')
|
||||||
|
|
||||||
# set_random_seed() // Set a custom random seed if desired, by default: "time(NULL)"
|
# set_random_seed() // Set a custom random seed if desired, by default: "time(NULL)"
|
||||||
|
|
||||||
randValue: int = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included)
|
randValue = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
framesCounter: int = 0 # Variable used to count frames
|
framesCounter = 0 # Variable used to count frames
|
||||||
|
|
||||||
set_target_fps(60) # Set our game to run at 60 frames-per-second
|
set_target_fps(60) # Set our game to run at 60 frames-per-second
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ while not window_should_close(): # Detect window close button or ESC key
|
||||||
framesCounter += 1
|
framesCounter += 1
|
||||||
|
|
||||||
# Every two seconds (120 frames) a new random value is generated
|
# Every two seconds (120 frames) a new random value is generated
|
||||||
if ((framesCounter/120)%2) == 1:
|
if ((framesCounter/120) % 2) == 1:
|
||||||
randValue = get_random_value(-8, 5)
|
randValue = get_random_value(-8, 5)
|
||||||
framesCounter = 0
|
framesCounter = 0
|
||||||
|
|
||||||
|
|
43
examples/shapes/shapes_logo_raylib.py
Normal file
43
examples/shapes/shapes_logo_raylib.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
"""
|
||||||
|
|
||||||
|
raylib [core] example - Logo Raylib
|
||||||
|
|
||||||
|
"""
|
||||||
|
from pyray import *
|
||||||
|
from raylib.colors import (
|
||||||
|
RAYWHITE,
|
||||||
|
BLACK,
|
||||||
|
GRAY
|
||||||
|
)
|
||||||
|
|
||||||
|
# Initialization
|
||||||
|
screenWidth = 800
|
||||||
|
screenHeight = 450
|
||||||
|
|
||||||
|
init_window(screenWidth, screenHeight, 'raylib [shapes] example - raylib logo using shapes')
|
||||||
|
|
||||||
|
set_target_fps(60) # Set our game to run at 60 frames-per-second
|
||||||
|
|
||||||
|
# Main game loop
|
||||||
|
while not window_should_close(): # Detect window close button or ESC key
|
||||||
|
# Update
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
# TODO: Update your variables here
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Draw
|
||||||
|
# ----------------------------------------------------------------------------------
|
||||||
|
begin_drawing()
|
||||||
|
|
||||||
|
clear_background(RAYWHITE)
|
||||||
|
|
||||||
|
draw_rectangle(int(screenWidth/2 - 128), int(screenHeight/2 - 128), 256, 256, BLACK)
|
||||||
|
draw_rectangle(int(screenWidth/2 - 112), int(screenHeight/2 - 112), 224, 224, RAYWHITE)
|
||||||
|
draw_text("raylib", int(screenWidth/2 - 44), int(screenHeight/2 + 48), 50, BLACK)
|
||||||
|
|
||||||
|
draw_text("this is NOT a texture!", 350, 370, 10, GRAY)
|
||||||
|
|
||||||
|
end_drawing()
|
||||||
|
|
||||||
|
# De-Initialization
|
||||||
|
close_window() # Close window and OpenGL context
|
Reference in a new issue