/
mine.py
executable file
·63 lines (44 loc) · 1.77 KB
/
mine.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
import pygame
import random
from water import Water
from locals import *
import util
def init():
Mine.image = util.load_image("miina")
Mine.sound = util.load_sound("poks")
class Mine(pygame.sprite.Sprite):
image = None
sound = None
def __init__(self):
pygame.sprite.Sprite.__init__(self)
# This is an easy way to get a random number that is a water level.
height = int(SCREEN_HEIGHT - Water.global_water.get_water_level(random.random() * 320)) - 4
if not Mine.image or not Mine.sound:
mine.init()
self.image = pygame.Surface((Mine.image.get_width(), Mine.image.get_height() + height), SRCALPHA, 32)
self.image.fill((0,0,0,0))
self.rect = self.image.get_rect()
self.rect.bottom = SCREEN_HEIGHT
self.rect.left = SCREEN_WIDTH
self.image.blit(Mine.image, Mine.image.get_rect())
pygame.draw.line(self.image, (25, 25, 25), (self.image.get_rect().centerx, Mine.image.get_height()),
(self.image.get_rect().centerx, self.image.get_height()))
self.hitmask = pygame.surfarray.array_alpha(self.image)
self.dx = -1
self.exploding = False
self.explode_frames = 0
def update(self):
water_level = Water.global_water.get_water_level(self.rect.centerx)
self.rect.left += self.dx
if SCREEN_HEIGHT - water_level < self.rect.height - 4:
self.rect.top = water_level - 4
else:
self.rect.bottom = SCREEN_HEIGHT
if self.exploding:
if self.explode_frames > 0:
self.explode_frames -= 1
# animate
def explode(self):
Mine.sound.play()
self.exploding = True
self.explode_frames = 10