-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrick.py
81 lines (73 loc) · 1.69 KB
/
brick.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
import pyxel
BrickType = {
1: {
"img": 0,
"u": 16,
"v": 0,
"w": 32,
"h": 8,
"score": 1
},
2: {
"img": 0,
"u": 16,
"v": 8,
"w": 32,
"h": 8,
"score": 3
},
3: {
"img": 0,
"u": 16,
"v": 16,
"w": 32,
"h": 8,
"score": 5
},
4: {
"img": 0,
"u": 16,
"v": 24,
"w": 32,
"h": 8,
"score": 7
},
}
class Brick:
def __init__(self, x, y, brick_type):
self.x = x
self.y = y
self.brick_type = brick_type
self.w = BrickType[brick_type]["w"]
self.h = BrickType[brick_type]["h"]
self.score = BrickType[brick_type]["score"]
def draw(self):
pyxel.blt(
self.x,
self.y,
BrickType[self.brick_type]["img"],
BrickType[self.brick_type]["u"],
BrickType[self.brick_type]["v"],
BrickType[self.brick_type]["w"],
BrickType[self.brick_type]["h"]
)
def check_levels():
found_levels = []
with open("assets/levels.txt") as f:
for line in f:
found_levels.append(line.rstrip())
return found_levels
def load_level(level):
this_level = []
possible_bricks = ["1", "2", "3", "4"]
# Load the level file, and read through it, adding bricks to this_level
with open("assets/" + level) as f:
y = 0
for line in f:
x = 0
for char in line:
if char in possible_bricks:
this_level.append(Brick(x, y, int(char)))
x += 32
y += 8
return this_level