-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupply.py
More file actions
91 lines (83 loc) · 3.42 KB
/
supply.py
File metadata and controls
91 lines (83 loc) · 3.42 KB
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
import pygame
import abc
import flywight
import random
class Supply:
__metaclass__= abc.ABCMeta #抽象类
@abc.abstractmethod
def move(self):
pass
@abc.abstractmethod
def reset(self):
pass
@abc.abstractmethod
def drawSupply(self, screen, clientPlane):
pass
class Bullet_Supply(Supply, pygame.sprite.Sprite):
def __init__(self, bg_size):
Supply.__init__(self)
pygame.sprite.Sprite.__init__(self)
self.flyWight = flywight.Supply_FlyWight()
self.image = self.flyWight.bullet_supply_image
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.rect.left, self.rect.bottom = \
random.randint(0, self.width - self.rect.width), -100
self.speed = 2
self.active = False
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.active = True
self.rect.left, self.rect.bottom = \
random.randint(0, self.width - self.rect.width), -100
def drawSupply(self, screen, clientPlane):
if self.active:
self.move()
screen.blit(self.image, self.rect)
if pygame.sprite.collide_mask(self, clientPlane):
self.flyWight.get_bullet_sound.play()
clientPlane.is_double_bullet = True
pygame.time.set_timer(self.flyWight.DOUBLE_BULLET_TIME, 18 * 1000)
self.active = False
class Bomb_Supply(Supply, pygame.sprite.Sprite):
def __init__(self, bg_size):
Supply.__init__(self)
pygame.sprite.Sprite.__init__(self)
self.flyWight = flywight.Supply_FlyWight()
self.image = self.flyWight.bomb_supply_image
self.rect = self.image.get_rect()
self.width, self.height = bg_size[0], bg_size[1]
self.rect.left, self.rect.bottom = \
random.randint(0, self.width - self.rect.width), -100
self.speed = 2
self.active = False
self.mask = pygame.mask.from_surface(self.image)
def move(self):
if self.rect.top < self.height:
self.rect.top += self.speed
else:
self.active = False
def reset(self):
self.active = True
self.rect.left, self.rect.bottom = \
random.randint(0, self.width - self.rect.width), -100
def drawSupply(self, screen, clientPlane):
if self.active:
self.move()
screen.blit(self.image, self.rect)
if pygame.sprite.collide_mask(self, clientPlane):
self.flyWight.get_bomb_sound.play()
clientPlane.increaseBombNum()#增加炸弹
self.active = False
bomb_image = pygame.image.load("images/bomb.png").convert_alpha()
bomb_rect = bomb_image.get_rect()
bomb_font = pygame.font.Font("font/font.ttf", 48)
bomb_text = bomb_font.render(" X %d" % clientPlane.bomb_num, True, self.flyWight.WHITE)
text_rect = bomb_text.get_rect()
screen.blit(bomb_image, (10, self.height - 10 - bomb_rect.height))
screen.blit(bomb_text, (20 + bomb_rect.width, self.height - 5 - text_rect.height))