-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sword.py
45 lines (38 loc) · 1.3 KB
/
Sword.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
import pygame
#The Sword that the AI and enemy use
class Sword(pygame.sprite.Sprite):
def __init__(self,x,y,width,height,facing):
super().__init__()
self.facing = facing
self.x = x
self.y = y
self.image = pygame.image.load('Images/swordUp.png')
self.rect = self.image.get_rect()
self.width = width
self.timer = 0
if facing == -1:
self.image = pygame.image.load('Images/swordLeft.png')
self.rect = self.image.get_rect()
self.rect.x = x - 50
self.rect.y = y + 30
elif facing == 1:
self.image = pygame.image.load('Images/swordRight.png')
self.rect = self.image.get_rect()
self.rect.x = x + 45
self.rect.y = y + 30
else:
self.rect.x = x + width
self.rect.y = y - 20
def update(self):
if self.facing == -1:
self.rect.x = self.x - 50
self.rect.y = self.y + 30
elif self.facing == 1:
self.rect.x = self.x + 45
self.rect.y = self.y + 30
else:
self.rect.x = self.x + self.width
self.rect.y = self.y - 20
self.timer += 1
if self.timer >= 3:
self.kill()