Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import pygame
- from pygame.locals import *
- '''
- brainstorm:
- level: collection of maps
- game: collection of levels
- progress: collection of things to keep track of progress
- engine: runs game (which is levels), and keeps track of progress
- '''
- class Engine(object):
- '''
- Engine
- ------
- This is the engine of the schlengine package.
- It uses the following technology:
- * pyTMX
- * pygame
- It supports the following features:
- * something about something
- '''
- def __init__(self):
- '''set up all basic internal variables'''
- self._running = False
- self._current_time = 0.0
- self._surface = None
- self._size = self.length, self.height = (0,0)
- self._map = None
- self.player = None
- self._tile_size = 0
- self._scale = 0
- self._scaled_tile_size = 0
- self._keymap = None
- self._initilised = False
- def on_init(self, x, y, repeat=100, keymap='keymap.json'):
- '''initialise a surface and set key repeats etc...'''
- pygame.init()
- self._surface = pygame.display.set_mode((x, y), HWSURFACE|DOUBLEBUF|RESIZABLE)
- pygame.key.set_repeat(repeat, repeat)
- self._running = True
- self._initilised = True
- def add_player(self, player):
- '''adds a player to the engine'''
- self.player = player
- def on_event(self, event):
- '''handle user interaction'''
- if event.type == QUIT:
- self._running = False
- user_input = pygame.key.get_pressed()
- if user_input[K_UP]:
- pass
- if user_input[K_DOWN]:
- pass
- if user_input[K_LEFT]:
- pass
- if user_input[K_RIGHT]:
- pass
- if user_input[K_SPACE]:
- self._running = False
- def on_loop(self):
- '''handles non interactive changes to the state of environemnt'''
- pass
- def on_render(self):
- '''control the rendering of the map and entities'''
- pass
- def _render_base(self):
- '''render the base map (layers below entities)'''
- pass
- def _render_entities(self):
- '''renders the entity layer of the map, items and characters'''
- pass
- def _render_top(self):
- '''renders layers above the entity layer (things that will obscure entities)'''
- pass
- def on_cleanup(self):
- '''handles any cleanup on quit'''
- pygame.quit()
- def on_execute(self):
- '''this represents the main loop of the engine'''
- if self._initilised:
- while self._running:
- # set internal time
- self._current_time = time.time()
- # handle events
- for event in pygame.event.get():
- self.on_event(event)
- # game loop
- self.on_loop()
- # render
- self.on_render()
- # cleanup and exit
- self.on_cleanup()
- if __name__ == '__main__':
- engine = Engine()
- engine.on_init(100, 100)
- engine.on_execute()
Add Comment
Please, Sign In to add comment