Examples

Models
"""
    Models are very similar to cubes!
"""
from rlzero import *

DATA_DIR="data"

wiz = Model('rpg_characters/Wizard')
wiz.size = (20,20,20)


def draw():
    clear()
    wiz.draw()


def update():
    wiz.x += 1
    if wiz.x > 100:
        wiz.x = -100

run()

"""TODO
    try some other 3d object build-ins
    try downloading some .glb files from the web
    try creating a .glb file using https://www.leocad.org/ or https://www.blender.org/
"""
Models
"""
    Most of this code is copied from previous programs
"""

from rlzero import *

cube = Cube((0, 10, 0), (10, 20, 10), 'blue')
DATA_DIR="data"
wiz = Model('rpg_characters/Wizard')
wiz.size = (20,20,20)
wiz.collision_radius = 20


def draw():
    clear()
    wiz.draw()
    cube.draw()

def update():
    if keyboard.right:
        wiz.x += 1
    elif keyboard.left:
        wiz.x -= 1
    cube.x += 1
    if cube.x > 100:
        cube.x = -100
    if wiz.check_collision(cube):
        wiz.color = RED
    else:
        wiz.color = WHITE

run()

""" TODO
    joystick input (again), vertical movement (again)
    make the box chase the alien
    print number of times hit (the score)
"""
Models
"""
    Demo game
"""

from rlzero import *
import random
import time

TIME = 20
NUMBER_OF_BALLS = 10
JUMP_POWER = 2

start_time = time.time()
time_left = TIME

CAMERA =pyray.CAMERA_PERSPECTIVE

balls = []
for i in range(0, NUMBER_OF_BALLS):
    ball = Sphere()
    ball.x = random.randint(-300, 300)
    ball.y = random.randint(10, 40)
    ball.z = random.randint(-300, 0)
    ball.color = 'green'
    balls.append(ball)

score = 0

DATA_DIR="data"

wiz = Model('rpg_characters/Wizard')
wiz.size = (10, 10, 10)
wiz.collision_radius = 5

wiz.yv = 0
wiz.xv = 0
wiz.zv = 0

sound = Sound('eep')
sound.volume = 0.7
sound.pitch = 0.5


def draw():
    clear()
    wiz.draw()
    for ball in balls:
        ball.draw()
        pyray.draw_circle_3d((ball.pos.x, 0, ball.pos.z),10,(1,0,0),90,BLACK)


def draw2d():
    if (time_left > 0):
        screen.draw_text(f"Score: {score}       Time: {time_left}", 0, 0, 50, VIOLET)
    else:
        screen.draw_text(f"Your Score: {score}\nOUT OF TIME", 30, 50, 50, RED)


def update(delta):
    global score
    global time_left

    print("frame delta: ", delta)
    camera.target = wiz.pos

    time_left = int(TIME + (start_time - time.time()))
    if time_left <= 0:
        return

    wiz.yv -= 0.05

    wiz.x += wiz.xv
    wiz.y += wiz.yv
    wiz.z += wiz.zv

    if wiz.y <= 0:  # Only control when wiz is on ground
        if keyboard.right:
            wiz.xv += 0.1
        elif keyboard.left:
            wiz.xv -= 0.1
        if keyboard.down:
            wiz.zv += 0.1
        elif keyboard.up:
            wiz.zv -= 0.1

        if keyboard.space:
            wiz.yv = JUMP_POWER

        if wiz.xv > 0.05:
            wiz.xv -= 0.05
        elif wiz.xv < -0.05:
            wiz.xv += 0.05

        if wiz.zv > 0.05:
            wiz.zv -= 0.05
        elif wiz.zv < -0.05:
            wiz.zv += 0.05

        wiz.y = 0

    for ball in balls:
        if wiz.check_collision(ball):
            balls.remove(ball)
            sound.play()
            score += 1


run()

""" TODO
    gamepad controls
    change jump power, number of balls
    second player
    enemy that chases player

"""
Models
"""
Simple game that displays text on screen
Note that text is 2d, not 3d, so it must be drawn in draw2d() function
"""

from rlzero import *

score = 0

def draw():
    clear()

def draw2d():
    pyray.draw_text(f"Player 1 score: {score}", 0, 0, 40, VIOLET)

def update():
    global score
    if keyboard.key_pressed('space'):
        score += 1

run()


"""
TODO
Make the score text larger and RED colored
Add score2 for player 2 that increases when P key is pressed
Add score display to another program, e.g. 17
"""