Beispiel #1
0
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    # to avoid conflict there can be multiple wad elements
    # of the same name so they are stored in a list
    level_music = wad['D_E1M1'][0]
    decoded_music = MusDecoder.decode_mus_to_midi(level_music)

    with open('music.mid', 'wb') as fd:
        fd.write(decoded_music)

    # test play midi file
    import pygame
    pygame.init()
    pygame.mixer.music.load(decoded_music)
    pygame.mixer.music.play()

    import time
    time.sleep(10)
Beispiel #2
0
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    for key in wad.flats:
        picture = wad.flats[key]
        path = "flats/{0}.jpeg".format(picture.name)
        print("trying to save: {0}".format(path))
        picture.save_jpeg(path, wad.playpals[0])
Beispiel #3
0
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    for texture in wad.texture1.textures:
        for patch in texture.patches:
            path = "textures/{0}_{1}.jpeg".format(texture.name,
                                                  patch.patch_name)
            picture = WadSprite.get_wad_picture_for_lump(patch.patch_lump)
            print("trying to save: {0}".format(path))
            picture.save_jpeg(path, wad.playpals[patch.colormap])
Beispiel #4
0
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    # to avoid conflict there can be multiple wad elements
    # of the same name so they are stored in a list
    level_music = wad['D_E1M1'][0]
    decoded_music = MusDecoder.decode_mus_to_midi(level_music)

    with open('music.mid', 'wb') as fd:
        fd.write(decoded_music)
Beispiel #5
0
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    for thing in wad.wad_levels["E1M9"].things:
        if thing.has_sprite is False:
            continue

        print(thing.definition)
        for sprite in thing.sprite:
            path = "things/{0}.jpeg".format(sprite.name)
            print("trying to save:", path)
            sprite.save_jpeg(path, wad.playpals[0])
Beispiel #6
0
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    level_to_render = "E1M1"

    level = wad.wad_levels[level_to_render]
    sectors, sides, lines, segs = level.compile_level()
    print("num sectors: {0}".format(len(sectors)))
    print("num sides: {0}".format(len(sides)))
    print("num lines: {0}".format(len(lines)))
    print("num segs: {0}".format(len(segs)))
    print("num nodes: {0}".format(len(level.nodes)))
    print("num vertexes: {0}".format(len(level.vertices)))
    print("num subsectors: {0}".format(len(level.sub_sectors)))

    for i in level.nodes:
        print(i)

    for i in level.things:
        print(i.definition)

    for i in level.sub_sectors:
        print(i)

    player_start = level.find_first_thing_by_name("PLAYER_1_START")
    print(player_start)

    root_node = level.root_node
    print(root_node)

    pygame.init()
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption("Render Player To Level {0} {1}".format(
        sys.argv[1], level_to_render))

    player = Player()
    player.position.x = player_start.x
    player.position.y = player_start.y
    player.angle = player_start.angle

    prev_time = time.time()
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT]:
            player.angle = player.angle - ROT_SPEED
        if keys[pygame.K_RIGHT]:
            player.angle = player.angle + ROT_SPEED

        if keys[pygame.K_UP] or keys[pygame.K_w]:
            player.move_player_pos(3, 0)
        if keys[pygame.K_DOWN] or keys[pygame.K_s]:
            player.move_player_pos(-3, 0)
        if keys[pygame.K_d]:
            player.move_player_pos(3, 180)
        if keys[pygame.K_a]:
            player.move_player_pos(-3, 180)

        # video buffer
        split_screen = pygame.Surface((WIDTH, HEIGHT))
        # clear
        split_screen.fill((0, 0, 0))

        # Draw wall, floor and ceiling

        pygame.draw.rect(split_screen, CEILING_COLOR,
                         pygame.Rect(0, 0, WIDTH, HEIGHT / 2))
        pygame.draw.rect(split_screen, FLOOR_COLOR,
                         pygame.Rect(0, HEIGHT / 2, WIDTH, HEIGHT / 2))

        for line in segs:
            # Wall absolute positions
            x1 = line.v1.x
            y1 = line.v1.y
            x2 = line.v2.x
            y2 = line.v2.y

            # Wall positions relative to player's position
            px1 = x1 - player.position.x
            py1 = y1 - player.position.y
            px2 = x2 - player.position.x
            py2 = y2 - player.position.y

            # Wall positions relative to player's position and rotation
            rx1 = math.cos(rad(-player.angle)) * px1 + math.sin(
                rad(-player.angle)) * py1
            ry1 = math.cos(rad(-player.angle)) * py1 - math.sin(
                rad(-player.angle)) * px1
            rx2 = math.cos(rad(-player.angle)) * px2 + math.sin(
                rad(-player.angle)) * py2
            ry2 = math.cos(rad(-player.angle)) * py2 - math.sin(
                rad(-player.angle)) * px2

            # Don't render walls behind us
            if ry1 <= 0 and ry2 <= 0:
                continue

            # Clip walls intersecting with user plane
            if ry1 <= 0 or ry2 <= 0:
                ix1 = intersect(rx1, ry1, rx2, ry2)
                if ry1 <= 0:
                    rx1 = ix1
                    ry1 = 0.01
                if ry2 <= 0:
                    rx2 = ix1
                    ry2 = 0.01

            # Wall positions relative to player's position, rotation and perspective
            zx1 = rx1 / ry1
            zu1 = WALL_HEIGHT / ry1  # Up   Z
            zd1 = -WALL_HEIGHT / ry1  # Down Z
            zx2 = rx2 / ry2
            zu2 = WALL_HEIGHT / ry2  # Up   Z
            zd2 = -WALL_HEIGHT / ry2  # Down Z

            # zx1 = rx1 / ry1
            # zu1 = WALL_HEIGHT / ry1  # Up   Z
            # zd1 = -WALL_HEIGHT / ry1  # Down Z
            # zx2 = rx2 / ry2
            # zu2 = WALL_HEIGHT / ry2  # Up   Z
            # zd2 = -WALL_HEIGHT / ry2  # Down Z

            poly = pygame.draw.polygon(split_screen, (100, 200, 150), [
                screen_coords_test(zx1, zd1),
                screen_coords_test(zx1, zu1),
                screen_coords_test(zx2, zu2),
                screen_coords_test(zx2, zd2)
            ], 0)

            #if line.side.top_texture:
            #    for t in line.side.top_texture.textures:
            #        for patch in t.patches:

        # Render split screen
        screen.blit(split_screen, (0, 0))

        # Update screen
        pygame.display.update()

        # Sleep
        new_time = time.time()
        diff_time = new_time - prev_time
        prev_time = new_time
        if diff_time < FRAME_MIN:
            time.sleep(FRAME_MIN - diff_time)
Beispiel #7
0
def main():
    global zombieIndex, shotgunZombieIndex, impIndex

    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    thingName = "FORMER_HUMAN"
    entities = tuple(
        filter(lambda t: t.definition.name == thingName,
               wad.wad_levels["E1M1"].things))
    if len(entities) == 0:
        raise Exception('unable to find [{0}] sprite set'.format(thingName))

    zombie = entities[0]

    thingName = "FORMER_HUMAN_SERGEANT"
    entities = tuple(
        filter(lambda t: t.definition.name == thingName,
               wad.wad_levels["E1M1"].things))
    if len(entities) == 0:
        raise Exception('unable to find [{0}] sprite set'.format(thingName))

    shotgunZombie = entities[0]
    # shotgunZombie.sprite[0].save_png("test_zombie.jpeg", wad.playpals[0])

    thingName = "IMP"
    entities = tuple(
        filter(lambda t: t.definition.name == thingName,
               wad.wad_levels["E1M2"].things))
    if len(entities) == 0:
        raise Exception('unable to find [{0}] sprite set'.format(thingName))

    imp = entities[0]

    pygame.init()
    width = 640
    height = 480
    screen_dimensions = width, height
    screen = pygame.display.set_mode(screen_dimensions)

    # get a thing to draw
    zombieIndex = 0
    shotgunZombieIndex = 0

    background = pygame.Surface(screen.get_size())
    background.fill((255, 255, 255))
    screen.blit(background, (0, 0))

    doom_zombie_sprite = DoomSprite(zombie.sprite[zombieIndex],
                                    wad.playpals[0])
    doom_zombie_label = DoomLabel(doom_zombie_sprite.name, size=20)
    doom_zombie_label.y = 100

    doom_shotgun_zombie_sprite = DoomSprite(
        shotgunZombie.sprite[shotgunZombieIndex], wad.playpals[0])
    doom_shotgun_zombie_sprite.x = 150

    doom_shotgun_zombie_label = DoomLabel(doom_shotgun_zombie_sprite.name,
                                          size=20)
    doom_shotgun_zombie_label.x = 150
    doom_shotgun_zombie_label.y = 100

    impIndex = 0
    doom_imp_sprite = DoomSprite(imp.sprite[impIndex], wad.playpals[0])
    doom_imp_sprite.x = 300

    doom_imp_label = DoomLabel(doom_imp_sprite.name, size=20)
    doom_imp_label.x = 300
    doom_imp_label.y = 100

    all_sprites = pygame.sprite.Group(doom_zombie_sprite, doom_zombie_label,
                                      doom_shotgun_zombie_sprite,
                                      doom_shotgun_zombie_label,
                                      doom_imp_sprite, doom_imp_label)

    zombieIndex += 1
    shotgunZombieIndex += 1
    impIndex += 1

    def timer_callback(*args):
        global zombieIndex, shotgunZombieIndex, impIndex
        zombieIndex = (zombieIndex + 1) % len(zombie.sprite)
        shotgunZombieIndex = (shotgunZombieIndex + 1) % len(
            shotgunZombie.sprite)
        impIndex = (impIndex + 1) % len(imp.sprite)

    timer = Timer(timer_callback, None)
    timer.start()

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                timer.stop()
                timer.join()
                running = False

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RIGHT:
                    zombieIndex += 1
                    if zombieIndex >= len(zombie.sprite):
                        zombieIndex = 0

                if event.key == pygame.K_LEFT:
                    zombieIndex -= 1
                    if zombieIndex == 0:
                        zombieIndex = len(zombie.sprite) - 1

                if event.key == pygame.K_a:
                    shotgunZombieIndex += 1
                    if shotgunZombieIndex >= len(shotgunZombie.sprite):
                        shotgunZombieIndex = 0

                if event.key == pygame.K_d:
                    shotgunZombieIndex -= 1
                    if shotgunZombieIndex == 0:
                        shotgunZombieIndex = len(shotgunZombie.sprite) - 1

        all_sprites.clear(screen, background)
        all_sprites.update()
        all_sprites.draw(screen)
        pygame.display.flip()

        doom_zombie_sprite.sprite = zombie.sprite[zombieIndex]
        doom_zombie_label.text = doom_zombie_sprite.name

        doom_shotgun_zombie_sprite.sprite = shotgunZombie.sprite[
            shotgunZombieIndex]
        doom_shotgun_zombie_label.text = doom_shotgun_zombie_sprite.name

        doom_imp_sprite.sprite = imp.sprite[impIndex]
        doom_imp_label.text = doom_imp_sprite.name

        time.sleep(0.1)

    pygame.quit()
def main():
    parser = optparse.OptionParser()
    options, args = parser.parse_args()

    if len(args) < 1:
        sys.exit("No specified input wad-file provided")

    input_wad_file = args[0]
    wad = WadFile.load(input_wad_file)

    level_to_render = "E1M1"

    level = wad.wad_levels[level_to_render]
    sectors, sides, lines, segs = level.compile_level()
    print("num sectors: {0}".format(len(sectors)))
    print("num sides: {0}".format(len(sides)))
    print("num lines: {0}".format(len(lines)))
    print("num segs: {0}".format(len(segs)))
    print("num nodes: {0}".format(len(level.nodes)))
    print("num vertexes: {0}".format(len(level.vertices)))
    print("num subsectors: {0}".format(len(level.sub_sectors)))

    level.save_svg('./test.svg')

    for i in level.nodes:
        print(i)

    for i in level.things:
        print(i.definition)

    for i in level.sub_sectors:
        print(i)

    player_start = level.find_first_thing_by_name("PLAYER_1_START")
    print(player_start)

    root_node = level.root_node
    print(root_node)

    pygame.init()
    screen = pygame.display.set_mode((WIDTH, HEIGHT))
    pygame.display.set_caption("Render Player To Level {0} {1}".format(
        sys.argv[1], level_to_render))

    player = Player()
    player.position.x = player_start.x
    player.position.y = player_start.y
    player.angle = player_start.angle

    prev_time = time.time()
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT]:
            player.angle = player.angle - ROT_SPEED
        if keys[pygame.K_RIGHT]:
            player.angle = player.angle + ROT_SPEED

        if keys[pygame.K_UP] or keys[pygame.K_w]:
            player.move_player_pos(1, 0)
        if keys[pygame.K_DOWN] or keys[pygame.K_s]:
            player.move_player_pos(-1, 0)
        if keys[pygame.K_d]:
            player.move_player_pos(1, 90)
        if keys[pygame.K_a]:
            player.move_player_pos(-1, 90)

        # video buffer
        split_screen = pygame.Surface((WIDTH, HEIGHT))
        # clear
        split_screen.fill((0, 0, 0))

        for line in segs:
            # Wall absolute positions
            x1 = line.v1.x
            y1 = line.v1.y
            x2 = line.v2.x
            y2 = line.v2.y

            # Wall positions relative to player's position
            px1 = x1 - player.position.x
            py1 = y1 - player.position.y
            px2 = x2 - player.position.x
            py2 = y2 - player.position.y

            # Wall positions relative to player's position and rotation
            rx1 = math.cos(rad(-player.angle)) * px1 + math.sin(
                rad(-player.angle)) * py1
            ry1 = math.cos(rad(-player.angle)) * py1 - math.sin(
                rad(-player.angle)) * px1
            rx2 = math.cos(rad(-player.angle)) * px2 + math.sin(
                rad(-player.angle)) * py2
            ry2 = math.cos(rad(-player.angle)) * py2 - math.sin(
                rad(-player.angle)) * px2

            begin = (rx1, ry1)
            end = (rx2, ry2)
            pygame.draw.line(split_screen, (150, 150, 150),
                             screen_coords(rx1, ry1), screen_coords(rx2, ry2),
                             1)

        # Draw player

        pygame.draw.line(split_screen, PLAYER_RAY_COLOR, screen_coords(0, 0),
                         screen_coords(0, RAY_LENGTH), 1)
        pygame.draw.line(split_screen, PLAYER_COLOR, screen_coords(0, 0),
                         screen_coords(0, 0), 1)

        # Render split screen
        screen.blit(split_screen, (0, 0))

        # Update screen
        pygame.display.update()

        # Sleep
        new_time = time.time()
        diff_time = new_time - prev_time
        prev_time = new_time
        if diff_time < FRAME_MIN:
            time.sleep(FRAME_MIN - diff_time)