-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.py
More file actions
199 lines (134 loc) · 6.27 KB
/
tile.py
File metadata and controls
199 lines (134 loc) · 6.27 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import pygame as pg
import os
import entity
class Tile(pg.sprite.Sprite):
def __init__(self, game, x, y, tileX, tileY, tileCollide):
#Sets if tile can be collided with or not#
if tileCollide == True:
self.groups = game.all_sprites, game.all_tiles, game.all_walls
else:
self.groups = game.all_sprites, game.all_floor
#Initalises sprite, sets size and texture used#
size = game.tileSize
pg.sprite.Sprite.__init__(self, self.groups)
self.image = pg.Surface((36,36), pg.SRCALPHA, 32).convert_alpha()
self.image.blit(game.TILE_SET,(0, 0), ((tileX)* size, (tileY)* size, size, size))
self.rect = self.image.get_rect()
#Sets tile location#
self.rect.x = x * size
self.rect.y = y * size
#Creates collsion mask for tile#
self.mask = pg.mask.from_surface(self.image)
class Shop(pg.sprite.Sprite):
def __init__(self, game, x, y , type):
self.groups = game.all_sprites, game.all_shops
#Initalises shop and texture used#
size = game.tileSize
pg.sprite.Sprite.__init__(self, self.groups)
self.SHOP = pg.image.load(os.path.join("Textures","World","ShopWeapons.png")).convert_alpha()
self.image = pg.Surface((32,32)).convert_alpha()
self.image.blit(self.SHOP, (0, 0))
self.rect = self.image.get_rect()
#Sets tile location#
self.rect.x = (x * size) + 2
self.rect.y = (y * size) + 2
self.type = type
#Creates collsion mask for shop#
self.mask = pg.mask.from_surface(self.image)
def update(self, delta):
self.mask = pg.mask.from_surface(self.image)
class Door(pg.sprite.Sprite):
def __init__(self, game, x, y , orientation, cost):
self.groups = game.all_sprites, game.all_tiles, game.all_doors
#Initalises door and texture used#
size = game.tileSize
pg.sprite.Sprite.__init__(self, self.groups)
self.DOOR = pg.image.load(os.path.join("Textures","World",("Door" + orientation + ".png"))).convert_alpha()
self.image = pg.Surface((36,36)).convert_alpha()
self.image.blit(self.DOOR, (0, 0))
self.rect = self.image.get_rect()
#Sets door location#
self.rect.x = (x * size)
self.rect.y = (y * size)
self.cost = cost
def update(self, delta):
#Creates collsion mask for door#
self.mask = pg.mask.from_surface(self.image)
class Upgrade(pg.sprite.Sprite):
def __init__(self, game, x, y, type):
self.groups = game.all_sprites, game.all_upgrades
#Initalises upgrade and texture used#
size = game.tileSize
pg.sprite.Sprite.__init__(self, self.groups)
self.UPGRADE = pg.image.load(os.path.join("Textures","World","ShopUpgrades.png")).convert_alpha()
self.image = pg.Surface((32,32)).convert_alpha()
self.image.blit(self.UPGRADE, (0, 0))
self.rect = self.image.get_rect()
#Sets upgrade location#
self.rect.x = (x * size) + 2
self.rect.y = (y * size) + 2
values = [["Fast Mag",1000],["Quick Shot",1200],["Damage Boost",1400],["Double Mag",1400],["Burst Shot",1600]]
try:
self.cost = values[type-1][1]
self.type = values[type-1][0]
self.num = type
except:
self.cost = 1000
self.type = values[1][0]
self.num = 1
#Creates collsion mask for upgrade#
self.mask = pg.mask.from_surface(self.image)
def update(self, delta):
self.mask = pg.mask.from_surface(self.image)
class Perks(pg.sprite.Sprite):
def __init__(self, game, x, y, type):
self.groups = game.all_sprites, game.all_perks
#Initalises upgrade and texture used#
size = game.tileSize
pg.sprite.Sprite.__init__(self, self.groups)
self.PERKS = pg.image.load(os.path.join("Textures","World","ShopPerks.png")).convert_alpha()
self.image = pg.Surface((32,32)).convert_alpha()
self.image.blit(self.PERKS, (0, 0))
self.rect = self.image.get_rect()
#Sets upgrade location#
self.rect.x = (x * size) + 2
self.rect.y = (y * size) + 2
#0: +100 base health, 1: -1 seconds before health, 2: +5 points for damage and +20 points for kills, 3: gives bettween 0 and 5 ammo for a gun after kill#
values = ["Long Life","Self Care","Pick Pocket","Salvager"]
try:
self.type = values[type]
self.num = type
except:
self.type = values[0]
self.num = 1
#Creates collsion mask for upgrade#
self.mask = pg.mask.from_surface(self.image)
def update(self, delta):
self.mask = pg.mask.from_surface(self.image)
class Spawner(pg.sprite.Sprite):
def __init__(self, game, x, y, link):
self.groups = game.all_sprites, game.all_spawners
#Initalises spawner and texture used#
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.SPAWNER = pg.image.load(os.path.join("Textures","World","Spawner.png")).convert_alpha()
self.image = pg.Surface((32,32)).convert_alpha()
self.image.blit(self.SPAWNER, (0, 0))
self.rect = self.image.get_rect()
#Sets tile location#
self.rect.x = (x * game.tileSize) + 2
self.rect.y = (y * game.tileSize) + 2
self.linkedDoors = link
self.canSpawn = False
#Creates collsion mask for spawner#
self.mask = pg.mask.from_surface(self.image)
def update(self, delta):
#Used to allow enemies to spawn at if a door connected to it is open (if there is no door is allowed by default)#
if not self.canSpawn:
if self.linkedDoors == []:
self.canSpawn = True
else:
for i in self.linkedDoors:
if list(self.game.aiMap[i[1]])[i[0]] == "*":
self.canSpawn = True
self.mask = pg.mask.from_surface(self.image)