def dpad_loop(dpad): keys = { glfw.KEY_W: False, glfw.KEY_A: False, glfw.KEY_S: False, glfw.KEY_D: False, } while True: _, key, _, action, _ = yield from listen.on_key(globs.window) if key in keys: if action == glfw.PRESS: keys[key] = True if action == glfw.RELEASE: keys[key] = False dpad.x = 0 dpad.y = 0 if keys[glfw.KEY_W]: dpad += Vec(0, 1) if keys[glfw.KEY_A]: dpad += Vec(-1, 0) if keys[glfw.KEY_S]: dpad += Vec(0, -1) if keys[glfw.KEY_D]: dpad += Vec(1, 0) if False: # don't bother normalizing norm = np.sqrt(dot(dpad, dpad)) if norm != 0: dpad /= norm
def escape_loop(): while True: _, key, _, action, _ = yield from listen.on_key(globs.window) if key != glfw.KEY_ESCAPE: continue if action != glfw.PRESS: continue for i in range(len(globs.playerarray.quads)): del globs.playerarray.quads[0] globs.playerarray.update() globs.mode = "grid_edit"
def editor_key_loop(): while True: _, key, _, action, _ = yield from listen.on_key(globs.window) # must be in grid_edit mode if globs.mode != "grid_edit": continue if action != glfw.PRESS: continue if key == glfw.KEY_TAB: print("switch", globs.world_state) mode_switch() print(globs.world_state) if key == glfw.KEY_F: print("fill") populate_grid()
def editor_camera_loop(): # keep track of keys in this dictionary keys = { glfw.KEY_W: False, glfw.KEY_A: False, glfw.KEY_S: False, glfw.KEY_D: False, glfw.KEY_LEFT_SHIFT: False, glfw.KEY_SPACE: False, glfw.KEY_P: False } while True: events = yield from listen.any( key=listen.on_key(globs.window), frame=listen.event("on_frame")) # update dictionary if "key" in events: _, key, _, action, _ = events["key"] if key in keys: if action == glfw.PRESS: keys[key] = True if action == glfw.RELEASE: keys[key] = False # must be in grid_edit mode if globs.mode != "grid_edit": continue # adjust camera position based on key state if "frame" in events: _, dt = events["frame"] v = -10 dx = 0 if keys[glfw.KEY_D]: dx += v if keys[glfw.KEY_A]: dx -= v globs.cam["pos"].x += dt*dx dy = 0 if keys[glfw.KEY_W]: dy += v if keys[glfw.KEY_S]: dy -= v globs.cam["pos"].y += dt*dy