-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.py
35 lines (30 loc) · 1.09 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
import pygame
class Bullet(pygame.sprite.Sprite):
def __init__(self, position, type=1, deviation=0):
pygame.sprite.Sprite.__init__(self)
self.type = type
self.deviation = deviation
if type == 1:
self.image = pygame.image.load('image/bullet1.png').convert_alpha()
elif type == 2:
self.image = pygame.image.load('image/bullet2.png').convert_alpha()
self.rect = self.image.get_rect()
self.rect.left, self.rect.top = position
if type == 2:
if deviation == 1:
self.rect.left -= 10
elif deviation == 2:
self.rect.left += 10
self.speed = 11
# 子弹碰撞即为false
self.active = True
pygame.mask.from_surface(self.image)
def move(self):
self.rect.top -= self.speed
def reset(self, position):
self.rect.left, self.rect.top = position
if self.type == 2:
if self.deviation == 1:
self.rect.left -= 10
elif self.deviation == 2:
self.rect.left += 10