Flappy Bird 3D in Python #coding #python #flappybird #code

preview_player
Показать описание
#shorts
Рекомендации по теме
Комментарии
Автор

The code (thanks for the views):
from ursina import *
from ursina.shaders import *
import random

app = Ursina()

Entity.default_shader = basic_lighting_shader

player = Entity(model = "cube", collider = "box", color = color.yellow)
pipe1 = Entity(model='cube', color = color.green, scale = (1, 5, 1), position = (0, 4, 20), collider = "box")
pipe2 = Entity(model='cube', color = color.green, scale = (1, 5, 1), position = (0, -4, 20), collider = "box")
bounds = Entity(model='cube', color = color.blue, scale = (1, 1, 50), position = (0, -5, 0), collider = "box")
bounds2 = Entity(model='cube', color = color.blue, scale = (1, 1, 50), position = (0, 5, 0), collider = "box")

score = 0

board = Text(text = f'Score: {score}', scale = 2, origin = (0, 0), position = (0, 0.4), color = color.black)

fall_speed = 0

def update():
global fall_speed, score

camera.x = player.x
camera.z = player.z - 8
camera.y = player.y + 2
camera.look_at(player)
player.y += fall_speed
fall_speed -= 0.001
if held_keys['space']:
fall_speed += 0.005

pipe1.z -= 0.05
pipe2.z = pipe1.z

hit_info1 = player.intersects(pipe1)
hit_info2 = player.intersects(pipe2)

if hit_info1.hit or hit_info2.hit or player.y > 4 or player.y < -4:
score = 0
board.text = f"Score: {score}"
pipe1.z = 20
pipe2.z = 20
pipe1.y = random.uniform(2, 3)
pipe2.y = pipe1.y - 8
fall_speed = 0
player.y = 0

if pipe1.z < player.z-4:
score += 1
board.text = f"Score: {score}"
pipe1.z = 20
pipe2.z = 20
pipe1.y = random.uniform(2, 3)
pipe2.y = pipe1.y - 8


Sky()

app.run()

programmingduntless
join shbcf.ru