forked from sai-byui/NEO2D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bullet.py
44 lines (33 loc) · 1.11 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
36
37
38
39
40
41
42
43
44
from enum import Enum
import pygame
green = (0, 255, 0)
class Bullet(pygame.sprite.Sprite):
def __init__(self, direction):
# Call the parent class (Sprite) constructor
super(Bullet, self).__init__()
# for shooting directions: 1 = UP, 2 = DOWN, 3 = LEFT, 4 = RIGHT
self.direction = direction
if self.direction == 1 or self.direction == 2:
self.image = pygame.Surface([2, 6])
self.rect = pygame.Rect(0, 0, 2, 6)
else :
self.image = pygame.Surface([6, 2])
self.rect = pygame.Rect(0, 0, 6, 2)
self.image.fill(green)
def move_up(self):
self.rect.y -= 8
def move_down(self):
self.rect.y += 8
def move_left(self):
self.rect.x -= 8
def move_right(self):
self.rect.x += 8
def update_movement(self):
"""moves the bullet's position based on its direction"""
movement = {1: self.move_up, 2: self.move_down, 3: self.move_left, 4: self.move_right}
movement[self.direction]()
class BulletDirection(Enum):
UP = 1
DOWN = 2
LEFT = 3
RIGHT = 4