def open_inner_menu(screen_str): global inner_cur_button inner_cur_button = 0 global tmp_x_base global tmp_y_base global tmp_menu_x_base global tmp_menu_y_base global tmp_menu_width global tmp_menu_height global inv_canvas_width global inv_canvas_height if inv_canvas_width == 0: inv_canvas_width = (g.tilesize * inv_width) + ((inv_width + 1) * 2) + 1 if inv_canvas_height == 0: inv_canvas_height = (g.tilesize * inv_height) + ( (inv_height + 1) * 2) + 1 tmp_x_base = (g.tilesize * main.mapsizex) / 2 - inv_canvas_width tmp_y_base = (g.tilesize * main.mapsizey - inv_canvas_height) / 2 tmp_menu_x_base = ((g.tilesize * main.mapsizex) / 2 - tmp_x_base) / 2 + \ tmp_x_base - g.buttons[screen_str + ".png"].get_width() tmp_menu_y_base = (g.tilesize * main.mapsizey + inv_canvas_height) / 2 tmp_menu_width = g.buttons[ screen_str + ".png"].get_width() + g.buttons["leave.png"].get_width() tmp_menu_height = g.buttons["leave.png"].get_height() create_inv_display(screen_str) #button rectangle g.create_norm_box((tmp_menu_x_base, tmp_menu_y_base), (tmp_menu_width, tmp_menu_height))
def box_with_text(xy, text, focused, active=False): in_color = "light_gray" if focused: in_color = "dh_green" if active: in_color = "light_red" g.create_norm_box((xy[0] + 2, xy[1] + 2), (176, 23), inner_color=in_color) g.print_string(g.screen, text, g.font, (xy[0] + 9, xy[1] + 10))
def refresh_buttons(): global prev_button if prev_button == cur_button: return prev_button = cur_button # main.canvas_map.delete("shop_buttons") g.create_norm_box((temp_button_x, temp_button_y), (temp_button_width, g.buttons["sell.png"].get_height())) # main.canvas_map.create_rectangle(temp_button_x, temp_button_y, # temp_button_x+temp_button_width, # temp_button_y+g.buttons["sell.png"].get_height(), fill=bgcolour, # tags=("shop_buttons", "shop")) if (cur_button == 0): g.screen.blit(g.buttons["sell_sel.png"], (temp_button_x, temp_button_y)) # main.canvas_map.create_image( # temp_button_x, temp_button_y, anchor=NW, # image=g.buttons["sell_sel.png"], # tags=("shop_buttons", "shop")) else: g.screen.blit(g.buttons["sell.png"], (temp_button_x, temp_button_y)) # main.canvas_map.create_image(temp_button_x, temp_button_y, anchor=NW, # image=g.buttons["sell.png"], # tags=("shop_buttons", "shop")) if (cur_button == 1): g.screen.blit(g.buttons["leave_shop_sel.png"], (temp_button_x + leave_height, temp_button_y)) # main.canvas_map.create_image( # temp_button_x+leave_height, temp_button_y, # anchor=NW, image=g.buttons["leave_shop_sel.png"], # tags=("shop_buttons", "shop")) else: g.screen.blit(g.buttons["leave_shop.png"], (temp_button_x + leave_height, temp_button_y)) # main.canvas_map.create_image(temp_button_x+leave_height, # temp_button_y, anchor=NW, # image=g.buttons["leave_shop.png"], # tags=("shop_buttons", "shop")) if (cur_button == 2): g.screen.blit(g.buttons["buy_sel.png"], (temp_button_x + buy_height, temp_button_y)) # main.canvas_map.create_image( # temp_button_x+buy_height, temp_button_y, anchor=NW, # image=g.buttons["buy_sel.png"], # tags=("shop_buttons", "shop")) else: g.screen.blit(g.buttons["buy.png"], (temp_button_x + buy_height, temp_button_y)) # main.canvas_map.create_image(temp_button_x+buy_height, # temp_button_y, anchor=NW, # image=g.buttons["buy.png"], # tags=("shop_buttons", "shop")) pygame.display.flip()
def refresh_key_window(adjusting=False): #create the window x_start = g.tilesize * g.main.mapsizex / 2 - 90 y_start = g.tilesize * g.main.mapsizey / 2 - 80 x_width = 180 g.create_norm_box((x_start, y_start), (x_width, 212)) #up tmp_string = "Up: " + pygame.key.name(tmp_keys["up"]) focused = False if curr_button == 10: focused = True box_with_text((x_start, y_start), tmp_string, focused, adjusting) #right tmp_string = "Right: " + pygame.key.name(tmp_keys["right"]) focused = False if curr_button == 11: focused = True box_with_text((x_start, y_start + 25), tmp_string, focused, adjusting) #down tmp_string = "Down: " + pygame.key.name(tmp_keys["down"]) focused = False if curr_button == 12: focused = True box_with_text((x_start, y_start + 50), tmp_string, focused, adjusting) #Left tmp_string = "Left: " + pygame.key.name(tmp_keys["left"]) focused = False if curr_button == 13: focused = True box_with_text((x_start, y_start + 75), tmp_string, focused, adjusting) #Action tmp_string = "Action: " + pygame.key.name(tmp_keys["action"]) focused = False if curr_button == 14: focused = True box_with_text((x_start, y_start + 100), tmp_string, focused, adjusting) #Cancel tmp_string = "Cancel: " + pygame.key.name(tmp_keys["cancel"]) focused = False if curr_button == 15: focused = True box_with_text((x_start, y_start + 125), tmp_string, focused, adjusting) #reset setttings focused = False if curr_button == 16: focused = True box_with_text((x_start, y_start + 160), "Reset Settings", focused) #leave focused = False if curr_button == 17: focused = True box_with_text((x_start, y_start + 185), "Back", focused) pygame.display.flip()
def display_stats(stat_dict, titles_dict): pixels_per_line = 20 g.unclean_screen = True g.screen.fill(g.colors["light_gray"], (g.tilesize * g.main.mapsizex / 4 + g.buttons["loadgame_up.png"].get_width() + 3, g.tilesize * g.main.mapsizey / 3, 150, 170)) info_x = g.tilesize * g.main.mapsizex / 4 + g.buttons[ "loadgame_up.png"].get_width() + 5 info_y = g.tilesize * g.main.mapsizey / 3 linenum = 0 g.print_string(g.screen, g.name_name + ": " + stat_dict["name"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.hp_name + ": " + stat_dict["hp"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.ep_name + ": " + stat_dict["ep"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.attack_name + ": " + stat_dict["attack"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.defense_name + ": " + stat_dict["defense"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.gold_name + ": " + stat_dict["gold"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.exp_name + ": " + stat_dict["exp"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 g.print_string(g.screen, g.level_name + ": " + stat_dict["level"], g.font, (info_x, info_y + pixels_per_line * linenum)) linenum += 1 for i in range(5): if i == saves_pos % 5: inner_color = "dh_green" else: inner_color = "light_gray" g.create_norm_box( (g.tilesize * g.main.mapsizex / 4 + 2, g.tilesize * g.main.mapsizey / 3 + g.buttons["loadgame_down.png"].get_height() + 1 + i * 20), (g.buttons["loadgame_down.png"].get_width() - 3, 17), inner_color=inner_color) g.print_string( g.screen, titles_dict[i], g.font, (g.tilesize * g.main.mapsizex / 4 + 5, g.tilesize * g.main.mapsizey / 3 + g.buttons["loadgame_down.png"].get_height() + 2 + i * 20))
def create_inv_display(screen_str): g.create_norm_box((tmp_x_base, tmp_y_base), ((g.tilesize * main.mapsizex) / 2 - tmp_x_base, (g.tilesize * main.mapsizey + inv_canvas_height) / 2 + g.buttons["leave.png"].get_height() - tmp_y_base)) #per-item borders for y in range(inv_height): for x in range(inv_width): g.create_norm_box( (tmp_x_base + x * g.tilesize + 2 * (x + 1), tmp_y_base + y * g.tilesize + 2 * (y + 1)), (g.tilesize, g.tilesize), inner_color="dh_green")
def refresh_joy_window(adjusting=False): #create the window x_start = g.tilesize * g.main.mapsizex / 2 - 90 y_start = g.tilesize * g.main.mapsizey / 2 - 80 x_width = 180 g.create_norm_box((x_start, y_start), (x_width, 212)) #left/right tmp_string = "Left/Right Axis: " + str(tmp_joy["lr"]) focused = False if curr_button == 20: focused = True box_with_text((x_start, y_start), tmp_string, focused, adjusting) #up/down tmp_string = "Up/Down Axis: " + str(tmp_joy["ud"]) focused = False if curr_button == 21: focused = True box_with_text((x_start, y_start + 25), tmp_string, focused, adjusting) #action tmp_string = "Action: " + str(tmp_joy["action"]) focused = False if curr_button == 22: focused = True box_with_text((x_start, y_start + 50), tmp_string, focused, adjusting) #Cancel tmp_string = "Cancel: " + str(tmp_joy["cancel"]) focused = False if curr_button == 23: focused = True box_with_text((x_start, y_start + 75), tmp_string, focused, adjusting) #reset setttings focused = False if curr_button == 24: focused = True box_with_text((x_start, y_start + 160), "Reset Settings", focused) #leave focused = False if curr_button == 25: focused = True box_with_text((x_start, y_start + 185), "Back", focused) pygame.display.flip()
def refresh_new_game(): g.create_norm_box( (g.tilesize * main.mapsizex / 4, g.tilesize * main.mapsizey / 3), (g.tilesize * main.mapsizex / 2, g.tilesize * main.mapsizey / 3)) g.print_string(g.screen, g.name_name + ": " + name_stat, g.font, (g.tilesize * main.mapsizex / 4 + 10, g.tilesize * main.mapsizey / 3 + 10)) g.print_string(g.screen, g.hp_name + ": " + str(hp_stat), g.font, (g.tilesize * main.mapsizex / 4 + 10, g.tilesize * main.mapsizey / 3 + 25)) g.print_string(g.screen, g.ep_name + ": " + str(ep_stat), g.font, (g.tilesize * main.mapsizex / 4 + 10, g.tilesize * main.mapsizey / 3 + 40)) g.print_string(g.screen, g.attack_name + ": " + str(attack_stat), g.font, (g.tilesize * main.mapsizex / 4 + 10, g.tilesize * main.mapsizey / 3 + 55)) g.print_string(g.screen, g.defense_name + ": " + str(defense_stat), g.font, (g.tilesize * main.mapsizex / 4 + 10, g.tilesize * main.mapsizey / 3 + 70)) g.print_string(g.screen, g.gold_name + ": " + str(gold_stat), g.font, (g.tilesize * main.mapsizex / 4 + 10, g.tilesize * main.mapsizey / 3 + 85))
def load_selected(): global return_from_loadgame global did_load global prevent_dbl_load if len(saves_array) == 0: return if prevent_dbl_load == 1: return prevent_dbl_load = 1 g.create_norm_box( (g.tilesize * g.main.mapsizex / 4, g.tilesize * g.main.mapsizey / 3), (g.tilesize * g.main.mapsizex / 2, 140 + g.buttons["load_scr.png"].get_height())) g.print_string( g.screen, "Loading game. Please wait", g.font, (g.tilesize * g.main.mapsizex / 2, g.tilesize * g.main.mapsizey / 3 + 70 + g.buttons["load_scr.png"].get_height() / 2)) pygame.display.flip() #g.loadgame(saves_array[saves_pos]) did_load = saves_array[saves_pos] # return_from_loadgame.set(1) g.break_one_loop = 1
def open_equip_item(): global curr_item open_inner_menu("equip") #Equip also needs the equip screen: temp_canvas_width = (g.tilesize * equip_size) + 8 g.create_norm_box((tmp_x_base - temp_canvas_width, tmp_y_base), (temp_canvas_width, temp_canvas_width)) g.cur_window = "inventory_equip" refresh_equip() refresh_equip_buttons() while 1: pygame.time.wait(30) g.clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: return elif event.type == pygame.KEYDOWN: if equip_key_handler(event.key) == 1: if curr_item >= inv_width * inv_height: curr_item = 0 return elif event.type == pygame.MOUSEMOTION: equip_mouse_move(event.pos) elif event.type == pygame.MOUSEBUTTONDOWN: if equip_mouse_click(event.pos) == 1: if curr_item >= inv_width * inv_height: curr_item = 0 return tmpjoy = g.run_joystick() if tmpjoy != 0: if equip_key_handler(tmpjoy) == 1: if curr_item >= inv_width * inv_height: curr_item = 0 return menu_bind_keys()
def begin_game(loadgame_name=""): #This prevents a race condition global already_started_game if already_started_game == 1: return 0 already_started_game = 1 g.create_norm_box((g.screen_size[0] / 4, g.screen_size[1] / 3), (g.screen_size[0] / 2, g.screen_size[1] / 3), "black", "light_gray") g.print_string(g.screen, "Starting game. Please wait", g.font, (g.screen_size[0] / 2, g.screen_size[1] / 2), align=1) pygame.display.flip() g.read_maps() g.item.load_dropped_items() #just in case someone changed the name #after rerolling or loading global name_stat player.name = name_stat if player.name == "": player.name = "Nameless" #bring the main window up. if loadgame_name != "": g.loadgame(loadgame_name) main.init_window_main(new_game) already_started_game = 0 g.break_one_loop = 0 #after returning to this screen, reset everything. # reroll_stats() init_window() return 1
def refresh_module_info(self): g.unclean_screen = True tmp = self.module_pos - (self.module_pos % 5) for i in range(5): if i == self.module_pos % 5: tmp_color = "dh_green" else: tmp_color = "light_gray" g.create_norm_box( (g.tilesize * g.main.mapsizex / 4 + 2, g.tilesize * g.main.mapsizey / 3 + g.buttons["loadgame_down.png"].get_height() + 1 + i * 20), (g.buttons["loadgame_down.png"].get_width() - 5, 17), inner_color=tmp_color) if len(self.array_mods) <= tmp + i: savetext = "" else: savetext = self.array_mods[tmp + i] g.print_string( g.screen, savetext, g.font, (g.tilesize * g.main.mapsizex / 4 + 5, g.tilesize * g.main.mapsizey / 3 + g.buttons["loadgame_down.png"].get_height() + 3 + i * 20))
def refresh_inv_display(screen_str): #Draw a selection box around the current item. x = tmp_x_base y = tmp_y_base for i in range(len(item.inv)): g.create_norm_box( (x + (i % inv_width) * g.tilesize + 2 * ((i % inv_width) + 1), y + (i / inv_width) * g.tilesize + 2 * ((i / inv_width) + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") if (curr_item != -1 and curr_item < inv_width * inv_height): g.create_norm_box((x + (curr_item % inv_width) * g.tilesize + 2 * ((curr_item % inv_width) + 1), y + (curr_item / inv_width) * g.tilesize + 2 * ((curr_item / inv_width) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green") #draw the item pictures. for i in range(len(item.inv)): if item.inv[i] != -1: draw_item(item.item[item.inv[i]].picturename, i % inv_width, i / inv_width, x, y, screen_str) #draw the help text if curr_item >= inv_width * inv_height: #equipment tempitem = convert_equip_loc_to_index(curr_item - (inv_width * inv_height)) if tempitem == -1: helptext = "" elif player.equip[tempitem] == -1: helptext = "" else: helptext = item.item[player.equip[tempitem]].name else: #Inv if curr_item == -1 or item.inv[curr_item] == -1: helptext = "" else: helptext = item.item[item.inv[curr_item]].name g.create_norm_box((tmp_menu_x_base, tmp_menu_y_base + tmp_menu_height), (tmp_menu_width, 17)) g.print_string( g.screen, helptext, g.font, (tmp_menu_x_base + 2, tmp_menu_y_base + tmp_menu_height + 1)) pygame.display.flip()
def refresh_skill_display(screen_str): # main.canvas_map.delete("item") #Draw a selection box around the current item. x = inv.tmp_x_base y = inv.tmp_y_base tmp_item = inv.curr_item for i in range(len(g.item.inv)): g.create_norm_box( (x + (i % inv.inv_width) * g.tilesize + 2 * ((i % inv.inv_width) + 1), y + (i / inv.inv_width) * g.tilesize + 2 * ((i / inv.inv_width) + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") if (tmp_item != -1 and tmp_item < inv.inv_width * inv.inv_height): g.create_norm_box( (x + (inv.curr_item % inv.inv_width) * g.tilesize + 2 * ((inv.curr_item % inv.inv_width) + 1), y + (inv.curr_item / inv.inv_width) * g.tilesize + 2 * ((inv.curr_item / inv.inv_width) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green") #draw the skill pictures. for i in range(len(player.skill)): if player.skill[i][5] != 0 and (player.skill[i][1] <= 4 or player.skill[i][1] == 6): inv.draw_item(player.skill[i][7], i % inv.inv_width, i / inv.inv_width, x, y, screen_str) #draw the help text g.create_norm_box( (inv.tmp_menu_x_base, inv.tmp_menu_y_base + inv.tmp_menu_height), (inv.tmp_menu_width, 17)) if len(player.skill) <= tmp_item: helptext = "" elif tmp_item == -1 or player.skill[tmp_item][5] == 0 or \ player.skill[tmp_item][1] == 5: helptext = "" else: helptext = (player.skill[tmp_item][0] + " (" + str(player.skill[tmp_item][2]) + " EP)") g.print_string(g.screen, helptext, g.font, (inv.tmp_menu_x_base + 2, inv.tmp_menu_y_base + inv.tmp_menu_height + 1)) pygame.display.flip()
def refresh_inv(x, y, input_tag): if action.has_dialog == 1: return 0 # canvas_inv.delete("item") # invpos = 0 #Draw a selection box around the current item. # if cur_button == 0 or (cur_button == 1): for i in range(len(item.inv)): g.create_norm_box( (x + (i % inv_width) * g.tilesize + 2 * ((i % inv_width) + 1), y + (i / inv_width) * g.tilesize + 2 * ((i / inv_width) + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") if (curr_item != -1): g.create_norm_box((x + (curr_item % inv_width) * g.tilesize + 2 * ((curr_item % inv_width) + 1), y + (curr_item / inv_width) * g.tilesize + 2 * ((curr_item / inv_width) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green") #draw the item pictures. for i in range(len(item.inv)): if item.inv[i] != -1: draw_item(item.item[item.inv[i]].picturename, i % inv_width, i / inv_width, x, y, input_tag) # invpos += 1 # canvas_equip.delete("item") if cur_button == 3: #equipment g.create_norm_box(((curr_item % equip_size) * g.tilesize + 2 * ((curr_item % equip_size) + 1), (curr_item / equip_size) * g.tilesize + 2 * ((curr_item / equip_size) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green")
def init_window_shop(store_type_input): g.cur_window = "shop" global last_click_time last_click_time = 0 global prev_button prev_button = 1 global temp_canvas_width global temp_canvas_height global canvas_x_start global canvas_y_start global temp_button_x global temp_button_width global temp_button_y temp_canvas_width = (g.tilesize * shop_width) + ((shop_width + 1) * 2) + 1 temp_canvas_height = (g.tilesize * shop_height) + ( (shop_height + 1) * 2) + 1 canvas_x_start = ((g.tilesize * main.mapsizex) - temp_canvas_width * 3) / 2 canvas_y_start = ((g.tilesize * main.mapsizey) - temp_canvas_height) / 2 temp_button_x = canvas_x_start + (temp_canvas_width * 3) / 2 - \ g.buttons["sell.png"].get_width() - g.buttons["leave_shop.png"].get_width() / 2 temp_button_width = g.buttons["sell.png"].get_width() + \ g.buttons["leave_shop.png"].get_width() + g.buttons["buy.png"].get_width() temp_button_y = canvas_y_start + temp_canvas_height + 1 global bgcolour bgcolour = "light_grey" g.create_norm_box((canvas_x_start - 2, canvas_y_start - 19), (temp_canvas_width * 3 + 3, temp_canvas_height + 20)) global curr_item curr_item = 0 global curr_focus curr_focus = 1 global cur_button cur_button = 2 store_type_input = store_type_input.lower() global store_num for i in range(len(g.shops)): if (g.shops[i].name.lower() == store_type_input): store_num = i break g.create_norm_box((canvas_x_start, canvas_y_start), (temp_canvas_width - 1, temp_canvas_height - 1)) #per-item borders for y in range(shop_height): for x in range(shop_width): g.create_norm_box( (canvas_x_start + x * g.tilesize + 2 * (x + 1), canvas_y_start + y * g.tilesize + 2 * (y + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") g.create_norm_box((temp_canvas_width * 2 + canvas_x_start, canvas_y_start), (temp_canvas_width - 1, temp_canvas_height - 1)) #per-item borders for y in range(shop_height): for x in range(shop_width): g.create_norm_box( (temp_canvas_width * 2 + canvas_x_start + x * g.tilesize + 2 * (x + 1), canvas_y_start + y * g.tilesize + 2 * (y + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") #Info labels g.print_string(g.screen, "Inventory", g.font, (canvas_x_start + (temp_canvas_width * 1) / 2, canvas_y_start - 15), align=1) g.print_string(g.screen, g.shops[store_num].name, g.font, (canvas_x_start + (temp_canvas_width * 5) / 2, canvas_y_start - 15), align=1) # main.canvas_map.create_text(canvas_x_start+(temp_canvas_width*1)/2, # canvas_y_start-1, anchor=S, text="Inventory", tags="shop") # main.canvas_map.create_text(canvas_x_start+(temp_canvas_width*5)/2, # canvas_y_start-1, anchor=S, text=g.shops[store_num].name, tags="shop") global leave_height leave_height = g.buttons["sell.png"].get_width() global buy_height buy_height = leave_height + g.buttons["leave.png"].get_width() #get data in listboxes # refresh_inv() refresh_shop() refresh_buttons() # main.canvas_map.unbind("<Motion>") #main.canvas_map.unbind("<Button-1>") show_details() pygame.display.flip() g.last_joy_times["ud"] = pygame.time.get_ticks() g.last_joy_times["lr"] = pygame.time.get_ticks() while 1: pygame.time.wait(30) g.clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: return elif event.type == pygame.KEYDOWN: if key_handler(event.key) == 1: return elif event.type == pygame.MOUSEMOTION: mouse_move(event.pos) elif event.type == pygame.MOUSEBUTTONDOWN: if mouse_sel_shop(event.pos) == 1: return tmpjoy = g.run_joystick() if tmpjoy != 0: if key_handler(tmpjoy) == 1: return
def begin(mon_index_input): # global window_battle global bgcolour bgcolour = "lightgrey" # window_battle = Frame(g.window_main, bd=4, relief=GROOVE, bg=bgcolour) # window_battle.grid(row=0, column=0) global mon_index mon_index = mon_index_input global monster_list monster_list = [] for line in monster.monster_groups[mon_index].monster_list: monster_list.append( monster.copy_monster( monster.monsters[monster.monster_name_to_index(line)])) for i in range(len(monster_list)): monster_list[i].reset() if g.difficulty == 0: monster_list[i].hp -= monster_list[i].hp / 5 monster_list[i].maxhp -= monster_list[i].maxhp / 5 monster_list[i].attack -= monster_list[i].attack / 5 monster_list[i].defense -= monster_list[i].defense / 5 if g.difficulty == 2: monster_list[i].hp += monster_list[i].hp / 5 monster_list[i].maxhp += monster_list[i].maxhp / 5 monster_list[i].attack += monster_list[i].attack / 5 monster_list[i].defense += monster_list[i].defense / 5 global did_run did_run = 0 global cur_button cur_button = 0 global run_attempts run_attempts = 0 global active_button active_button = -1 # Set the current window g.cur_window = "battle" global canvas_mon_pic global background_pic background_pic = g.maps[g.zgrid].battle_background global monster_pic monster_pic = [] global base_mon_hp_start base_mon_hp_start = [] global base_mon_hp_width base_mon_hp_width = [] global base_mon_hp_y_start base_mon_hp_y_start = [] global monster_slashes monster_slashes = [] global monster_start monster_start = (main.tilesize * main.half_mapx - background_pic.get_width() / 2, main.tilesize * main.half_mapy - background_pic.get_height() / 2) for i in range(len(monster_list)): monster_slashes.append([0, 0, 0]) try: monster_pic.append(g.tiles["monsters/" + monster_list[i].name + ".png"]) except KeyError: monster_pic.append(g.tiles["monsters/generic.png"]) #if x and y positions were given, use them; otherwise, start at the #middle, and go right. This works for 1 or two monsters, but xy #coords are recommended for more. if len(monster.monster_groups[mon_index].x_pos) > i: xstart = monster_start[0] + monster.monster_groups[ mon_index].x_pos[i] else: xstart = monster_start[0] + background_pic.get_width() / 2 + i * 40 ystart = y_start(i) base_mon_hp_start.append(xstart - monster_pic[i].get_width() / 2) base_mon_hp_width.append(monster_pic[i].get_width()) base_mon_hp_height.append(monster_pic[i].get_height()) base_mon_hp_y_start.append(ystart + 5 + monster_pic[i].get_height()) monster_slashes.append([0, 0, 0]) global hero_pic try: hero_pic = g.tiles["people/hero_n" + g.maps[g.zgrid].hero_suffix + ".png"] except KeyError: hero_pic = g.tiles["blank"] global hero_loc hero_loc = (monster_start[0] + (background_pic.get_width() - base_mon_hp_width[0]) / 2, background_pic.get_height() - hero_pic.get_height() * 5 / 2 + monster_start[1]) global attack_button_loc global item_button_loc global skill_button_loc global inspect_button_loc global run_button_loc global final_button_loc global button_y_start global button_height attack_button_loc = main.tilesize * main.half_mapx - \ g.buttons["attack.png"].get_width() - g.buttons["use.png"].get_width() - \ g.buttons["skill.png"].get_width() / 2 item_button_loc = attack_button_loc + g.buttons["attack.png"].get_width() skill_button_loc = item_button_loc + g.buttons["use.png"].get_width() inspect_button_loc = skill_button_loc + g.buttons["skill.png"].get_width() run_button_loc = inspect_button_loc + g.buttons["inspect.png"].get_width() final_button_loc = run_button_loc + g.buttons["quit.png"].get_width() button_y_start = main.tilesize * main.half_mapy + background_pic.get_height( ) / 2 button_height = g.buttons["attack.png"].get_height() g.create_norm_box((attack_button_loc, button_y_start), (final_button_loc - attack_button_loc, button_height)) #bindings bind_keys() main.print_message(monster.monster_groups[mon_index].attack_message) set_description_text(0) refresh() refresh_buttons() while 1: pygame.time.wait(30) g.clock.tick(30) if g.break_one_loop > 0: g.break_one_loop -= 1 break for event in pygame.event.get(): if event.type == pygame.QUIT: g.break_one_loop = 2 elif event.type == pygame.KEYDOWN: if key_handler(event.key) == 1: break elif event.type == pygame.MOUSEMOTION: if (event.pos[1] > button_y_start and event.pos[1] < button_height + button_y_start): mouse_handler_move(event.pos) elif event.type == pygame.MOUSEBUTTONDOWN: mouse_handler_move(event.pos) if key_handler(pygame.K_RETURN) == 1: break tmpjoy = g.run_joystick() if tmpjoy != 0: key_handler(tmpjoy) if g.unclean_screen: pygame.display.flip() if player.hp <= 0: did_run = "end" return did_run
def refresh(): global monster_slashes g.screen.fill( g.colors["black"], (main.tilesize * main.half_mapx - background_pic.get_width() / 2 - 2, main.tilesize * main.half_mapy - background_pic.get_height() / 2 - 2, background_pic.get_width() + 2, background_pic.get_height() + 2)) g.screen.blit( background_pic, (main.tilesize * main.half_mapx - background_pic.get_width() / 2 - 1, main.tilesize * main.half_mapy - background_pic.get_height() / 2 - 1)) #monsters for i in range(len(monster_list)): #if x and y positions were given, use them; otherwise, start at the #middle, and go right. This works for 1 or two monsters, but xy #coords are recommended for more. if len(monster.monster_groups[mon_index].x_pos) > i: xstart = monster_start[0] + monster.monster_groups[ mon_index].x_pos[i] else: xstart = monster_start[0] + background_pic.get_width() / 2 + i * 40 ystart = y_start(i) g.screen.blit(monster_pic[i], (base_mon_hp_start[i], ystart)) # if monster_slashes[i][0] == 1: # g.screen.blit(g.buttons["slash_attack.png"], # (base_mon_hp_start[i]+4, ystart+4)) #Under (red) part of the monster hp display g.create_norm_box((base_mon_hp_start[i], base_mon_hp_y_start[i]), (base_mon_hp_width[i], 5), inner_color="hp_red") #Over (green) part of the monster hp display temp_width = base_mon_hp_width[i] * int(monster_list[i].hp) / \ int(monster_list[i].maxhp) if temp_width < 0: temp_width = 0 g.create_norm_box((base_mon_hp_start[i], base_mon_hp_y_start[i]), (temp_width, 5), inner_color="hp_green") g.print_string(g.screen, str(monster_list[i].hp) + "/" + str(monster_list[i].maxhp), g.font, (xstart, base_mon_hp_y_start[i] + 6), align=1) #refresh the player g.screen.blit(hero_pic, hero_loc) # if monster_slashes[-1][0] == 1: # g.screen.blit(g.buttons["slash_attack.png"], (hero_loc[0]+4,hero_loc[1]+4)) #Under (red) part of the player hp display g.create_norm_box((monster_start[0] + (background_pic.get_width() - base_mon_hp_width[0]) / 2, monster_start[1] + background_pic.get_height() - hero_pic.get_height() * 3 / 2 - 2), (base_mon_hp_width[0], 5), inner_color="hp_red") #Over (green) part of the player hp display temp_width = base_mon_hp_width[0] * int(player.hp) / \ int(player.adj_maxhp) if temp_width < 0: temp_width = 0 g.create_norm_box((monster_start[0] + (background_pic.get_width() - base_mon_hp_width[0]) / 2, monster_start[1] + background_pic.get_height() - hero_pic.get_height() * 3 / 2 - 2), (temp_width, 5), inner_color="hp_green") g.print_string( g.screen, str(player.hp) + "/" + str(player.adj_maxhp), g.font, (monster_start[0] + background_pic.get_width() / 2, monster_start[1] + background_pic.get_height() - hero_pic.get_height() * 3 / 2 + 4), align=1) #refresh the player ep bar #Under (red) part of the player ep display g.create_norm_box((monster_start[0] + (background_pic.get_width() - base_mon_hp_width[0]) / 2, monster_start[1] + background_pic.get_height() - hero_pic.get_height()), (base_mon_hp_width[0], 5), inner_color="hp_red") #Over (green) part of the player ep display temp_width = base_mon_hp_width[0] * int(player.ep) / int(player.adj_maxep) if temp_width < 0: temp_width = 0 g.create_norm_box((monster_start[0] + (background_pic.get_width() - base_mon_hp_width[0]) / 2, monster_start[1] + background_pic.get_height() - hero_pic.get_height()), (temp_width, 5), inner_color="ep_blue") g.print_string( g.screen, str(player.ep) + "/" + str(player.adj_maxep), g.font, (monster_start[0] + background_pic.get_width() / 2, monster_start[1] + background_pic.get_height() - hero_pic.get_height() + 7), align=1) #slashes tmp_surface = pygame.Surface((32, 64)) for i in range(len(monster_list)): if monster_slashes[i][0] == 1: monster_slashes[i][0] = 0 ystart = y_start(i) tmp_surface.blit(g.screen, (0, 0), (base_mon_hp_start[i], ystart - 32, 32, 64)) for j in range(13): g.screen.blit(tmp_surface, (base_mon_hp_start[i], ystart - 32)) g.screen.blit(g.buttons["slash_attack.png"], (base_mon_hp_start[i] + j, ystart + j)) pygame.display.flip() g.screen.blit(tmp_surface, (base_mon_hp_start[i], ystart - 32)) pygame.display.flip() if monster_slashes[-1][0] == 1: monster_slashes[-1][0] = 0 tmp_surface.blit(g.screen, (0, 0), (hero_loc[0], hero_loc[1] - 32, 32, 64)) for j in range(13): g.screen.blit(tmp_surface, (hero_loc[0], hero_loc[1] - 32)) g.screen.blit(g.buttons["slash_attack.png"], (hero_loc[0] + j, hero_loc[1] + j)) pygame.display.flip() g.screen.blit(tmp_surface, (hero_loc[0], hero_loc[1] - 32)) pygame.display.flip() #Draw the monster selection arrow if needed. # main.canvas_map.delete("monster_arrow") global active_button if active_button != -1: g.screen.blit(g.buttons["sword_pointer.png"], (base_mon_hp_start[active_button], base_mon_hp_y_start[active_button] - 20)) # main.canvas_map.create_image( # base_mon_hp_start[active_button], # base_mon_hp_y_start[active_button]-20, # anchor=N, image=g.buttons["sword_pointer.png"], # tags=("monster_arrow", "battle")) main.refresh_bars()
def refresh_equip(): refresh_inv_display("equip") #rebuild the equipment display temp_canvas_width = (g.tilesize * equip_size) + 8 tmpx = tmp_x_base - temp_canvas_width tmpy = tmp_y_base for i in range(9): g.create_norm_box( (tmpx + (i % equip_size) * g.tilesize + 2 * ((i % equip_size) + 1), tmpy + (i / equip_size) * g.tilesize + 2 * ((i / equip_size) + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") #Draw selection rectangle for equipment display if (curr_item != -1 and curr_item >= inv_width * inv_height): c_item = curr_item - inv_width * inv_height g.create_norm_box((tmpx + (c_item % equip_size) * g.tilesize + 2 * ((c_item % equip_size) + 1), tmpy + (c_item / equip_size) * g.tilesize + 2 * ((c_item / equip_size) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green") #Weapon if player.equip[0] != -1: draw_item(item.item[player.equip[0]].picturename, 0, 1, tmpx, tmpy, "equip") else: draw_item("items/weapon_eq.png", 0, 1, tmpx, tmpy, "equip") #Armor if player.equip[1] != -1: draw_item(item.item[player.equip[1]].picturename, 1, 1, tmpx, tmpy, "equip") else: draw_item("items/armor_eq.png", 1, 1, tmpx, tmpy, "equip") #Shield if player.equip[2] != -1: draw_item(item.item[player.equip[2]].picturename, 2, 1, tmpx, tmpy, "equip") else: draw_item("items/shield_eq.png", 2, 1, tmpx, tmpy, "equip") #Helmet if player.equip[3] != -1: draw_item(item.item[player.equip[3]].picturename, 1, 0, tmpx, tmpy, "equip") else: draw_item("items/helmet_eq.png", 1, 0, tmpx, tmpy, "equip") #Gloves if player.equip[4] != -1: draw_item(item.item[player.equip[4]].picturename, 2, 0, tmpx, tmpy, "equip") else: draw_item("items/gloves_eq.png", 2, 0, tmpx, tmpy, "equip") #Boots if player.equip[5] != -1: draw_item(item.item[player.equip[5]].picturename, 1, 2, tmpx, tmpy, "equip") else: draw_item("items/boots_eq.png", 1, 2, tmpx, tmpy, "equip") main.refresh_bars() pygame.display.flip()
def init_window_loadgame(): #create the window global prevent_dbl_load prevent_dbl_load = 0 g.create_norm_box((g.tilesize * g.main.mapsizex / 4 - 2, g.tilesize * g.main.mapsizey / 3 - 2), (g.tilesize * g.main.mapsizex / 2 + 2, +140 + g.buttons["load_scr.png"].get_height() + 2)) global did_load did_load = "" #add the saves images g.screen.blit( g.buttons["loadgame_up.png"], (g.tilesize * g.main.mapsizex / 4, g.tilesize * g.main.mapsizey / 3)) g.screen.blit( g.buttons["loadgame_down.png"], (g.tilesize * g.main.mapsizex / 4, g.tilesize * g.main.mapsizey / 3 + 140 - g.buttons["loadgame_down.png"].get_height())) pixels_per_line = 20 #If there is no save directory, make one. if path.isdir(g.mod_directory + "/saves") == 0: if path.exists(g.mod_directory + "/saves") == 1: remove(g.mod_directory + "/saves") mkdir(g.mod_directory + "/saves") #show the files contained in the saves directory. global saves_array saves_array = [] tmp_saves_array = listdir(g.mod_directory + "/saves") for save_name in tmp_saves_array: if save_name[:1] != "." and save_name != "CVS": saves_array.append(save_name) global saves_pos saves_pos = 0 refresh_buttons() refresh_save_info() global repeat_key repeat_key = 0 global key_down key_down = "" while 1: pygame.time.wait(30) g.clock.tick(30) if g.break_one_loop > 0: g.break_one_loop -= 1 break for event in pygame.event.get(): if event.type == pygame.QUIT: return elif event.type == pygame.KEYDOWN: key_handler(event.key) repeat_key = 0 elif event.type == pygame.KEYUP: key_handler_up(event.key) elif event.type == pygame.MOUSEMOTION: mouse_handler_move(event.pos) elif event.type == pygame.MOUSEBUTTONDOWN: if mouse_handler_down(event.pos) == 1: return tmpjoy = g.run_joystick() if tmpjoy != 0: if tmpjoy != g.bindings["left"] and tmpjoy != g.bindings["right"]: global cur_button if cur_button != 0: cur_button = 0 refresh_buttons() key_handler(tmpjoy) if g.unclean_screen: pygame.display.flip() return did_load
def refresh_stat_display(): start_x = (g.tilesize * main.mapsizex) / 2 start_y = (g.tilesize * main.mapsizey - total_height) / 2 #hp/ep bars # main.canvas_map.delete("stats") #Create the hp/ep background bars bar_height = 15 bar_start = start_y + 21 g.create_norm_box((start_x + 5, bar_start - 1), (g.hpbar_width, bar_height), inner_color="hp_red") g.create_norm_box((start_x + 5, bar_start + bar_height + 1), (g.hpbar_width, bar_height), inner_color="hp_red") temp_width = g.hpbar_width * player.hp / player.adj_maxhp if temp_width < 0: temp_width = 0 bar_height = 15 bar_start = start_y + 21 g.create_norm_box((start_x + 5, bar_start - 1), (temp_width, bar_height), inner_color="hp_green") # main.canvas_map.create_rectangle(start_x+5, bar_start-1, start_x+temp_width+5, # bar_start+bar_height-1, fill="#05BB05", tags=("stats", "inv")) # main.canvas_map.delete("show_ep") temp_width = g.hpbar_width * player.ep / player.adj_maxep if temp_width < 0: temp_width = 0 g.create_norm_box((start_x + 5, bar_start + bar_height + 1), (temp_width, bar_height), inner_color="ep_blue") # main.canvas_map.create_rectangle(start_x+5, bar_start+bar_height+1, start_x+temp_width+5, # bar_start+bar_height*2+1, fill="#2525EE", tags=("stats", "inv")) # main.canvas_map.lift("bar") tmp_width = 52 g.screen.fill( g.colors["light_gray"], (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 5, 50, 14)) g.print_string(g.screen, player.name, g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 5)) g.print_string(g.screen, str(player.hp) + "/" + str(player.adj_maxhp), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 22)) g.print_string(g.screen, str(player.ep) + "/" + str(player.adj_maxep), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 39)) g.screen.fill( g.colors["light_gray"], (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 55, 50, 80)) g.print_string(g.screen, str(player.adj_attack), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 55)) g.print_string(g.screen, str(player.adj_defense), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 70)) g.print_string(g.screen, str(player.gold), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 85)) g.print_string(g.screen, str(player.level), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 100)) tmp = str(player.exp_till_level()) if tmp == "9999": g.print_string(g.screen, str(player.exp) + "/----", g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 115)) else: g.print_string( g.screen, str(player.exp) + "/" + str(player.exp_till_level() + player.exp), g.font, (start_x + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2 + 115)) main.refresh_bars() main.refresh_inv_icon() pygame.display.flip()
def refresh_window(): #create the window x_start = g.tilesize * g.main.mapsizex / 2 - 90 y_start = g.tilesize * g.main.mapsizey / 2 - 80 x_width = 180 g.create_norm_box((x_start, y_start), (x_width, 212)) #fullscreen fullscreen_img = "check.png" if tmp_fullscreen == 1: fullscreen_img = "check_sel.png" in_color = "light_gray" if curr_button == 0: in_color = "dh_green" g.create_norm_box((x_start + 2, y_start + 2), (x_width - 4, 23), inner_color=in_color) g.screen.blit(g.buttons[fullscreen_img], (x_start + 7, y_start + 3)) g.print_string(g.screen, "Fullscreen", g.font, (x_start + 27, y_start + 10)) #difficulty if tmp_difficulty == 0: diff_string = "Difficulty: Easy" elif tmp_difficulty == 1: diff_string = "Difficulty: Normal" else: diff_string = "Difficulty: Hard" focused = False if curr_button == 1: focused = True box_with_text((x_start, y_start + 25), diff_string, focused) #custom keyboard focused = False if curr_button == 2: focused = True box_with_text((x_start, y_start + 50), "Customize Keyboard", focused) #use joystick joystick_img = "check_sel.png" if tmp_joystick == 0: joystick_img = "check.png" in_color = "light_gray" if curr_button == 3: in_color = "dh_green" g.create_norm_box((x_start + 2, y_start + 77), (x_width - 4, 23), inner_color=in_color) g.screen.blit(g.buttons[joystick_img], (x_start + 7, y_start + 78)) g.print_string(g.screen, "Use Joystick", g.font, (x_start + 27, y_start + 85)) #custom joystick focused = False if curr_button == 4: focused = True box_with_text((x_start, y_start + 100), "Customize Joystick", focused) #save setttings focused = False if curr_button == 5: focused = True box_with_text((x_start, y_start + 135), "Apply and Save Settings", focused) #reset setttings focused = False if curr_button == 6: focused = True box_with_text((x_start, y_start + 160), "Reset Settings", focused) #leave focused = False if curr_button == 7: focused = True box_with_text((x_start, y_start + 185), "Cancel (Don't Save)", focused) pygame.display.flip()
def refresh_shop(): # main.canvas_map.delete("item") invpos = 0 # main.canvas_map.create_rectangle( # canvas_x_start+temp_canvas_width*2+(curr_item%shop_width)*g.tilesize + 2 * # ((curr_item%shop_width)+1), # canvas_y_start+(curr_item/shop_width)*g.tilesize + 2 * # ((curr_item/shop_width)+1), # canvas_x_start+temp_canvas_width*2+((curr_item%shop_width)+1)*(g.tilesize + 2), # canvas_y_start+((curr_item/shop_width)+1)*(g.tilesize + 2), # fill=g.fill_sel_colour, tags=("item", "shop")) #per-item borders for y in range(shop_height): for x in range(shop_width): g.create_norm_box( (canvas_x_start + x * g.tilesize + 2 * (x + 1), canvas_y_start + y * g.tilesize + 2 * (y + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") for y in range(shop_height): for x in range(shop_width): g.create_norm_box( (temp_canvas_width * 2 + canvas_x_start + x * g.tilesize + 2 * (x + 1), canvas_y_start + y * g.tilesize + 2 * (y + 1)), (g.tilesize, g.tilesize), inner_color="dh_green") #if the shop is selected, draw a selection box around the current item. if curr_focus == 1: g.create_norm_box(((canvas_x_start + temp_canvas_width * 2 + (curr_item % shop_width) * g.tilesize + 2 * ((curr_item % shop_width) + 1)), canvas_y_start + (curr_item / shop_width) * g.tilesize + 2 * ((curr_item / shop_width) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green") #draw the item pictures. for i in range(len(g.shops[store_num].itemlist)): if i != -1: g.screen.blit(g.tiles[g.shops[store_num].itemlist[i].picture], (canvas_x_start + temp_canvas_width * 2 + (invpos % shop_width) * g.tilesize + 2 * ((invpos % shop_width) + 1), canvas_y_start + (invpos / shop_width) * g.tilesize + 2 * ((invpos / shop_width) + 1))) # main.canvas_map.create_image( # canvas_x_start+temp_canvas_width*2+(invpos%shop_width)*g.tilesize + 2 * # ((invpos%shop_width)+1), # canvas_y_start+(invpos/shop_width)*g.tilesize + 2 * ((invpos/shop_width)+1), # image=g.tiles[g.shops[store_num].itemlist[i].picture], # anchor="nw", tags=("item", "shop")) invpos += 1 invpos = 0 #if the inv is selected, draw a selection box around the current item. if curr_focus == 0: g.create_norm_box( (canvas_x_start + (curr_item % shop_width) * g.tilesize + 2 * ((curr_item % shop_width) + 1), canvas_y_start + (curr_item / shop_width) * g.tilesize + 2 * ((curr_item / shop_width) + 1)), (g.tilesize, g.tilesize), inner_color="dark_green") # main.canvas_map.create_rectangle( # canvas_x_start+(curr_item%shop_width)*g.tilesize + # 2 * ((curr_item%shop_width)+1), # canvas_y_start+(curr_item/shop_width)*g.tilesize + # 2 * ((curr_item/shop_width)+1), # canvas_x_start+((curr_item%shop_width)+1)*(g.tilesize + 2), # canvas_y_start+((curr_item/shop_width)+1)*(g.tilesize + 2), # fill=g.fill_sel_colour, tags=("item", "shop")) #draw the item pictures. for i in range(len(item.inv)): if item.inv[i] != -1: g.screen.blit( g.tiles[item.item[item.inv[i]].picturename], (canvas_x_start + (i % shop_width) * g.tilesize + 2 * ((i % shop_width) + 1), canvas_y_start + (i / shop_width) * g.tilesize + 2 * ((i / shop_width) + 1))) # main.canvas_map.create_image(canvas_x_start+(i%shop_width)*g.tilesize + 2 * # ((i%shop_width)+1), # canvas_y_start+(i/shop_width)*g.tilesize + 2 * ((i/shop_width)+1), # image=g.tiles[item.item[item.inv[i]].picturename], # anchor="nw", tags=("item", "shop")) invpos += 1 #set gold and skillpoints g.screen.fill(g.colors["light_gray"], (canvas_x_start + temp_canvas_width + 5, canvas_y_start + temp_canvas_height - 26, 120, 25)) g.print_string(g.screen, g.gold_name + ": " + str(player.gold), g.font, (canvas_x_start + temp_canvas_width + 5, canvas_y_start + temp_canvas_height - 26)) g.print_string(g.screen, g.skill_name + ": " + str(player.skillpoints), g.font, (canvas_x_start + temp_canvas_width + 5, canvas_y_start + temp_canvas_height - 11)) # main.canvas_map.create_text(canvas_x_start+temp_canvas_width+5, # canvas_y_start+temp_canvas_height-20, anchor=SW, # text=g.gold_name+": "+str(player.gold), tags=("item", "shop")) # main.canvas_map.create_text(canvas_x_start+temp_canvas_width+5, # canvas_y_start+temp_canvas_height-2, anchor=SW, # text=g.skill_name+": "+str(player.skillpoints), tags=("item", "shop")) # curr_gold.set("Gold: " + str(player.gold)) # curr_skill.set("Skillpoints: " + str(player.skillpoints)) main.refresh_inv_icon() main.refresh_bars()
def init_window_inv(): # main.canvas_map.delete("inv") global cur_button cur_button = 0 global oldbutton oldbutton = 99 #Location of the various buttons. global equip_height equip_height = g.buttons["use.png"].get_height() global drop_height drop_height = equip_height + g.buttons["equip.png"].get_height() global skill_height skill_height = drop_height + g.buttons["skill.png"].get_height() global save_height save_height = skill_height + g.buttons["drop.png"].get_height() global leave_height leave_height = save_height + g.buttons["save.png"].get_height() global total_height total_height = leave_height + g.buttons["leave.png"].get_height() global button_width button_width = g.buttons["drop.png"].get_width() global base_x base_x = (g.tilesize * main.mapsizex) / 2 - button_width global base_y base_y = (g.tilesize * main.mapsizey - total_height) / 2 global inv_canvas_width global inv_canvas_height inv_canvas_width = (g.tilesize * inv_width) + ((inv_width + 1) * 2) + 1 inv_canvas_height = (g.tilesize * inv_height) + ((inv_height + 1) * 2) + 1 start_x = (g.tilesize * main.mapsizex) / 2 start_y = (g.tilesize * main.mapsizey - total_height) / 2 #Create the main inv box. #The +20 is just "wiggle room", to prevent the length of the name #affecting the dimensions. g.create_norm_box( (base_x, base_y), ((g.tilesize * main.mapsizex) / 2 + g.hpbar_width + 15 - base_x, (g.tilesize * main.mapsizey + total_height) / 2 - base_y)) global curr_item curr_item = 0 #Set current window to inventory g.cur_window = "inventory" temp_width = g.hpbar_width * player.ep / player.adj_maxep if temp_width < 0: temp_width = 0 #Create the labels to the right: tmp_width = 52 label_start = ((g.tilesize * main.mapsizex) / 2 + tmp_width, (g.tilesize * main.mapsizey - total_height) / 2) text = g.name_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 5), align=2) text = g.hp_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 22), align=2) text = g.ep_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 39), align=2) text = g.attack_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 55), align=2) text = g.defense_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 70), align=2) text = g.gold_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 85), align=2) text = g.level_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 100), align=2) text = g.exp_name + ":" g.print_string(g.screen, text, g.font, (label_start[0], label_start[1] + 115), align=2) #bindings menu_bind_keys() refresh_menu_buttons() refresh_stat_display() while 1: pygame.time.wait(30) g.clock.tick(30) for event in pygame.event.get(): if event.type == pygame.QUIT: return elif event.type == pygame.KEYDOWN: if menu_key_handler(event.key) == 1: return elif event.type == pygame.MOUSEMOTION: menu_mouse_move(event.pos) elif event.type == pygame.MOUSEBUTTONDOWN: if menu_mouse_click(event.pos) == 1: return tmpjoy = g.run_joystick() if tmpjoy != 0: if tmpjoy != g.bindings["left"] and tmpjoy != g.bindings["right"]: if menu_key_handler(tmpjoy) == 1: return