source: python-game/game.py@ b632a7c

Last change on this file since b632a7c was b632a7c, checked in by Dmitry Portnoy <dmp1488@…>, 8 years ago

Add a README and correctly detect the native resolution on Linux

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[3960923]1import pygame, platform
2
3system = platform.system()
4
5[w, h] = [0, 0]
6
7if system == 'Windows':
8 print("Windows detected")
9
10 import ctypes
11 user32 = ctypes.windll.user32
[b632a7c]12 w = user32.GetSystemMetrics(0)
13 h = user32.GetSystemMetrics(1)
[3960923]14elif system == 'Linux':
15 print("Linux detected")
[b632a7c]16
17 import tkinter
18 root = tkinter.Tk()
19 w = root.winfo_screenwidth()
20 h = root.winfo_screenheight()
[3960923]21else:
22 print("Unknown OS: " + system)
23
24print("Detected native resolution: {:d}x{:d}".format(w, h))
25
26pygame.init()
27
28if w == 0 and h == 0:
29 print("Not using fullscreen")
30 gameDisplay = pygame.display.set_mode((800, 600))
31else:
32 gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN)
33
34pygame.display.set_caption('Space Game')
35
36clock = pygame.time.Clock()
37
38running = True
39
40while running:
41 for event in pygame.event.get():
42 if event.type == pygame.QUIT:
43 running = False
44 elif event.type == pygame.KEYDOWN:
45 if event.key == pygame.K_ESCAPE:
46 running = False
47
48 #print(event)
49
50 pygame.display.update()
51 clock.tick(60)
52
53pygame.quit()
54print("Game ended")
[b632a7c]55quit()
Note: See TracBrowser for help on using the repository browser.