Exemplo n.º 1
0
def start_screen():  # Выполняется до начала игры
    # создание кнопок
    menu_buttons = [
        Sprite(general.load_image('fon.jpg'), Transform((0, 0))),
        Sprite(general.load_image('title.png'), Transform((560, 80))),
        Button(general.load_image('btn_start.png'), Transform((710, 500)),
               start_game, general.buttons_group),
        Button(general.load_image('btn_exit.png'), Transform((760, 700)),
               terminate, general.buttons_group)
    ]
    while is_menu:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                terminate()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                general.buttons_group.update(event.pos)
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    terminate()
        general.all_sprites.update()
        general.all_sprites.draw(general.screen)
        pygame.display.flip()
        general.clock.tick(general.FPS)
    # удаление кнопок
    for btn in menu_buttons:
        btn.kill()
Exemplo n.º 2
0
def make_enemy(game):
    return GameObject(game, components = [
        Sprite('brick.png', size = Vector2(32, 32)), 
        Follow(target=game.player), 
        Wiggle(1), 
        Physics(debug_color = (255,0,0,50))
    ])
Exemplo n.º 3
0
 def initialize_player(self, x, y):
     """ initializes a player entity at x, y
     """
     position = Position(x, y)
     player_rect = pg.Rect(position.x, position.y, 32, 32)
     collider = Collider(
         layer=0b00000001,
         mask=0b11111110,
         rect=player_rect,
         callbacks={
             # floor
             0b00000010: self.player_floor,
         },
         debug=DEBUG
     )
     sprite = Sprite(
         base_image=self.images[0],
         anims=[],
         rect=player_rect,
     )
     physics = Physics(
         gravity=75,
         air_friction=0,
         ground_friction=1,
     )
     player_id = self.create_entity(position)
     self.add_component(player_id, collider)
     self.add_component(player_id, sprite)
     self.add_component(player_id, Input())
     self.add_component(player_id, physics)
Exemplo n.º 4
0
def load_map():  # Загрузка карты
    for y in range(len(map_txt)):
        for x in range(len(map_txt[y])):
            platform = map_txt[y][x]
            if platform == '#':
                platform = '#-'

                key = up_or_down(x, y, platform)
                key += ' ' + right_or_left(x, y, platform)

                if key == ' ' and map_txt[y][x + 1] in platform and map_txt[y - 1][x] in platform \
                        and map_txt[y - 1][x + 1] not in platform:
                    key = 'descent'

                Sprite(platforms[KEY_PLATFORM[key.strip(' ')]],
                       Transform((x * 100, y * 100)), borders_group)

            elif platform == '-':
                key = 'bridge '
                key += right_or_left(x, y, platform)
                Sprite(platforms[KEY_PLATFORM[key.strip(' ')]],
                       Transform((x * 100, y * 100)), borders_group)

            elif platform == '=':
                key = 'iron '
                key += right_or_left(x, y, platform)
                Sprite(irons[KEY_PLATFORM[key.strip(' ')]],
                       Transform((x * 100, y * 100)), borders_group)
                if 'left' in key:
                    Sprite(load_image('Tros.png'),
                           Transform((x * 100 + 40, y * 100 - 2000)))
                elif 'right' in key:
                    Sprite(load_image('Tros.png'),
                           Transform((x * 100 + 50, y * 100 - 2000)))

            elif platform == '|':
                for i in range(20):
                    Sprite(load_image('rope.png'),
                           Transform((x * 100, y * 100 - 100 * i)),
                           ropes_group)
            elif platform == 'f':
                Sprite(load_image('flag.png'), Transform((x * 100, y * 100)))
            elif platform == 'b':
                Bandages(load_image('bandages.png'),
                         Transform((x * 100, y * 100)))

    # Добавление врагов после прогрузки карты для того, что бы плаформы не были на врагах
    for y in range(len(map_txt)):
        for x in range(len(map_txt[y])):
            platform = map_txt[y][x]
            if platform == '1':
                Enemy(0, Transform((x * 100, y * 100)))
            elif platform == '2':
                Enemy(1, Transform((x * 100, y * 100)))
            elif platform == '3':
                Enemy(2, Transform((x * 100, y * 100)))
            elif platform == '4':
                Enemy(3, Transform((x * 100, y * 100)))
            elif platform == '5':
                Enemy(4, Transform((x * 100, y * 100)))
Exemplo n.º 5
0
    def spriteDrawController(self, assetAddress, drawType):
        if drawType == "sprite":
            self.sprites.append(Sprite(QImage(assetAddress)))
            self.update()

        elif drawType == "sprite type 2":
            print("draw sprite type 2")
        else:
            print("draw other sprite")
Exemplo n.º 6
0
 def initialize_floor(self, x, y):
     position = Position(x, y)
     floor_rect = (x, y, 100, 20)
     collider = Collider(
         layer=0b00000010,
         mask=0b00000000,
         rect=floor_rect,
         callbacks={},
         debug=DEBUG
     )
     sprite = Sprite(
         base_image=None,
         anims=[],
         rect=floor_rect
     )
     floor_id = self.create_entity(position, collider)
     self.add_component(floor_id, position)
     self.add_component(floor_id, collider)
     self.add_component(floor_id, sprite)
Exemplo n.º 7
0
def make_wall(game, pos):
    return GameObject(game, components = [
        Sprite('block.png'), 
        Physics(pos = pos, debug_color = (150,150,255,50), is_dynamic=False)
    ])
Exemplo n.º 8
0
def make_player(game):
    return GameObject(game, components = [
        Sprite('tank_0.png', size = Vector2(32, 32)), 
        WASDControlled(200), 
        Physics(debug_color = (0,255,0,50))
    ])
Exemplo n.º 9
0
clock = pygame.time.Clock()

w = World(size=1024, tilesize=32)
s = Screen(800, 800)

gs = GraphicsSystem()
cs = ControlSystem()
ss = SpriteSystem()

p = Entity(w)
p.camera = Camera(0, 0, 800, 800, track=True, entitytotrack=p)
p.position = Position(0, 0, 32, 32, 2)
p.control = Control(pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT)
p.state = State()

p.sprite = Sprite()
p.sprite.sprites['idle'] = [
    pygame.image.load('images/player/idle.png'),
    pygame.image.load('images/player/idle2.png'),
    pygame.image.load('images/player/idle3.png')
]
p.sprite.animate = True

running = True

while running:
    # clear screen
    s.screen.fill((0, 0, 0))

    # quit if window closed
    for event in pygame.event.get():