Bladeren bron

adjust tetris ui for larger display

Thomas Buck 1 jaar geleden
bovenliggende
commit
af3af38160
1 gewijzigde bestanden met toevoegingen van 48 en 12 verwijderingen
  1. 48
    12
      tetris.py

+ 48
- 12
tetris.py Bestand weergeven

@@ -51,8 +51,12 @@ class Tetris:
51 51
         self.text[1].setText("0", "tom-thumb")
52 52
         self.text[2].setText("Paused", "tom-thumb")
53 53
         self.text[3].setText("next", "tom-thumb")
54
-        self.text[4].setText("Tetris", "tom-thumb")
55
-        self.text[5].setText("up", "tom-thumb")
54
+        if self.gui.height > self.gui.panelH:
55
+            self.text[4].setText("Tetris", "ib8x8u")
56
+            self.text[5].setText("up:", "tom-thumb")
57
+        else:
58
+            self.text[4].setText("Tetris", "tom-thumb")
59
+            self.text[5].setText("up", "tom-thumb")
56 60
 
57 61
         # all [y][x] sub-lists must be the same length
58 62
         self.pieces = [
@@ -113,12 +117,18 @@ class Tetris:
113 117
         self.max_width += 2
114 118
         self.max_height += 2
115 119
 
120
+
121
+        self.fact = 1
116 122
         self.x_off = 1
117 123
         self.y_off = self.gui.height - self.height - 3
118
-
119
-        self.next_x_off = self.gui.panelW - self.max_width - 3
124
+        self.next_x_off = self.gui.panelW - self.max_width + 24
120 125
         self.next_y_off = self.gui.panelH - self.max_height - 3
121 126
 
127
+        if self.gui.height > self.gui.panelH:
128
+            self.fact = 2
129
+            self.y_off = self.gui.height - self.height * self.fact - 3
130
+            self.next_y_off = self.gui.panelH - self.max_height * self.fact + 29
131
+
122 132
         random.seed()
123 133
         self.restart()
124 134
 
@@ -346,11 +356,18 @@ class Tetris:
346 356
     def draw_stats(self, off):
347 357
         x_off, y_off = off
348 358
 
349
-        self.text[0].draw(-x_off - 2, y_off - 11)
350
-        self.text[1].draw(-x_off - 2, y_off - 5)
359
+        if self.fact > 1:
360
+            self.text[0].draw(-x_off - 2, y_off - 6)
361
+            self.text[1].draw(-x_off - 2, y_off)
362
+        else:
363
+            self.text[0].draw(-x_off - 2, y_off - 11)
364
+            self.text[1].draw(-x_off - 2, y_off - 5)
351 365
 
352 366
         if self.pause:
353
-            self.text[2].draw(-x_off - 2, -y_off + 11)
367
+            if self.fact > 1:
368
+                self.text[2].draw(-x_off - 2 + 16, -y_off + 11 - 5)
369
+            else:
370
+                self.text[2].draw(-x_off - 2, -y_off + 11)
354 371
 
355 372
     def draw(self):
356 373
         if self.input != None:
@@ -380,9 +397,14 @@ class Tetris:
380 397
                 self.endText.restart()
381 398
 
382 399
         # static text
383
-        self.text[4].draw(-2, -11)
384
-        self.text[3].draw(-14, 5)
385
-        self.text[5].draw(-14, 12)
400
+        if self.fact > 1:
401
+            self.text[4].draw(-2, -22)
402
+            self.text[3].draw(-34, 13)
403
+            self.text[5].draw(-34, 20)
404
+        else:
405
+            self.text[4].draw(-2, -11)
406
+            self.text[3].draw(-14, 5)
407
+            self.text[5].draw(-14, 12)
386 408
 
387 409
         # draw play area and border
388 410
         for x in range(-1, self.width + 1):
@@ -390,7 +412,14 @@ class Tetris:
390 412
                 c = self.colors[1] # border color
391 413
                 if (x >= 0) and (y >= 0) and (x < self.width) and (y < self.height):
392 414
                     c = self.data[x][y]
393
-                self.gui.set_pixel(x + 1 + self.x_off, y + 1 + self.y_off, c)
415
+
416
+                for x1 in range(0, self.fact):
417
+                    for y1 in range(0, self.fact):
418
+                        self.gui.set_pixel(
419
+                            self.fact * x + 1 + self.x_off + x1,
420
+                            self.fact * y + 1 + self.y_off + y1,
421
+                            c
422
+                        )
394 423
 
395 424
         # draw next piece and border
396 425
         for x in range(-1, self.max_width + 1):
@@ -407,7 +436,14 @@ class Tetris:
407 436
                                 c = (0, 0, 0)
408 437
                         else:
409 438
                             c = (0, 0, 0)
410
-                self.gui.set_pixel(x + 1 + self.next_x_off, y + 1 + self.next_y_off, c)
439
+
440
+                for x1 in range(0, self.fact):
441
+                    for y1 in range(0, self.fact):
442
+                        self.gui.set_pixel(
443
+                            self.fact * x + 1 + self.next_x_off + x1,
444
+                            self.fact * y + 1 + self.next_y_off + y1,
445
+                            c
446
+                        )
411 447
 
412 448
         # find position for stats
413 449
         stats_off = None

Laden…
Annuleren
Opslaan