Browse Source

adjust tetris ui for larger display

Thomas Buck 1 year ago
parent
commit
af3af38160
1 changed files with 48 additions and 12 deletions
  1. 48
    12
      tetris.py

+ 48
- 12
tetris.py View File

51
         self.text[1].setText("0", "tom-thumb")
51
         self.text[1].setText("0", "tom-thumb")
52
         self.text[2].setText("Paused", "tom-thumb")
52
         self.text[2].setText("Paused", "tom-thumb")
53
         self.text[3].setText("next", "tom-thumb")
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
         # all [y][x] sub-lists must be the same length
61
         # all [y][x] sub-lists must be the same length
58
         self.pieces = [
62
         self.pieces = [
113
         self.max_width += 2
117
         self.max_width += 2
114
         self.max_height += 2
118
         self.max_height += 2
115
 
119
 
120
+
121
+        self.fact = 1
116
         self.x_off = 1
122
         self.x_off = 1
117
         self.y_off = self.gui.height - self.height - 3
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
         self.next_y_off = self.gui.panelH - self.max_height - 3
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
         random.seed()
132
         random.seed()
123
         self.restart()
133
         self.restart()
124
 
134
 
346
     def draw_stats(self, off):
356
     def draw_stats(self, off):
347
         x_off, y_off = off
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
         if self.pause:
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
     def draw(self):
372
     def draw(self):
356
         if self.input != None:
373
         if self.input != None:
380
                 self.endText.restart()
397
                 self.endText.restart()
381
 
398
 
382
         # static text
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
         # draw play area and border
409
         # draw play area and border
388
         for x in range(-1, self.width + 1):
410
         for x in range(-1, self.width + 1):
390
                 c = self.colors[1] # border color
412
                 c = self.colors[1] # border color
391
                 if (x >= 0) and (y >= 0) and (x < self.width) and (y < self.height):
413
                 if (x >= 0) and (y >= 0) and (x < self.width) and (y < self.height):
392
                     c = self.data[x][y]
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
         # draw next piece and border
424
         # draw next piece and border
396
         for x in range(-1, self.max_width + 1):
425
         for x in range(-1, self.max_width + 1):
407
                                 c = (0, 0, 0)
436
                                 c = (0, 0, 0)
408
                         else:
437
                         else:
409
                             c = (0, 0, 0)
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
         # find position for stats
448
         # find position for stats
413
         stats_off = None
449
         stats_off = None

Loading…
Cancel
Save