@@ -66,15 +66,11 @@ def run(self):
6666 restart_cnt = 10
6767
6868 # Waits for user ready
69+ screen .draw_text ((screen .width // 2 ) - 4 , (screen .height // 2 ) - 8 , "BREAKOUT" )
6970 screen .draw_text (
70- (screen .x_width // 2 ) - 4 , (screen .y_height // 2 ) - 8 , "BREAKOUT"
71- )
72- screen .draw_text (
73- (screen .x_width // 2 ) - 5 , (screen .y_height // 2 ) - 4 , "PRESS START"
74- )
75- screen .draw_text (
76- (screen .x_width // 2 ) - 4 , (screen .y_height // 2 ) - 2 , "TO BEGIN"
71+ (screen .width // 2 ) - 5 , (screen .height // 2 ) - 4 , "PRESS START"
7772 )
73+ screen .draw_text ((screen .width // 2 ) - 4 , (screen .height // 2 ) - 2 , "TO BEGIN" )
7874 screen .push ()
7975
8076 # Don't start until user presses start
@@ -87,15 +83,11 @@ def run(self):
8783 yield
8884
8985 # Erase startup text and initialize screen
86+ screen .draw_text ((screen .width // 2 ) - 4 , (screen .height // 2 ) - 8 , " " )
9087 screen .draw_text (
91- (screen .x_width // 2 ) - 4 , (screen .y_height // 2 ) - 8 , " "
92- )
93- screen .draw_text (
94- (screen .x_width // 2 ) - 5 , (screen .y_height // 2 ) - 4 , " "
95- )
96- screen .draw_text (
97- (screen .x_width // 2 ) - 4 , (screen .y_height // 2 ) - 2 , " "
88+ (screen .width // 2 ) - 5 , (screen .height // 2 ) - 4 , " "
9889 )
90+ screen .draw_text ((screen .width // 2 ) - 4 , (screen .height // 2 ) - 2 , " " )
9991 screen .push ()
10092 self .init_screen (self .screen )
10193
@@ -117,8 +109,8 @@ def run(self):
117109 # Pause and unpause routine
118110 if keypress == "START_P" :
119111 screen .draw_text (
120- (screen .x_width // 2 ) - 3 ,
121- (screen .y_height // 2 ) - 8 ,
112+ (screen .width // 2 ) - 3 ,
113+ (screen .height // 2 ) - 8 ,
122114 "PAUSED" ,
123115 push = True ,
124116 )
@@ -133,8 +125,8 @@ def run(self):
133125 ):
134126 if keypress == "START_P" :
135127 screen .draw_text (
136- (screen .x_width // 2 ) - 3 ,
137- (screen .y_height // 2 ) - 8 ,
128+ (screen .width // 2 ) - 3 ,
129+ (screen .height // 2 ) - 8 ,
138130 " " ,
139131 push = True ,
140132 )
@@ -180,14 +172,14 @@ def run(self):
180172 is_down = True
181173
182174 # Checks to see if ball hits paddle
183- if self .ball [1 ] == screen .y_height - 2 :
175+ if self .ball [1 ] == screen .height - 2 :
184176 if self .ball [0 ] in self .paddle :
185177 spin , is_left = self .get_angle (self .paddle )
186178 self .frame_rate = 20 + (spin // (1 + spin // 2 ))
187179 is_down = False
188180
189181 # Checks to see if ball falls out of screen
190- if self .ball [1 ] >= screen .y_height - 1 :
182+ if self .ball [1 ] >= screen .height - 1 :
191183 is_down = True
192184 lives -= 1
193185 self .frame_rate = 20
@@ -200,15 +192,15 @@ def run(self):
200192 if lives == 0 :
201193 self .gameover = True
202194 break
203- self .ball = [screen .x_width // 2 , screen .y_height // 2 ]
195+ self .ball = [screen .width // 2 , screen .height // 2 ]
204196
205197 # Calculates ball path
206198 is_left , is_down = self .ball_travel (is_left , is_down , spin , screen )
207199
208200 # Quick pause to reorient if life lost
209201 if restart :
210202 restart_cnt -= 1
211- self .ball = [screen .x_width // 2 , screen .y_height // 2 ]
203+ self .ball = [screen .width // 2 , screen .height // 2 ]
212204 if restart_cnt == 0 :
213205 restart_cnt = 10
214206 restart = False
@@ -220,13 +212,13 @@ def run(self):
220212 self .paddle [val ] -= 1
221213 screen .draw_pixel (
222214 self .paddle [0 ],
223- screen .y_height - 1 ,
215+ screen .height - 1 ,
224216 PIXEL_ON ,
225217 combine = False ,
226218 )
227219 screen .draw_pixel (
228220 self .paddle [- 1 ] + 1 ,
229- screen .y_height - 1 ,
221+ screen .height - 1 ,
230222 PIXEL_OFF ,
231223 combine = False ,
232224 )
@@ -236,13 +228,13 @@ def run(self):
236228 self .paddle [val ] += 1
237229 screen .draw_pixel (
238230 self .paddle [0 ] - 1 ,
239- screen .y_height - 1 ,
231+ screen .height - 1 ,
240232 PIXEL_OFF ,
241233 combine = False ,
242234 )
243235 screen .draw_pixel (
244236 self .paddle [- 1 ],
245- screen .y_height - 1 ,
237+ screen .height - 1 ,
246238 PIXEL_ON ,
247239 combine = False ,
248240 )
@@ -262,19 +254,19 @@ def run(self):
262254
263255 screen .clear ()
264256 screen .draw_text (
265- (screen .x_width // 2 ) - 4 , (screen .y_height // 2 ) - 8 , "GAME OVER"
257+ (screen .width // 2 ) - 4 , (screen .height // 2 ) - 8 , "GAME OVER"
266258 )
267259 screen .draw_text (
268- (screen .x_width // 2 ) - 4 , (screen .y_height // 2 ) - 6 , "---------"
260+ (screen .width // 2 ) - 4 , (screen .height // 2 ) - 6 , "---------"
269261 )
270262 screen .draw_text (
271- (screen .x_width // 2 ) - 4 ,
272- (screen .y_height // 2 ) - 4 ,
263+ (screen .width // 2 ) - 4 ,
264+ (screen .height // 2 ) - 4 ,
273265 "SCORE " + str (score ),
274266 )
275267 screen .draw_text (
276- (screen .x_width // 2 ) - 4 ,
277- (screen .y_height // 2 ) - 2 ,
268+ (screen .width // 2 ) - 4 ,
269+ (screen .height // 2 ) - 2 ,
278270 "HISCORE " + str (hscore ),
279271 )
280272 screen .push ()
@@ -295,22 +287,22 @@ def init_screen(self, screen):
295287 self .paddle = [24 ]
296288
297289 if self .level == 1 :
298- self .line_right = screen .x_width - ARENA_START
290+ self .line_right = screen .width - ARENA_START
299291 self .line_left = ARENA_START - 1
300292
301- self .ball = [screen .x_width // 2 , screen .y_height // 2 ]
293+ self .ball = [screen .width // 2 , screen .height // 2 ]
302294
303295 if self .level % 2 == 0 :
304- for pix in range (screen .y_height ):
296+ for pix in range (screen .height ):
305297 screen .draw_pixel (self .line_left , pix , 0x0 )
306298 screen .draw_pixel (self .line_right , pix , 0x0 )
307299 self .line_left = 13 - self .level
308- self .line_right = (screen .x_width - ARENA_START ) + self .level
300+ self .line_right = (screen .width - ARENA_START ) + self .level
309301 else :
310302 self .rows = self .level + 2
311303
312- screen .draw_vline (self .line_left , 0 , screen .y_height , left = False )
313- screen .draw_vline (self .line_right , 0 , screen .y_height )
304+ screen .draw_vline (self .line_left , 0 , screen .height , left = False )
305+ screen .draw_vline (self .line_right , 0 , screen .height )
314306
315307 for row in range (self .rows ):
316308 self .bricks [row ] = []
@@ -331,10 +323,10 @@ def init_screen(self, screen):
331323 self .paddle .append (self .paddle [- 1 ] + 1 )
332324
333325 for val in range (self .line_left + 1 , self .line_right ):
334- screen .draw_pixel (val , screen .y_height - 1 , PIXEL_OFF )
326+ screen .draw_pixel (val , screen .height - 1 , PIXEL_OFF )
335327
336328 for val in self .paddle :
337- screen .draw_pixel (val , screen .y_height - 1 , PIXEL_ON , combine = False )
329+ screen .draw_pixel (val , screen .height - 1 , PIXEL_ON , combine = False )
338330
339331 screen .push ()
340332
@@ -401,10 +393,10 @@ def ball_travel(self, is_left, is_down, spin, screen):
401393
402394 if is_down :
403395 # A possible conflict with ball trying to jump paddle
404- if (screen .y_height - 1 ) - (self .ball [1 ] + spin ) <= 0 and spin > 1 :
396+ if (screen .height - 1 ) - (self .ball [1 ] + spin ) <= 0 and spin > 1 :
405397 for block in collide_field :
406398 if block [0 ] in self .paddle :
407- self .ball [1 ] = screen .y_height - 2
399+ self .ball [1 ] = screen .height - 2
408400 is_down = False
409401 if self .paddle .index (block [0 ]) > len (self .paddle ) // 2 :
410402 is_left = False
@@ -433,7 +425,7 @@ def ball_travel(self, is_left, is_down, spin, screen):
433425
434426 if self .ball [1 ] < 0 :
435427 self .ball [1 ] = 0
436- elif self .ball [1 ] > screen .y_height - 1 :
437- self .ball [1 ] = screen .y_height - 1
428+ elif self .ball [1 ] > screen .height - 1 :
429+ self .ball [1 ] = screen .height - 1
438430
439431 return is_left , is_down
0 commit comments