ASCII dungeon template

This is a discussion on ASCII dungeon template within the C++ Programming forums, part of the General Programming Boards category; im currently designing my rpg engine.. just to see what i can do. im currently at the point where i ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    ASCII dungeon template

    im currently designing my rpg engine.. just to see what i can do. im currently at the point where i would like to implement a visual dungeon. im thinking of making a text file with the design

    text file::
    Code:
    |===============|
    |               |
    |               |
    |               |
    |               |
    |               |
    |===============|
    int the DrawMap function it looks for the folder where the text files are located and picks the most logical map ie map1a map2b

    everyline in the text file is converted to an array and represented on the screen. i have this much working. mostly. but movement is a problem. a serious problem. im having troubles figuring out how to make it so the user cannot move out of boundarys or an event occurs etc etc. can anyone help with this problem
    Last edited by Salem; 11-09-2007 at 06:22 AM. Reason: Code tags preserve the whitespace

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Maybe add some dots to mark the floors / passageways?
    Code:
    |=======|
    |.......|
    |.......|
    |.......|
    |=======|
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, I presume when you load the map for a particular room/area, you do so into a 2D character array?

    If so, the movement should be restricted to the parts of [or inside of] the map that is spaces delimited by your | and = signs (walls). The player obviously has a starting point within the room, and can then move within the room by [for example] keypresses. If the movement "hits a wall", then it's not a valid move.

    What part of this procedure is it that you can't achieve?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    11
    Quote Originally Posted by lilhawk2892 View Post
    im currently designing my rpg engine.. just to see what i can do. im currently at the point where i would like to implement a visual dungeon. im thinking of making a text file with the design

    text file::
    Code:
    |===============|
    |               |
    |               |
    |               |
    |               |
    |               |
    |===============|
    int the DrawMap function it looks for the folder where the text files are located and picks the most logical map ie map1a map2b

    everyline in the text file is converted to an array and represented on the screen. i have this much working. mostly. but movement is a problem. a serious problem. im having troubles figuring out how to make it so the user cannot move out of boundarys or an event occurs etc etc. can anyone help with this problem
    Hi Lil!

    You can store an entire area where the user is in a matrix, then store user position and when he moves check inside the matrix if the destination square is valid.
    This way you can control any kind of event, not only collisions against walls

    Regards,
    Tesctassa

  5. #5
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Post

    Heres some pseudo code of how you could check for collisions:
    Code:
    void Input()
    {
        if(KEY_HIT_RIGHT)
            if(!Collision(player_x+1, player_y))
                player_x++;
        if(KEY_HIT_LEFT)
            if(!Collision(player_x-1, player_y))
               player_x--;
        if(KEY_HIT_DOWN)
            if(!Collission(player_x, player_y+1))
               player_y--;
        if(KEY_HIT_UP)
            if(!Collission(player_x, player_y-1))
               player_y--;
    }
    
    bool Collsion(x, y)
    {
        if(x < 0 || x>= MAP_WIDTH)
            return true;
        if(y < 0 || y>= MAP_HEIGHT)
            return true; 
    
        if(map[x][y] == '=') 
            return true;
        if(map[x][y] == '|')
            retrun true;
    
        return false;
    }

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mike_g View Post
    Heres some pseudo code of how you could check for collisions:

    bool Collsion(x, y)
    [/code]
    which is it, collisions or collsions?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Well I said it was pseudo code, so I should be allowed to make typos ;D

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mike_g View Post
    Well I said it was pseudo code, so I should be allowed to make typos ;D
    Of course you are: I just spotted another typo:
    Code:
        if(KEY_HIT_DOWN)
            if(!Collission(player_x, player_y+1))
               player_y--;
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21