Exemple #1
0
def next_level(gamestart=False):
    global finish, level, level_width, level_height, player1, player2
    global all_sprites, player_group, tile_group
    global tile_size, displace, width
    level, level_width, level_height = load_level(levels[current_level %
                                                         len(levels)])

    width, height = 350, 350
    screen = pygame.display.set_mode(
        (width, height),
        pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
    pygame.display.set_caption("Run")
    pygame.display.set_icon(load_image("invert.png"))

    width_fraction = 0.9
    displace = (width - int(width_fraction * width)) // 2
    width = int(width_fraction * width)
    tile_size = width // level_width
    displace += (width - tile_size * level_width) / 2

    if gamestart:
        start_screen(["QR", "WASD <^>"], screen, height)

    all_sprites = pygame.sprite.Group()
    player_group = pygame.sprite.Group()
    tile_group = pygame.sprite.Group()

    player1, player2 = generate_level(level, all_sprites, tile_group,
                                      player_group, tile_size)

    for sprite in all_sprites:
        sprite.rect.x += displace
    finish = Finish()
    finish_screen([
        "Stage Over!",
        play(screen, height),
        str(SCORE[1]) + " : " + str(SCORE[2]), "SPACE to continue"
    ], screen, height)
Exemple #2
0
    def update(self):

        # -- Position Management --

        self.pos.x += self.vel.x
        self.rect.x = self.pos.x
        self.super_jump = False

        self.collided = pygame.sprite.spritecollide(self, public.blocks, False)
        for block in self.collided:

            if block.color != public.bg_type:

                if self.vel.x > 0 and functions.block_check(block, 4):
                    self.rect.right = block.rect.left

                elif self.vel.x < 0 and functions.block_check(block, 4):
                    self.rect.left = block.rect.right

                if functions.block_check(block, 2):
                    self.accelerating = False

                self.pos.x = self.rect.x

                if block.type in ['Pit', 'KillBlock'] and not self.died:
                    self.died = True
                    self.anim_ticks = 0
                    self.anim_index = 0
                    dictionaries.MEDIA['died'].play()

                elif block.type == 'Exit' and not self.died:
                    public.level += 1

                    if public.level == public.level_max:
                        pass

                    elif public.level != public.level_max:
                        functions.generate_level(True)
                        dictionaries.MEDIA['finish'].play()

                        self.kill()

                elif block.type == 'Breakable':
                    if not block.dead and not block.recovering:
                        dictionaries.MEDIA['crumble'].play()
                        block.broken = True

                elif block.type == 'Jumpad' and not (self.died
                                                     and self.super_jump):

                    if not self.super_jump:
                        dictionaries.MEDIA['jumpad'].play()
                        self.super_jump = True

                    self.vel.y = -4.5
                    self.on_ground = False

                elif block.type == 'RGBSphere':
                    dictionaries.MEDIA['collect'].play()
                    block.rect.y -= 10
                    self.won = True

        self.pos.y += self.vel.y
        self.rect.y = self.pos.y
        self.super_jump = False

        self.collided = pygame.sprite.spritecollide(self, public.blocks, False)
        for block in self.collided:

            if block.color != public.bg_type:

                if self.vel.y > 0 and functions.block_check(block, 4):
                    self.rect.bottom = block.rect.top
                    self.on_ground = True
                    self.vel.y = 0

                elif self.vel.y < 0 and functions.block_check(block, 4):
                    self.rect.top = block.rect.bottom
                    self.on_ground = True
                    self.vel.y = 0

                if functions.block_check(block, 2):
                    self.super_jump = False
                    self.jumping = False

                self.pos.y = self.rect.y

                if block.type in ['Pit', 'KillBlock'] and not self.died:
                    self.died = True
                    self.anim_ticks = 0
                    self.anim_index = 0
                    dictionaries.MEDIA['died'].play()

                elif block.type == 'Pit' and not self.died:
                    self.died = True
                    self.anim_ticks = 0
                    self.anim_index = 0
                    dictionaries.MEDIA['died'].play()

                elif block.type == 'Breakable':
                    if not block.dead and not block.recovering:
                        dictionaries.MEDIA['crumble'].play()
                        block.broken = True

        if public.wrapping:
            if self.rect.right >= public.SWIDTH + 10:
                self.rect.left = 1
                self.pos.x = self.rect.left

            elif self.rect.right <= 0:
                self.rect.right = public.SWIDTH - 1
                self.pos.x = self.rect.left

        elif not public.wrapping:
            if self.rect.right >= public.SWIDTH:
                self.rect.right = public.SWIDTH
                self.accelerating = False
                self.pos.x = self.rect.left

            elif self.rect.left <= 0:
                self.rect.left = 0
                self.accelerating = False
                self.pos.x = self.rect.left

        if self.rect.top >= public.SHEIGHT and not self.died:
            self.died = True
            self.anim_ticks = 0
            self.anim_index = 0
            dictionaries.MEDIA['died'].play()

        self.vel.y += public.GRAVITY

        if self.vel.y < -0.5 or self.vel.y > 0.5 and not self.jumping:
            self.on_ground = False

        if public.level == 0:
            public.player.vel.x = functions.clamp(public.player.vel.x, -5.0,
                                                  5.0)

        else:
            public.player.vel.x = functions.clamp(public.player.vel.x, -10.0,
                                                  10.0)

        public.player.pos.x += public.player.vel.x
        public.player.vel.x *= 0.925

        # -- Animation --

        self.anim_ticks += 1

        if self.anim_ticks == self.anim_caps[self.anim_type]:
            self.anim_index = (self.anim_index + 1) % 4
            self.anim_ticks = 0

        else:
            if self.anim_ticks > self.anim_caps[self.anim_type]:
                self.anim_ticks = 0

        self.anim_type = functions.anim_check(self)

        if self.died and self.anim_index == 3:
            if public.level == 0:
                raise Exception(
                    '@!^& // Sometimes its better to let secrets be secrets. // %$#&'
                )

            functions.generate_level(False)
        self.image = dictionaries.IMAGES[self.anim_type]
        self.invert = dictionaries.I_IMAGES[self.anim_type]

        if self.flip_cooldown > 0:
            self.flip_cooldown -= public.dt
Exemple #3
0
def game():
    if public.music:
        dictionaries.MEDIA['greetings'].play(-1)

    functions.generate_clouds()
    functions.generate_level(True)

    dt = public.clock.tick(public.FPS) / 1000
    cover_alpha = 0
    cover_surf = pygame.Surface((public.SWIDTH, public.SHEIGHT))
    cover_surf.set_alpha(cover_alpha)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return 0

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_w:
                    public.player.jump()

                elif event.key == pygame.K_SPACE:
                    public.player.flip()

        keys = pygame.key.get_pressed()

        if keys[pygame.K_d] and not (public.player.died or public.player.won):

            public.player.move('right')

        elif keys[pygame.K_a] and not (public.player.died or public.player.won):

            public.player.move('left')

        else:
            public.player.accelerating = False

        if public.player.won and cover_alpha != 255:
            cover_alpha += 1
            cover_surf.set_alpha(cover_alpha)

            if cover_alpha == 255:
                end('A GAME BY TEAM-ABSTRACTANDROID')
                return 0

        if public.level == public.level_max:
            end('More levels to come soon!')
            return 0

        public.all_sprites.update()

        sorted_sprites = sorted(
            public.all_sprites.sprites(), key=lambda x: x.layer)

        public.screen.fill([public.bg_type] * 3)

        for sprite in sorted_sprites:
            sprite.draw()

        public.screen.blit(cover_surf, (0, 0))

        pygame.display.flip()
        public.clock.tick(public.FPS)
Exemple #4
0
    def update(self):

        # -- Position Management --

        self.pos.x += self.vel.x
        self.rect.x = self.pos.x
        self.super_jump = False

        self.collided = pygame.sprite.spritecollide(self, public.blocks, False)
        for block in self.collided:

            if block.color != public.bg_type:

                if self.vel.x > 0 and functions.block_check(block, 3):
                    self.rect.right = block.rect.left

                elif self.vel.x < 0 and functions.block_check(block, 3):
                    self.rect.left = block.rect.right

                if functions.block_check(block, 2):
                    self.accelerating = False

                self.pos.x = self.rect.x

                if block.type == 'Pit' and not self.died:
                    self.died = True
                    self.anim_ticks = 0
                    self.anim_index = 0
                    dictionaries.MEDIA['died'].play()

                elif block.type == 'Exit' and not self.died:
                    public.level += 1
                    functions.generate_level(True)
                    dictionaries.MEDIA['finish'].play()

                    if public.level == 21:
                        dictionaries.MEDIA['greetings'].stop()
                        dictionaries.MEDIA['deathly'].play(-1)

                    self.kill()

                elif block.type == 'Breakable':
                    dictionaries.MEDIA['crumble'].play()
                    block.broken = True

                elif block.type == 'Jumpad' and not (self.died
                                                     and self.super_jump):
                    if self.flipped and block.direction == 'D':
                        self.vel.y = 4.5

                    elif not self.flipped and block.direction == 'U':
                        self.vel.y = -4.5

                    self.on_ground = False
                    self.super_jump = True

                elif block.type == 'Flipad' and not self.died:
                    if block.direction == 'D' and self.flipped:
                        dictionaries.MEDIA['flipad'].play()
                        self.flipped = False
                        self.vel.y = 2

                    elif block.direction == 'U' and not self.flipped:
                        dictionaries.MEDIA['flipad'].play()
                        self.flipped = True
                        self.vel.y = -2

                elif block.type == 'RGBSphere':
                    dictionaries.MEDIA['collect'].play()
                    block.rect.y -= 10
                    self.won = True

        self.pos.y += self.vel.y
        self.rect.y = self.pos.y
        self.super_jump = False

        self.collided = pygame.sprite.spritecollide(self, public.blocks, False)
        for block in self.collided:

            if block.color != public.bg_type:

                if self.vel.y > 0 and functions.block_check(block, 3):
                    self.rect.bottom = block.rect.top
                    self.on_ground = True
                    self.vel.y = 0

                elif self.vel.y < 0 and functions.block_check(block, 3):
                    self.rect.top = block.rect.bottom
                    self.on_ground = True
                    self.vel.y = 0

                if functions.block_check(block, 2):
                    self.super_jump = False
                    self.jumping = False

                self.pos.y = self.rect.y

                if block.type == 'Pit' and not self.died:
                    self.died = True
                    self.anim_ticks = 0
                    self.anim_index = 0
                    dictionaries.MEDIA['died'].play()

                elif block.type == 'Breakable':
                    dictionaries.MEDIA['crumble'].play()
                    block.broken = True

                elif block.type == 'Jumpad' and not (self.died
                                                     and self.super_jump):
                    if self.flipped and block.direction == 'D':
                        self.vel.y = 4.5
                        dictionaries.MEDIA['jumpad'].play()

                    elif not self.flipped and block.direction == 'U':
                        self.vel.y = -4.5
                        dictionaries.MEDIA['jumpad'].play()

                    self.on_ground = False
                    self.super_jump = True

                elif block.type == 'Flipad' and not self.died:
                    if block.direction == 'D' and self.flipped:
                        dictionaries.MEDIA['flipad'].play()
                        self.flipped = False
                        self.vel.y = 2

                    elif block.direction == 'U' and not self.flipped:
                        dictionaries.MEDIA['flipad'].play()
                        self.flipped = True
                        self.vel.y = -2

                elif block.type == 'RGBSphere':
                    dictionaries.MEDIA['collect'].play()
                    block.rect.y -= 10
                    self.won = True

        if public.wrapping:
            if self.rect.right >= public.SWIDTH + 10:
                self.rect.left = 1
                self.pos.x = self.rect.left

            elif self.rect.right <= 0:
                self.rect.right = public.SWIDTH - 1
                self.pos.x = self.rect.left

        elif not public.wrapping:
            if self.rect.right >= public.SWIDTH:
                self.rect.right = public.SWIDTH
                self.accelerating = False
                self.pos.x = self.rect.left

            elif self.rect.left <= 0:
                self.rect.left = 0
                self.accelerating = False
                self.pos.x = self.rect.left

        if self.rect.top <= -10 and not self.died:
            self.died = True
            dictionaries.MEDIA['died'].play()

        if self.flipped:
            self.vel.y -= public.GRAVITY

        elif not self.flipped:
            self.vel.y += public.GRAVITY

        if self.vel.y < -0.5 or self.vel.y > 0.5 and not self.jumping:
            self.on_ground = False

        public.player.vel.x = functions.clamp(public.player.vel.x, -10.0, 10.0)
        public.player.pos.x += public.player.vel.x
        public.player.vel.x *= 0.925

        # -- Animation --

        self.anim_ticks += 1

        if self.anim_ticks == self.anim_caps[self.anim_type]:
            self.anim_index = (self.anim_index + 1) % 4
            self.anim_ticks = 0

        else:
            if self.anim_ticks > self.anim_caps[self.anim_type]:
                self.anim_ticks = 0

        self.anim_type = functions.anim_check(self)

        if self.died and self.anim_index == 3:
            functions.generate_level(False)

        self.image = dictionaries.IMAGES[self.anim_type]
        self.invert = dictionaries.I_IMAGES[self.anim_type]

        if self.flip_cooldown > 0:
            self.flip_cooldown -= public.dt
Exemple #5
0
     checkpoint = data['first']['checkpoint']
     path.write_text(json.dumps(data), encoding='utf-8')
     if checkpoint == 2:
         level_name = '2'
     startsc = False
 elif 400 <= y <= 435 and 538 <= x <= 738:
     per = get('http://127.0.0.1:8800/levels_get').json()
     level_x = per['ok']
     level_name = level_x[0]
     level = level_x[1:]
     level = level.split('\n')
     screen.fill((255, 255, 255))
     screen.blit(loading_image, (0, 0))
     pygame.display.flip()
     player = generate_level(level, Tile, level_name, Player,
                             all_sprites, wall_group, load_image,
                             player_group)
     startsc = False
     web_level = True
 if not web_level:
     screen.fill((255, 255, 255))
     level = load_level(level_name)
     screen.blit(loading_image, (0, 0))
     pygame.display.flip()
     player = generate_level(level, Tile, level_name, Player,
                             all_sprites, wall_group, load_image,
                             player_group)
 marx = player[1]
 marx += 0.6
 marx2 = marx - 0.2
 mary = player[2] + 0.8