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):
        if entity.shoot_counter > 0:
            entity.shoot_counter -= dt

        if entity.shoot_counter <= 0:
            entity.shoot_counter = entity.shoot_rate

            p = Entity('bad_guy_projectile')

            target = engine.get().entity_manager.get_by_name('player')

            x = target.x - entity.x
            y = target.y - entity.y

            v = entity.launch_speed
            g = p.gravity

            test = v * v * v * v - g * (g * x * x + 2 * y * v * v)

            if x < 0:
                add = pi
            else:
                add = 0

            if test >= 0:
                angle = atan((v * v + sqrt(test)) / (g * x)) + add

                p.x = entity.x
                p.y = entity.y
                p.vel_x = cos(angle) * entity.launch_speed
                p.vel_y = sin(angle) * entity.launch_speed

                engine.get().entity_manager.add(p)
                entity.handle("play_sound", "enemy-shoot")
    def handle_input(self, entity, action, value):
        if action == 'fire' and value == 1 and entity.animation_name != 'character-shoot':
            entity.shoot_counter = entity.shoot_time

            #m = engine.get().entity_manager.get_by_name('mouse')

            #angle = radians((Vec2d(m.x, m.y) - Vec2d(entity.x, entity.y)).angle)

            if entity.facing == 'right':
                angle = radians(45)
            else:
                angle = radians(135)

            for i in range(entity.num_projectiles):
                p = Entity('projectile')

                p.x = entity.x + i * cos(angle) * 10
                p.y = entity.y + i * sin(angle) * 10
                p.vel_x = cos(angle) * entity.launch_speed  # + entity.vel_x
                p.vel_y = sin(angle) * entity.launch_speed  # + entity.vel_y

                if p.vel_x > 0:
                    p.flip = False
                else:
                    p.flip = True

                engine.get().entity_manager.add(p)
            entity.handle('play_animation', 'character-shoot')
 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):
        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 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):
        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):
        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
示例#9
0
 def handle_clicked(self, entity):
     e = engine.get()
     try:
         selector = e.entity_manager.get_by_name('selector')
         e.entity_manager.remove(selector.follow)
         e.entity_manager.remove(selector)
     except:
         pass
    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.follow_enabled:
         p = engine.get().entity_manager.get_by_name('player')
         if p.x > entity.x + entity.dead_zone_width / 2:
             entity.x = p.x - entity.dead_zone_width / 2
         elif p.x < entity.x - entity.dead_zone_width / 2:
             entity.x = p.x + entity.dead_zone_width / 2
         if p.y > entity.y + entity.dead_zone_height / 2:
             entity.y = p.y - entity.dead_zone_height / 2
         elif p.y < entity.y - entity.dead_zone_height / 2:
             entity.y = p.y + entity.dead_zone_height / 2
    def handle_draw(self, entity, cam):
        e = engine.get()
        p = e.entity_manager.get_by_name('player')

        for i in range(p.max_health):
            if i < p.health:
                img = e.resource_manager.get('image', entity.full_img)
            else:
                img = e.resource_manager.get('image', entity.empty_img)

            r = Rect(entity.top_left[0] + (0.5 + i) * entity.heart_width / 2,
                     entity.top_left[1] - entity.heart_height / 2,
                     entity.heart_width, entity.heart_height)

            cam.draw_image(r, img)
    def handle_update(self, entity, dt):
        entity.rate_count += dt
        if entity.rate_count > entity.rate:
            entity.rate_count = 0

            e = engine.get()

            target = e.entity_manager.get_by_name('player')

            angle = radians(
                (Vec2d(target.x, target.y) - Vec2d(entity.x, entity.y)).angle)

            p = Entity('fireball')

            p.x = entity.x
            p.y = entity.y
            p.vel_x = cos(angle) * entity.speed
            p.vel_y = sin(angle) * entity.speed

            e.entity_manager.add(p)
示例#14
0
 def handle_input(self, entity, action, value):
     e = engine.get()
     try:
         selector = e.entity_manager.get_by_name('selector')
         p = selector.follow
         if value == 1:
             if action == 'right':
                 p.x += 10
             elif action == 'left':
                 p.x -= 10
             elif action == 'up':
                 p.y += 10
             elif action == 'down':
                 p.y -= 10
             elif action == 'grow_x':
                 p.width += 10
             elif action == 'shrink_x':
                 p.width = max(p.width - 10, 0)
             elif action == 'grow_y':
                 p.height += 10
             elif action == 'shrink_y':
                 p.height = max(p.height - 10, 0)
     except:
         pass
示例#15
0
 def handle_input(self, entity, action, value):
     if action == 'button' and value == 1:
         e = engine.get()
         place_button = e.entity_manager.get_by_name('place_button')
         if place_button.selected:
             chooser = e.entity_manager.get_by_name('entity_chooser')
             name = chooser.entity_list[chooser.entity_list_selected_index]
             new_entity = Entity(name, x=entity.world_x, y=entity.world_y)
             if not e.entity_manager.has_by_name(new_entity.name):
                 e.entity_manager.add(new_entity)
         select_button = e.entity_manager.get_by_name('select_button')
         if select_button.selected:
             try:
                 selector = e.entity_manager.get_by_name('selector')
                 e.entity_manager.remove(selector)
             except:
                 pass
             to_select = e.entity_manager.get_in_area(
                 "editable", Rect(entity.world_x, entity.world_y, 0, 0))
             if to_select:
                 f = to_select.pop()
                 selector = Entity('editor_selector',
                                   follow=f,
                                   x=f.x,
                                   y=f.y)
                 e.entity_manager.add(selector)
         move_button = e.entity_manager.get_by_name('move_button')
         if move_button.selected:
             try:
                 selector = e.entity_manager.get_by_name('selector')
                 selector.follow.x = entity.world_x
                 selector.follow.y = entity.world_y
                 selector.x = entity.world_x
                 selector.y = entity.world_y
             except:
                 pass
 def handle_update(self, entity, dt):
     if entity.health == 0:
         engine.get().entity_manager.remove(entity)
         entity.handle('play_sound', 'enemy-death')
 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.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):
        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
 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):
     entity.x = entity.target.x
     entity.y = entity.target.y
     # entity.angle = entity.target.angle - 90
     engine.get().entity_manager.update_position(entity)