Beispiel #1
0
def move_dot(old_world, new_world, dot_id, path, speed):  # TODO: Set travel speed while moving. Or something. Have to handle it, since we pass it to the browser, too.
    assert isinstance(path, collections.Iterable)
    assert len(path[0]) == 2
    #import pdb; pdb.set_trace()
    return attr_update(
        new_world,
        entities = lambda entities: utils.replace_true(
            new_val_fn = lambda dot: attr_update(dot, path=path),
            cmp = lambda dot: dot.id == dot_id,
            seq = entities
        )
    )
Beispiel #2
0
def game_loop(worldstate, current_tick_time, ttl=None):
    logger.debug("New tick: %d", worldstate.ticks)

    events_ = itertools.chain(
        ai.dot_ai(worldstate),
        events.process_browser_events(worldstate)
    )
    worldstate = events.handle_events(worldstate, events_)  # TODO: New variable name, because FP

    new_worldstate = attr_update(
        worldstate,
        ticks=_+1,  # Elapsed ticks in game
    )

    next_tick_time, delta = calc_next_tick_time(current_tick_time)  # Get times for next frame
    logger.debug("Sleeping for %s (%s%%)", delta, round(delta * 1000, 2))
    time.sleep(delta)

    # TTL stuff is in place to let us unit test this function, which we can't do if it runs forever
    if ttl is None:
        new_ttl = ttl
    else:
        new_ttl = ttl - 1
    if ttl == 0:
        continue_ = False
    else:
        continue_ = True

    return continue_, (new_worldstate, next_tick_time, new_ttl)
Beispiel #3
0
def new_dot(old_world, new_world, new_dot):
    return attr_update(new_world, entities=_ + (new_dot,))