adding core_random_values example
This commit is contained in:
parent
6aaf3bb391
commit
50e74a7e26
1 changed files with 54 additions and 0 deletions
54
examples/core/core_random_values.py
Normal file
54
examples/core/core_random_values.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""
|
||||
|
||||
raylib [core] example - random values
|
||||
|
||||
"""
|
||||
from pyray import *
|
||||
from raylib.colors import (
|
||||
RAYWHITE,
|
||||
MAROON,
|
||||
LIGHTGRAY
|
||||
)
|
||||
|
||||
# Initialization
|
||||
SCREEN_WIDTH: int = 800
|
||||
SCREEN_HEIGHT: int = 450
|
||||
|
||||
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)"
|
||||
|
||||
randValue: int = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included)
|
||||
|
||||
framesCounter: int = 0 # Variable used to count frames
|
||||
|
||||
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
|
||||
# ----------------------------------------------------------------------------------
|
||||
framesCounter += 1
|
||||
|
||||
# Every two seconds (120 frames) a new random value is generated
|
||||
if ((framesCounter/120)%2) == 1:
|
||||
randValue = get_random_value(-8, 5)
|
||||
framesCounter = 0
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
# Draw
|
||||
# ----------------------------------------------------------------------------------
|
||||
begin_drawing()
|
||||
|
||||
clear_background(RAYWHITE)
|
||||
|
||||
draw_text("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON)
|
||||
|
||||
draw_text(str(randValue), 360, 180, 80, LIGHTGRAY)
|
||||
|
||||
end_drawing()
|
||||
|
||||
# De-Initialization
|
||||
close_window() # Close window and OpenGL context
|
Reference in a new issue