示例#1
0
def game_chess(surface: pygame.Surface, game, clock, keys):
    global SIZE
    SIZE = (main.window_size_x, main.window_size_y)
    quit = False
    selected = None
    board_rect = pygame.Rect(SIZE[0] * 0.1, SIZE[1] * 0.25, SIZE[0] * 0.3,
                             SIZE[0] * 0.3)
    board_rect2 = board_rect.copy()
    board_rect2.left += SIZE[0] / 2 + 5
    time = game.chess_time
    home = False
    while True:
        clock.tick(30)
        quit, selected, pause = Controller.chess(board_rect, board_rect2, game,
                                                 selected, keys)
        if pause:
            quit, home = pause_menu(surface, keys)
            clock.tick(30)
        else:
            game.chess_time -= clock.get_time() / 1000
            if game.board.turn:
                game.p1.time -= clock.get_time() / 1000
                p = False
                if game.p1.move_time >= 3:
                    p = True
                game.p1.move_time -= clock.get_time() / 1000
                if game.p1.move_time <= 3:
                    if p:
                        Model.AudioController('count.wav', 0.2)

                if game.p1.time <= 0 or game.p1.move_time <= 0:
                    game.winner = game.p2

            else:
                game.p2.move_time -= clock.get_time() / 1000
                p = False
                if game.p2.move_time >= 3:
                    p = True
                game.p2.time -= clock.get_time() / 1000
                if game.p1.move_time <= 3:
                    if p:
                        Model.AudioController('count.wav', 0.2)
                if game.p1.time <= 0 or game.p2.move_time <= 0:
                    game.winner = game.p1
            if game.chess_time <= 0:
                game.chess_time = 60
                break
        if quit or home:
            break
        chess_update(surface, game, selected, board_rect, board_rect2)

        pygame.display.flip()
        if game.winner:
            quit, home = game_end(surface, game, keys)
            if quit or home:
                break
    return quit, home
示例#2
0
def countdown(surface, game, clock, keys):
    global SIZE
    SIZE = (main.window_size_x, main.window_size_y)
    time = 3
    font = pygame.font.Font('freesansbold.ttf', 200)
    t = 3
    Model.AudioController('count.wav', 0.2)
    while True:
        clock.tick(10)
        surface.fill(BLACK)
        time -= clock.get_time() / 1000
        quit = Controller.count(keys)
        if quit:
            break
        te = None
        if time + 1 <= t and t > 0:
            t -= 1
            Model.AudioController('count.wav', 0.2)
        if time > 0:

            text = font.render(str(int(time) + 1), True, WHITE, BLACK)
            textRect = text.get_rect()
            textRect.center = (SIZE[0] / 2, SIZE[1] / 2)
            surface.blit(text, textRect)
            te = textRect.bottom

        else:
            text = font.render("GO!", True, WHITE, BLACK)
            textRect = text.get_rect()
            textRect.center = (SIZE[0] / 2, SIZE[1] / 2)
            surface.blit(text, textRect)
            te = textRect.bottom
        secondfont = pygame.font.Font('freesansbold.ttf', 50)
        if game.round % 2 == 0:
            text = "Martial Arts"
        else:
            text = "Chess"
        text = secondfont.render(f"Round {str(game.round)}: {text}", True,
                                 WHITE, BLACK)
        textRect = text.get_rect()
        textRect.midtop = (SIZE[0] / 2, te + 10)
        surface.blit(text, textRect)
        if time <= -1:
            break
        pygame.display.flip()
    return quit
示例#3
0
def game_fight(surface: pygame.Surface, game, clock, keys):
    global SIZE
    SIZE = (main.window_size_x, main.window_size_y)
    quit = False
    bkgrnd = str(randint(2, 5))
    #     bkgrnd = '5'

    blit_image(surface, ['Background', bkgrnd + '.png'], "topleft", (0, 0),
               (int(SIZE[0]), int(SIZE[1])))
    #     blit_image(surface, ['Martial Hero', 'Sprites', 'Idle.png'], "topleft", (0,0))

    p1 = game.p1.fighter
    p2 = game.p2.fighter
    pl = False
    pr = False
    p1j = False
    pl2 = False
    pr2 = False
    p2j = False
    home = False
    zone = None

    font = pygame.font.Font('freesansbold.ttf', 100)
    text = font.render(f"Zone closing in", True, PURPLE, BLACK)
    inc = True
    textRect = text.get_rect()
    textRect.center = (SIZE[0] * 0.3, SIZE[1] * 0.1)
    zoneWarn = pygame.Surface((SIZE[0] * 0.6, SIZE[1] * 0.2))
    pygame.draw.rect(zoneWarn, PURPLE, pygame.Rect((0, 0),
                                                   zoneWarn.get_size()), 5)
    zoneWarn.blit(text, textRect)
    zoneWarn.set_alpha(255)
    if game.round >= 6:
        meteor = Model.MeteorWarning(100, int(SIZE[1] * 0.8), (255, 122, 0))
    else:
        meteor = None
    music = Model.AudioController('fight.wav', 0.2, -1)
    if meteor:
        meteorx = randint(0, SIZE[0] - 100)
    while True:
        clock.tick(30)
        surface.fill((0, 0, 0))

        if game.fight_time < 25 and not zone and game.round >= 6:
            zone = Model.Zone(350, 100, p1, p2)
        quit, pause, shoot, pl, pr, p1j, shoot2, pl2, pr2, p2j, s1, s2 = Controller.fight1(
            game, pl, pr, p1j, pl2, pr2, p2j, keys)
        if meteor:
            if meteor.update():
                meteorx = randint(0, SIZE[0] - 100)
            meteor_rect = meteor.meteor.rect.copy()
            meteor_rect.left = meteorx
            meteor_back = False
            if p1.rect:
                if meteor_rect.colliderect(p1.rect):
                    meteor_back = True
                    p1.take_damage(10, meteor_rect.centerx)
            if p2.rect:
                if meteor_rect.colliderect(p2.rect):
                    meteor_back = True
                    p2.take_damage(10, meteor_rect.centerx)
            if meteor_back:
                meteorx = randint(0, SIZE[0] - 100)
                meteor.dropping = False
                meteor.surface.fill(meteor.color)
                meteor.surface.set_alpha(125)
                meteor.meteor.set_y(-50)

                meteor.dropping = False
        if pl2 and not pr2 and p2.animation != TAKE_HIT and p2.rect.left > p2.speed:
            p2.dir = False
            p2.x -= p2.speed
            if not p2.animation in [ATTACK_ONE, ATTACK_TWO, RUN]:
                p2.animate(2, RUN, True)
        elif pr2 and not pl2 and p2.animation != TAKE_HIT and p2.rect.right < SIZE[
                0] - p2.speed:
            p2.dir = True
            p2.x += p2.speed
            if not p2.animation in [ATTACK_ONE, ATTACK_TWO, RUN]:
                p2.animate(2, RUN, True)
        else:
            if not p2.animation in [ATTACK_ONE, ATTACK_TWO, TAKE_HIT]:
                p2.animation = IDLE
        if p2j and p2.y >= SIZE[1] * 0.8:
            p2.jump()
        if shoot2 and p2.t1 >= p2.cd1 and not p2.animation in [
                ATTACK_ONE, ATTACK_TWO
        ]:
            p2.animate(2, ATTACK_ONE, False)
            p2.t1 = 0
        if s2 and p2.t2 >= p2.cd2 and not p2.animation in [
                ATTACK_ONE, ATTACK_TWO
        ]:
            p2.animate(2, ATTACK_TWO, False)
            Martials.Bullet(2, game.p2.fighter, game.p1.fighter)
            p2.t2 = 0

        if pl and not pr and p1.animation != TAKE_HIT and p1.rect.left > p1.speed:
            p1.dir = False
            p1.x -= p1.speed
            if not p1.animation in [ATTACK_ONE, ATTACK_TWO, RUN]:
                p1.animate(2, RUN, True)
        elif pr and not pl and p1.animation != TAKE_HIT and p1.rect.right < SIZE[
                0] - p1.speed:
            p1.dir = True
            p1.x += p1.speed
            if not p1.animation in [ATTACK_ONE, ATTACK_TWO, RUN]:
                p1.animate(2, RUN, True)
        else:
            if not p1.animation in [ATTACK_ONE, ATTACK_TWO, TAKE_HIT]:
                p1.animation = IDLE
        if p1j and p1.y >= SIZE[1] * 0.8:
            p1.jump()

        if shoot and p1.t1 >= p1.cd1 and not p1.animation in [
                ATTACK_ONE, ATTACK_TWO
        ]:
            p1.animate(2, ATTACK_ONE, False)
            p1.t1 = 0
        if s1 and p1.t2 >= p1.cd2 and not p1.animation in [
                ATTACK_ONE, ATTACK_TWO
        ]:
            p1.animate(2, ATTACK_TWO, False)
            Martials.Bullet(1, game.p1.fighter, game.p2.fighter)
            p1.t2 = 0
        blit_image(surface, ['Background', bkgrnd + '.png'], "topleft", (0, 0),
                   (int(SIZE[0]), int(SIZE[1] * 0.8)))
        if meteor:
            surface.blit(meteor.surface, (meteorx, 0))
        if zone:
            zone.update()
            ts = zone.draw()
            ts.set_colorkey(ts.get_at((0, 0)))
            ts.set_colorkey(BLACK)
            surface.blit(ts, (0, 0))
            pygame.draw.line(surface, (255, 0, 255), (zone.left, 0),
                             (zone.left, SIZE[1] * 0.8), 3)
            pygame.draw.line(surface, (255, 0, 255), (zone.right, 0),
                             (zone.right, SIZE[1] * 0.8), 3)
            pygame.draw.line(surface, (255, 255, 255), (zone.dest_left, 0),
                             (zone.dest_left, SIZE[1] * 0.8), 3)
            pygame.draw.line(surface, (255, 255, 255), (zone.dest_right, 0),
                             (zone.dest_right, SIZE[1] * 0.8), 3)
        p1.update(p2)
        p1_surface = p1.draw()
        p2.update(p1)
        p2_surface = p2.draw()
        if 25 < game.fight_time < 28 and game.round >= 6:
            zr = pygame.Rect((0, 0), zoneWarn.get_size())
            zr.center = (SIZE[0] / 2, SIZE[1] * 0.4)
            surface.blit(zoneWarn, zr)
            if inc:
                zoneWarn.set_alpha(zoneWarn.get_alpha() - 50)
            else:
                zoneWarn.set_alpha(zoneWarn.get_alpha() + 50)
            if zoneWarn.get_alpha() <= 0 or zoneWarn.get_alpha() >= 255:
                inc = not inc
        surface.blit(p1_surface, p1.rect)
        surface.blit(p2_surface, p2.rect)

        for i in Martials.Bullet.bullets:
            i.update()
            i.draw(surface)
        update_UI(surface, game)

        pygame.display.flip()
        if quit:
            break

        if game.p1.consciousness <= 0:
            game.winner = game.p2

            quit, home = game_end(surface, game, keys)
        if game.p2.consciousness <= 0:
            game.winner = game.p1
            quit, home = game_end(surface, game, keys)
        if pause:
            quit, home = pause_menu(surface, keys)
            clock.tick()
        else:
            game.fight_time -= clock.get_time() / 1000
        if quit or home:
            break
        if game.fight_time <= 0:
            game.fight_time = 30
            break
        pygame.display.flip()
    music.stop()
    return quit, home