1. Post #1

    January 2012
    9 Posts
    So I'm trying to make something that will read a picture, and generate a map based on pixel color (Or a number string if that works better). What code would I use to have it place a certain material based on that? Say for example, if the pixel is blue, generate a stone "block." I'm trying to make a map system similar to that of Dungeon Keeper 2 by Bullfrog. It's 3D, and the map is in a grid-like fashion. I haven't found any tutorials that teach something like this. Thank you in advance for your input.

  2. Post #2

  3. Post #3
    A lot of if/elseif statements
    Reply With Quote Edit / Delete Reply Netherlands Show Events Dumb Dumb x 5Programming King Programming King x 1 (list)

  4. Post #4

    January 2012
    9 Posts
    Thank you for the link, hopefully it's 4.0 compatible, I've found a lot of the stuff on there isn't.
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Dumb Dumb x 1 (list)

  5. Post #5
    Hack's Avatar
    March 2011
    261 Posts
    So I'm trying to make something that will read a picture, and generate a map based on pixel color (Or a number string if that works better). What code would I use to have it place a certain material based on that? Say for example, if the pixel is blue, generate a stone "block." I'm trying to make a map system similar to that of Dungeon Keeper 2 by Bullfrog. It's 3D, and the map is in a grid-like fashion. I haven't found any tutorials that teach something like this. Thank you in advance for your input.
    Your map loading would take much longer because of that method call to check each individual pixel. I personally recommend having a XML File with all the blocks inside, the loading times will decrease substantially.

    Up to you though.
    Reply With Quote Edit / Delete Reply Windows 7 Canada Show Events Disagree Disagree x 2 (list)

  6. Post #6
    dajoh's Avatar
    March 2011
    625 Posts
    Your map loading would take much longer because of that method call to check each individual pixel. I personally recommend having a XML File with all the blocks inside, the loading times will decrease substantially.

    Up to you though.
    XML is definitely going to be slower to load from compared to an image where each pixel is a block.
    Reply With Quote Edit / Delete Reply Windows 7 Sweden Show Events Agree Agree x 4Disagree Disagree x 1 (list)

  7. Post #7

    January 2012
    414 Posts
    Ohh runtime tests. Number 2, make it so!

  8. Post #8
    Ybbats's Avatar
    February 2012
    810 Posts
    The best way to do this would probably extend the content pipeline for image objects so you could just use Content.Load<Map>() to load your maps.

  9. Post #9

    January 2012
    9 Posts
    So that link shows how to get the pixel's color, how do I tell that to place a certain model into a grid? I know that there are going to be if statements involved, but I haven't coded anything like this yet.

  10. Post #10
    Person
    geel9's Avatar
    June 2008
    5,561 Posts
    You make the grid yourself. You say "if r == x && g == y && b == z" or, even better, use some sort of hashmap/dictionary.

  11. Post #11

    January 2012
    9 Posts
    I've only been coding in XNA for about 2 months, I'm not familiar with what a hashmap is, or the context for dictionary. '~' Everything I know is from RB Whitaker, Riemers, and Aaron Reed's XNA book. I've found that there's not much that teaches past this point. Thank you for the suggestion, but could you elaborate a bit more?

  12. Post #12

    January 2012
    414 Posts

  13. Post #13

    January 2012
    9 Posts
    Thank you for the link, I actually managed to forget I could just look that up. Whoops. Anyway, how do I set one of these up in XNA? And how do I make sure it loads correctly?

  14. Post #14

    January 2012
    9 Posts
    I can't find the code to tell the game 1, what to place based on color, and 2, where to place it in the grid based on the pixels location. Anyone know how these work?

  15. Post #15
    Richy19's Avatar
    May 2010
    5,368 Posts
    Isnt a hashmap just a C# dictionary?
    Reply With Quote Edit / Delete Reply Windows XP United Kingdom Show Events Agree Agree x 2 (list)