コード例 #1
0
    def f(*args):
        pos = makePos(*args)
        # coords of the top left tile. if (x, y) is the top left
        # then (x+1, y) is the top right, and (x, y+1) and (x+1, y+1)
        # the left and right walls of the pipe.
        sheet = vars.tile_data['tile_sheets']['main']
        tl = kwargs.get('top_left')
        height = args[3]
        data = [tl[0], tl[1] + 1, tl[0] + 1, tl[1] + 1] * (height - 1)
        data.extend([tl[0], tl[1], tl[0] + 1, tl[1]])
        e = entity.Entity(pos=pos)
        e.add_component(
            comp.TiledGfx(tile_sheet=sheet['file'],
                          sheet_size=sheet['sheet_size'],
                          tile_data=data,
                          width=2,
                          height=height,
                          size=vars.tile_size))
        shape = sh.Rect(width=2 * vars.tile_size,
                        height=height * vars.tile_size)
        e.add_component(
            comp.Collider(flag=vars.flags.platform, mask=1, tag=1,
                          shape=shape))
        foe = kwargs.get('foe', None)
        exit = kwargs.get('exit', None)
        if foe:
            foe_tag = monkey.engine.get_next_tag()
            pct = 1
            if exit:
                if exit not in vars.disable_update_on_start:
                    vars.disable_update_on_start[exit] = []
                vars.disable_update_on_start[exit].append(foe_tag)
                pct = 0.5
            p = plant(model=foe, pct=pct)(1, height, -0.1)
            p.tag = foe_tag
            plant_id = e.add(p)
            sensor = entity.Entity(pos=(vars.tile_size,
                                        height * vars.tile_size))
            size = (8.0, 0.4, 0.0)
            sensor.add_component(
                comp.Collider(debug=True,
                              flag=vars.flags.foe,
                              mask=vars.flags.player,
                              tag=vars.tags.generic_hotspot,
                              shape=sh3d.AABB(size=size,
                                              offset=(-size[0] * 0.5, 0.0,
                                                      0.0))))
            sensor.add_component(
                comp.Info(on_enter=freeze_plant(p.tag, False),
                          on_leave=freeze_plant(p.tag, True)))
            e.add(sensor)
        warp_info = kwargs.get('warp', None)
        if warp_info:
            w = warp()(1, height, 0, warp_info[0], warp_info[1])
            e.add(w)

        return e
コード例 #2
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):

        ym = kwargs.get('y_min')
        y0 = kwargs.get('y_min_goto')
        wa: WalkAreaInfo = vars.walk_areas[y0[0]]
        ymg = wa.transform(y0[1:])
        print('y m goto = ' + str(ymg))

        yM = kwargs.get('y_max')
        y1 = kwargs.get('y_max_goto')
        wa: WalkAreaInfo = vars.walk_areas[y1[0]]
        yMg = wa.transform(y1[1:])
        print('y M goto = ' + str(yMg))

        x0 = args[0]
        depth_y = args[2] * math.sqrt(2.0)
        y0 = args[1] - args[2]
        z0 = -depth_y
        pos = (x0, y0, z0)
        e = entity.Entity(pos=pos)
        e.add_component(
            comp.Collider(debug=True,
                          shape=sh3d.AABB(size=(args[3], args[4], args[5])),
                          flag=vars.flags.foe,
                          mask=vars.flags.player,
                          tag=vars.tags.ladder))
        e.add_component(
            comp.Info(x=522,
                      y_min=ym,
                      y_max=yM,
                      y_min_goto=ymg,
                      y_max_goto=yMg))
        return e
コード例 #3
0
 def f(*args):
     pos = makePos(*args)
     e = entity.Entity(pos=pos)
     e.add_component(
         comp.TiledGfx(tile_sheet='gfx/smb1.png',
                       sheet_size=[16, 16],
                       tile_data=[15, 5],
                       width=1,
                       height=1,
                       size=vars.tile_size,
                       repx=args[3],
                       repy=1))
     e.add_component(
         comp.Collider(flag=vars.flags.platform_passthrough,
                       mask=vars.flags.player,
                       tag=0,
                       shape=sh.Line(
                           a=[0, vars.tile_size, 0],
                           b=[args[3] * vars.tile_size, vars.tile_size,
                              0])))
     e.add_component(
         comp.PolygonalMover(origin=(pos[0], pos[1]),
                             loop=args[6],
                             pct=args[4],
                             moves=[{
                                 'delta': [0, args[5] * vars.tile_size],
                                 'speed': args[7],
                                 'hold': 0
                             }]))
     e.add_component(comp.Platform())
     return e
コード例 #4
0
 def f(*args):
     shape = None
     tile_set_id = kwargs['id']
     tile_set = vars.tile_data['tile_sets'][tile_set_id]
     pos = makePos2(*args)
     sheet_id = tile_set['sheet']
     sheet = vars.tile_data['tile_sheets'][sheet_id]
     width = tile_set['size'][0]
     height = tile_set['size'][1]
     solid = tile_set['solid']
     data = tile_set['data']
     e = entity.Entity(pos=pos)
     e.add_component(
         comp.TiledGfx(tile_sheet=sheet['file'],
                       sheet_size=sheet['sheet_size'],
                       tile_data=data,
                       width=width,
                       height=height,
                       size=vars.tile_size))
     if solid:
         shape = sh.Rect(width=width * vars.tile_size,
                         height=height * vars.tile_size)
         e.add_component(
             comp.Collider(flag=vars.flags.platform,
                           mask=1,
                           tag=1,
                           shape=shape))
     return e
コード例 #5
0
 def f(*args):
     # the first argument is the callback function
     # the second, if present, is the model
     model = kwargs.get('model', None)
     callback = kwargs.get('func')
     info = kwargs.get('info', None)
     pos = makePos2(*args)
     if model is None:
         a = entity.Entity(pos=pos)
         size = [args[2] * vars.tile_size, args[3] * vars.tile_size, 0]
         a.add_component(
             comp.Collider(debug=True,
                           flag=vars.flags.foe,
                           mask=vars.flags.player,
                           tag=vars.tags.key,
                           shape=sh3d.AABB(size=size)))
         a.add_component(
             comp.Info(func=callback,
                       info=info,
                       args=args,
                       bounds=[0, 0, size[0], size[1]]))
     else:
         a = entity.Sprite(model=model, pos=pos)
         a.add_component(
             comp.SmartCollider(debug=True,
                                flag=vars.flags.foe,
                                mask=vars.flags.player,
                                tag=vars.tags.key))
         a.add_component(comp.Info(func=callback, info=info, args=args))
     return a
コード例 #6
0
 def create_player(self, position, max_hp, max_x_vel, max_y_vel, attack_list):
     
     """Create player.
     
     :param position: position where player is created
     :type position: 2d list
     """
     #Create players hp gui
     temp = pygame.image.load(os.path.join('data', 'hp.png')).convert_alpha()
     hp = components.Health(max_hp, 8, temp)
     c_hp = (hp, hp.current_image)
     hp_ID = self.create_entity(c_hp)
     #Players hitbox, it is 50 pixel width and 96 pixel height
     coll = components.Collider(position[0], position[1], 50, 96)
     vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
     #Create players animations
     temp = pygame.image.load(os.path.join('data', 'char.png')).convert_alpha()
     anim_list = [4, 10, 8, 8, 2, 2]
     anim_time_list = [240, 50, 44, 60, 30, 44]
     anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
     anim.rect.center = coll.center
     direction = components.Direction([1, 0])
     player = components.Player(0, hp_ID, )
     c = (direction, coll, vel, anim, player)
     self.player = self.create_entity(c)
     #Now create the players orb
     #It is created afterward, so orb will be
     #displayed over players sprite
     temp = pygame.image.load(os.path.join('data', 'orb.png'))
     orb_sprite = components.Appearance(temp.convert_alpha())
     c_orb = (orb_sprite,)
     orb_ID = self.create_entity(c_orb)
     #Set orb ID
     self.players[self.player].orb_ID = orb_ID
     self.add_component_to_entity(self.player, attack_list)
コード例 #7
0
 def f(*args):
     pos = makePos(*args)
     # coords of the top left tile. if (x, y) is the top left
     # then (x+1, y) is the top right, and (x, y+1) and (x+1, y+1)
     # the left and right walls of the pipe.
     sheet = vars.tile_data['tile_sheets']['main']
     tl = kwargs.get('top_left')
     width = args[3]
     height = args[4]
     data = [tl[0], tl[1]]
     data.extend([tl[0] + 1, tl[1]] * (width - 2))
     data.extend([tl[0] + 2, tl[1]])
     e = entity.Entity(pos=pos)
     e.add_component(
         comp.TiledGfx(tile_sheet=sheet['file'],
                       sheet_size=sheet['sheet_size'],
                       tile_data=data,
                       width=width,
                       height=1,
                       size=vars.tile_size))
     shape = sh.Line(a=(0, vars.tile_size),
                     b=(width * vars.tile_size, vars.tile_size))
     e.add_component(
         comp.Collider(flag=vars.flags.platform,
                       mask=1,
                       tag=1,
                       shape=shape,
                       debug=True))
     return e
コード例 #8
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):
        pos = (args[0], args[1], args[2])
        width = args[3]
        height = args[4]
        depth = args[5]
        offset = (0, 0, 0)
        if len(args) > 6:
            offset = (args[6], args[7], args[8])
        color = kwargs.get('color', [1, 1, 1, 1])
        e = entity.Entity(pos=pos)
        shape = sh3d.AABB(size=(width, height, depth), offset=offset)
        e.add_component(comp.ShapeGfxColor(shape=shape, color=color))
        e.add_component(
            comp.Collider(shape=shape,
                          flag=vars.flags.platform,
                          mask=0,
                          tag=vars.tags.platform))

        tx_top = kwargs.get('top', None)
        tx_front = kwargs.get('front', None)
        if tx_top:
            e.add(
                make_plat(
                    glm.vec3(0, height, depth) + offset, (width, depth),
                    tx_top))
        if tx_front:
            e.add(
                make_wall(
                    glm.vec3(0, 0, depth) + offset, (width, height), tx_front))
        #e.add(make_wall(offset + glm.vec3(0, 0, depth), (width, height), '2'))
        #e.add(make_wall(offset + glm.vec3(width, 0, depth), (depth, height), '2', 90))
        return e
コード例 #9
0
ファイル: items.py プロジェクト: fabr1z10/glib3
 def f(*args):
     desc = args[1]
     pos = desc.get('pos')
     size = desc.get('size')
     s = entity.Entity(pos=pos)
     s.add_component(compo.Collider(flag=vars.Collision.Flags.other, mask=vars.Collision.Flags.player,
                                    tag=vars.Collision.Tags.trap, shape=shapes.Rect(width=size[0],height=size[1]),debug=True))
     s.add_component(compo.Info(on_enter=desc.get('on_enter', None), on_leave=desc.get('on_leave', None)))
     return s
コード例 #10
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):
        sheet_id = kwargs.get('sheet', 0)
        sheet = vars.tile_sheets[sheet_id]
        tl = kwargs.get('top_left')
        tiledata = dict()
        lup = args[3]
        ldown = args[4]
        dy = ldown - lup
        x0 = tl[0]
        y0 = tl[1]
        tiledata[(0, 0)] = (x0 + 3, y0)
        tiledata[(0, -1)] = (x0, y0 + 3)
        x = 1
        y = 1
        for i in range(1, lup):
            tiledata[(x, y)] = (x0 + 3, y0)
            tiledata[(x, y - 1)] = (x0, y0 + 2)

            for j in range(0, 2 * i - 1):
                tiledata[(x, y - j - 2)] = (x0 + 1, y0 + 1)
            tiledata[(x, y - 2 - (2 * i - 1))] = (x0 + 2, y0 + 3)
            x += 1
            y += 1
        y -= 1
        for i in range(0, ldown):
            tiledata[(x, y)] = (x0 + 1, y0 + 3) if i == 0 else (x0 + 3, y0 + 3)
            for j in range(0, ldown - i - 1):
                tiledata[(x, y - j - 1)] = (x0 + 1, y0 + 1)
            x += 1
            y -= 1
            # tiledata[(x, y-2*i-1)] = (x0+2,y0+3)            # for j in range(0, 2*i-1):
            #     tiledata[(x, y-j-2)] = (x0+1, y0+1)
            # tiledata[(x, y-2*i-1)] = (x0+2,y0+3)
        tdata = make_tiledata(tiledata)
        pos = (args[0] * vars.tile_size, (args[1] - dy) * vars.tile_size,
               args[2])
        e = entity.Entity(pos=pos)
        e.add_component(
            comp.TiledGfx(tile_sheet=sheet['file'],
                          sheet_size=sheet['sheet_size'],
                          tile_data=tdata[0],
                          width=tdata[1],
                          height=tdata[2],
                          size=vars.tile_size))
        e.add_component(
            comp.Collider(debug=True,
                          flag=vars.flags.platform_passthrough,
                          mask=0,
                          tag=0,
                          shape=sh.Line(a=[0, dy * vars.tile_size],
                                        b=[
                                            lup * vars.tile_size,
                                            (dy + lup) * vars.tile_size
                                        ])))
        return e
コード例 #11
0
 def f(*args):
     pos = makePos2(*args)
     a = entity.Entity(pos=pos)
     print('DDD')
     a.add_component(
         comp.Collider(flag=vars.flags.platform,
                       mask=vars.flags.player,
                       tag=1,
                       shape=sh.Rect(width=1, height=16 * vars.tile_size)))
     print('DDE')
     return a
コード例 #12
0
 def f(*args):
     pos = makePos(*args)
     pin = entity.Entity(pos=pos, tag=kwargs.get('tag', None))
     pin.add_component(
         comp.Collider(debug=True,
                       flag=vars.flags.foe,
                       mask=vars.flags.player,
                       tag=vars.tags.warp,
                       shape=sh3d.AABB(size=(4, 2, 0), offset=(-2, 0, 0))))
     pin.add_component(
         comp.Info(world=args[3], start=args[4], bounds=[0, 0, 4, 2]))
     return pin
コード例 #13
0
def _brick(x, y, model, hits, callback):
    pos = makePos2(x, y)
    a = entity.Sprite(model=model, pos=pos)
    a.add_component(
        comp.Collider(flag=vars.flags.platform,
                      mask=0,
                      tag=0,
                      shape=sh.Rect(width=vars.tile_size,
                                    height=vars.tile_size)))
    a.add_component(comp.Info(hitsLeft=hits, callback=callback))
    b = entity.Entity()
    b.pos = (2, -0.5, 0)
    b.add_component(
        comp.Collider(flag=vars.flags.foe,
                      mask=vars.flags.player,
                      tag=vars.tags.bonus_brick_sensor,
                      debug=True,
                      shape=sh3d.AABB(size=(vars.tile_size - 4, 1, 0))
                      #shape=sh.Rect(width=vars.tile_size - 4, height=1.0)
                      ))
    a.add(b)
    return a
コード例 #14
0
 def f(*args):
     model = kwargs.get('model')
     piece = kwargs.get('piece')
     pos = makePos2(*args)
     a = entity.Sprite(model=model, pos=pos)
     a.add_component(
         comp.Collider(flag=vars.flags.platform,
                       mask=0,
                       tag=0,
                       shape=sh.Rect(width=vars.tile_size,
                                     height=vars.tile_size)))
     a.add_component(comp.Info(piece=piece))
     b = entity.Entity()
     b.pos = (2, -0.5, 0)
     b.add_component(
         comp.Collider(flag=vars.flags.foe,
                       mask=vars.flags.player,
                       tag=vars.tags.brick_sensor,
                       shape=sh3d.AABB(size=(vars.tile_size - 4, 1, 1))
                       #shape=sh.Rect(width=vars.tile_size-4, height=1.0)
                       ))
     a.add(b)
     return a
コード例 #15
0
ファイル: items.py プロジェクト: fabr1z10/glib3
 def f(*args):
     x0 = args[0]
     depth_y = args[2] * math.sqrt(2.0)
     y0 = args[1] - args[2]
     z0 = -depth_y
     pos = (x0, y0, z0)
     e = entity.Entity(pos=pos)
     e.add_component(
         comp.Collider(debug=True,
                       shape=sh3d.AABB(size=(args[3], args[4],
                                             args[5] * sqrt2)),
                       flag=vars.flags.foe,
                       mask=vars.flags.player,
                       tag=vars.tags.spawn))
     e.add_component(comp.Info(enemies=args[6]))
     return e
コード例 #16
0
 def f(*args):
     pos = makePos(*args)
     w = args[3]
     h = args[4]
     a = entity.Entity(pos=pos)
     img = kwargs.get('image', None)
     if img:
         a.add_component(comp.Gfx(image=img, repeat=[w, h]))
     a.add_component(
         comp.Info(bounds=[0, 0, w * vars.tile_size, h * vars.tile_size]))
     a.add_component(
         comp.Collider(flag=vars.flags.platform,
                       mask=vars.flags.player,
                       tag=1,
                       shape=sh.Rect(width=w * vars.tile_size,
                                     height=h * vars.tile_size)))
     return a
コード例 #17
0
 def f(*args):
     x = args[0] * vars.tile_size
     y = args[1] * vars.tile_size
     ax = args[2] * vars.tile_size
     ay = args[3] * vars.tile_size
     bx = args[4] * vars.tile_size
     by = args[5] * vars.tile_size
     minx = min(ax, bx)
     maxx = max(ax, bx)
     miny = min(ay, by)
     maxy = max(ay, by)
     a = entity.Entity()
     a.add_component(
         comp.Collider(flag=vars.flags.platform,
                       mask=vars.flags.player,
                       tag=1,
                       shape=sh.Line(a=[ax, ay, 0], b=[bx, by, 0])))
     a.add_component(comp.Info(bounds=[minx, miny, maxx, maxy]))
     a.pos = (x, y, 0)
     return a
コード例 #18
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):
        outline = kwargs.get('poly')
        depth = kwargs.get('depth')
        fy = kwargs.get('fy', 0)
        if fy > 0:
            outline = [
                fy - outline[i] if i % 2 == 1 else outline[i]
                for i in range(0, len(outline))
            ]
            print(outline)
            #exit(1)

        height = kwargs.get('height', 1.0)
        depth_y = depth * math.sqrt(2.0)
        y0 = outline[1] - depth - height
        x0 = outline[0]
        z0 = -depth_y
        pos = (x0, y0, z0)
        top = (x0, y0 + height, z0)
        vars.walk_areas.append(
            WalkAreaInfo(x0, y0 + height, z0, fy, outline[1]))
        #print('PISUZIONA = ' + str(pos))
        color = kwargs.get('color', [1, 1, 1, 1])
        oline = []
        a0 = outline[1]
        for i in range(0, len(outline), 2):
            oline.append(outline[i] - x0)
            oline.append((outline[i + 1] - a0) * math.sqrt(2.0))
        print(oline)
        e = entity.Entity(pos=pos)
        shape = sh3d.Prism(shape=sh.Poly(outline=oline),
                           height=height,
                           walls=kwargs.get('walls', []))
        print(shape)
        e.add_component(comp.ShapeGfxColor(shape=shape, color=color))
        e.add_component(
            comp.Collider(shape=shape,
                          flag=vars.flags.platform,
                          mask=0,
                          tag=vars.tags.platform))
        return e
コード例 #19
0
ファイル: items.py プロジェクト: fabr1z10/glib3
 def f(*args):
     key = args[0]
     is_player = key == vars.current_player
     desc = args[1]
     model = desc.get('model', None)
     text_color = monkey.engine.read(desc.get('text_color', [255, 255, 255, 255]))
     #text_color =
     text_offset = desc.get('text_offset', [0, 60])
     pos = desc.get('pos')
     tag = desc.get('tag', key)
     s = None
     dir = desc.get('dir', 's')
     if model:
         s = entity.Sprite(model=model, pos=pos, tag='player' if is_player else tag)
         s.add_component(compo.Collider(debug=True, flag=vars.Collision.Flags.player, mask=vars.Collision.Flags.other,
                                    tag=vars.Collision.Tags.player, shape=shapes.Rect(width=8, height=2, offset=[-4, 0])))
         if is_player:
             s.add_component(compo.Follow())
     else:
         s = entity.Entity(pos=pos, tag='player' if is_player else tag)
     s.add_component(scumm.components.CharacterController(dir=dir, speed=vars.speed, text_color=text_color, text_offset=text_offset))
     return s
コード例 #20
0
    def __init__(self, screen, event_manager):
        """
        :param screen: game screen
        :type screen: python.Surface
        :param event_managere: event manager
        :type event_manager: events.EventManager
        """
        self.level = level.Level()
        self.screen = screen
        self.event_manager = event_manager

        #Components and entities
        self.mask = list()
        self.appearance = {}
        self.collider = {}
        self.velocity = {}
        self.direction = {}
        self.players = {}
        self.attacks = {}
        self.player = None
        self.ai = {}
        self.inactive_enemy_count = 0
        self.tags = {}
        self.hp = {}
        self.collectibles = {}
        
        self.inactive_entities = list()
        self.to_remove = list()
        
        #Create all game entities
        walls = list()
        #Get layer width and height in tiles
        layer_width = len(self.level.tmx_data.layers[0].data)
        layer_height = len(self.level.tmx_data.layers[0].data[0])
        for layer_index in range(len(self.level.tmx_data.layers)):
            #BUG? pyTMX reads from top to down, then from left to right
            #So: y in range(layer_width) and x in range (layer_heigt)
            player_position = None
            player_hp = None
            player_max_x_vel = None
            player_max_y_vel = None
            player_attack_list = None
            for y in range(layer_width):
                for x in range(layer_height):
                    ####
                    tile_properties = self.level.tmx_data.get_tile_properties(x, y, layer_index)
                    if self.level.tmx_data.layers[layer_index].name == "characters":
                        if tile_properties:
                            self.create_game_object(x, y, tile_properties)
                            if tile_properties["type"] == "player":
                                player_position = (x*64+32, y*64+32)
                                if "max_hp" in tile_properties:
                                    player_hp = int(tile_properties["max_hp"])
                                if "max_x_vel" in tile_properties:
                                    player_max_x_vel = int(tile_properties["max_x_vel"])
                                if "max_y_vel" in tile_properties:
                                    player_max_y_vel = int(tile_properties["max_y_vel"])
                                #Attack related:
                                if "att_1_damage" in tile_properties:
                                    damage1 = int(tile_properties["att_1_damage"])
                                if "att_1_stun" in tile_properties:
                                    stun1 = int(tile_properties["att_1_stun"])
                                if "att_1_cooldown" in tile_properties:
                                    cooldown1 = int(tile_properties["att_1_cooldown"])
                                if "att_1_projectile_amount" in tile_properties:
                                    proj1 = int(tile_properties["att_1_projectile_amount"])
                                if "att_1_projectile_lifetime" in tile_properties:
                                    proj_life1 = int(tile_properties["att_1_projectile_lifetime"])
                                if "att_1_spread_angle" in tile_properties:
                                    spread1 = int(tile_properties["att_1_spread_angle"])
                                if "att_1_projectile_speed" in tile_properties:
                                    proj_speed1 = int(tile_properties["att_1_projectile_speed"])
                                if "att_1_pierce" in tile_properties:
                                    att1_pierce = tile_properties["att_1_pierce"] == "1"
                                #Create players attacks
                                player_attack_list = list()
                                #Attack 1:
                                effect_ID = self.create_attack_effect('char_attack1_effect.png',
                                                                      250, 250, 8, 30)
                                #Create projectile image
                                proj_image = "simple_projectile_light_circle.png"
                                proj_anim_list = [2, 4]
                                proj_anim_time_list = [20, 13]
                                particle_emitter = self.create_attack(player_position, damage1, stun1,
                                                                      cooldown1, proj1, proj_image,
                                                                      proj_anim_list, proj_anim_time_list,
                                                                      25, 25,
                                                                      proj_life1, proj_speed1, [0,0],
                                                                      spread1, effect_ID)
                                particle_emitter.piercing = att1_pierce
                                player_attack_list.append(particle_emitter)
                    #Create walls
                    if self.level.tmx_data.layers[layer_index].name == "walls":
                        tile = self.level.tmx_data.get_tile_image(x, y, layer_index)
                        if tile:
                            tags = list()
                            if tile_properties:
                                if "type" in tile_properties:
                                    if tile_properties["type"] == "corner":
                                        #Tile is a corner
                                        tags.append("corner")
                                    if tile_properties["type"] == "deadly":
                                        #Deadly tile, instant death on player collision
                                        tags.append("deadly")
                                if "curse" in tile_properties:
                                    if tile_properties["curse"] == "green":
                                        tags.append("green")
                                    if tile_properties["curse"] == "pink":
                                        tags.append("pink")
                            coll = components.Collider(x*64, y*64, 64, 64, tags)
                            walls.append(coll)                                
        # Add player afterwards so he is on top of game objects 
        self.create_player(player_position, player_hp, player_max_x_vel, player_max_y_vel,
                               player_attack_list)
        self.create_curse()
        #---
        #Quad Tree
        self.tree = quadTree.QuadTree(walls)
コード例 #21
0
 def create_enemy(self, position, max_hp, max_x_vel, max_y_vel, attack_list, ai_ID, tags):
     """Create an enemy.
     
     :param position: position where enemy is created
     :type position: 2d list
     """
     if ai_ID == "green_1":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 50, 96, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_green_1.png')).convert_alpha()
         anim_list = [2, 10, 4, 8, 2, 1]
         anim_time_list = [240, 60, 44, 120, 10, 10]
         anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_1(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "green_2":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 100, 100, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_green_2.png')).convert_alpha()
         anim_list = [5, 6, 4, 2, 2, 2]
         anim_time_list = [74, 60, 60, 10, 10, 10]
         anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         enemy_AI = ai.AI_3(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_1":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 50, 96, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_1.png')).convert_alpha()
         anim_list = [4, 8, 6, 8, 2, 4]
         anim_time_list = [240, 60, 44, 58, 10, 44]
         anim = components.Appearance(temp, 243, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_2(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_2":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 70, 70, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_2.png')).convert_alpha()
         anim_list = [5, 6, 5, 2, 2, 2]
         anim_time_list = [60, 60, 44, 10, 10, 10]
         anim = components.Appearance(temp, 75, 75, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_3(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_3":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 50, 96, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_3.png')).convert_alpha()
         anim_list = [5, 10, 7, 8, 2, 1]
         anim_time_list = [240, 60, 54, 120, 10, 10]
         anim = components.Appearance(temp, 128, 128, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         
         enemy_AI = ai.AI_4(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     elif ai_ID == "pink_boss":
         #Enemy's hitbox, it is 50 pixel width and 96 pixel height
         coll = components.Collider(position[0], position[1], 86, 170, tags)
         vel = components.Velocity(0, 0, max_x_vel, max_y_vel)
         #Create enemy's animations
         temp = pygame.image.load(os.path.join('data', 'enemy_pink_boss.png')).convert_alpha()
         anim_list = [4, 8, 5, 8, 2, 4, 5, 5]
         anim_time_list = [240, 60, 44, 58, 10, 44, 44, 44]
         anim = components.Appearance(temp, 250, 200, anim_list, anim_time_list)
         anim.rect.center = coll.center
         direction = components.Direction([1, 0])
         hp = components.Health(max_hp)
         c = (coll, direction, vel, anim, hp)
         enemy_ID = self.create_entity(c)
         enemy_AI = ai.AI_Boss_2(self, enemy_ID, self.event_manager)
         self.add_component_to_entity(enemy_ID, enemy_AI)
         self.add_component_to_entity(enemy_ID, attack_list)
     self.deactivate_entity(enemy_ID)
コード例 #22
0
 def create_game_object(self, x, y, tile_properties):
     if "type" in tile_properties:
         if tile_properties["type"] == "enemy":
             tags = list()
             position = (x*64+32, y*64+32)
             if "max_hp" in tile_properties:
                 hp = int(tile_properties["max_hp"])
             if "max_x_vel" in tile_properties:
                 max_x_vel = int(tile_properties["max_x_vel"])
             if "max_y_vel" in tile_properties:
                 max_y_vel = int(tile_properties["max_y_vel"])
             if "no_gravity" in tile_properties:
                 if int(tile_properties["no_gravity"]) == 1:
                     tags.append("no_gravity")
             #Attack related:
             #Create enemy attacks
             attack_list = list()
             effect_ID = None
             #Attack 1:
             if "att_1_damage" in tile_properties:
                 damage1 = int(tile_properties["att_1_damage"])
             if "att_1_stun" in tile_properties:
                 stun1 = int(tile_properties["att_1_stun"])
             if "att_1_cooldown" in tile_properties:
                 cooldown1 = int(tile_properties["att_1_cooldown"])
             if "att_1_projectile_amount" in tile_properties:
                 proj1 = int(tile_properties["att_1_projectile_amount"])
             if "att_1_projectile_lifetime" in tile_properties:
                 proj_life1 = int(tile_properties["att_1_projectile_lifetime"])
             if "att_1_spread_angle" in tile_properties:
                 spread1 = int(tile_properties["att_1_spread_angle"])
             if "att_1_projectile_speed" in tile_properties:
                 proj_speed1 = int(tile_properties["att_1_projectile_speed"])
             if "ai" in tile_properties:
                 ai_ID = tile_properties["ai"]
             if "att_1_pierce" in tile_properties:
                 att1_pierce = tile_properties["att_1_pierce"] == "1"
             #Create projectile image
             if ai_ID == "green_1":
                 proj_image = "projectile_fly_green.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [28, 13]
                 proj_width = 40
                 proj_height = 40
             elif ai_ID == "green_2":
                 proj_image = "projectile_fly_green.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [28, 13]
                 proj_width = 40
                 proj_height = 40
             elif ai_ID == "pink_1":
                 proj_image = "pink_proj.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [50, 13]
                 proj_width = 32
                 proj_height = 32
             elif ai_ID == "pink_2":
                 proj_image = "pink_proj.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [50, 13]
                 proj_width = 32
                 proj_height = 32
                 effect_ID = self.create_attack_effect('enemy_pink_2_effect.png',
                                                   200, 200, 6, 60)
             elif ai_ID == "pink_3":
                 proj_image = "pink_proj.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [50, 13]
                 proj_width = 32
                 proj_height = 32
                 effect_ID = self.create_attack_effect('tentakel2.png',
                                                   200, 200, 8, 52)
             elif ai_ID == "pink_boss":
                 proj_image = "pink_proj.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [50, 13]
                 proj_width = 32
                 proj_height = 32
                 effect_ID = self.create_attack_effect('pink_boss_block_effect.png',
                                                   250, 250, 8, 30)
             particle_emitter1 = self.create_attack(position, damage1, stun1,
                                                   cooldown1, proj1, proj_image,
                                                   proj_anim_list, proj_anim_time_list,
                                                   proj_width, proj_height,
                                                   proj_life1, proj_speed1, [0,0],
                                                   spread1, effect_ID)
             particle_emitter1.piercing = att1_pierce
             attack_list.append(particle_emitter1)
             #Attack 2
             damage2 = None
             if "att_2_damage" in tile_properties:
                 damage2 = int(tile_properties["att_2_damage"])
             if "att_2_stun" in tile_properties:
                 stun2 = int(tile_properties["att_2_stun"])
             if "att_2_cooldown" in tile_properties:
                 cooldown2 = int(tile_properties["att_2_cooldown"])
             if "att_2_projectile_amount" in tile_properties:
                 proj2 = int(tile_properties["att_2_projectile_amount"])
             if "att_2_projectile_lifetime" in tile_properties:
                 proj_life2 = int(tile_properties["att_2_projectile_lifetime"])
             if "att_2_spread_angle" in tile_properties:
                 spread2 = int(tile_properties["att_2_spread_angle"])
             if "att_2_projectile_speed" in tile_properties:
                 proj_speed2 = int(tile_properties["att_2_projectile_speed"])
             if "att_2_pierce" in tile_properties:
                 att2_pierce = tile_properties["att_2_pierce"] == "1"
             #Create projectile image
             if ai_ID == "pink_boss":
                 proj_image = "pink_proj.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [50, 13]
                 proj_width = 32
                 proj_height = 32
             if damage2: #Attack exists
                 particle_emitter2 = self.create_attack(position, damage2, stun2,
                                                       cooldown2, proj2, proj_image,
                                                       proj_anim_list, proj_anim_time_list,
                                                       proj_width, proj_height,
                                                       proj_life2, proj_speed2, [0,0],
                                                       spread2)
                 particle_emitter2.piercing = att2_pierce
                 attack_list.append(particle_emitter2)
             #Attack 3
             damage3 = None
             if "att_3_damage" in tile_properties:
                 damage3 = int(tile_properties["att_3_damage"])
             if "att_3_stun" in tile_properties:
                 stun3 = int(tile_properties["att_3_stun"])
             if "att_3_cooldown" in tile_properties:
                 cooldown3 = int(tile_properties["att_3_cooldown"])
             if "att_3_projectile_amount" in tile_properties:
                 proj3 = int(tile_properties["att_3_projectile_amount"])
             if "att_3_projectile_lifetime" in tile_properties:
                 proj_life3 = int(tile_properties["att_3_projectile_lifetime"])
             if "att_3_spread_angle" in tile_properties:
                 spread3 = int(tile_properties["att_3_spread_angle"])
             if "att_3_projectile_speed" in tile_properties:
                 proj_speed3 = int(tile_properties["att_3_projectile_speed"])
             if "att_3_pierce" in tile_properties:
                 att3_pierce = tile_properties["att_3_pierce"] == "1"
             #Create projectile image
             effect_ID = None
             if ai_ID == "pink_boss":
                 proj_image = "pink_proj.png"
                 proj_anim_list = [2, 2]
                 proj_anim_time_list = [50, 13]
                 proj_width = 32
                 proj_height = 32
                 effect_ID = self.create_attack_effect('tentakel2.png',
                                                   200, 200, 8, 52)
             if damage3: #Attack exists
                 particle_emitter3 = self.create_attack(position, damage3, stun3,
                                                       cooldown3, proj3, proj_image,
                                                       proj_anim_list, proj_anim_time_list,
                                                       proj_width, proj_height,
                                                       proj_life3, proj_speed3, [0,0],
                                                       spread3, effect_ID)
                 particle_emitter3.piercing = att3_pierce
                 attack_list.append(particle_emitter3)
             
             self.create_enemy(position, hp, max_x_vel, max_y_vel,
                               attack_list, ai_ID, tags)
         elif tile_properties["type"] == "heal_potion":
             #Add fields
             recovery = int(tile_properties["recovery"])
             size = tile_properties["size"]
             tags = list()
             tags.append("heal_potion")
             collider = components.Collider(x*64, y*64, 64, 64, tags)
             image_name = 'heal_potion_s.png'
             if size == 'l':
                 image_name = 'heal_potion_l.png'
             elif size == 'm':
                 image_name = 'heal_potion_m.png'
             temp = pygame.image.load(os.path.join('data', image_name))
             heal_sprite = components.Appearance(temp.convert_alpha(), 32, 32, [9], [74])
             heal_sprite.rect.center = collider.center
             heal_pot = collectible.HealPotion(self, self.event_manager, recovery)
             colle_ID = self.create_entity((heal_sprite, heal_pot, collider))
             heal_pot.entity_ID = colle_ID
         elif tile_properties["type"] == "skill_up":
             tags = list()
             tag = None
             if "tag" in tile_properties:
                 tag = tile_properties["tag"]
                 tags.append(tag)
             collider = components.Collider(x*64, y*64, 64, 64, tags)
             if tag == "add_projectile":
                 temp = pygame.image.load(os.path.join('data', 'skill_additional_projectile.png'))
             elif tag == "pierce":
                 temp = pygame.image.load(os.path.join('data', 'skill_piercing_projectile.png'))
             skillup_sprite = components.Appearance(temp.convert_alpha(), 32, 32, [9], [74])
             skillup_sprite.rect.center = collider.center
             skillup_pot = collectible.SkillUp(self, self.event_manager)
             colle_ID = self.create_entity((skillup_sprite, skillup_pot, collider))
             skillup_pot.entity_ID = colle_ID
         elif tile_properties["type"] == "portal":
             x_pos = int(tile_properties["x"])
             y_pos = int(tile_properties["y"])
             # Calculate right position
             x_pos, y_pos = x_pos*64, y_pos*64
             collider = components.Collider(x*64+96, y*64+74, 64, 64)
             if tile_properties["setting"] == "pink":
                 temp = pygame.image.load(os.path.join('data', 'portal_pink.png'))
             elif tile_properties["setting"] == "green":
                 temp = pygame.image.load(os.path.join('data', 'portal_green.png'))
             else:
                 temp = pygame.image.load(os.path.join('data', 'portal.png'))
             portal_sprite = components.Appearance(temp.convert_alpha(), 256, 197, [8], [80])
             portal_sprite.rect.center = collider.center
             portal = collectible.Portal(self, self.event_manager, x_pos, y_pos)
             colle_ID = self.create_entity((portal_sprite, portal, collider))
             portal.entity_ID = colle_ID
コード例 #23
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):
        sheet_id = kwargs.get('sheet', 0)
        sheet = vars.tile_sheets[sheet_id]
        tl = kwargs.get('top_left')
        extend_down = args[3]
        pos = (args[0] * vars.tile_size, (args[1]) * vars.tile_size, args[2])
        x0 = tl[0]
        y0 = tl[1]
        data = args[4:]
        tiledata = dict()
        xmap = dict()
        cd = None
        x = 0
        y = 0
        cpoints = []
        cpoints.append((0, 0))
        left_border = False
        right_border = False
        for i in data:
            if i[-1] == 'S':
                tiledata[(x, y)] = (x0 + 3, y0 + 1)
                left_border = True
                x += 1
                cpoints.append((x, y))
                cd = 'R'
            elif i[-1] == 'E':
                tiledata[(x, y)] = (x0 + 4, y0 + 1)
                right_border = True
                x += 1
                cpoints.append((x, y))
            elif i[-1] == 'R':
                n = int(i[:-1])
                if cd == 'U':
                    y -= 1
                    tiledata[(x, y)] = (x0, y0)
                    x += 1
                    n -= 1
                elif cd == '/':
                    y -= 1
                elif cd == 'D':
                    tiledata[(x, y)] = (x0 + 2, y0 + 2)
                    x += 1
                elif cd == '\\':
                    x -= 1
                    tiledata[(x, y)] = (x0 + 2, y0 + 2)
                    x += 1
                for j in range(0, n):
                    tiledata[(x, y)] = (x0 + 1, y0)
                    x += 1
                cpoints.append((x, y))
                cd = i[-1]
            elif i[-1] == 'U':
                if cd == 'R':
                    tiledata[(x, y)] = (x0, y0 + 2)
                    y += 1
                elif cd == '/':
                    y -= 1
                    tiledata[(x, y)] = (x0, y0 + 2)
                # joint up
                n = int(i[:-1])
                for j in range(0, n):
                    tiledata[(x, y)] = (x0, y0 + 1)
                    y += 1
                cpoints.append((x, y - 1))
                cd = 'U'
            elif i[-1] == 'D':
                n = int(i[:-1])
                if cd == 'R':
                    x -= 1
                    tiledata[(x, y)] = (x0 + 2, y0)
                    y -= 1
                    n -= 1
                for j in range(0, n):
                    tiledata[(x, y)] = (x0 + 2, y0 + 1)
                    y -= 1
                cpoints.append((x + 1, y))
                cd = 'D'
            elif i[-1] == '/':
                # slope up
                n = int(i[:-1])
                if cd == 'R':
                    tiledata[(x, y)] = (x0, y0 + 2)
                    y += 1
                for i in range(0, n):
                    tiledata[(x, y)] = (x0 + 3, y0)
                    if i < n - 1:
                        tiledata[(x + 1, y)] = (x0, y0 + 2)
                    x += 1
                    y += 1
                cpoints.append((x, y - 1))
                cd = '/'
            elif i[-1] == '\\':
                # slope down
                n = int(i[:-1])
                if cd == 'D':
                    tiledata[(x, y)] = (x0 + 2, y0 + 2)
                    x += 1
                for i in range(0, n):
                    tiledata[(x, y)] = (x0 + 4, y0)
                    if i < n - 1:
                        tiledata[(x, y - 1)] = (x0 + 2, y0 + 2)
                    x += 1
                    y -= 1
                cpoints.append((x, y))
                cd = '\\'
        print(cpoints)
        xmin = 0
        xmax = 0
        ymin = 0
        ymax = 0

        for t in tiledata.keys():
            xmin = min(xmin, t[0])
            xmax = max(xmax, t[0])
            ymin = min(ymin, t[1])
            ymax = max(ymax, t[1])
        ymin -= extend_down
        width = xmax - xmin + 1
        height = ymax - ymin + 1
        for ix in range(xmin, xmax + 1):
            for iy in range(ymin, ymax + 1):
                if (ix, iy) in tiledata:
                    break
                if ix == 0 and left_border:
                    tiledata[(ix, iy)] = (x0 + 3, y0 + 2)
                elif ix == xmax and right_border:
                    tiledata[(ix, iy)] = (x0 + 4, y0 + 2)
                else:
                    tiledata[(ix, iy)] = (x0 + 1, y0 + 1)
        tdata = []
        for iy in range(ymin, ymax + 1):
            for ix in range(xmin, xmax + 1):
                td = tiledata.get((ix, iy), None)
                if td:
                    tdata.extend([td[0], td[1]])
                else:
                    tdata.extend([-1])
        pos = (args[0] * vars.tile_size,
               (args[1] - 1 - abs(ymin)) * vars.tile_size, args[2])
        e = entity.Entity(pos=pos)
        e.add_component(
            comp.TiledGfx(tile_sheet=sheet['file'],
                          sheet_size=sheet['sheet_size'],
                          tile_data=tdata,
                          width=width,
                          height=height,
                          size=vars.tile_size))
        for i in range(1, len(cpoints)):
            a = entity.Entity()
            a.add_component(
                comp.Collider(
                    debug=True,
                    flag=vars.flags.platform_passthrough,
                    mask=0,
                    tag=0,
                    shape=sh.Line(a=[
                        cpoints[i - 1][0] * vars.tile_size,
                        (cpoints[i - 1][1] + 1 + abs(ymin)) * vars.tile_size
                    ],
                                  b=[
                                      cpoints[i][0] * vars.tile_size,
                                      (cpoints[i][1] + 1 + abs(ymin)) *
                                      vars.tile_size
                                  ])))
            e.add(a)
        return e