-
Notifications
You must be signed in to change notification settings - Fork 0
/
MysteryShip.py
33 lines (30 loc) · 1.32 KB
/
MysteryShip.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
import os
import pygame
import random
class MysteryShip(pygame.sprite.Sprite):
def __init__(self, game_resources, game_state):
pygame.sprite.Sprite.__init__(self)
self.image = game_resources.get_image('mystery_ship.png')
self.image.set_colorkey((255, 255, 255))
self.rect = self.image.get_rect()
self.explosion_sound = game_resources.get_sound('explosion.mp3')
self.game_state = game_state
self.health = 3
self.size = 100
self.rect.x = game_state.width
self.rect.y = 44
game_state.all_sprites.add(self)
def update(self):
self.rect.x -= 1
for rocket in self.game_state.rockets:
if (self.rect.x + self.size > rocket.x > self.rect.x - self.size and
self.rect.y + self.size > rocket.y > self.rect.y - self.size):
self.game_state.rockets.remove(rocket)
self.game_state.all_sprites.remove(rocket)
self.game_state.all_sprites.remove(self)
self.game_state.score += random.choice([50, 100, 150, 200])
self.explosion_sound.play()
self.game_state.mystery_ship_flying = False
if self.rect.right <= 0:
self.game_state.all_sprites.remove(self)
self.game_state.mystery_ship_flying = False