def init(self, game_data, gfx_data): # first items self.consumable_markers = [] x = self.pos.x + 30 y = self.pos.y + 30 for idx, item in enumerate(game_data.inventory.items): cm = ConsumableMarker(item, idx, pos=Pos(x, y), size=Size(self.slot_width, 50), parent=self) self.consumable_markers.append(cm) x += 150 if idx % self.items_per_row == 0: y += 60 x = self.pos.x + 30 # then quickslots self.quickslot_markers = [] x = self.pos.x + 10 y = 410 for qs in range(self.num_quickslots): qm = QuickslotMarker(qs, pos=Pos(x, y), size=Size(self.slot_width, 50), parent=self) self.quickslot_markers.append(qm) x += self.slot_width + 20
def __init__(self, parent, sourceKey): KeyDisplayPane.__init__(self, parent, border=10, displayMode=DISPLAY_MODE_WRAPPED) self._displayKeys = {} KeyDisplayPane._initKeys(self) self.Bind(wx.EVT_PAINT, self.OnPaint) self._keySize = Size(6.0, 2.5) self._keySpacing = Size(0.2, 0.2) keyRect = Rect(0, 0, *self._keySize) handle = None if sourceKey.usage: handle = sourceKey.usage.MakeHandle() elif sourceKey.mode: handle = "mode:%s" % sourceKey.mode elif len(sourceKey.macro) > 0: for (i, macroKey) in enumerate(sourceKey.macro): handle = macroKey.MakeHandle(i) self._displayKeys[handle] = DisplayKey(handle, keyRect) self._orderedKeyHandles.append(handle) handle = None if handle is not None: dispKey = DisplayKey(handle, keyRect) self._displayKeys[handle] = dispKey self._orderedKeyHandles.append(handle) self._updateKeys()
def __init__(self, parent, displayMode, border): wx.ScrolledWindow.__init__(self, parent) self._displayKeys = {} self._orderedHeyHandles = [] self._keySize = wx.Size(4, 4) self._keySpacing = wx.Size(1, 1) self._border = border self._selectedKeyHandle = None self._contentSize = Size(200, 200) self._displayMode = displayMode self._scroll = wx.Size(0, 0) self._scrollUnit = wx.Size(0, 0) self._tooltip = wx.ToolTip("") self._zoom = 1 if displayMode == DISPLAY_MODE_DYNAMIC_RESIZE: self._zoom = 10 # 25 self._dragStart = None self._dragMode = DRAG_MODE_NONE self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse) self.Bind(wx.EVT_CHAR, self.OnChar) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.SetToolTip(self._tooltip) self.SetScrollRate(1, 1) displayRect = self._getDisplayRect() print "displayRect: %s" % displayRect # dc.SetMapMode(wx.MM_TEXT) dc.SetMapMode(wx.MM_METRIC) contentRect = Rect(dc.DeviceToLogicalX(displayRect.x), dc.DeviceToLogicalY(displayRect.y), dc.DeviceToLogicalXRel(displayRect.width), dc.DeviceToLogicalYRel(displayRect.height))
def generate(self): self.fields = [] seed = id(self) gen_size = Size(self.size, self.size) map = NoiseMap(gen_size, seed) map.generate_noise(map.sinussinus_noise) for i in range(10): map2 = NoiseMap(gen_size, seed * i) map2.generate_noise(map2.sinussinus_noise) if i % 2: map2.reverse() map = map + map2 map.for_every(abs) map.soft_focus() map.normalize() map.equalize_range(7, 10, 9) map.equalize_range(0, 6, 0) map.equalize_range(6, 8, 9) map.dualize() for y, line in enumerate(map.map): for x, value in enumerate(line): ground_type = GROUNDS['DIRT'] if value: ground_type = GROUNDS['WATER'] self.fields.append(Field(ground_type, Vec((x, y))))
def __init__(self, pos, formula_idx, player, size=Size(100, 30)): super().__init__(pos, size, click_mode=ClickMode.LEFT) self.formula_idx = formula_idx self.player = player self.cooldown_bar = Bar( pos, None, colors.COOLDOWN_BAR_FRONT, colors.COOLDOWN_BAR_BACKGROUND, show_numbers=False, ) self.font = Assets.get().font_message
def get_constants(): window_title = "Formula" map_size = Size(40, 30) camera_size = Size(25, 20) game_window_size = Size((camera_size.width + 1) * CELL_WIDTH, (camera_size.height + 1) * CELL_HEIGHT) window_size = Size(150 + game_window_size.width, 900) right_panel_size = Size(150, window_size.height) message_log_size = Size( window_size.width - right_panel_size.width, window_size.height - game_window_size.height, ) message_log_text_size = Size( message_log_size.width - 2 * CELL_WIDTH, message_log_size.height - 2 * CELL_HEIGHT, ) helper_window_size = Size(800, 600) helper_window_pos = Pos(100, 100) num_consumables = 5 num_quickslots = 3 room_max_size = 15 room_min_size = 6 max_rooms = 5 fov_algorithm = 0 fov_light_walls = True fov_radius = 10 retr = AttrDict({ "window_title": window_title, "window_size": window_size, "game_window_size": game_window_size, "camera_size": camera_size, "map_size": map_size, "right_panel_size": right_panel_size, "message_log_size": message_log_size, "message_log_text_size": message_log_text_size, "helper_window_size": helper_window_size, "helper_window_pos": helper_window_pos, "room_max_size": room_max_size, "room_min_size": room_min_size, "max_rooms": max_rooms, "fov_algorithm": fov_algorithm, "fov_light_walls": fov_light_walls, "fov_radius": fov_radius, "num_consumables": num_consumables, "num_quickslots": num_quickslots, }) return retr
def __init__(self, org, platform): self.org = org self.platform = platform self.keyhash = {} self.copyright = '' self.maxSize = Size(0, 0) self.matrix = [] self.maps = [] self.platformMap = None self.layout = None
def _updateKeys(self): """ Adjust position and scale of each display key based on current display rect. """ displayRect = self._getDisplayRect() self._scroll.width = self._scroll.height = 0 self._scrollUnit = displayRect.size scale = self._getScale(displayRect) if self._displayMode == DISPLAY_MODE_DYNAMIC_RESIZE: print scale contentRect = deepcopy(displayRect) if scale > 0: adjustedSize = Size( self._contentSize.width * scale * self._zoom, self._contentSize.height * scale * self._zoom) contentRect.width = adjustedSize.width contentRect.height = adjustedSize.height contentRect = contentRect.CenterIn(displayRect) contentRect.x /= scale contentRect.y /= scale for displayKey in self._displayKeys.values(): displayKey.scaled = displayKey.unscaled * self._zoom displayKey.scaled.OffsetXY(contentRect.x, contentRect.y) else: maxWidth = displayRect.width / scale origin = Point(0, 0) for displayKeyHandle in self._orderedHeyHandles: displayKey = self._displayKeys[displayKeyHandle] if origin.x + self._keySize.width > maxWidth: origin.x = 0 origin.y += self._keySize.height + self._keySpacing.height displayKey.unscaled.x = origin.x displayKey.unscaled.y = origin.y displayKey.scaled = displayKey.unscaled * scale self._scroll.width = max( self._scroll.width, displayKey.scaled.x + displayKey.scaled.width) self._scroll.height = max( self._scroll.height, displayKey.scaled.y + displayKey.scaled.height) displayKey.scaled.OffsetXY(displayRect.x, displayRect.y) origin.x += self._keySize.width + self._keySpacing.width self._scrollUnit.width = min(self._scrollUnit.width, displayKey.scaled.width) self._scrollUnit.height = min(self._scrollUnit.height, displayKey.scaled.height) self._scroll.width += self._border * 2 self._scroll.height += self._border * 2 self._scrollUnit.width += self._keySpacing.width * scale self._scrollUnit.height += self._keySpacing.height * scale
def __init__( self, pos, text=None, color=colors.WHITE, bgcolor=colors.BACKGROUND, size=Size(100, 30), show_numbers=True, ): super().__init__(pos, size) self.color = color self.text = text self.bgcolor = bgcolor self.show_numbers = show_numbers
def __init__(self, parent, displayMode, border): wx.ScrolledWindow.__init__(self, parent) self._displayKeys = {} self._orderedKeyHandles = [] self._keySize = Size(1.8, 1.8) self._keySpacing = Size(0.2, 0.2) self._border = border self._selectedKeyHandle = None self._displayMode = displayMode self._scroll = wx.Size(0, 0) self._scrollUnit = wx.Size(0, 0) self._tooltip = wx.ToolTip("") self._dragStart = None self._dragMode = DRAG_MODE_NONE self._fontSize = 10 self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse) self.Bind(wx.EVT_CHAR, self.OnChar) self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) self.SetToolTip(self._tooltip) self.SetScrollRate(1, 1) self._createContextMenu()
def run_new_game(self): self.game = self.game_class(Size(10, 10)) if self.game.DEBUG: print('LOADING: gui: create planets') for i in range(10): self.game.planetmap.add_planet(GuiPlanet, 10, 'yellow') print('LOADING: gui: add players') self.game.add_player(GuiPlayer, 'fred') self.game.add_player(KiPlayer, 'ki1') self.game.add_player(KiPlayer, 'ki2') self.game.add_player(KiPlayer, 'ki3') self.game.add_player(KiPlayer, 'ki4') self.game.add_player(KiPlayer, 'ki5') print('\nLOADING: gui: finished') self.game.run()
def get_monsters(level): game_map = GameMap(Size(10, 10), dungeon_level=1) def helper(name): room = Rect(2, 2, 10, 10) return get_monster(0, 0, game_map, room, name, [])[0] if level == 1: monster_names = [ "thug", "axe_thrower", "dog_group", ] elif level == 2: monster_names = ["mercenary", "rifleman", "boar_group"] else: raise ValueError(f"No monsters specified for level {level}") retr = [] for name in monster_names: retr.append(helper(name)) return retr
def __init__(self, constants, parent=None): super().__init__( Pos(0, 0), constants.right_panel_size, visible=False, parent=parent, click_mode=ClickMode.LEFT, ) self.health_bar = Bar(Pos(10, 20), "HP", colors.HP_BAR_FRONT, colors.HP_BAR_BACKGROUND, size=Size(120, 30),) self.shield_bar = Bar( Pos(10, 60), "Shield", colors.SHIELD_BAR_FRONT, colors.SHIELD_BAR_BACKGROUND, size=Size(120, 30), ) self.xp_bar = Bar( Pos(10, 130), text=None, color=colors.XP_BAR_FRONT, bgcolor=colors.XP_BAR_BACKGROUND, size=Size(120, 30), show_numbers=False, ) self.formula_label = Label(Pos(10, 180), "Formulas") self.helplabel = Label(Pos(10, 800), "Help? Tab", font=Assets.get().font_message) self.formula_markers = [] self.setup_consumables(constants.num_quickslots) self.drawing_priority = 2
def load_map(path, level): with open(path, "r") as reader: content = reader.read() lines = content.split("\n") lines = [line for line in lines if line != ""] width = len(lines[0]) height = len(lines) retr = GameMap(Size(width, height), level) for x in range(retr.width): for y in range(retr.height): if lines[y][x] == "P": retr.tiles[x][y].blocked = False retr.tiles[x][y].block_sight = False retr.player_pos = Pos(x, y) retr.orig_player_pos = Pos(x, y) elif lines[y][x] == " ": retr.tiles[x][y].blocked = False retr.tiles[x][y].block_sight = False elif lines[y][x] == "#": retr.tiles[x][y].blocked = True retr.tiles[x][y].block_sight = True retr.set_tile_info(retr.tiles) return retr
def __init__(self, pos, text, ingredient, parent): super().__init__(pos=pos, text=text, size=Size(100, 30), parent=parent) self.ingredient = ingredient
def __init__(self, pos, consumable_index, size=Size(130, 30)): super().__init__(pos, size, click_mode=ClickMode.LEFT) self.consumable_index = consumable_index self.shortcut = self.get_shortcut(self.consumable_index) self.font = Assets.get().font_message
def _getContentSize(self): return Size(6.0, 8.0)
def startElement(self, name, attrs): # handle XIncludes if name == 'xi:include': self.include(attrs['href']) return self.level += 1 debug("%s<%s %s>", ' ' * self.level, name, pprint.saferepr(attrs.items())) last = self.state[-1] while True: # Root elements if last == 'Root': if name == 'Keyboard': platform = None if attrs.has_key('platform'): platform = attrs['platform'] self.kb = Keyboard(attrs['org'], platform) self.kb.copyright = self.copyright self.state.append('Keyboard') break if name == 'Copyright': self.state.append('Copyright') def anon(chars): self.copyright += chars self.content = anon break # Root sub-elements elif last == 'Keyboard': if name == 'Layout': eid = attrs['id'] rev = extractRev(attrs['rev']) self.kb.layout = KeyLayout(eid, rev) self.state.append('Layout') break if name == 'Map': eid = attrs['id'] rev = extractRev(attrs['rev']) if not attrs.has_key('base'): if not self.kb.platformMap == None: self.kb.maps.append(deepcopy(self.kb.platformMap)) self.kb.maps[-1].ids.append(eid) self.kb.maps[-1].revs.append(rev) else: self.kb.maps.append(KeyMap(eid, rev)) else: self.include(attrs['base']) self.kb.maps[-1].ids.append(eid) self.kb.maps[-1].revs.append(rev) self.currentKeyMap = self.kb.maps[-1] self.state.append('Map') break if name == 'Matrix': self.kb.matrixId = attrs['id'] self.state.append('Matrix') break # <Keyboard> sub-elements elif last == 'Layout': if name == 'Spacing': def anon(chars): self.kb.layout.spacing = float(chars) self.content = anon break if name == 'Colors': self.kb.colors = {} self.state.append('Colors') break if name == 'Mount': self.kb.layout.mount = Size(0.0, 0.0) self.state.append('Mount') break if name == 'KeyDefs': self.state.append('KeyDefs') break elif last == 'Map': if name == 'Keys': if attrs.has_key('default_color'): self.defaultColor = self.kb.colors[ attrs['default_color']] self.state.append('Keys') break elif last == 'Matrix': if name == 'Row': self.currentMatrixRow = int(attrs['id']) self.kb.matrix.append({}) self.state.append('MatrixRow') break # <Matrix> sub-elements elif last == 'MatrixRow': if name == 'Col': matrixCol = int(attrs['id']) def anon(chars): self.kb.matrix[ self.currentMatrixRow][matrixCol] = chars self.content = anon break # <Layout> sub-elements elif last == 'Colors': if name == 'Color': self.state.append('Color') self.currentColor = attrs['name'] break elif last == 'Mount': if name == 'Height': def anon(chars): self.kb.layout.mount.height = float(chars) self.content = anon break if last == 'Width': def anon(chars): self.kb.layout.mount.width = float(chars) self.content = anon break elif last == 'KeyDefs': if name == 'Row': self.pos.x = 0.0 self.currentRow += 1 self.currentRowDef = RowDef(self.currentRow) self.state.append('KeyDefRow') break # <KeyDefs> sub-elements elif last == 'KeyDefRow': if name == 'OffsetY': def anon(chars): self.currentRowDef.offset.y = float(chars) self.pos.y += self.currentRowDef.offset.y + self.kb.layout.spacing self.content = anon break if name == 'OffsetX': def anon(chars): self.currentRowDef.offset.x = float(chars) self.pos.x += self.currentRowDef.offset.x self.content = anon break if name == 'KeyDef': location = attrs['location'] self.currentKeyDef = KeyDef(location) self.kb.keyhash[location] = self.currentKeyDef self.currentKeyDef.origin = deepcopy(self.pos) self.state.append('KeyDef') break # <Row> (of <KeyDef>) sub-elements elif last == 'KeyDef': if name == 'Height': def anon(chars): self.currentKeyDef.size.height = float(chars) self.content = anon break if name == 'Width': def anon(chars): self.currentKeyDef.size.width = float(chars) self.pos.x += self.currentKeyDef.size.width + self.kb.layout.spacing self.content = anon break if name == 'OffsetY': def anon(chars): self.currentKeyDef.offset.y = float(chars) self.currentKeyDef.origin.y = self.pos.y + self.currentKeyDef.offset.y self.content = anon break if name == 'OffsetX': def anon(chars): self.currentKeyDef.offset.x = float(chars) self.currentKeyDef.origin.x = self.pos.x + self.currentKeyDef.offset.x self.content = anon break if name == 'Background' or name == 'Bump' or name == 'NullKey': break # <Colors> sub-elements elif last == 'Color': if name == 'Rgb': def anon(chars): self.kb.colors[self.currentColor] = chars self.content = anon break # <Map> sub-elements elif last == 'Keys': if name == 'KeyRef': location = attrs['location'] keyHandle = attrs['id'] if not self.kb.keyhash.has_key(location): raise RuntimeError, "Keymap %s: %s: Key definition %s has not been defined" % ( self.currentKeyMap, keyHandle, location) if self.kb.keyhash[location].isNullKey: raise RuntimeError, "Keymap %s: %s: Cannot assign key to a NullKey definition (%s)" % ( self.currentKeyMap, keyHandle, location) if not self.sourceModel.has_key(keyHandle): raise RuntimeError( "Keymap %s: Key with id '%s' for location '%s' does not exist in SourceKeys" % (self.currentKeyMap, keyHandle, location)) oldKey = None if self.currentKeyMap.keys.has_key(location): oldKey = self.currentKeyMap.keys[location] self.currentKey = self.currentKeyMap.keys[ location] = KeyRef(location, keyHandle) self.currentKey.prevKey = oldKey break else: raise RuntimeError("Unknown state '%s'" % last) raise RuntimeError("Unknown element '%s' for state '%s'" % (name, last))
def initialize_map(self): assert self.game_data self.map_size = Size(self.game_data.map.width, self.game_data.map.height) self.width = min(self.map_size.width, self.width) self.height = min(self.map_size.height, self.height)
def _getContentSize(self): """ Return, in logical units, the max height and width of the content. """ return Size(200, 200)
def dualize(self): medium = self.get_max() - abs(self.get_max() - self.get_min()) self.for_every((lambda x: int(x > medium))) if __name__ == '__main__': map = NoiseMap((100, 100), 500 * time.time()) map.generate_noise(map.sinussinus_noise) #map2 = NoiseMap((100, 100), 23)#3123123*i+time.time()) #map2.generate_noise(map2.sinus_noise) #map2.reverse() #map = map+map2 for i in range(10): map2 = NoiseMap(Size(100, 100), 3123123 * i * time.time()) map2.generate_noise(map2.sinussinus_noise) if i % 2: map2.reverse() map = map + map2 def sqr(x): return abs(x)**1 map.for_every(sqr) map.soft_focus() map.soft_focus() map.soft_focus() map.normalize() map.equalize_range(7, 10, 9) map.equalize_range(0, 6, 0)
def reverse(self): self.size = Size(*[i for i in reversed(self.size)]) self.map = [[line[col] for line in self.map] for col in range(self.size.width)]
def __init__(self, pos, text, font=None, parent=None): super().__init__(pos, Size(0, 0), parent=parent) self.text = text self.font = font if font else Assets.get().font_title
def _getContentSize(self): return Size(1.8, 1.8)
def __init__(self, location): self.location = location self.origin = Point(0.0, 0.0) self.size = Size(0.0, 0.0) self.isNullKey = False self.offset = Point(0.0, 0.0)