Legend of the Gold Box... A game written for the LOWREZJAM 2018 game jam
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

98 lines
2.6KB

  1. '''
  2. Filename display.py
  3. Author: Bryan "ObsidianBlk" Miller
  4. Date Created: 8/1/2018
  5. Python Version: 3.7
  6. '''
  7. import pygame
  8. class Display:
  9. def __init__(self, width=640, height=480):
  10. self._init = False
  11. self._resolution = (width, height)
  12. self._display_surface = None
  13. self._display_flags = Display.FLAG_RESIZABLE | Display.FLAG_HWSURFACE | Display.FLAG_DOUBLEBUF
  14. def _isFlagSet(self, flag):
  15. return (self._display_flags & flag) == flag
  16. @property
  17. def surface(self):
  18. return self._display_surface
  19. @property
  20. def width(self):
  21. if self._display_surface is None:
  22. return 0
  23. return self._resolution[0]
  24. @property
  25. def height(self):
  26. if self._display_surface is None:
  27. return 0
  28. return self._resolution[1]
  29. @property
  30. def resolution(self):
  31. if self._display_surface is None:
  32. return (0,0)
  33. return self._display_surface.get_size()
  34. @property
  35. def fullscreen(self):
  36. return self._isFlagSet(Display.FLAG_FULLSCREEN)
  37. @property
  38. def double_buffered(self):
  39. return self._isFlagSet(Display.FLAG_DOUBLEBUF)
  40. @property
  41. def resizable(self):
  42. return self._isFlagSet(Display.FLAG_RESIZABLE)
  43. @property
  44. def no_frame(self):
  45. return self._isFlagSet(Display.FLAG_NOFRAME)
  46. @property
  47. def opengl(self):
  48. return self._isFlagSet(Display.FLAG_OPENGL)
  49. def toggle_fullscreen(self):
  50. if self._isFlagSet(Display.FLAG_FULLSCREEN):
  51. self._display_flags ^= Display.FLAG_FULLSCREEN
  52. else:
  53. self._display_flags |= Display.FLAG_FULLSCREEN
  54. self.set_mode(self._resolution, flags)
  55. def set_mode(self, resolution, flags):
  56. if (self._init == False):
  57. self._init = True
  58. pygame.init()
  59. self._display_surface = pygame.display.set_mode(resolution, flags)
  60. self._display_flags = self._display_surface.get_flags()
  61. self._resolution = self._display_surface.get_size()
  62. return self
  63. def init(self):
  64. if self._init == False:
  65. self._init = True
  66. pygame.init()
  67. self.set_mode(self._resolution, self._display_flags)
  68. return self
  69. def close(self):
  70. pygame.quit()
  71. FLAG_SWSURFACE = pygame.SWSURFACE
  72. FLAG_HWSURFACE = pygame.HWSURFACE
  73. FLAG_HWPALETTE = pygame.HWPALETTE
  74. FLAG_DOUBLEBUF = pygame.DOUBLEBUF
  75. FLAG_FULLSCREEN = pygame.FULLSCREEN
  76. FLAG_OPENGL = pygame.OPENGL
  77. FLAG_RESIZABLE = pygame.RESIZABLE
  78. FLAG_NOFRAME = pygame.NOFRAME