0% found this document useful (0 votes)
16 views1 page

Jeu Py

This document contains a Python script using the Ursina game engine to create a simple 2D car game. The game features a player-controlled car that can move left and right, while enemies spawn randomly and move down the screen. The script includes collision detection to shake the car upon impact with enemies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Jeu Py

This document contains a Python script using the Ursina game engine to create a simple 2D car game. The game features a player-controlled car that can move left and right, while enemies spawn randomly and move down the screen. The script includes collision detection to shake the car upon impact with enemies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

from ursina import *

import random

app = Ursina()
[Link] = True

[Link] = 10

car = Entity(model='quad', texture='assets\car', collider='box', scale=(2,1),


rotation_z=-90, y = -3)

road1 = Entity(model='quad', texture='assets\\road', scale=15, z=1)


road2= duplicate(road1, y=15)
pair = [road1, road2]

enemies = []
def newEnemy():
val = [Link](-2,2)
new = duplicate(car, texture='assets\enemy', x = 2*val, y = 25,
color=color.random_color(),
rotation_z = 90 if val < 0 else -90)
[Link](new)
invoke(newEnemy, delay=0.5)
newEnemy()

def update():
car.x -=held_keys['a']*5*[Link]
car.x +=held_keys['d']*5*[Link]
for road in pair:
road.y -= 6*[Link]
if road.y < -15:
road.y += 30
for enemy in enemies:
if enemy.x < 0:
enemy.y -= 10 * [Link]
else:
enemy.y -= 5 * [Link]
if enemy.y < -10:
[Link](enemy)
destroy(enemy)
if [Link]().hit:
[Link]()

[Link]()

You might also like