source:
python-game/game.py@
1d1c77e
Last change on this file since 1d1c77e was 1d1c77e, checked in by , 8 years ago | |
---|---|
|
|
File size: 1.3 KB |
Line | |
---|---|
1 | import pygame, platform |
2 | |
3 | system = platform.system() |
4 | |
5 | [w, h] = [0, 0] |
6 | |
7 | if 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) |
14 | elif system == 'Linux': |
15 | print("Linux detected") |
16 | |
17 | import tkinter |
18 | root = tkinter.Tk() |
19 | w = root.winfo_screenwidth() |
20 | h = root.winfo_screenheight() |
21 | elif 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) |
28 | else: |
29 | print("Unknown OS: " + system) |
30 | |
31 | print("Detected native resolution: {:d}x{:d}".format(w, h)) |
32 | |
33 | pygame.init() |
34 | |
35 | if w == 0 and h == 0: |
36 | print("Not using fullscreen") |
37 | gameDisplay = pygame.display.set_mode((800, 600)) |
38 | else: |
39 | gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN) |
40 | |
41 | pygame.display.set_caption('Space Game') |
42 | |
43 | clock = pygame.time.Clock() |
44 | |
45 | running = True |
46 | |
47 | while 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 | |
60 | pygame.quit() |
61 | print("Game ended") |
62 | quit() |
Note:
See TracBrowser
for help on using the repository browser.