-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.py
72 lines (65 loc) · 2.86 KB
/
world.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
from character import Character
import constants as const
from items import Item
class World():
def __init__(self):
self.map_tiles = []
self.obstacle_tiles = []
self.item_list = []
self.character_list = []
self.exit_tile = None
self.player = None
def process_data(self, data, tile_list, item_images, mob_animations):
self.level_length = len(data)
# iterate through each value in level data file
for y, row in enumerate(data):
for x, tile in enumerate(row):
image = tile_list[tile]
image_rect = image.get_rect()
image_x = x*const.TILE_SIZE
image_y = y*const.TILE_SIZE
image_rect.center = (image_x, image_y)
tile_data = [image, image_rect, image_x, image_y]
if tile == 7:
self.obstacle_tiles.append(tile_data)
elif tile == 8:
self.exit_tile = tile_data
elif tile == 9:
coin = Item(image_x, image_y, 0, item_images[0])
self.item_list.append(coin)
tile_data[0] = tile_list[0]
elif tile == 10:
potion = Item(image_x, image_y, 1, [item_images[1]])
self.item_list.append(potion)
tile_data[0] = tile_list[0]
elif tile == 21:
player = Character(
image_x, image_y, 100, mob_animations, 0, False, 1)
self.player = player
tile_data[0] = tile_list[0]
elif tile == 22:
player = Character(
image_x, image_y, 100, mob_animations, 0, False, 1)
self.player = player
tile_data[0] = tile_list[0]
elif tile >= 12 and tile <= 20:
enemy = Character(
image_x, image_y, 100, mob_animations, tile-11, False, 1)
self.character_list.append(enemy)
tile_data[0] = tile_list[0]
elif tile == 11:
enemy = Character(
image_x, image_y, 200, mob_animations, 6, True, 2)
self.character_list.append(enemy)
tile_data[0] = tile_list[0]
# add image data to main tiles list
if tile >= 0:
self.map_tiles.append(tile_data)
def update(self, screen_scroll):
for tile in self.map_tiles:
tile[2] += screen_scroll[0]
tile[3] += screen_scroll[1]
tile[1].center = (tile[2], tile[3])
def draw(self, surface):
for tile in self.map_tiles:
surface.blit(tile[0], tile[1])