-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.py
74 lines (38 loc) · 1.96 KB
/
level.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
import pygame
pygame.init()
class Level:
def __init__(self, input_array, tile_size, imgs):
self.input_array = input_array
self.tile_size = tile_size
self.tiles_to_collide = [[],[],[]]
self.imgs = imgs
y = 0
for row in self.input_array:
x = 0
for tile in row:
if tile == 1 or tile == 2:
self.tiles_to_collide[0].append(pygame.Rect(x * self.tile_size, y * self.tile_size, self.tile_size, self.tile_size))
elif tile == 3:
self.tiles_to_collide[1].append(pygame.Rect(x * self.tile_size, y * self.tile_size, self.tile_size, self.tile_size))
elif tile == 4:
self.tiles_to_collide[2].append(pygame.Rect(x * self.tile_size, y * self.tile_size, self.tile_size, self.tile_size))
elif tile == 5:
self.respawn_x = x * self.tile_size
self.respawn_y = y * self.tile_size
x += 1
y += 1
def draw(self, screen, camera):
y = 0
for row in self.input_array:
x = 0
for tile in row:
if tile == 1:
screen.blit(self.imgs[0],(x * self.tile_size - camera.x_offset, y * self.tile_size - camera.y_offset))
if tile == 2:
screen.blit(self.imgs[1],(x * self.tile_size - camera.x_offset, y * self.tile_size - camera.y_offset))
elif tile == 3:
screen.blit(self.imgs[2],(x * self.tile_size - camera.x_offset, y * self.tile_size - camera.y_offset))
elif tile == 4:
screen.blit(self.imgs[3],(x * self.tile_size - camera.x_offset, y * self.tile_size - camera.y_offset))
x += 1
y += 1