def RenderUI(game, background): """Render the map""" TILE_SIZE = game.data['map']['tile_size'] # If we dont have a Player yet, get their name if game.player == None: ui_back = rpg_image.Load('data/ui/board_500.png') rpg_gfx.Draw(ui_back, background, (70, 55)) ui_back_slot = rpg_image.Load('data/ui/board_500_slot_61.png') ui_back_slot_small = rpg_image.Load('data/ui/board_500_slot_35.png') #rpg_gfx.Draw(ui_back_slot, background, (70+30,55+75)) rpg_gfx.Draw(ui_back_slot, background, (70 + 30, 55 + 145)) #rpg_gfx.Draw(ui_back_slot, background, (70+30,55+215)) #rpg_gfx.Draw(ui_back_slot, background, (70+30,55+285)) rpg_image.DrawText('Enter your name', 35, (255, 255, 255), (100, 80), background, outline=1) rpg_image.DrawText(game.core.input.GetAutoString() + '|', 35, (255, 255, 255), (70 + 30 + 15, 55 + 145 + 15), background, outline=1) # If we have a name entered if game.core.input.GetNewEnteredString(): name = game.core.input.GetNewEnteredString() # Create the player game.player = rpg_player.Player(game, name) # The player is here, update visibility game.map.UpdateVisibility() # If there is a dialobue going on, render it if game.dialogue: game.dialogue.Render(background) if 0: # Get the cursor tile position pos = GetMapOffsetTilePos(game) pos[0] += game.mouse.pos[0] / TILE_SIZE pos[1] += game.mouse.pos[1] / TILE_SIZE cursor_pos = ((game.mouse.pos[0] - game.mouse.pos[0] % TILE_SIZE), (game.mouse.pos[1] - game.mouse.pos[1] % TILE_SIZE)) Log('Map Pos: %s = %s. %s' % (str(pos), game.map.GetPosData(pos), str(cursor_pos))) # Draw the tile cursor cursor = rpg_image.Load(rpg_data.UI['cursor_tile'], colorkey=(0, 255, 0)) rpg_gfx.Draw(cursor, background, cursor_pos)
def Render(self, background): """Draw the barter on the background.""" ui_back = rpg_image.Load('data/ui/board_500.png') rpg_gfx.Draw(ui_back, background, (70, 55)) ui_back_slot = rpg_image.Load('data/ui/board_500_slot_61.png') ui_back_slot_small = rpg_image.Load('data/ui/board_500_slot_35.png') # Print option background borders if len(self.options) >= 1: rpg_gfx.Draw(ui_back_slot, background, (70 + 30, 55 + 75)) if len(self.options) >= 2: rpg_gfx.Draw(ui_back_slot, background, (70 + 30, 55 + 145)) if len(self.options) >= 3: rpg_gfx.Draw(ui_back_slot, background, (70 + 30, 55 + 215)) if len(self.options) >= 4: rpg_gfx.Draw(ui_back_slot, background, (70 + 30, 55 + 285)) # Draw the Prompt rpg_image.DrawText(self.dialogue.prompt, 30, (255, 255, 255), (100, 80), background, outline=1) # Print all the option texts for count in range(0, len(self.options)): #TODO(g): Make the show_always data option check and force this option # to be the last option, if we have it set to be on # Only drawing 4 now if count >= 4: break option = self.options[count] x = 70 + 30 + 15 y = 55 + 75 + (70 * count) + 15 # If this option is selected, highlight it if self.selected_option == count: color = (255, 0, 0) else: color = (255, 255, 255) rpg_image.DrawText(option['text'], 20, color, (x, y), background, outline=1)
def RenderMap(game, background): """Render the map""" TILE_SIZE = game.data['map']['tile_size'] MAP_SCREEN_WIDTH = (game.core.size[0] / TILE_SIZE) + 1 MAP_SCREEN_HEIGHT = (game.core.size[1] / TILE_SIZE) + 1 tile_x_offset = game.map.offset[0] tile_y_offset = game.map.offset[1] #Log('Render map offset: %s, %s' % (tile_x_offset, tile_y_offset)) #TODO(g): Make screen drawing dynamic based on core.size and scrolling offsets for y in range(0, MAP_SCREEN_HEIGHT): for x in range(0, MAP_SCREEN_WIDTH): tile_x = tile_x_offset + x tile_y = tile_y_offset + y index = game.map.GetTileIndex((tile_x, tile_y)) filename = game.map.GetPaletteImage(index) image = rpg_image.Load(filename) pos = (x * TILE_SIZE, y * TILE_SIZE) if game.map.CheckVisibility(tile_x, tile_y): rpg_gfx.Draw(image, background, pos) else: rpg_gfx.DrawBlack(background, pos, (TILE_SIZE, TILE_SIZE))
def __init__(self, game, data): """Create the actor, place it on the map.""" self.game = game self.data = data self.name = data['name'] # Create our attributes (need to make new field references) self.attributes = {} for key in self.data.get('attributes', {}): self.attributes[key] = self.data['attributes'][key] # Create items self.items = [] for key in self.data.get('items', {}): item = rpg_item.Item(self.game, self, self.data['items'][key]) self.items.append(item) # Image self.image = rpg_image.Load(data['image'], colorkey=data.get('image_color_key', game.data['game']['color_key'])) starting_position = data['pos'] self.pos = rpg_base.Position(starting_position[0], starting_position[1]) self.pos_last = self.pos # Save any data we need to manipulate self.money = data.get('money', 0) # More stats self.fatigued = False
def __init__(self, game, path): """Load up the map.""" self.game = game self.path = path self.map_filename = '%s/map.bmp' % path self.palette = yaml.load(YamlOpen('%s/palette.txt' % path)) self.data = yaml.load(YamlOpen('%s/map.txt' % path)) self.image = rpg_image.Load(self.map_filename, convert=False) self.width = self.image.get_width() self.height = self.image.get_height() self.image_buffer = rpg_image.GetImageBuffer(self.image) #TODO(g): Convert to Position self.offset = [0, 0] log.Log('Map: %s,%s' % (self.width, self.height)) # Visibility map: Make it true initially, to give a background to the # opening UI. self.ClearVisibilityMap(value=1) # Create our Actors self.CreateActors()
def __init__(self, game, name): """Create the player, place it on the map.""" self.game = game self.name = name starting_position = game.map.data['player']['starting_pos'] self.pos = rpg_base.Position(starting_position[0], starting_position[1]) self.pos_last = self.pos #TODO(g): Unhard-code the default player self.data = yaml.load(YamlOpen(DATA_FILE))['default'] # Image self.image = rpg_image.Load(self.data['image'], colorkey=self.data.get( 'image_color_key', game.data['game']['color_key'])) # Save any attributes we want specifically out of our data self.money = self.data.get('money', 0) # Create our attributes (need to make new field references) self.attributes = {} for key in self.data.get('attributes', {}): self.attributes[key] = self.data['attributes'][key] # Create our items self.items = [] for key in self.data.get('items', {}): item = rpg_item.Item(self.game, self, self.data['items'][key]) self.items.append(item) # Save the current health of the player if 'heath' in self.attributes: self.health_current = self.attributes['health'] else: #NOTE(g): This makes the player alive. Apparently health isnt important # in this game... self.health_current = 1 # Get the quests we start with #TODO(g): Make this a deep copy, so we arent changing the data we loaded self.quests = dict(self.data['quests']) # Save the current health of the player if 'mana' in self.attributes: self.mana_current = self.attributes['mana'] else: #NOTE(g): Mana is not necessary, like health i self.mana_current = 0 # More stats self.fatigued = False # Achievements self.achievements = {}