-
Notifications
You must be signed in to change notification settings - Fork 6
/
bullet.py
57 lines (48 loc) · 1.81 KB
/
bullet.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
import pygame
import math
import random
import util
import sprite
import asteroid
import alien
class Bullet(sprite.Sprite):
def __init__(self, world):
super(Bullet, self).__init__(world)
self.points = [[1, 0],
[util.cos(120), util.sin(120)],
[util.cos(240), util.sin(240)]]
self.scale = 2
self.life = 100
self.angle = 0
def update(self):
super(Bullet, self).update()
self.life -= 1
if self.life == 0:
self.kill = True
def collision(self, other):
# don't chain up, we don't want to exchange velocity or anything like
# that
pass
def impact(self, other):
if isinstance(other, alien.Alien):
other.kill = True
self.kill = True
self.world.score += 1000
self.world.particle.explosion(20,
other.position, other.velocity)
elif isinstance(other, asteroid.Asteroid):
other.kill = True
self.kill = True
self.world.score += other.scale
self.world.n_asteroids -= 1
self.world.particle.explosion(other.scale / 3,
other.position, other.velocity)
if other.scale > 15:
n = random.randint(2, max(2, min(5, int(other.scale / 5))))
for i in range(n):
new_asteroid = asteroid.Asteroid(self.world,
other.scale / n, 1)
new_asteroid.position[0] = other.position[0]
new_asteroid.position[1] = other.position[1]
new_asteroid.velocity[0] += other.velocity[0]
new_asteroid.velocity[1] += other.velocity[1]