def handle_update(self, entity, dt): e = engine.get() if entity.grounded: if entity.dir == 'right': entity.vel_x = entity.ground_speed elif entity.dir == 'left': entity.vel_x = -entity.ground_speed # will we run into something r = from_entity(entity) r.x += entity.vel_x * dt blocking = e.entity_manager.get_in_area('platform', r) if blocking: # we hit something # lets move into it o = blocking.pop() if entity.vel_x > 0: side = from_entity(o).left entity.x = side - entity.width / 2 - 0.1 entity.dir = 'left' else: side = from_entity(o).right entity.x = side + entity.width / 2 + 0.1 entity.dir = 'right' entity.vel_x = 0 else: #check if we will run off the edge if entity.dir == 'left': px, py = r.bottom_left else: px, py = r.bottom_right py -= 0.1 if not e.entity_manager.get_in_area('platform', Rect(px, py, 0, 0)): if entity.dir == 'left': entity.dir = 'right' else: entity.dir = 'left' entity.x += entity.vel_x * dt else: entity.vel_y -= entity.gravity * dt if entity.vel_y < 0: test = Rect(entity.x, entity.y - entity.height / 2 - 0.1, entity.width, 0) ground = e.entity_manager.get_in_area('platform', test) if ground: entity.grounded = True entity.vel_y = 0 floor = ground.pop() r = from_entity(floor) entity.y = r.top + entity.height / 2 + 0.01 entity.y += entity.vel_y * dt
def handle_update(self, entity, dt): if entity.ai_mode == 'roam' and entity.next_corner is not None: e = engine.get() corners = e.entity_manager.get_in_area('corner', rectangle.from_entity(entity)) if entity.next_corner in corners: # print entity.next_corner.next_corners if entity.last_corner in entity.next_corner.next_corners and len(entity.next_corner.next_corners) > 1: choices = entity.next_corner.next_corners[:] choices.remove(entity.last_corner) # print 'a' else: choices = entity.next_corner.next_corners # print 'b' # print choices, entity.last_corner, entity.next_corner, entity.next_corner.next_corners c = random.choice(choices) if c == entity.last_corner: print 'u-turn at', entity.next_corner.x, entity.next_corner.y, 'to', c.x, c.y entity.last_corner = entity.next_corner entity.next_corner = random.choice(choices) entity.target = (entity.next_corner.x, entity.next_corner.y) else: entity.target = None
def handle_update(self, entity, dt): hit = engine.get().entity_manager.get_in_area('player', from_entity(entity)) for h in hit: h.handle('damage', 1) if hit: engine.get().entity_manager.remove(entity)
def handle_update(self, entity, dt): entity.x += entity.vel_x * dt entity.y += entity.vel_y * dt hit = engine.get().entity_manager.get_in_area('player', from_entity(entity)) if hit: hit.pop().supre_dead = True
def handle_update(self, entity, dt): hit = engine.get().entity_manager.get_in_area('bad_guy', from_entity(entity)) for h in hit: h.health -= 2 h.image = h.images[h.health - 1] if hit: engine.get().entity_manager.remove(entity) entity.handle('play_sound', 'enemy-hit')
def handle_update(self, entity, dt): entity.vel_y -= entity.gravity * dt entity.x += entity.vel_x * dt entity.y += entity.vel_y * dt r = from_entity(entity) if engine.get().entity_manager.get_in_area('platform', r): engine.get().entity_manager.remove(entity) entity.handle('play_sound', 'hit')
def handle_update(self, entity, dt): to_sleep = engine.get().entity_manager.get_in_area('car', rectangle.from_entity(entity)) to_wake = engine.get().entity_manager.get_in_area('car', rectangle.Rect(entity.x, entity.y, entity.awake_width, entity.awake_height)) for e in to_sleep - to_wake: e.box2d_car.set_awake(False) for e in to_wake: e.box2d_car.set_awake(True)
def update(self, dt): engine = awesomeengine.get() for e in engine.entity_manager.get_by_tag('always_update'): e.handle('update', dt) r = rectangle.from_entity(engine.entity_manager.get_by_name('update-rect')) for e in engine.entity_manager.get_in_area('update', r): e.handle('update', dt) velocity_iters = 6 position_iters = 2 engine.box2d_world.Step(dt, velocity_iters, position_iters) engine.box2d_world.ClearForces()
def find_next_corner(corner, dir): r = rectangle.from_entity(corner) current_tile = corner distance = 0 while True: check_rect = rectangle.Rect(current_tile.x + dir.x * current_tile.width, current_tile.y + dir.y * current_tile.height, 2, 2) next_tiles = awesomeengine.get().entity_manager.get_in_area('road', check_rect) if len(next_tiles) > 0: distance += 1 next_tile = next_tiles.pop() if 'corner' in next_tile.tags and distance > 1: return next_tile else: current_tile = next_tile else: return None
def handle_draw(self, entity, camera): r = from_entity(entity) camera.draw_rect((255, 0, 0, 0), r)
def handle_update(self, entity, dt): e = engine.get() if entity.grounded: if entity.dir == 'none': entity.vel_x = toward_zero(entity.vel_x, entity.ground_acceleration, dt) elif entity.dir == 'right': entity.vel_x = min( entity.max_ground_speed, entity.vel_x + entity.ground_acceleration * dt) elif entity.dir == 'left': entity.vel_x = max( -entity.max_ground_speed, entity.vel_x - entity.ground_acceleration * dt) entity.vel_y = 0 #will we run into something r = from_entity(entity) r.x += entity.vel_x * dt blocking = e.entity_manager.get_in_area('platform', r) if blocking: # we hit something # lets move into it o = blocking.pop() if entity.vel_x > 0: side = from_entity(o).left entity.x = side - entity.width / 2 - 0.1 else: side = from_entity(o).right entity.x = side + entity.width / 2 + 0.1 entity.vel_x = 0 else: entity.x += entity.vel_x * dt if entity.jump: entity.grounded = False entity.vel_y = entity.jump_vel entity.y += entity.vel_y * dt #are we still grounded test = Rect(entity.x, entity.y - entity.height / 2 - 0.1, entity.width, 0) ground = e.entity_manager.get_in_area('platform', test) if not ground: #we are floating entity.grounded = False else: entity.vel_y -= entity.gravity * dt if entity.air_jump: entity.vel_y = entity.jump_vel entity.air_jump = False if entity.jump: entity.vel_y += entity.jump_force * dt * entity.jump_count entity.jump_count -= dt if entity.jump_count <= 0: entity.jump = False #if falling test for ground if entity.vel_y < 0: test = Rect(entity.x, entity.y - entity.height / 2 - 0.1, entity.width, 0) ground = e.entity_manager.get_in_area('platform', test) if ground: entity.grounded = True entity.air_jumps_remaining = entity.air_jumps entity.vel_y = 0 floor = ground.pop() r = from_entity(floor) entity.y = r.top + entity.height / 2 + 0.01 else: #test for ceiling test = Rect(entity.x, entity.y + entity.height / 2 + 0.1, entity.width, 0) ceiling = e.entity_manager.get_in_area('platform', test) if ceiling: entity.vel_y = 0 c = ceiling.pop() r = from_entity(c) entity.y = r.bottom - entity.height / 2 - 0.01 if entity.dir == 'none': entity.vel_x = toward_zero(entity.vel_x, entity.air_acceleration, dt) elif entity.dir == 'right': entity.vel_x = min(entity.max_air_speed, entity.vel_x + entity.air_acceleration * dt) elif entity.dir == 'left': entity.vel_x = max(-entity.max_air_speed, entity.vel_x - entity.air_acceleration * dt) # will we run into something r = from_entity(entity) r.x += entity.vel_x * dt blocking = e.entity_manager.get_in_area('platform', r) if blocking: # we hit something # lets move into it o = blocking.pop() if entity.vel_x > 0: side = from_entity(o).left entity.x = side - entity.width / 2 - 0.1 else: side = from_entity(o).right entity.x = side + entity.width / 2 + 0.1 entity.vel_x = 0 entity.x += entity.vel_x * dt entity.y += entity.vel_y * dt
def handle_update(self, entity, dt): if entity.i_count > 0: entity.i_count -= dt if engine.get().entity_manager.get_in_area('death_zone', from_entity(entity)): entity.handle('damage', 1)
def handle_update(self, entity, dt): if engine.get().entity_manager.get_in_area('death_zone', from_entity(entity)): print 'ow'
def handle_update(self, entity, dt): e = engine.get() if entity.pickup_target is not None: targets = engine.get().entity_manager.get_in_area('pickup_zone', rectangle.from_entity(entity)) for t in targets: if t == entity.pickup_target: fare = e.entity_manager.get_by_name('fare') fare.active = True start = Vec2d(entity.pickup_target.x, entity.pickup_target.y) e.remove_entity(entity.pickup_target) entity.pickup_target = None road = list(e.entity_manager.get_by_tag('road')) random.shuffle(road) r = road[0] new_target = engine.get().add_entity('dropoff-zone', x=r.x, y=r.y) entity.dropoff_target = new_target end = Vec2d(new_target.x, new_target.y) d = start.get_distance(end) timer = e.entity_manager.get_by_name('timer') timer.time = timer.time_per_distatnce * d return elif entity.dropoff_target is not None: targets = engine.get().entity_manager.get_in_area('dropoff_zone', rectangle.from_entity(entity)) for t in targets: if t == entity.dropoff_target: fare = e.entity_manager.get_by_name('fare') fare.active = False timer = e.entity_manager.get_by_name('timer') cash = e.entity_manager.get_by_name('cash') time_left = timer.time earned = fare.fare + time_left * fare.bonus_rate cash.amount += earned timer.time = 0 fare.fare =0 e.remove_entity(entity.dropoff_target) entity.dropoff_target = None road = list(e.entity_manager.get_by_tag('road')) random.shuffle(road) r = road[0] new_target = engine.get().add_entity('pickup-zone', x=r.x, y=r.y) entity.pickup_target = new_target e.entity_manager.get_by_name('score').score += 1 return timer = e.entity_manager.get_by_name('timer') if timer.time == 0: fare = e.entity_manager.get_by_name('fare') fare.fare = 0 fare.active = False timer.time = 0 e.remove_entity(entity.dropoff_target) entity.dropoff_target = None road = list(e.entity_manager.get_by_tag('road')) random.shuffle(road) r = road[0] new_target = engine.get().add_entity('pickup-zone', x=r.x, y=r.y) entity.pickup_target = new_target e.entity_manager.get_by_name('dropped').dropped += 1 return