source: python-game/game.py@ 1d1c77e

Last change on this file since 1d1c77e was 1d1c77e, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 8 years ago

Correctly detect the native resolution on Mac

  • Property mode set to 100644
File size: 1.3 KB
Line 
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
12 w = user32.GetSystemMetrics(0)
13 h = user32.GetSystemMetrics(1)
14elif system == 'Linux':
15 print("Linux detected")
16
17 import tkinter
18 root = tkinter.Tk()
19 w = root.winfo_screenwidth()
20 h = root.winfo_screenheight()
21elif system == 'Darwin':
22 print("Mac detected")
23
24 from AppKit import NSScreen
25 res = NSScreen.mainScreen().frame().size
26 w = int(res.width)
27 h = int(res.height)
28else:
29 print("Unknown OS: " + system)
30
31print("Detected native resolution: {:d}x{:d}".format(w, h))
32
33pygame.init()
34
35if w == 0 and h == 0:
36 print("Not using fullscreen")
37 gameDisplay = pygame.display.set_mode((800, 600))
38else:
39 gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN)
40
41pygame.display.set_caption('Space Game')
42
43clock = pygame.time.Clock()
44
45running = True
46
47while running:
48 for event in pygame.event.get():
49 if event.type == pygame.QUIT:
50 running = False
51 elif event.type == pygame.KEYDOWN:
52 if event.key == pygame.K_ESCAPE:
53 running = False
54
55 #print(event)
56
57 pygame.display.update()
58 clock.tick(60)
59
60pygame.quit()
61print("Game ended")
62quit()
Note: See TracBrowser for help on using the repository browser.