def set_lights(self): """Set up the lights.""" light_nodes = [None] * 9 for i, dirs in zip(range(9), [0] + Object.values(directions) * 2): dlight = DirectionalLight(f"directional light {i}") if i <= 4: dlight.setColor((0.5, 0.5, 0.5, 0.8)) else: dlight.setColor((2, 2, 2, 2)) light_nodes[i] = self.base.render.attachNewNode(dlight) if i == 0: light_nodes[i].setPos(0, 0, 1) else: light_nodes[i].setPos(*dirs, 0) light_nodes[i].lookAt(0, 0, 0) if i <= 4: self.base.render.setLight(light_nodes[i]) self.terrain.terrain_node.clearLight(light_nodes[i]) else: # self.terrain.terrain_node.setLight(light_nodes[i]) pass alight = AmbientLight('ambient light') alight.setColor((0.3, 0.3, 0.3, 1)) ambient_light_node = self.base.render.attachNewNode(alight) self.base.render.setLight(ambient_light_node) return light_nodes, ambient_light_node
def generate_maze(self, seed, origin): """ Start the generation wrt the seed. origin: 1 4 0 8 2 """ random.seed(seed) if not origin: self.insert_point( ((field_size//2, field_size//2), (-1, -1)) ) for j, (dx, dy) in zip(range(4), Object.values(directions)): if origin & (1 << j): for i in range(field_size): self.insert_point((( (field_size-1)*(dx+1)//2 if dx else i, (field_size-1)*(dy+1)//2 if dy else i ), (-1, -1))) self.process_next() self.remove_random_edges() if not origin: self.clear_core() return self.result
def process_point(self, point, parent): """Link the point to its parent, remove the wall between.""" if not self.in_range(point): return if point in self.used_set: return self.used_set.add(point) self.remove_wall_between(point, parent) for dx, dy in Object.values(directions): self.insert_point(((point[0]+dx, point[1]+dy), point))
def neighbors(self, pos): ans = set() for dx, dy in Object.values(directions): for j in [-1, 1]: for i in range(self.search_width): cur = (pos[0] + dx + dy * i * j, pos[1] + dy + dx * i * j) try: if not self.get_tile(cur).enemy_walkable(): break except TypeError: print(self.get_tile(cur)) raise EOFError ans.add(cur) # print(ans) return [*ans]
def remove_pillars(self): """Remove standalone pillars.""" def get(i, j): if i < 0 or i >= self.map_size: return False if j < 0 or j >= self.map_size: return False return self.maze_map[i][j] for i in range(self.map_size): for j in range(self.map_size): if get(i, j): for dx, dy in Object.values(directions): if get(i + dx, j + dy): break else: self.maze_map[i][j] = False
def __init__(self): """Start the app.""" self.base = ShowBase() self.base.disableMouse() filters = CommonFilters(self.base.win, self.base.cam) filters.setBloom(blend=(0, 0, 0, 1)) self.base.render.setShaderAuto( BitMask32.allOn() & ~BitMask32.bit(Shader.BitAutoShaderGlow)) ts = TextureStage('ts') ts.setMode(TextureStage.MGlow) tex = self.base.loader.loadTexture('models/black.png') self.base.render.setTexture(ts, tex) self.terrain = Terrain(self.base.render, self.base.loader) minimap_size = 200 self.minimap = Minimap( self.base.win.makeDisplayRegion( 1 - minimap_size / self.base.win.getProperties().getXSize(), 1, 1 - minimap_size / self.base.win.getProperties().getYSize(), 1)) self.minimap.node_path.reparentTo(self.base.render) # self.light_nodes = self.set_lights() self.set_fog() self.key_state = dict.fromkeys(Object.values(config.key_map.character), False) self.set_key_state_handler() self.game_state = "pause" self.toggle_pause() self.selection = Selection(self.base.loader, self.terrain.geom_node) self.selection_text = OnscreenText( mayChange=True, scale=0.07, align=TextNode.ALeft, pos=(0.02 - self.base.getAspectRatio(), 1 - 0.07)) self.timer_text = OnscreenText(mayChange=True, scale=0.07, align=TextNode.ALeft, pos=(0.02 - self.base.getAspectRatio(), -1 + 0.02 + 0.07)) self.enemies = set() self.base.accept(config.key_map.utility.pause, self.toggle_pause) self.base.accept( "q", lambda: self.selection.advance_tower(self.base.loader)) self.base.accept("mouse1", self.player_click) self.base.cam.node().setCameraMask(BitMask32.bit(0)) self.base.setBackgroundColor(*config.map_params.colors.sky) self.player = Player() self.base.taskMgr.add(lambda task: self.terrain.start_up(), "start up") self.mouse_pos = (0.0, 0.0) self.base.taskMgr.add(self.move_player_task, "move_player_task") self.base.taskMgr.add(self.move_enemies_task, "move_enemies_task") self.base.taskMgr.add(self.player_select_task, "player_select_task") self.base.taskMgr.add(self.tower_task, "tower_task") self.base.taskMgr.add(self.check_end_game, "check_end_game_task") rand = Random() rand.seed(config.map_params.seed) self.base.taskMgr.doMethodLater(1, self.clock_task, 'clock_task', extraArgs=[rand]) self.rounds = 0 self.coin = 40