Ejemplo n.º 1
0
def preparelevel(screen, level):
    if level == "random map":
        return prepareRandomLevel(screen)
    elif level == "Random 35 x 35":
        return prepareRandomLevel(screen, 35, 35)
    elif level == "Random 60 x 60":
        return prepareRandomLevel(screen, 60, 60)
    elif level == "Random 60 x 25":
        return prepareRandomLevel(screen, 60, 25)
    else:
        levelname = os.path.join("data", "rooms", level)
        graphics.load(levelname)
        world = pygame.Surface((graphics.world_w, graphics.world_h))
        t = topbar.TopBar(screen)
        r = room.load(levelname)
        test.mark(r.background)
        r.topbar = t
        return world, t, r
Ejemplo n.º 2
0
def main():
    pygame.init()
    pygame.display.set_mode(graphics.screen_size)
    pygame.display.set_caption("Dungeon Crawler")
    pygame.mouse.set_visible(1)
    pygame.key.set_repeat(1, 30)
    
    clock = pygame.time.Clock()
    
    player = animation.Animation((32, 32))
  #  player1 = player.Player("player1",fist,none,100,50,1000,[])
    
    
    tile.init()
    map = room.load(os.path.join("data", "level1.txt"))
    screen = pygame.display.get_surface()
    
    running = True
    while running:
    
        clock.tick(30)
        screen.fill((0, 0, 0))
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
               
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.event.post(pygame.event.Event(pygame.QUIT))
                    
        
        
        map.draw(screen)
        player.handle_event(event)  
        screen.blit(player.image, player.rect)
        
        pygame.display.flip()
        clock.tick(30)
Ejemplo n.º 3
0
def game_run():
    pygame.event.set_blocked(None)
    pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN])

    #music = pygame.mixer.music.load("POL-sunset-route-short.wav")
    music = pygame.mixer.music.load("POL-miracle-park-short.wav")
    pygame.mixer.music.play(-1)

    #jump_sound = Sound("Jump27.wav")

    screen = pygame.display.get_surface()
    screen_rect = screen.get_rect()

    p = player.Player()
    p.place((100, 200))

    new_item = item.Item()
    new_item.place((220, 200))

    L = []
    r = room.load("sample room2.txt")
    r2 = room.load("sample room3.txt")

    L.append(r)
    L.append(r2)

    clock = pygame.time.Clock()
    dt = 0
    #        while True:

    while True:
        if pygame.event.get(pygame.QUIT):
            return

        key_presses = pygame.event.get(pygame.KEYDOWN)
        key_states = pygame.key.get_pressed()

        #if event.key == pygame.K_SPACE:
        #jump_sound.play()

        assets = [p] + [new_item]
        p.update(dt, key_states, key_presses)
        p.calculate_next_position()

        for a in assets:
            p0 = a.position
            p1 = a.next_position

            tc = pygame.rect.Rect(p1)

            x, y = 1, 1
            tiles = r.tiles_around(p0.center)

            if tiles[x][y + 1] and tiles[x][y + 1][1].solid and tc.colliderect(
                    tiles[x][y + 1][0]):
                tc.bottom = tiles[x][y + 1][0].top
                a.speed[1] = 0

            if tiles[x][y - 1] and tiles[x][y - 1][1].solid and tc.colliderect(
                    tiles[x][y - 1][0]):
                tc.top = tiles[x][y - 1][0].bottom
                a.speed[1] = 0

            if tiles[x - 1][y] and tiles[x - 1][y][1].solid and tc.colliderect(
                    tiles[x - 1][y][0]):
                tc.left = tiles[x - 1][y][0].right
                a.collide_wall()

            if tiles[x + 1][y] and tiles[x + 1][y][1].solid and tc.colliderect(
                    tiles[x + 1][y][0]):
                tc.right = tiles[x + 1][y][0].left + 1
                a.collide_wall()

            a.set_next_position(tc)

        if p.position.colliderect(new_item.position):
            print "You Win!"
            return

# Draw stuff
#if p.position.colliderect(new_item.position):
#        print "You Win!!"
        L[0].draw(screen)
        p.draw(screen)
        new_item.draw(screen)

        pygame.display.flip()
        dt = clock.tick(15)
Ejemplo n.º 4
0
def game_run():
    pygame.event.set_blocked(None)
    pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN])

    screen = pygame.display.get_surface()
    screen_rect = screen.get_rect()

    p = player.Player()
    p.place((200, 200))

    r = room.load("sample room2.txt")

    clock = pygame.time.Clock()
    dt = 0
    while True:
        # Handle quitting
        if pygame.event.get(pygame.QUIT):
            return

        # Handle player input
        key_presses = pygame.event.get(pygame.KEYDOWN)
        key_states = pygame.key.get_pressed()

        # Get the actors' new positions
        actors = [p]
        for a in actors:
            a.update(dt, key_states, key_presses)
            a.calculate_next_position()

        for a in actors:
            p0 = a.position
            p1 = a.next_position

            # Collision actor-wall version 3
            tp = pygame.rect.Rect(p1)

            x, y = 1, 1
            tiles = r.tiles_around(p0.center)
            # Test bottom
            if tiles[x][y + 1] and tiles[x][y + 1][1].solid and tp.colliderect(
                    tiles[x][y + 1][0]):
                tp.bottom = tiles[x][y + 1][0].top
                a.speed[1] = 0
            # Test top
            if tiles[x][y - 1] and tiles[x][y - 1][1].solid and tp.colliderect(
                    tiles[x][y - 1][0]):
                tp.top = tiles[x][y - 1][0].bottom
                a.speed[1] = 0
            # Test left
            if tiles[x - 1][y] and tiles[x - 1][y][1].solid and tp.colliderect(
                    tiles[x - 1][y][0]):
                tp.left = tiles[x - 1][y][0].right
                a.collide_wall()
            # Test right
            if tiles[x + 1][y] and tiles[x + 1][y][1].solid and tp.colliderect(
                    tiles[x + 1][y][0]):
                tp.right = tiles[x + 1][y][0].left + 1
                a.collide_wall()

            for e in key_presses:
                if e.key == pygame.K_SPACE:
                    print tp.topleft, tp.bottomright
                    for y in range(3):
                        for x in range(3):
                            print tiles[x][y][0].topleft,
                        print

            a.set_next_position(tp)

        # Collision player-mobs version 1
        #for m in mobs:
        #    if p.position.colliderect(m.position):
        #        print "Boing"

        # Draw stuff
        r.draw(screen)
        p.draw(screen)
        #for m in mobs:
        #    m.draw(screen)

        pygame.display.flip()
        dt = clock.tick(15)
Ejemplo n.º 5
0
def map_editor():
    level = 1
    pygame.init()
    pygame.display.set_mode(graphics.screen_size)
    pygame.display.set_caption("Dungeon Crawler")
    pygame.mouse.set_visible(1)
    pygame.key.set_repeat(1, 30)
    clock = pygame.time.Clock()
    tile.init()
    screen = pygame.display.get_surface()
    running = True
    curser_position = (0,0)
    name_sign_dict = {"floor":" ","wall": "#","warp":"+","finish":"-","trap":"T","back":"B","sword":"S","interact":"I","shopping":"G","managain":"M","healthgain":"H","cashgain":"C","quest":"Q","interact2":"L"} 
    name_list = ["floor","wall","warp","finish","trap","back","sword","interact","shopping","managain","healthgain","cashgain","quest","interact2"]
    while running:
        # run game with 10 frames
        clock.tick(10)
        # screen surface black
        screen.fill((0, 0, 0))
        map = room.load(os.path.join("data", "level" + str(level) + ".txt"))
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sys.exit()
                elif event.key == pygame.K_a:#Levelauswahl
                    if level < 9:
                        level = level + 1
                    else:
                        pass
                elif event.key == pygame.K_z:
                    if level > 1:
                        level = level - 1
                    else:
                        pass
                elif event.key == pygame.K_UP:#cursersteuerung
                    if curser_position[1]-32 < 0:
                        pass
                    elif curser_position[1]-32 > 448:
                        pass
                    else:
                        curser_position = (curser_position[0], curser_position[1]-32)
                
                elif event.key == pygame.K_DOWN:
                    if curser_position[1]+32 < 0:
                        pass
                    elif curser_position[1]+32 > 448:
                        pass
                    else:
                        curser_position = (curser_position[0], curser_position[1]+32)
                
                elif event.key == pygame.K_LEFT:
                    if curser_position[0]-32 < 0:
                        pass
                    elif curser_position[1]-32 > 608:
                        pass
                    else:
                        curser_position = (curser_position[0]-32, curser_position[1])
                        
                elif event.key == pygame.K_RIGHT:
                    if curser_position[0]+32 < 0:
                        pass
                    elif curser_position[0]+32 > 608:
                        pass
                    else:
                        curser_position = (curser_position[0]+32, curser_position[1])
                elif event.key == pygame.K_RETURN:#Aenderung des Spielfelds
                    dict = map.get_coordinates_and_tiles()
                    block = dict[curser_position]
                    name = block.get_name()
                    z = 0
                    for f in range(10):
                        if name == name_list[f]:
                            z = f
                    if z > 8: 
                        z = 0
                    else:
                        z = z + 1
                    file = open(os.path.join("data","level" + str(level) + ".txt"), "w")
                    string = ""
                    for x in range(15):
                        for y in range(20):
                            if (y*tile.width, x*tile.height) == curser_position:
                                string = string + str(name_sign_dict[name_list[z]])
                            else:
                                string = string +  str(name_sign_dict[dict[(y*tile.width, x*tile.height)].get_name()])
                        string = string + "\n"
                    file.write(string)
                    file.close()
                    
        map.draw(screen)
        curser = pygame.image.load(os.path.join(os.path.join("tiles"), "marker.png")).convert_alpha()
        screen.blit(curser,curser_position)
        pygame.display.flip()