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
|
import pygame, random
from baseSprite import BaseSprite
import crashteroidsconfig
class Bullet(BaseSprite):
def __init__(self,x,y,orientation, imgName = None):
img = "bullet.png"
if imgName != None:
img = imgName
BaseSprite.__init__(self, img)
self.launchSound = pygame.mixer.Sound(crashteroidsconfig.guy_shoot_sound)
self.launchSound.set_volume(.05)
self.launchSound.play()
self.explosionSound = pygame.mixer.Sound(crashteroidsconfig.guy_bullet_explode)
self.explosionSound.set_volume(.2)
self.orientation = orientation
self.x = x
self.y = y
self.accelerating = True
self.accelerationDivisor = .75
self.maxVelocity = 100
self.maxticks = 10
self.ticks = 0
self.exploding = False
self.explodestage = 0
self.update_image()
def update(self):
BaseSprite.update(self)
self.ticks += 1
if not self.exploding and self.ticks > self.maxticks:
self.kill()
if self.exploding:
self.explodestage += 1
e = self.explodestage
if e < 5:
e = str(e)
self.masterImage = pygame.image.load(crashteroidsconfig.bullet_explode_stage + e + ".png")
self.update_image()
else:
self.kill()
def explode(self):
self.accelerating = False
self.velocityX = 0
self.velocityY = 0
self.explosionSound.play()
self.exploding = True
|