def attack(event=0): global active_button if can_leave() == 1: return 0 if active_button == -1: last_mon_num = select_monster() else: last_mon_num = active_button if last_mon_num == -1: return 0 global cur_button cur_button = 0 clear_slashes() #Both hp's *should* be over 0. Just a precaution. if monster_list[last_mon_num].hp > 0 and player.hp > 0: attack_monster(last_mon_num, player.adj_attack) global used_gem global num_dice if used_gem == 1: player.adj_attack = old_attack main.refresh_bars() num_dice = 1 used_gem = 0 attack_player() if can_leave() == 0: active_button = -1 monster_mouse_move((0, 0)) refresh() refresh_buttons()
def useskill(free_skill=0): #sanity checks skill_index = curr_item if skill_index >= len(player.skill): return 0 if free_skill == 0: if player.skill[skill_index][5] == 0: return 0 if player.skill[skill_index][2] > player.ep: return 0 if player.skill[skill_index][1] == 5 or \ player.skill[skill_index][1] == 6: #Scripted tempxy = (g.xgrid, g.ygrid, g.zgrid) #If the scripting ends with an "end" command, if action.activate_lines(g.xgrid, g.ygrid, g.zgrid, player.skill[skill_index][6]) == 1: if free_skill == 0: #pay for the skill player.give_stat("ep", -1 * player.skill[skill_index][2]) main.refresh_bars() refresh_stat_display() if tempxy != (g.xgrid, g.ygrid, g.zgrid): return "end" return 1
def useskill(skill_index, free_skill=0): global active_button #don't do anything if monster is dead. if can_leave() == 1: return 0 clear_slashes() #sanity checks if skill_index >= len(player.skill): return 0 if free_skill == 0: if player.skill[skill_index][5] == 0: return 0 if player.skill[skill_index][2] > player.ep: return 0 if player.skill[skill_index][1] == 5: return 0 #actually use the skill. if player.skill[skill_index][1] == 0: #rage if free_skill == 0: #pay for the skill player.give_stat("ep", -1 * player.skill[skill_index][2]) main.print_message("You fly into a rage.") #increase attack ability player.give_stat("adj_attack", (1 + int(player.level) / 4)) main.refresh_bars() main.refresh_inv_icon() attack_player() elif player.skill[skill_index][1] == 1: #Sneak away if free_skill == 0: #pay for the skill player.give_stat("ep", -1 * player.skill[skill_index][2]) global run_attempts if g.die_roll(1, 10 + int(player.level) + run_attempts) > 4: runaway(True) global did_run did_run = 1 else: run_attempts += 3 main.print_message("You fail to sneak away.") attack_player() elif player.skill[skill_index][1] == 2: #Frenzy if free_skill == 0: #pay for the skill player.give_stat("ep", -1 * player.skill[skill_index][2]) mon_num = select_monster() for i in range(2 + int(player.level) / 4): if monster_list[mon_num].hp < 1: mon_num = select_monster() if mon_num == -1: return 0 attack_monster(mon_num, player.adj_attack) if can_leave() == 1: break active_button = -1 monster_mouse_move((0, 0)) refresh() if can_leave() == 0: attack_player() elif player.skill[skill_index][1] == 3: #Dismember if free_skill == 0: #pay for the skill player.give_stat("ep", -1 * player.skill[skill_index][2]) mon_num = select_monster() if mon_num == -1: return 0 damage = (player.adj_attack) monster_hurt(mon_num, damage) if can_leave() == 0: attack_player() elif player.skill[skill_index][1] == 4 or \ player.skill[skill_index][1] == 6: #Scripted #If the scripting ends with an "end" command, if action.activate_lines(g.xgrid, g.ygrid, g.zgrid, player.skill[skill_index][6]) == 1: if free_skill == 0: #pay for the skill player.give_stat("ep", -1 * player.skill[skill_index][2]) if can_leave() == 0: attack_player() main.refresh_bars() if can_leave() == 1: inv.leave_inner() return 0 active_button = -1 monster_mouse_move((0, 0)) refresh() #replace the cursor if free_skill == 0: inv.leave_inner() refresh_buttons()
def useitem(item_index, leave_item=0): global active_button #don't do anything if battle is over. if can_leave() == 1 or item_index == -1: return 0 clear_slashes() item_value = item_index item_type = g.item.item[item_value].type #if item is healing if item_type == 11: #heal the player, delete the item player.give_stat("hp", g.item.item[item_value].quality) main.print_message("You are healed for " + str(g.item.item[item_value].quality) + " " + g.hp_name + ".") if leave_item == 0: g.item.drop_inv_item(g.item.find_inv_item(item_value)) attack_player() #if item is a gem if item_type == 14: global old_attack old_attack = player.adj_attack gem_power = g.item.item[item_value].quality #gem power increases attack strength potential player.give_stat("adj_attack", gem_power * 0.75) #gem power increases num_dice (ie. chance to hit and total damage) global num_dice num_dice = num_dice + gem_power / 4 main.print_message("The " + g.item.item[item_value].name + " focuses the power of your " + g.attack_name.lower() + ".") main.refresh_bars() if leave_item == 0: g.item.drop_inv_item(g.item.find_inv_item(item_value)) global used_gem used_gem = 1 if leave_item == 0: attack() #if item is explosive if item_type == 12: sel_mon = select_monster() if sel_mon == -1: return 0 #if monster is still alive if monster_list[sel_mon].hp > 0: damage = int(g.item.item[item_value].quality) if leave_item == 0: g.item.drop_inv_item(g.item.find_inv_item(item_value)) monster_hurt(sel_mon, damage) if can_leave() == 0 and leave_item == 0: attack_player() active_button = -1 #If item is scripted: if item_type == 15 or item_type == 17: #If the scripting ends with an "end" command, if action.activate_lines(g.xgrid, g.ygrid, g.zgrid, g.item.item[item_value].scripting) == 1: if leave_item == 0: g.item.drop_inv_item(g.item.find_inv_item(item_value)) if can_leave() == 0 and leave_item == 0: attack_player() active_button = -1 #If item is equippable: if item_type < 6: #trade the item and whatever's in the equip slot temp = player.equip[item_type] player.equip[item_type] = item_index g.item.drop_inv_item(g.item.find_inv_item(item_index)) g.item.take_inv_item(temp) main.print_message("You equip yourself with your " + g.item.item[player.equip[item_type]].name + ".") player.reset_stats() if can_leave() == 0 and leave_item == 0: attack_player() if can_leave() == 1: inv.leave_inner() return 0 refresh() #back to battle if leave_item == 0: inv.leave_inner() refresh_buttons()
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_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 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_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()