X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=client_prototype.py;h=19ac3fd20ae2a8cca1e323e5a6b2714bb0ae9ebc;hb=727cc6b9e6419617dd19dbb2573dd5f4c83045b3;hp=cf8aea63399feb23c1b2278f0d7bff453af4db1d;hpb=f6b3078f4e3aea23f310e863c05a21d31c60cb2e;p=plomrogue diff --git a/client_prototype.py b/client_prototype.py index cf8aea6..19ac3fd 100644 --- a/client_prototype.py +++ b/client_prototype.py @@ -177,7 +177,7 @@ def draw_screen(): draw_winmap() draw_scroll_hints() - stdscr.clear() + stdscr.erase() draw_window_border_lines() draw_window_border_corners() draw_window_contents() @@ -282,9 +282,15 @@ def cursed_main(stdscr): draw_screen() cursed_main.redraw = False char = stdscr.getch() - if char >= 0 and chr(char) in commands: - commands[chr(char)]() - cursed_main.redraw = True + if char >= 0: + char = chr(char) + if char in commands: + if len(commands[char]) == 1 or not world_data["look_mode"]: + commands[char][0]() + cursed_main.redraw = True + else: + commands[char][1]() + cursed_main.redraw = True new_data_from_server = io["file_in"].read() ping_test() read_into_message_queue() @@ -309,6 +315,8 @@ def win_map(): < world_data["map_size"] * (i + 1) - win_size[i] / 2: offset[i] = world_data["map_center"][i] * (i + 1) \ - int(win_size[i] / 2) + if i == 1: + offset[1] = offset[1] + world_data["map_center"][0] % 2 else: offset[i] = world_data["map_size"] * (i + 1) - win_size[i] + i winmap_size = [world_data["map_size"], world_data["map_size"] * 2 + 1] @@ -319,7 +327,7 @@ def win_map(): for x in range(world_data["map_size"]): char = world_data["fov_map"][y * world_data["map_size"] + x] if world_data["look_mode"] and y == world_data["map_center"][0] \ - and x == world_data["map_center"][1]: + and x == world_data["map_center"][1]: if char == " ": char = \ world_data["mem_map"][y * world_data["map_size"] + x] @@ -379,13 +387,55 @@ def win_log(): def command_quit(): - io["file_out"].write("QUIT\n") - io["file_out"].flush() + command_sender("QUIT")() raise SystemExit("Received QUIT command, forwarded to server, leaving.") def command_toggle_look_mode(): - world_data["look_mode"] = False if world_data["look_mode"] else True + if not world_data["look_mode"]: + world_data["look_mode"] = True + else: + world_data["look_mode"] = False + world_data["map_center"] = world_data["avatar_position"] + + +def command_sender(string): + def command_send(): + io["file_out"].write(string + "\n") + io["file_out"].flush() + return command_send + + +def command_looker(string): + def command_look(): + if string == "west" \ + and world_data["map_center"][1] > 0: + world_data["map_center"][1] -= 1 + elif string == "east" \ + and world_data["map_center"][1] < world_data["map_size"] - 1: + world_data["map_center"][1] += 1 + else: + y_unevenness = world_data["map_center"][0] % 2 + y_evenness = int(not(y_unevenness)) + if string[6:] == "west" and \ + world_data["map_center"][1] > -y_unevenness: + if string[:5] == "north" and world_data["map_center"][0] > 0: + world_data["map_center"][0] -= 1 + world_data["map_center"][1] -= y_evenness + if string[:5] == "south" and world_data["map_center"][0] \ + < world_data["map_size"] - 1: + world_data["map_center"][0] += 1 + world_data["map_center"][1] -= y_evenness + elif string[6:] == "east" and world_data["map_center"][1] \ + < world_data["map_size"] - y_unevenness: + if string[:5] == "north" and world_data["map_center"][0] > 0: + world_data["map_center"][0] -= 1 + world_data["map_center"][1] += y_unevenness + if string[:5] == "south" and world_data["map_center"][0] \ + < world_data["map_size"] - 1: + world_data["map_center"][0] += 1 + world_data["map_center"][1] += y_unevenness + return command_look windows = [ @@ -401,8 +451,14 @@ io = { "path_worldstate": "server/worldstate" } commands = { - "l": command_toggle_look_mode, - "Q": command_quit + "Q": (command_quit,), + "c": (command_sender("move south-east"), command_looker("south-east")), + "d": (command_sender("move east"), command_looker("east")), + "e": (command_sender("move north-east"), command_looker("north-east")), + "l": (command_toggle_look_mode,), + "s": (command_sender("move west"), command_looker("west")), + "w": (command_sender("move north-west"), command_looker("north-west")), + "x": (command_sender("move south-west"), command_looker("south-west")), } message_queue = { "open_end": False,