-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPC_Base.py
120 lines (93 loc) · 3.31 KB
/
NPC_Base.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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
## NPC Base Classes
import pygame
class Basic(pygame.sprite.Sprite):
"""
The root class
self.x and self.y are pixels, not coordinates
"""
def __init__(self, screen, x, y):
pygame.sprite.Sprite.__init__(self)
self.x = 32 * x + 160
self.y = 32 * y
def getY(self): return self.y
def getX(self): return self.x
def setX(self, x): self.x = 32 * x + 160
def setY(self, y): self.y = 32 * y
def update(self): self.rect.topleft = (self.x, self.y)
class NPC(Basic):
"""
The NPC base class
Initialize the type for all NPCs
Sets self.type = "NPC"
"""
def __init__(self, screen, x, y):
Basic.__init__(self, screen, x, y)
self.group = "NPC"
class MrAgnew(NPC):
"""
The MrAgnew base class
Key point: self.image, self.rect, self.name, self.role
"""
def __init__(self, screen, x, y, img):
NPC.__init__(self, screen, x, y)
self.image = pygame.image.load('./imgSource/All/{}.png'.format(img))
self.image.set_colorkey((0, 0, 0))
self.rect = self.image.get_rect()
self.screen = screen
self.name = 'Mr. Agnew'
self.type = "Ally"
class Princess(Basic):
def __init__(self, screen, x, y):
Basic.__init__(self, screen, x, y)
self.imageList = []
for i in range(1, 14, 4):
image = pygame.image.load(('./imgSource/Princess/images/Princess_'+\
str(i).rjust(2, '0')+'.png')).convert()
image.set_colorkey((0, 0, 0))
self.imageList.append(image)
self.image = self.imageList[0]
self.image.set_colorkey((0, 0, 0))
## Here, self.imageList is useless because it will
## always be overriden
self.screen = screen
self.rect = self.image.get_rect()
self.type = 'Ally'
class Merchant(NPC):
"""
The Merchant base class
Key point: self.image, self.rect, self.name, self.role
"""
def __init__(self, screen, x, y, img):
NPC.__init__(self, screen, x, y)
self.image = pygame.image.load('./imgSource/All/{}.png'.format(img))
self.image.set_colorkey((0, 0, 0))
self.rect = self.image.get_rect()
self.screen = screen
self.name = 'Merchant'
self.type = "Ally"
class Thief(NPC):
"""
The Thief base class
Key point: self.image, self.rect, self.name, self.role
"""
def __init__(self, screen, x, y, img):
NPC.__init__(self, screen, x, y)
self.image = pygame.image.load('./imgSource/All/{}.png'.format(img))
self.image.set_colorkey((0, 0, 0))
self.rect = self.image.get_rect()
self.screen = screen
self.name = 'Thief'
self.type = "Ally"
class Nemo(NPC):
"""
The Nemo base class
Key point: self.image, self.rect, self.name, self.role
"""
def __init__(self, screen, x, y, img):
NPC.__init__(self, screen, x, y)
self.image = pygame.image.load('./imgSource/All/{}.png'.format(img))
self.image.set_colorkey((0, 0, 0))
self.rect = self.image.get_rect()
self.screen = screen
self.name = 'Nemo'
self.type = "Ally"