def __init__(self): self.data_list = [] # 当前在执行的事件列表 self.auto = False # 自动执行中 self.wait_key = None # 等待驱动的关键按钮 self.PlayerCon = global_var.get_value("PlayerCon") self.CurrentMap = global_var.get_value("CurrentMap") self.TEXTBOX = global_var.get_value("TEXTBOX") self.supported_events = { "if": "self.EVENT.if_cond(event)", "setValue": "self.EVENT.set_value(event)", "addValue": "self.EVENT.set_value(event)", "openShop": "self.EVENT.open_shop(event)", "openDoor": "self.EVENT.open_door(event)", "playSound": "self.EVENT.play_sound(event)", "sleep": "self.EVENT.sleep(event)", "callSave": "self.EVENT.call_save(event)", "choices": "self.EVENT.choices(event)", "confirm": "self.EVENT.confirm(event)", "function": "self.EVENT.function(event)", "win": "self.EVENT.win(event)", "battle": "self.EVENT.battle(event)", "restart": "self.EVENT.restart(event)", "loadBgm": "self.EVENT.load_bgm(event)", "playBgm": "self.EVENT.play_bgm(event)" }
def jumpShoes(): Music = global_var.get_value("Music") PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") x_coord = PlayerCon.pos[0] y_coord = PlayerCon.pos[1] if PlayerCon.face[0] == 0 and y_coord + 2 < int(HEIGHT / BLOCK_UNIT): y_coord += 2 if CurrentMap.get_block(x_coord, y_coord) == 0: Music.play_SE("jump.ogg") PlayerCon.pos[1] += 2 PlayerCon.change_hero_loc(PlayerCon.pos[0], PlayerCon.pos[1]) return {"result": True} elif PlayerCon.face[0] == 1 and x_coord - 2 >= 0: x_coord -= 2 if CurrentMap.get_block(x_coord, y_coord) == 0: Music.play_SE("jump.ogg") PlayerCon.pos[0] -= 2 PlayerCon.change_hero_loc(PlayerCon.pos[0], PlayerCon.pos[1]) return {"result": True} elif PlayerCon.face[0] == 2 and x_coord + 2 < int(WIDTH / BLOCK_UNIT): x_coord += 2 if CurrentMap.get_block(x_coord, y_coord) == 0: Music.play_SE("jump.ogg") PlayerCon.pos[0] += 2 PlayerCon.change_hero_loc(PlayerCon.pos[0], PlayerCon.pos[1]) return {"result": True} elif PlayerCon.face[0] == 3 and y_coord - 2 >= 0: y_coord -= 2 if CurrentMap.get_block(x_coord, y_coord) == 0: Music.play_SE("jump.ogg") PlayerCon.pos[1] -= 2 PlayerCon.change_hero_loc(PlayerCon.pos[0], PlayerCon.pos[1]) return {"result": True} return {"result": False, "msg": "落点有障碍物!"}
def change_floor(self, block, floor=None, loc=None): # 刷新显伤 self.CurrentMap.show_damage_update = True # 使用楼层传送器,直接递归调用change_floor if block == "fly": if floor >= self.PlayerCon.floor: self.change_floor(87, floor=floor) elif floor < self.PlayerCon.floor: self.change_floor(88, floor=floor) return True MAP_DATABASE = global_var.get_value("MAP_DATABASE") floor_index = global_var.get_value("floor_index") self.Music.play_SE("floor.ogg") # 上楼处理 if block == 87: if floor is not None: self.PlayerCon.floor = floor else: self.PlayerCon.floor += 1 self.CurrentMap.set_map(self.PlayerCon.floor) check_map_result = self.CurrentMap.check_block(88) self.WriteLog.debug(__name__, f"目标楼层楼梯位置:{check_map_result}") if len(check_map_result) == 1: x_coordinate = check_map_result[0][0] y_coordinate = check_map_result[0][1] self.PlayerCon.change_hero_loc(x_coordinate, y_coordinate) # 下楼处理 elif block == 88: if floor is not None: self.PlayerCon.floor = floor else: self.PlayerCon.floor -= 1 self.CurrentMap.set_map(self.PlayerCon.floor) check_map_result = self.CurrentMap.check_block(87) self.WriteLog.debug(__name__, f"目标楼层楼梯位置:{check_map_result}") if len(check_map_result) == 1: x_coordinate = check_map_result[0][0] y_coordinate = check_map_result[0][1] self.PlayerCon.change_hero_loc(x_coordinate, y_coordinate) # 事件调用(不通过楼梯触发) else: if floor != None: self.PlayerCon.floor = floor self.CurrentMap.set_map(self.PlayerCon.floor) if loc != None: self.PlayerCon.change_hero_loc(loc[0], loc[1]) # 切换BGM self.Music.change_BGM(self.PlayerCon.floor) # 检查玩家是否去过目标楼层 if self.CurrentMap.floor_index["index"][ self.PlayerCon.floor] not in self.PlayerCon.visited: self.PlayerCon.visited.append( self.CurrentMap.floor_index["index"][self.PlayerCon.floor]) self.flush_status()
def hammer(): PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") x_coord = PlayerCon.pos[0] y_coord = PlayerCon.pos[1] if PlayerCon.face[0] == 0 and y_coord + 1 < int(HEIGHT / BLOCK_UNIT): y_coord += 1 if CurrentMap.get_block(x_coord, y_coord) > 200: CurrentMap.remove_block(x_coord, y_coord) return {"result": True} elif PlayerCon.face[0] == 1 and x_coord - 1 >= 0: x_coord -= 1 if CurrentMap.get_block(x_coord, y_coord) > 200: CurrentMap.remove_block(x_coord, y_coord) return {"result": True} elif PlayerCon.face[0] == 2 and x_coord + 1 < int(WIDTH / BLOCK_UNIT): x_coord += 1 if CurrentMap.get_block(x_coord, y_coord) > 200: CurrentMap.remove_block(x_coord, y_coord) return {"result": True} elif PlayerCon.face[0] == 3 and y_coord - 1 >= 0: y_coord -= 1 if CurrentMap.get_block(x_coord, y_coord) > 200: CurrentMap.remove_block(x_coord, y_coord) return {"result": True} return {"result": False, "msg": "玩家面对的不是怪物!"}
def __init__(self, **kwargs): UIComponent.__init__(self, **kwargs) self.name = "显伤层" self.showing = False self.damage_cache = None self.key_map = {pygame.K_p: 'open'} self.PlayerCon = global_var.get_value("PlayerCon") self.CurrentMap = global_var.get_value("CurrentMap")
def update(self, *args): EVENTFLOW = global_var.get_value("EVENTFLOW") while len(EVENTFLOW.data_list ) > 0 and not self.lock and not EVENTFLOW.wait_finish: EVENTFLOW.do_event() self.speedx = 0 self.speedy = 0 keystate = pygame.key.get_pressed() key_map = { pygame.K_LEFT: [-1, 0], pygame.K_RIGHT: [1, 0], pygame.K_UP: [0, -1], pygame.K_DOWN: [0, 1], pygame.K_z: "change_face", pygame.K_a: "load_auto", pygame.K_b: "text_demo" } # text_demo暂时跟B键绑定在一起,方便测试文本框 if not self.moving and not self.lock: for k in key_map: op = key_map[k] # 一次只响应一个按键,由self.key_pressed控制 if keystate[k] and not self.key_pressed: self.key_pressed = True if type(op) is list: if not self.proc_block( CurrentMap.get_block(self.pos[0] + op[0], self.pos[1] + op[1]), self.pos[0] + op[0], self.pos[1] + op[1]): self.change_face(*op) else: x = op[0] + self.pos[0] y = op[1] + self.pos[1] def temp_fun(): self.pos = [x, y] self.move(CurrentMap.trans_locate(x, y, "down"), callback=temp_fun) elif type(op) is str: if op == "change_face": # face[0]调用勇士朝向 0=下,1=左,2=右,3=上 face = self.get_face() face_map = {0: 1, 1: 3, 3: 2, 2: 0} self.face[0] = face_map[face] pygame.time.wait(self.animate_speed) # 文本框测试(B键触发) elif op == "text_demo": TEXTBOX = global_var.get_value("TEXTBOX") TEXTBOX.show( "欢迎来到python魔塔样板v0.9\n1. 本窗口使用TextBox包装,内部调用使用TextWin,字体默认36号,字数自适应。\n2. 实现更多窗口使用WinBase,目前只能做文字显示,后续补充选择光标和图像以及计算式\n3. 事件触发可以考虑用列表\n4. 文本解析也许比较费时?可以考虑先解析\n5. 更多乱七八糟的功能还在开发中。。。。。。\n目前写得乱七八糟,因为目标是先能用再说,以后肯定需要重构下的。\nby Azure(蓝皮鼠) & dljgs1(君浪)\n以下是测试内容:\n目前实现了文本框的自适应。\n当前设定的最大行数为10。\n可以看到,当文字行数超过10之后,文本框会自动截断,按回车键之后继续展示。\n如果需要展示的文字数量特别多,TextBox能够将文本每十行截断一次,并且文本框高度为自适应!\n那么接下来要演示的就是最后的自适应部分。\n由于画布在创建后无法随意调整大小,因此这里的技术原理就是获取剩下需要展示的文字list,然后计算出需要的文本框高度,最后创建一个新的对象用于覆盖旧的对象,这样就可以重新设定画布的大小。" ) elif op == "load_auto": self.FUNCTION.load() pygame.time.wait(250) self.key_pressed = False super().update(*args)
def downFly(): PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") if PlayerCon.floor - 1 < 0: return {"result": False, "msg": "玩家已经在最低层"} elif CurrentMap.get_block(PlayerCon.pos[0], PlayerCon.pos[1], floor=PlayerCon.floor - 1) == 0: PlayerCon.floor -= 1 CurrentMap.set_map(PlayerCon.floor) return {"result": True} else: return {"result": False, "msg": "落点有障碍物!"}
def upFly(): PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") if PlayerCon.floor + 1 > len(CurrentMap.floor_index["index"]): return {"result": False, "msg": "玩家已经在最高层"} elif CurrentMap.get_block(PlayerCon.pos[0], PlayerCon.pos[1], floor=PlayerCon.floor + 1) == 0: PlayerCon.floor += 1 CurrentMap.set_map(PlayerCon.floor) return {"result": True} else: return {"result": False, "msg": "落点有障碍物!"}
def draw_status_bar(self, StatusBar=None): if StatusBar == None: self.StatusBar = global_var.get_value("StatusBar") if 21 in self.PlayerCon.item: yellowkey = self.PlayerCon.item[21] else: yellowkey = 0 if 22 in self.PlayerCon.item: bluekey = self.PlayerCon.item[22] else: bluekey = 0 if 23 in self.PlayerCon.item: redkey = self.PlayerCon.item[23] else: redkey = 0 self.StatusBar.fill(SKYBLUE) self.StatusBar.draw_text("FLOOR = " + str(self.PlayerCon.floor), 36, BLACK, 0, 0) self.StatusBar.draw_text("HP = " + str(self.PlayerCon.hp), 36, BLACK, 0, 1) self.StatusBar.draw_text("ATK = " + str(self.PlayerCon.attack), 36, BLACK, 0, 2) self.StatusBar.draw_text("DEF = " + str(self.PlayerCon.defend), 36, BLACK, 0, 3) self.StatusBar.draw_text("MDEF = " + str(self.PlayerCon.mdefend), 36, BLACK, 0, 4) self.StatusBar.draw_text("GOLD = " + str(self.PlayerCon.gold), 36, BLACK, 0, 5) self.StatusBar.draw_text("EXP = " + str(self.PlayerCon.exp), 36, BLACK, 0, 6) self.StatusBar.draw_text("Y_KEY = " + str(yellowkey), 36, BLACK, 0, 7) self.StatusBar.draw_text("B_KEY = " + str(bluekey), 36, BLACK, 0, 8) self.StatusBar.draw_text("R_KEY = " + str(redkey), 36, BLACK, 0, 9)
def draw(self, current_index=0, map_index=None): if map_index is None: map_index = self.PlayerCon.floor # UI背景和左侧状态栏 self.fill(SKYBLUE) self.FUNCTION.draw_status_bar() # 获得当前地图中全部的怪物的信息 CurrentMap = global_var.get_value("CurrentMap") enemy_info_list = self.FUNCTION.get_current_enemy(CurrentMap.get_map(self.PlayerCon.floor)) # 如果当前楼层没有怪物 if len(enemy_info_list) == 0: self.draw_text("本层无怪物", 72, BLACK, (17 * BLOCK_UNIT / 2) - (72 * 1.5), (13 * BLOCK_UNIT / 2) - 36, "px") return self.current_index = max(0, self.current_index) self.current_index = min(self.current_index, len(enemy_info_list) - 1) # 计算分页并从enemy_info_list中提取需要展示的数据 item_per_page = 6 total_page = math.ceil(len(enemy_info_list) / item_per_page) current_page = math.ceil((current_index + 1) / item_per_page) slice_start = (current_page - 1) * item_per_page slice_end = min(slice_start + item_per_page, len(enemy_info_list)) enemy_info_list = enemy_info_list[slice_start:slice_end] # 绘制怪物手册条目 i = 0 drawSprite = len(self.group.spritedict) == 0 for enemy in enemy_info_list: if drawSprite : self.draw_icon(enemy["mon_num_id"], 4, 2 * i) self.draw_text(str(enemy["mon_name"]), 30, BLACK, 6 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 10, "px") # 显示怪物特殊能力 ability_text = self.FUNCTION.get_ability_text(enemy["mon_ability"]) if len(ability_text) == 0: pass elif len(ability_text) == 1: for item in ability_text: self.draw_text(item, 30, BLACK, 6 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 46, "px") elif len(ability_text) == 2: temp_index = 1 for item in ability_text: self.draw_text(item, 30, BLACK, 6 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 10 + 36 * temp_index, "px") temp_index += 1 else: self.draw_text("能力太多", 30, BLACK, 6 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 46, "px") self.draw_text("生命 " + str(enemy["mon_hp"]), 30, BLACK, 8 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 10, "px") self.draw_text("攻击 " + str(enemy["mon_atk"]), 30, BLACK, 11 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 10, "px") self.draw_text("防御 " + str(enemy["mon_def"]), 30, BLACK, 14 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 10, "px") self.draw_text("金币 " + str(enemy["mon_gold"]), 30, BLACK, 8 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 46, "px") self.draw_text("经验 " + str(enemy["mon_exp"]), 30, BLACK, 11 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 46, "px") self.draw_text("伤害 " + str(enemy["damage"]), 30, BLACK, 14 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 46, "px") self.draw_text("临界 " + str(enemy["next_critical"]), 30, BLACK, 8 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 82, "px") self.draw_text("减伤 " + str(enemy["next_critical_decrease"]), 30, BLACK, 11 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 82, "px") self.draw_text("1防 " + str(enemy["next_def_critical"]), 30, BLACK, 14 * BLOCK_UNIT, (2 * i * BLOCK_UNIT) + 82, "px") i += 1 # 根据当前current_index绘制高亮框 i = current_index % item_per_page self.draw_rect((4 * BLOCK_UNIT, 2 * BLOCK_UNIT * i), (17 * BLOCK_UNIT - 10, 2 * BLOCK_UNIT * (i + 1)), 3, RED,"px")
def draw_map(self, map_data=None): if self.show_damage_update: self.damage_layer_cache = {} WriteLog.debug(__name__, "绘制地图") self.clear_map() # 清空精灵 if map_data is None: map_data = self.map_data temp_x = 0 temp_y = 0 px, py = self.trans_locate(0, 0) rect = Rect(px, py, self.block_size, self.block_size) ground = get_resource('0') # 地板 先暂时这么搞吧 self.fill_surface(ground, mode="repeat") PlayerCon = global_var.get_value("PlayerCon") self.add_sprite(PlayerCon) while temp_y < self.height: while temp_x < self.width: map_element = map_data[temp_y][temp_x] if int(map_element) != 0: # sprite的显示需要接通group name = str(map_element) ret = get_resource(name) px, py = self.trans_locate(temp_x, temp_y, "down") rect.centerx = px rect.bottom = py if type(ret) is tuple: # 属于精灵 (注意:此时不能直接导入精灵,因为先有map后有精灵) img = ret[0] img_rect = ret[1] # 以资源本体大小显示 用以支持超过32*32的图像 img_rect.topleft = rect.topleft sp = list(ret[2]) self.add_sprite(EventSprite(name, img, sp), fill_rect=img_rect) elif ret is not None: self.fill_surface(ret, fill_rect=rect) # 显伤怪物id和位置的缓存 if map_element > 200: if self.show_damage_update: if map_element in self.damage_layer_cache: self.damage_layer_cache[map_element]["loc"].append([temp_x, temp_y]) else: self.damage_layer_cache[map_element] = {} self.damage_layer_cache[map_element]["loc"] =[] self.damage_layer_cache[map_element]["loc"].append([temp_x, temp_y]) check_result = self.FUNCTION.get_damage_info(map_element) critical = self.FUNCTION.get_criticals(map_element, 1, damage_info=check_result) if check_result == False: self.damage_layer_cache[map_element]["damage"] = "???" else: self.damage_layer_cache[map_element]["damage"] = check_result["damage"] if critical == []: self.damage_layer_cache[map_element]["critical"] = 0 else: self.damage_layer_cache[map_element]["critical"] = critical[0][0] temp_x += 1 temp_y += 1 temp_x = 0 self.temp_srufcae = self.surface.copy() self.show_damage_update = False
def pickaxe(): Music = global_var.get_value("Music") PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") x_coord = PlayerCon.pos[0] y_coord = PlayerCon.pos[1] if PlayerCon.face[0] == 0 and y_coord + 1 < int(HEIGHT / BLOCK_UNIT): y_coord += 1 temp_block = CurrentMap.get_block(x_coord, y_coord) # 可能破坏的是三种墙,编号是1-3 if temp_block in range(1, 4): if BlockData[str(temp_block)]["canBreak"]: Music.play_SE("pickaxe.ogg") CurrentMap.remove_block(x_coord, y_coord) return {"result": True} elif PlayerCon.face[0] == 1 and x_coord - 1 >= 0: x_coord -= 1 temp_block = CurrentMap.get_block(x_coord, y_coord) # 可能破坏的是三种墙,编号是1-3 if temp_block in range(1, 4): if BlockData[str(temp_block)]["canBreak"]: Music.play_SE("pickaxe.ogg") CurrentMap.remove_block(x_coord, y_coord) return {"result": True} elif PlayerCon.face[0] == 2 and x_coord + 1 < int(WIDTH / BLOCK_UNIT): x_coord += 1 temp_block = CurrentMap.get_block(x_coord, y_coord) # 可能破坏的是三种墙,编号是1-3 if temp_block in range(1, 4): if BlockData[str(temp_block)]["canBreak"]: Music.play_SE("pickaxe.ogg") CurrentMap.remove_block(x_coord, y_coord) return {"result": True} elif PlayerCon.face[0] == 3 and y_coord - 1 >= 0: y_coord -= 1 temp_block = CurrentMap.get_block(x_coord, y_coord) # 可能破坏的是三种墙,编号是1-3 if temp_block in range(1, 4): if BlockData[str(temp_block)]["canBreak"]: Music.play_SE("pickaxe.ogg") CurrentMap.remove_block(x_coord, y_coord) return {"result": True} return {"result": False, "msg": "玩家面对的不是墙!"}
def confirm(self, event): text = event["text"] choices = [{}, {}] choices[0]["text"] = "是" choices[0]["action"] = event["yes"] choices[1]["text"] = "否" choices[1]["action"] = event["no"] ChoiceBox = global_var.get_value("CHOICEBOX") ChoiceBox.init(text, choices) ChoiceBox.open()
def centerFly(): Music = global_var.get_value("Music") PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") x_coordinate = PlayerCon.pos[0] y_coordinate = PlayerCon.pos[1] x_max_index = int(WIDTH / BLOCK_UNIT) - 5 y_max_index = int(HEIGHT / BLOCK_UNIT) - 1 x_center = x_max_index / 2 y_center = y_max_index / 2 x_after_fly = int(x_coordinate - (2 * (x_coordinate - x_center))) y_after_fly = int(y_coordinate - (2 * (y_coordinate - y_center))) if CurrentMap.get_block(x_after_fly, y_after_fly) == 0: Music.play_SE("centerFly.ogg") PlayerCon.pos[0] = x_after_fly PlayerCon.pos[1] = y_after_fly PlayerCon.change_hero_loc(PlayerCon.pos[0], PlayerCon.pos[1]) return {"result": True} else: return {"result": False, "msg": "落点有障碍物!"}
def bigKey(): from project.function import add_item, remove_item PlayerCon = global_var.get_value("PlayerCon") CurrentMap = global_var.get_value("CurrentMap") if BIG_KEY_OPEN_YELLOW_DOORS: temp_x = 0 temp_y = 0 while temp_y < HEIGHT / BLOCK_UNIT: while temp_x < WIDTH / BLOCK_UNIT - 4: # 81 = Yellow Door if CurrentMap.get_block(temp_x, temp_y) == 81: CurrentMap.remove_block(temp_x, temp_y) temp_x += 1 temp_y += 1 temp_x = 0 else: add_item(21, 1) add_item(22, 1) add_item(23, 1) return {"result": True}
def draw_text(self, text, size, color, x, y, mode=None): font_name = global_var.get_value("font_name") font = pygame.font.Font(font_name, size) text_surface = font.render(text, True, color) text_rect = text_surface.get_rect() if mode == "px": text_rect.left = x text_rect.top = y else: text_rect.left = x * BLOCK_UNIT text_rect.top = y * BLOCK_UNIT self.surface.blit(text_surface, text_rect)
def __init__(self): self.cls = '' # 类型: 逻辑/显示 self.PlayerCon = global_var.get_value("PlayerCon") self.CurrentMap = global_var.get_value("CurrentMap") self.TEXTBOX = global_var.get_value("TEXTBOX") self.BlockDataReverse = global_var.get_value("BlockDataReverse") self.Music = global_var.get_value("Music") self.FUNCTION = global_var.get_value("FUNCTION")
def draw_bulk_text(self, content, size, mode=None): font_name = global_var.get_value("font_name") font = pygame.font.Font(font_name, size) for text_obj in content: text_surface = font.render(text_obj["text"], True, text_obj["color"]) text_rect = text_surface.get_rect() if mode == "px": text_rect.left = text_obj["x"] text_rect.top = text_obj["y"] else: text_rect.left = text_obj["x"] * BLOCK_UNIT text_rect.top = text_obj["y"] * BLOCK_UNIT self.surface.blit(text_surface, text_rect)
def __init__(self, w, h, block_size=32): self.block_size = block_size self.width = w self.height = h self.map_data = None self.event_data = None self.event_database = {} self.temp_srufcae = None self.map_database_init() self.event_database_init() self.FUNCTION = global_var.get_value("FUNCTION") self.show_damage_update = True self.damage_layer_cache = {} super().__init__(mode="custom",x=0,y=0,w=w * block_size,h=h * block_size)
def __init__(self, **kwargs): Menu.__init__(self, **kwargs) self.name = "楼层传送器" self.key_map = {pygame.K_LEFT: -1, pygame.K_RIGHT: +1, pygame.K_UP: -4, pygame.K_DOWN: +4, pygame.K_g: 'open', pygame.K_ESCAPE: 'close', pygame.K_RETURN: 'enter'} CurrentMap = global_var.get_value("CurrentMap") self.floor_index = CurrentMap.floor_index["index"] self.max_floor_index = len(self.floor_index) - 1 self.floor_per_row = 4
def earthquake(): CurrentMap = global_var.get_value("CurrentMap") temp_x = 0 temp_y = 0 while temp_y < HEIGHT / BLOCK_UNIT: while temp_x < WIDTH / BLOCK_UNIT - 4: temp_block = CurrentMap.get_block(temp_x, temp_y) # 可能破坏的是三种墙,编号是1-3 if temp_block in range(1, 4): if BlockData[str(temp_block)]["canBreak"]: CurrentMap.remove_block(temp_x, temp_y) temp_x += 1 temp_y += 1 temp_x = 0 return {"result": True}
def init_var(self): from project.enemy import MONSTER_DATA from project.block import BlockData from project.items import ITEMS_DATA from lib.utools import get_time from lib import WriteLog self.get_time = get_time self.PlayerCon = global_var.get_value("PlayerCon") self.RootScreen = global_var.get_value("RootScreen") self.CurrentMap = global_var.get_value("CurrentMap") self.Music = global_var.get_value("Music") self.StatusBar = global_var.get_value("StatusBar") self.TEXTBOX = global_var.get_value("TEXTBOX") self.BlockDataReverse = global_var.get_value("BlockDataReverse") self.EVENTFLOW = global_var.get_value("EVENTFLOW") self.MONSTER_DATA = MONSTER_DATA self.BlockData = BlockData self.ITEMS_DATA = ITEMS_DATA self.WriteLog = WriteLog self.save_path = os.path.join(os.getcwd(), "save")
def action(self, event): key_map = self.key_map key = event.key if key in key_map: idx = key_map[key] if self.active: WriteLog.debug(__name__, (self.name,key,key_map)) if idx == 'enter': if self.current_index == 0: self.close() idx = 0 elif self.current_index == 1: self.close() idx = 0 load = global_var.get_value("LOAD") load.open() elif type(idx) is not int: idx = 0 else: self.current_index += idx return True
def use_item(self): k = self.detail_index % self.item_per_page item = self.current_sort_list[k] try: item_name_id = block.BlockData[str(item)]["id"] item_type = ITEMS_DATA["items"][item_name_id]["cls"] item_function = ITEMS_DATA["useItemEffect"][item_name_id] except KeyError: return False command = ( f"item_result = {item_function}\n" f"if item_result['result'] == True:\n" f" if '{item_type}' != 'constants':\n" f" self.FUNCTION.remove_item(item, 1)\n" f"else:\n" f" print(item_result['msg'])\n" ) exec(command) CurrentMap = global_var.get_value("CurrentMap") CurrentMap.set_map(self.PlayerCon.floor) self.FUNCTION.draw_status_bar() return True
def reset(self): self.speedx = 0 self.speedy = 0 self.pos = [X_COORDINATE, Y_COORDINATE] self.floor = PLAYER_FLOOR self.visited = [CurrentMap.floor_index["index"][self.floor]] # 玩家已经去过的楼层,默认去过起始楼层 self.lock = False self.key_pressed = False map_pos = CurrentMap.trans_locate(*self.pos, "down") self.rect.centerx = map_pos[0] self.rect.bottom = map_pos[1] self.animate_speed = PLAYER_SPEED # 移动一格所需要的毫秒数 & 换腿所需时间的两倍 self.animate = False self.hp = PLAYER_HP self.attack = PLAYER_ATK self.defend = PLAYER_DEF self.mdefend = PLAYER_MDEF self.gold = PLAYER_GOLD self.exp = PLAYER_EXP self.floor = PLAYER_FLOOR self.item = PLAYER_ITEM self.var = {} self.FUNCTION = global_var.get_value("FUNCTION")
def proc_block(self, block_id, x, y): if [x, y] in CurrentMap.event_data: EVENTFLOW = global_var.get_value("EVENTFLOW") EVENTFLOW.add_action(x, y) elif block_id == "onSide": return False # block_id = 0 -> 空地 elif int(block_id) == 0: return True # block_id = 1-5 -> 各类墙 elif int(block_id) >= 1 and int(block_id) <= 5: return False # block_id = 21~69 -> 道具 elif int(block_id) >= 21 and int(block_id) <= 69: self.FUNCTION.pickup_item(block_id, x, y) return True # block_id = 81~86 -> 门 elif int(block_id) >= 81 and int(block_id) <= 86: # 快速存档 self.FUNCTION.save() result = self.FUNCTION.open_door(block_id, x, y) if result == False: return False # block_id = 87~88 -> 楼梯 elif int(block_id) == 87 or int(block_id) == 88: result = self.FUNCTION.change_floor(block_id) return False # block_id = 201+ -> 怪物 elif int(block_id) >= 201: result = self.FUNCTION.get_damage_info(block_id) if result["status"] == True and result["damage"] < self.hp: # 快速存档 self.FUNCTION.save() result = self.FUNCTION.battle(block_id, x, y, result=result) if result == False: return False return False
def get_event_flow_module(self): self.EVENTFLOW = global_var.get_value("EVENTFLOW")
def get_event_module(self): self.EVENT = global_var.get_value("EVENT")
def do_action(self): EVENTFLOW = global_var.get_value("EVENTFLOW") command = list(self.choices.items())[self.current_index][1] EVENTFLOW.insert_action(command)
def __init__(self, **kwargs): ground.GroundSurface.__init__(self, **kwargs) self.active = False self.PlayerCon = global_var.get_value("PlayerCon") self.FUNCTION = global_var.get_value("FUNCTION")