[pygame] working with tile map,tiled map editor

[pygame] working with tile map,tiled map editor

Postby kostik » Sat Aug 03, 2013 7:18 pm

iam trying to make an adventure game....The main problem I have is with implementing tiles into my game...I am doing it very basic way...In my function i make multidimensional array....and according to digits in arrays iam making tiles(class object) with different position....

Code: Select all
def map():
    group_of_sprites = pygame.sprite.Group()
    block_length = 22
    main_map = [[0,0,0,0,0,0,0]\,
                [0,0,1,1,1,1,0]\,
                [0,0,0,0,0,0,0]]
    for x in range(len(main_map)):
        for y in range(len(main_map[x])):
            if main_map[x][y] ==0:
                wall = Wall(black)#wall is the sprite class and its color would be black
                wall.rect.x = tile_length * y
                wall.rect.y = tile_length * x
                group_of_sprites.add(wall)

theres som problem with my code....if I want to make for example wall with different color i would have to put other digit in my code and also make other if statement

Code: Select all
def map():
    group_of_sprites = pygame.sprite.Group()
    block_length = 22
    main_map = [[2,2,2,2,2,2,2]\,
                [0,0,1,1,1,1,0]\,
                [0,0,0,0,0,0,0]]
    for x in range(len(main_map)):
        for y in range(len(main_map[x])):
            if main_map[x][y] ==0:
                wall = Wall(black)#wall is the sprite class and its color would be black
                wall.rect.x = tile_length * y
                wall.rect.y = tile_length * x
                group_of_sprites.add(wall)
    for x in range(len(main_map)):
        for y in range(len(main_map[x])):
            if main_map[x][y] ==2:
                wall = Wall(redk)#wall is the sprite class and its color would be red
                wall.rect.x = tile_length * y
                wall.rect.y = tile_length * x
                group_of_sprites.add(wall)

So probably woud be imposible to make adventure game by this way with so many tiles.

Also i love the idea making maps with tiled map editor,setting layers and so on....But implementing the map to game is beyond my knowledge...So what is the best way for begginer to make tile map??
Last edited by Yoriz on Mon Aug 05, 2013 5:28 pm, edited 1 time in total.
Reason: changed title
kostik
 
Posts: 13
Joined: Tue Apr 16, 2013 10:26 am

Re: working with tile map,tiled map editor

Postby Pedro H. Forli » Sat Aug 03, 2013 10:45 pm

To work with tiles you can use the program Tiled. Download it in http://www.mapeditor.org/.
Now, when you want to load tiles in your game you can use a TMX library already set. The most used one is the TMX loader.
You can find it in http://www.pygame.org/project-Tiled+TMX+Loader-2036-.html, and it has the instructions on how to use it in the code.
There is also the TMX library written by Richard Jones (the one i use), in which you can set a viewport, load tiles and detect collisions with different objects.
To download it go to https://bitbucket.org/r1chardj0n3s/pygame-tutorial/src/09279ca76e8ee1ec1afa6928cae1bc5f15070985/tmx.py.
You can see how to use it in his pygame tutorial, and learn about a bunch of other stuff related to game programing, http://www.youtube.com/watch?v=mTmJfWdZzbo

PS: Both TMX libraries were released for python 2.7

For more informations go to: http://gamedev.tutsplus.com/tutorials/level-design/introduction-to-tiled-map-editor/
Last edited by Yoriz on Mon Aug 05, 2013 5:16 pm, edited 1 time in total.
Reason: Turned links into real links
Pedro H. Forli
 
Posts: 10
Joined: Thu Aug 01, 2013 1:50 am

Re: working with tile map,tiled map editor

Postby kostik » Mon Aug 05, 2013 1:02 pm

thanky you for thousand times...It helped my in many ways!!
kostik
 
Posts: 13
Joined: Tue Apr 16, 2013 10:26 am

Re: working with tile map,tiled map editor

Postby Pedro H. Forli » Tue Aug 06, 2013 12:51 am

kostik wrote:thanky you for thousand times...It helped my in many ways!!

You are welcome, also, i just find out about a functional TMX library for python 3.
Is based on Richard's Jones TMX library. Check it out(or not) lather
https://github.com/RenfredH04/tmx/blob/master/tmx.py
Pedro H. Forli
 
Posts: 10
Joined: Thu Aug 01, 2013 1:50 am

Re: [pygame] working with tile map,tiled map editor

Postby kostik » Tue Aug 06, 2013 6:18 am

and also...I write you a message
kostik
 
Posts: 13
Joined: Tue Apr 16, 2013 10:26 am


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest