def __init__(self, agent_black=None, agent_white=None, gui=True, dir_save=None): """ BLACK always has the first move on the center of the board. :param agent_black: agent or None(human) :param agent_white: agent or None(human) :param gui: if show GUI; always true if there are human playing :param dir_save: directory to save board image if GUI is shown; no save for None """ self.agent_black = agent_black self.agent_white = agent_white self.board = Board(next_color='BLACK') gui = gui if agent_black and agent_white else True self.ui = UI() if gui else None self.dir_save = dir_save # Metadata self.time_elapsed = None
def __init__(self, character, renderer, proxy, input_mgr, res_mgr, audio_mgr, conf): """Constructor. :param character: The character name :type character: str :param renderer: The rederer instance. :type renderer: :class:`renderer.Renderer` :param proxy: The message proxy :type proxy: :class:`network.message.MessageProxy` :param input_mgr: The input manager :type input_mgr: :class:`core.InputManager` :param res_mgr: The resource manager :type res_mgr: :class:`loader.ResourceManager` :param audio_mgr: The audio manager :type audio_mgr: :class:`game.audio.AudioManager` :param conf: Configuration :type conf: mapping """ self.renderer = renderer self.proxy = proxy # Setup the context context = Context(conf) context.input_mgr = input_mgr context.res_mgr = res_mgr context.audio_mgr = audio_mgr # Setup the player c_res = res_mgr.get('/characters') c_data = c_res.data['map'][character] context.character_name = c_data['name'] context.character_type = ActorType[c_data['type']] context.character_avatar = c_data['avatar'] # Setup the level matrix map_res = res_mgr.get('/map') context.matrix = map_res['matrix'] context.scale_factor = map_res.data['scale_factor'] # Setup lights, scene, camera, terrain and map context.light = self.setup_light() context.scene = self.setup_scene(context) context.camera, context.ratio = self.setup_camera(context) context.terrain = self.setup_terrain(context) context.map = self.setup_map(context) # Setup UI ui_res = context.res_mgr.get('/ui') player_data = { 'name': context.character_name, 'type': context.character_type, 'avatar': context.character_avatar, 'avatar_res': c_res['avatar'], } context.ui = UI(ui_res, self.renderer.width, self.renderer.height, player_data) self.context = context # Client status variable self.exit = False # Wether or not the client should stop the game loop self.last_update = None # Last tick update self.sync_counter = count() # The computed time delta with the server self._syncing = {} self.delta = 0 # The computed time delta with the server self.time_acc = 0.0 # FPS time accumulator self.fps_count = 0 # FPS counter
from game.player import Player from game.sprite import * from game.raycaster import ray_casting_walls from game.ui import UI from game.logic import Logic # initializing game pygame.init() screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.DOUBLEBUF) clock = pygame.time.Clock() # game objects screen_map = pygame.Surface(MAP_RESOLUTION) sprites = SpriteSet() player = Player(sprites) ui = UI(screen, screen_map, player, clock) logic = Logic(player, sprites, ui) # displaying initial screen ui.menu() pygame.mouse.set_visible(False) ui.play_music() while True: player.movement() ui.background() walls, wall_shot = ray_casting_walls(player, ui.textures) # UI items ui.world(walls + [obj.object_locate(player) for obj in sprites.list_of_objects]) ui.fps(clock)