Thread: the maze

  1. #16
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Ok you are trying to do a maze just using what's on screen, and I'm doing a maze based on what's in memory.

    Essentially you draw a maze based on what's in memory. Your approach is not going to work correctly.

    A player cannot touch a wall in the maze because you do not allow him to move if there is a wall. He will never hit a wall. Now if you want to track the maze coordinates in memory and do a collision test, that opens up a whole new plethora of issues.

  2. #17
    Registered User
    Join Date
    Feb 2006
    Posts
    11

    Lightbulb see attachment also

    brainwave time !!!
    and this time i almost completed it (phew!)using my method of doing things

    but now (ahem!) the problem is that the check() function is working for all lines parallel to y axis but only for few lines parallel to x axis why is that happening

    i am sending my entire cpp file on which iam working

    and of course thanx for all that help and i need that very same sweet help from u all once again
    if u all want to contact me by mail
    my id is: [email protected]
    Last edited by nikhil_trichy; 03-02-2006 at 11:53 AM.

  3. #18
    Registered User
    Join Date
    Feb 2006
    Posts
    11
    brainwave time !!!
    and this time i almost completed it (phew!)using my method of doing things

    but now (ahem!) the problem is that the check() function is working for all lines parallel to y axis but only for few lines parallel to x axis why is that happening

    i am sending my entire cpp file on which iam working

    and of course thanx for all that help and i need that very same sweet help from u all once again
    if u all want to contact me by mail
    my id is: [email protected]

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I have no idea why you are checking line intersections.

  5. #20
    Registered User
    Join Date
    Mar 2006
    Posts
    3
    Grr, ok so i had a better explanation 30 seconds ago but turns out I wasnt logged in and it vanished when I hit post.

    Bubba is right, you can't draw a line and then try to figure out where that line was drawn. The line data that you have to work with is only the ends of the lines, you need info on the middle of lines too (the walls). This info is in the graphics card! This is most likely why your horizontal lines aren't being detected - they dont actually exist unless you have a drawline function in your checker. I think you MAY be able to access the graphics card data (maybe?) but it's complicated and i forget how to do it. If you want go to cprogramming.com and on the side bar theres a link that says "advanced graphics programming" and you might find it somewhere in there. But I doubt even that will help you.

    I know you dont want to, but I really think what you need to do is create your walls somewhere where YOU can access them. This means making a 2D array/text file which is a 'map' of the maze, like the 0's and 1's that Bubba showed you. To do this youll need a drawline function of some sorts since you are starting with points and connecting them together - google, or theres one in the advanced graphics tutorials at cprogramming.com. Then you need to 'draw' your walls into a 2D array of the map - im assuming your not moving in 3D? Just put 1 if theres a wall, and 0 if not. or the opposite. whatever.

    Now you have something to check your location against, since you can't check it against the line vertices (well you can but that doesnt tell you if theres a wall there. only the corners!). As your guy moves around, you are going to draw what he's seeing, and also check his position against the map. If theres a wall at his position (it's a big position, a circle, youll have to check all his boundaries) then reset his position to start. The map will be fairly high res, the same resolution as what his movements could be. You may or may not want to allow him to move more than 1 pixel - up to you.

    Basics:
    Code:
    drawmazetoscreen();
    map = createmap();
    loop {
         movedude();
         if (map[dudex][dudey] == 1)
                 {dudex = dudestart;
                  dudey = dudestart;}
          }
    I hope this made some kind of sense. Good luck.

    Mith~
    Last edited by MithTS; 03-15-2006 at 06:54 PM.

  6. #21
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You can figure out where/if a point intersects a line using slope intercept.

    DOS rendering engines used to use an alternate form of slope intercept to clip lines to the screen so you wouldn't get nasty overdraw in the buffer.

    But this is far from what needs to be done.

    I've already explained how to do this quite well and have nearly written the program here in the post.

    I think I'm done here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 01:52 AM
  2. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM
  3. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  4. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM
  5. Maze game, complete with maze editor and an example maze!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-20-2002, 03:27 AM