Results 1 to 5 of 5

Thread: Making a maze using arrays

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    21

    Making a maze using arrays

    Basically I am trying to make a maze in OpenGL. The problem I am having is that I am using array lists for the maze map but it doesn't create the shape I want. The code is below:
    Code :
    float wallX[13] = {25, 15, 35, 55, 45, 45, 65, 15, 65, 55, 45, 35, 25}; //Array for columns
    float wallY[26] = {10, 25, 15, 45, 15, 35, 15, 45, 15, 25, 35, 55, 35, 45, 55, 75, 55, 75, 65, 75, 65, 85, 75, 85, 95, 105}; //Array for what part of the columns are coloured, each pair is a line
    float pi = 0;
    int WallXCo = 0;
    int WallYCo = 0;
    float WallXCo1;
    float WallXCo2;
    float WallYCo1;
    float WallYCo2;
    for(pi = 0; pi < 13; pi++)
    {
    	WallXCo1 = wallX[WallXCo] - 1.25;
    	WallXCo2 = wallX[WallXCo] + 1.25;
    	WallYCo1 = (wallY[WallYCo] - 1.25) * -1;
    	WallYCo2 = (wallY[WallYCo + 1] + 1.25)*-1;
    	drawWall(WallXCo1, WallYCo1, WallXCo2, WallYCo2);
    	WallXCo = WallXCo + 1;
    	WallYCo = WallYCo + 2;
    }

    Code :
     void drawWall(float WallXCo1, float WallYCo1, float WallYCo2, float WallXCo2)
    {
    	glColor3f(1,0,1);
    	glBegin(GL_POLYGON);
    	glVertex2f((WallXCo1),(WallYCo1));
    	glVertex2f((WallXCo2),(WallYCo1));
    	glVertex2f((WallXCo2),(WallYCo2));
    	glVertex2f((WallXCo1),(WallYCo2));
    	glEnd();
    }

    This is just the code for the vertical sections of the map. Each X coordinate has two Y coordinates (WallX[0] equates to wallY[0] and wallY[1] making a line 5 in width between the two points).

    However instead of any sort of map coming out of it I just get a mass of green with no shape. Anyone know what I am doing wrong?

  2. #2
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    21

    Re: Making a maze using arrays


    That is what it looks like, the pink is what is generated by the above code.

    Anyone know why it is doing this? It is really annoying me.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    21

    Re: Making a maze using arrays

    Anyone? I have tested each bit of the code and it outputs the numbers correctly and draws a square correctly yet won't do it all together.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Making a maze using arrays

    Aside from hurting the eyes with pink/green colors, I do not understand what is your problem.

    How do you expect it to look like ?

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    21

    Re: Making a maze using arrays

    Colours are only there till I texture it.

    The idea was to have lines, like the first one would go from 23.75 to 26.25 across and from -8.5 to -26.75 down (using one number from WallX and two from wallY).

Similar Threads

  1. openGL 2D maze
    By C4X4SIX in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-27-2012, 03:26 PM
  2. 3D Maze
    By fleurmtl in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-07-2009, 12:47 PM
  3. creating a maze
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-21-2006, 07:01 AM
  4. 3D Maze screensaver?
    By guest in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-06-2003, 12:52 PM
  5. HELP!!! with the Simple 2D Maze
    By jatin in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-20-2000, 07:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean