예제 #1
0
def update(dt):
    global moving_ids
    for entity_id, direction in moving_ids.iteritems():
        speed = jetengines[entity_id] * dt
        speed_vec = direction.normalized() * speed
        spatial.move_vec(entity_id, speed_vec)
    moving_ids = {}
예제 #2
0
파일: evoseed.py 프로젝트: ghostonline/ld24
def update(dt):
    global collected, collected_change
    for entity_id, state in evoseeds.iteritems():
        max_health = state.max_health
        current_health = health.get_health(entity_id)
        if current_health > max_health:
            continue

        position = spatial.get_position_vec(entity_id)
        timeout = state.timeout - dt
        if timeout < 0:
            explosions.create_within_radius(position, state.radius, big=False)
            timeout = state.explode_timeout
        state.timeout = timeout

        nearest_collector, collector_position, collector_distance = spatial.nearest(
            entity_id, [collector_id], threshold=DEFAULT_COLLECTOR_THRESHOLD)
        if nearest_collector:
            pull_strength = 1 - collector_distance / DEFAULT_COLLECTOR_THRESHOLD
            drift_direction = (collector_position - position).normalized()
            drift = drift_direction * pull_strength * DRIFT_SPEED * dt
            spatial.move_vec(entity_id, drift)

    for entity_id, recipient_id in collect_events:
        addition = health.get_health(entity_id)
        health.heal(recipient_id, addition)
        collected += 1
        collected_change = True
        manager.destroy_entity(entity_id)
예제 #3
0
def update(dt):
    global world_events
    global collide_events_data
    global collide_events
    world_events = set()
    collide_events = set()
    collide_events_data = {}

    player_id = player.player_id

    for entity_id, data in world_collidables.iteritems():
        radius, world_name = data
        world = worlds[world_name]
        pos_vec = spatial.get_position_vec(entity_id)
        distances = map(lambda ray: ray.distance_to(pos_vec), world)
        push_back = [v * -(d - radius) for d,v in zip(distances, push_back_vectors) if d - radius < 0]
        if push_back:
            push_back_vec = reduce(operator.add, push_back, planar.Vec2(0,0))
            spatial.move_vec(entity_id, push_back_vec)
            world_events.add(entity_id)

    for entity_id, radius in collidables.iteritems():
        pos_vec = spatial.get_position_vec(entity_id)

        candidates = ((id_, d) for (id_, d) in collidables.iteritems() if id_ != entity_id)
        for other_id, other_radius in candidates:
            other_vec = spatial.get_position_vec(other_id)
            distance = other_vec.distance_to(pos_vec) 
            if distance - other_radius - radius < 0:
                collide_events.add(entity_id)
                data = collide_events_data.get(entity_id, [])
                data.append(other_id)
                collide_events_data[entity_id] = data

    other_id = player_id
    other_radius = collidables[player_id]
    other_vec = spatial.get_position_vec(other_id)
    for entity_id, radius in player_collidables.iteritems():
        pos_vec = spatial.get_position_vec(entity_id)
        distance = other_vec.distance_to(pos_vec) 
        if distance - other_radius - radius < 0:
            collide_events.add(entity_id)
            data = collide_events_data.get(entity_id, [])
            data.append(other_id)
            collide_events_data[entity_id] = data