-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathCarGame.py
More file actions
43 lines (35 loc) · 998 Bytes
/
CarGame.py
File metadata and controls
43 lines (35 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from ursina import *
import random
app = Ursina()
camera.orthographic = True
camera.fov = 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 = random.uniform(-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)
enemies.append(new)
invoke(newEnemy, delay=0.5)
newEnemy()
def update():
car.x -=held_keys['a']*5*time.dt
car.x +=held_keys['d']*5*time.dt
for road in pair:
road.y -= 6*time.dt
if road.y < -15:
road.y += 30
for enemy in enemies:
if enemy.x < 0:
enemy.y -= 10 * time.dt
else:
enemy.y -= 5 * time.dt
if enemy.y < -10:
enemies.remove(enemy)
destroy(enemy)
if car.intersects().hit:
car.shake()
app.run()