|
@@ -29,6 +29,7 @@ class Snake:
|
29
|
29
|
3, 50, sc)
|
30
|
30
|
|
31
|
31
|
self.text_c = (0, 0, 255)
|
|
32
|
+ self.fact = int(self.gui.width / self.gui.panelW)
|
32
|
33
|
|
33
|
34
|
random.seed()
|
34
|
35
|
self.restart()
|
|
@@ -39,9 +40,9 @@ class Snake:
|
39
|
40
|
self.direction = "r"
|
40
|
41
|
self.directionTmp = "r"
|
41
|
42
|
self.score = 0
|
42
|
|
- self.data = [[0 for y in range(self.gui.height)] for x in range(self.gui.width)]
|
|
43
|
+ self.data = [[0 for y in range(int(self.gui.height / self.fact))] for x in range(int(self.gui.width / self.fact))]
|
43
|
44
|
|
44
|
|
- self.player = [ (int(self.gui.width / 2), int(self.gui.height / 2)) ]
|
|
45
|
+ self.player = [ (int(self.gui.width / 2 / self.fact), int(self.gui.height / 2 / self.fact)) ]
|
45
|
46
|
self.data[self.player[0][0]][self.player[0][1]] = 1
|
46
|
47
|
|
47
|
48
|
DrawText = util.getTextDrawer()
|
|
@@ -77,9 +78,9 @@ class Snake:
|
77
|
78
|
return False
|
78
|
79
|
|
79
|
80
|
def placeDot(self):
|
80
|
|
- d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
|
|
81
|
+ d = (random.randrange(0, int(self.gui.width / self.fact)), random.randrange(0, int(self.gui.height / self.fact)))
|
81
|
82
|
while (self.data[d[0]][d[1]] != 0) or (d[0] < 15) or (d[1] < 8):
|
82
|
|
- d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
|
|
83
|
+ d = (random.randrange(0, int(self.gui.width / self.fact)), random.randrange(0, int(self.gui.height / self.fact)))
|
83
|
84
|
self.data[d[0]][d[1]] = 2
|
84
|
85
|
|
85
|
86
|
def buttons(self):
|
|
@@ -109,7 +110,7 @@ class Snake:
|
109
|
110
|
elif self.direction == "d":
|
110
|
111
|
player = (player[0], player[1] + 1)
|
111
|
112
|
|
112
|
|
- if (player[0] < 0) or (player[1] < 0) or (player[0] >= self.gui.width) or (player[1] >= self.gui.height):
|
|
113
|
+ if (player[0] < 0) or (player[1] < 0) or (player[0] >= int(self.gui.width / self.fact)) or (player[1] >= int(self.gui.height / self.fact)):
|
113
|
114
|
return False
|
114
|
115
|
|
115
|
116
|
if self.data[player[0]][player[1]] == 0:
|
|
@@ -122,7 +123,7 @@ class Snake:
|
122
|
123
|
else:
|
123
|
124
|
# collected a dot
|
124
|
125
|
self.score += 1
|
125
|
|
- if self.score >= self.gui.width * self.gui.height:
|
|
126
|
+ if self.score >= int(self.gui.width / self.fact) * int(self.gui.height / self.fact):
|
126
|
127
|
return False
|
127
|
128
|
|
128
|
129
|
self.timestep = self.timestep * self.speedup
|
|
@@ -133,13 +134,13 @@ class Snake:
|
133
|
134
|
return True
|
134
|
135
|
|
135
|
136
|
def finishedEndScreen(self):
|
136
|
|
- if self.score >= self.gui.width * self.gui.height:
|
|
137
|
+ if self.score >= int(self.gui.width / self.fact) * int(self.gui.height / self.fact):
|
137
|
138
|
return self.winText.finished()
|
138
|
139
|
else:
|
139
|
140
|
return self.loseText.finished()
|
140
|
141
|
|
141
|
142
|
def drawEndScreen(self):
|
142
|
|
- if self.score >= self.gui.width * self.gui.height:
|
|
143
|
+ if self.score >= int(self.gui.width / self.fact) * int(self.gui.height / self.fact):
|
143
|
144
|
self.winText.draw()
|
144
|
145
|
else:
|
145
|
146
|
self.loseText.draw()
|
|
@@ -179,9 +180,11 @@ class Snake:
|
179
|
180
|
self.loseText.restart()
|
180
|
181
|
self.scoreText.restart()
|
181
|
182
|
|
182
|
|
- for x in range(0, self.gui.width):
|
183
|
|
- for y in range(0, self.gui.height):
|
184
|
|
- self.gui.set_pixel(x, y, self.colors[self.data[x][y]])
|
|
183
|
+ for x in range(0, int(self.gui.width / self.fact)):
|
|
184
|
+ for y in range(0, int(self.gui.height / self.fact)):
|
|
185
|
+ for x1 in range(0, self.fact):
|
|
186
|
+ for y1 in range(0, self.fact):
|
|
187
|
+ self.gui.set_pixel(x * self.fact + x1, y * self.fact + y1, self.colors[self.data[x][y]])
|
185
|
188
|
|
186
|
189
|
# draw score
|
187
|
190
|
self.text.setText(str(self.score), "tom-thumb")
|