-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpaceX_Invader.py
94 lines (76 loc) · 2.6 KB
/
SpaceX_Invader.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from ursina import *
from random import randint
def update():
global invaders, bullets, score, text
player.x += held_keys['right arrow'] * time.dt * player.dx
player.x -= held_keys['left arrow'] * time.dt * player.dx
for invader in invaders:
invader.y += time.dt * invader.dy
if invader.y < -0.55:
Entity(model='quad', scale=60, color=color.gray)
player.y = 10
Text(text='|GAME OVER|', origin=(0, 0), scale=5, color=color.yellow, background=True)
return
for bullet in bullets:
bullet.y += time.dt * bullet.dy
hit_info = bullet.intersects()
if hit_info.hit:
Audio('assets/explosion_sound.wav')
bullet.x = 10
score += 1
text.text = f"SCORE: {score}"
if hit_info.entity in invaders:
hit_info.entity.x = randint(-50, 50) * 0.01
hit_info.entity.y = randint(80, 120) * 0.01
def input(key):
if key == "space":
Audio('assets/laser_sound.wav')
bullet = Bullet()
bullets.append(bullet)
class Invader(Entity):
def __init__(self):
super().__init__()
self.parent = field
self.model = 'quad'
self.texture = 'alien.png'
self.scale = 0.1
self.position = (randint(-50, 50) * 0.01, randint(80, 120) * 0.01, -0.1)
self.collider = 'box'
self.dy = -0.15
class Player(Entity):
def __init__(self):
super().__init__()
self.parent = field
self.model = 'cube'
self.color = color.orange
self.texture = 'assets/Astra'
self.scale = (0.1, 0.2, 0.2)
self.position = (0, -0.5, -0.1)
self.dx = 0.5
class Bullet(Entity):
def __init__(self):
super().__init__()
self.parent = field
self.model = 'cube'
self.color = color.green
self.texture = 'assets/laser'
self.scale = (0.02, 0.1, 0.1)
self.position = player.position + Vec3(0, 0.2, 0)
self.collider = 'box'
self.dy = 0.8
app = Ursina()
field_size = 19
Entity(model='quad', scale=60, texture='assets/blue_sky')
field = Entity(model='quad', color=color.rgba(255, 255, 255, 0), scale=(12, 18),
position=(field_size // 2, field_size // 2, -.01))
bullets = []
invaders = []
player = Player()
for i in range(10):
invader = Invader()
invaders.append(invader)
score = 0
text = Text(text='Score: 0', position=(-0.65, 0.4), origin=(0, 0), scale=2, color=color.yellow, background=True)
camera.position = (field_size // 2, -18, -18)
camera.rotation_x = -56
app.run()