Guest User

Untitled

a guest
Jan 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. import time
  2. import pygame
  3.  
  4. from pygame.locals import *
  5.  
  6. '''
  7.  
  8. brainstorm:
  9. level: collection of maps
  10. game: collection of levels
  11. progress: collection of things to keep track of progress
  12. engine: runs game (which is levels), and keeps track of progress
  13.  
  14. '''
  15.  
  16. class Engine(object):
  17. '''
  18. Engine
  19. ------
  20. This is the engine of the schlengine package.
  21. It uses the following technology:
  22. * pyTMX
  23. * pygame
  24. It supports the following features:
  25. * something about something
  26. '''
  27. def __init__(self):
  28. '''set up all basic internal variables'''
  29. self._running = False
  30. self._current_time = 0.0
  31. self._surface = None
  32. self._size = self.length, self.height = (0,0)
  33. self._map = None
  34. self.player = None
  35. self._tile_size = 0
  36. self._scale = 0
  37. self._scaled_tile_size = 0
  38. self._keymap = None
  39. self._initilised = False
  40.  
  41. def on_init(self, x, y, repeat=100, keymap='keymap.json'):
  42. '''initialise a surface and set key repeats etc...'''
  43. pygame.init()
  44. self._surface = pygame.display.set_mode((x, y), HWSURFACE|DOUBLEBUF|RESIZABLE)
  45. pygame.key.set_repeat(repeat, repeat)
  46. self._running = True
  47. self._initilised = True
  48.  
  49. def add_player(self, player):
  50. '''adds a player to the engine'''
  51. self.player = player
  52.  
  53. def on_event(self, event):
  54. '''handle user interaction'''
  55. if event.type == QUIT:
  56. self._running = False
  57.  
  58. user_input = pygame.key.get_pressed()
  59. if user_input[K_UP]:
  60. pass
  61. if user_input[K_DOWN]:
  62. pass
  63. if user_input[K_LEFT]:
  64. pass
  65. if user_input[K_RIGHT]:
  66. pass
  67. if user_input[K_SPACE]:
  68. self._running = False
  69.  
  70.  
  71. def on_loop(self):
  72. '''handles non interactive changes to the state of environemnt'''
  73. pass
  74.  
  75. def on_render(self):
  76. '''control the rendering of the map and entities'''
  77. pass
  78.  
  79. def _render_base(self):
  80. '''render the base map (layers below entities)'''
  81. pass
  82.  
  83. def _render_entities(self):
  84. '''renders the entity layer of the map, items and characters'''
  85. pass
  86.  
  87. def _render_top(self):
  88. '''renders layers above the entity layer (things that will obscure entities)'''
  89. pass
  90.  
  91. def on_cleanup(self):
  92. '''handles any cleanup on quit'''
  93. pygame.quit()
  94.  
  95. def on_execute(self):
  96. '''this represents the main loop of the engine'''
  97. if self._initilised:
  98. while self._running:
  99. # set internal time
  100. self._current_time = time.time()
  101. # handle events
  102. for event in pygame.event.get():
  103. self.on_event(event)
  104. # game loop
  105. self.on_loop()
  106. # render
  107. self.on_render()
  108. # cleanup and exit
  109. self.on_cleanup()
  110.  
  111. if __name__ == '__main__':
  112. engine = Engine()
  113. engine.on_init(100, 100)
  114. engine.on_execute()
Add Comment
Please, Sign In to add comment