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
|
Rev | Line | |
---|
[3960923] | 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
|
---|
[b632a7c] | 12 | w = user32.GetSystemMetrics(0)
|
---|
| 13 | h = user32.GetSystemMetrics(1)
|
---|
[3960923] | 14 | elif 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] | 21 | else:
|
---|
| 22 | print("Unknown OS: " + system)
|
---|
| 23 |
|
---|
| 24 | print("Detected native resolution: {:d}x{:d}".format(w, h))
|
---|
| 25 |
|
---|
| 26 | pygame.init()
|
---|
| 27 |
|
---|
| 28 | if w == 0 and h == 0:
|
---|
| 29 | print("Not using fullscreen")
|
---|
| 30 | gameDisplay = pygame.display.set_mode((800, 600))
|
---|
| 31 | else:
|
---|
| 32 | gameDisplay = pygame.display.set_mode((w, h), pygame.FULLSCREEN)
|
---|
| 33 |
|
---|
| 34 | pygame.display.set_caption('Space Game')
|
---|
| 35 |
|
---|
| 36 | clock = pygame.time.Clock()
|
---|
| 37 |
|
---|
| 38 | running = True
|
---|
| 39 |
|
---|
| 40 | while 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 |
|
---|
| 53 | pygame.quit()
|
---|
| 54 | print("Game ended")
|
---|
[b632a7c] | 55 | quit()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.