   Need help with Mr.Pacman
  I have hoping to finish this pacman clone before I smash and burn my computer.The way I wanted to implement it, is by have and AxB array that keeps track of Mr.Pacman,Food,and enimies position, so it would be easier for say collision detection,or just to keep track . But I am having problem with this part.MY screen is 500x500. Here is some relevant code : GameScreen::GameScreen(){//Init Gamemap to none occupied map//P = pacman//E = Enemy//* = Blank Spaceint Size = 35;//Initially set Size to 25x50GameMap.resize(Size,vector<char>(Size,'*')); }I guess I would have to have some type of conversion because the screenwidth/height does not match my vector size. So I have a not implementedfunction that returns index.and this function :void GameScreen::UpdateMap(float *PacManPos, float *EnemiesPos){unsigned int i(0),j(0);int posX = PacManPos[POS_X];int posY = PacManPos[POS_Y];//I Need some conversion here,I guess//Reset BoardGameMap.resize(GameMap.size(),vector<char>(GameMap[0].size(),'*'));GameMap[posX][posY] = 'P';cout<<"\n\n\n"<<endl;for( i =0; i < GameMap.size(); i++){for( j = 0; j<GameMap.size(); j++){cout << GameMap[j];}printf("\n");}}I am not sure if I am going about this right. Any Help?   
  My advise in general is to lay out the algorithms you plan to use in pseudo code in comments. Begin there and then work your way through the comments in order to derive your code.   ;  A couple things...1) Why are you storing the positions of Pacman and Enemies as arrays?  I would assume structs with two variables (xPos and yPos) would be much simpler to use there, so you could then writeint posX = PacManPos.xPos;int posY = PacManPos.yPos;or something similar.2) If I recall correctly, a 2d array works in the (y,x) orientation, so your array-printing function is going to be printing it out sideways.  For instance, in a 5x5 array, the points at array[0][2] and array[4][1] would be00x00  0000000000  0000000000  0000000000  0000000000  0x000respectively.   ;  You know right now I am getting very frustrated with even displaying Food, viaglPoints. I tried debugging it but could not find any problem. Can you help.Relevant code : My Display List for foodvoid DisplayList::Render_Food(string *FoodCol, float Diameter){cFood.dListIDFd[0] = glGenLists(3);glNewList(cFood.dListIDFd[0],GL_COMPILE);//Determine Colorif(FoodCol[0].compare("RED") == 0)RED; elseif(FoodCol[0].compare("BLUE") == 0)BLUE; elseif(FoodCol[0].compare("YELLOW") == 0)YELLOW;glPointSize(Diameter);glBegin(GL_POINTS);glVertex2f(0.0,0.0);glEnd();glEndList();cFood.dListIDFd[1] = cFood.dListIDFd[0]+1;glNewList(cFood.dListIDFd[1],GL_COMPILE);//Determine Colorif(FoodCol[1].compare("RED") == 0)RED; elseif(FoodCol[1].compare("BLUE") == 0)BLUE; elseif(FoodCol[1].compare("YELLOW") == 0)YELLOW;glPointSize(Diameter);glBegin(GL_POINTS);glVertex2f(0.0,0.0);glEnd();glEndList();cFood.dListIDFd[2] = cFood.dListIDFd[1]+1;glNewList(cFood.dListIDFd[2],GL_COMPILE);//Determine Colorif(FoodCol[2].compare("RED") == 0)RED; elseif(FoodCol[2].compare("BLUE") == 0)BLUE; elseif(FoodCol[2].compare("YELLOW") == 0)YELLOW;glPointSize(Diameter);glBegin(GL_POINTS);glVertex2f(10.0,-10.0);glEnd();glEndList();}This gets called in the constructor : FOOD::FOOD(){//4 * Mr.Pacman RadiusDiameter = (SCREEN_W+SCREEN_H)/200;//Set Food ColorFoodColor[0] = "RED";FoodColor[1] = "BLUE";FoodColor[2] = "YELLOW";//Render Food Display ListcFood.Render_Food(FoodColor,Diameter); }Here is the Draw food Func: void DrawFood(float PosX, float PosY,int colNum) {  glTranslatef(PosX,PosY,-1.0); glCallList(dListIDFd[colNum]);    };And  void LEVELS::DrawLevel1(){srand(0);cLevel.DrawFood((rand()%SCREEN_W)-Line_width,rand()%SCREEN_H-Line_width,cLevel.dListIDFd[(rand()%3)]);}and in this func : void StateFunc::GameState(){//Draw our blue borders RED;cScreen.DrawBorders(SCREEN_W,SCREEN_H);glPushMatrix();//Determine Level Numberswitch(cLevel.GetLevel()){case 1:  cLevel.DrawLevel1(); break;default: cLevel.DrawLevel1();break;}glPopMatrix();//Move Mr. PacmancPacman.Move_Pacman(cPacman.Direction,cPacman.vec2DPos,cPacman.Speed);//Rotate Mr.pacman accordinglyglRotatef(cPacman.GetAngle(),0,0,1);//Render Mr.Pacman by switching between D-listscPacman.Animate_Pacman(cPacman.AnimateChange);//Handle Wall to pacman CollisioncHandle_collision.CheckWallToObjectCollision(cPacman.vec2DPos[POS_X],cPacman.vec2DPos[POS_Y],cPacman.vec2DPos,cPacman.Speed);//cout<<"X : "<<cPacman.vec2DPos[POS_X]<<","<<"Y :  "<< cPacman.vec2DPos[POS_Y]<<endl;}and Its been a while since I first tried to fix this problem. So its not like I did not try. I am at the point of starting all over, if that. And also thislevel1 is just a test;  Pacman has some suprisingly tricky things to deal with for a first time project.  Rather than trying to get everything working all at once, I suggest you focus on individual pieces first.  Try taking it in a few steps like these (or whatever you think works best for you):1. Get pacman on an empty screen.  1a. Move him around freely on the screen.2 Use an array to define and draw a maze.2a. Get pacman to appear and move around the maze (no wall collision checking).2b. Add wall collision checking.3. Add food.3a. Add functionality so when everything has been eaten you move to next level.3b. Add scoring.4. Add enemies (no collision with pacman checking).4a. Develop a simple enemy movement AI.4b. Add pacman collision checking and death.4c. Enhance enemy movement if desired.I have some code on my website for a pacman clone that you could look at but it isn't openGL.  It's also a bit buggy in places.   ;  QUOTE : 1. Get pacman on an empty screen. Done...QUOTE : 1a. Move him around freely on the screen.Done...QUOTE : 2 Use an array to define and draw a maze. Not Done...This was the OP question.If it would help, I could zip my project to anyone willing to help.   ;  Use a couple of for loops to go through your array.  If an element of the array indicates a wall, display the wall similarily as you would display a pacman (if not do nothing).  As you go through the array, change the x,y destination of where the wall might be displayed on the screen.  For examplefor (y=0;y<MAZEYARRAYSIZE;y++){for (x=0;x<MAZEXARRAYSIZE;x++){if (TheMaze[x][y] == 1) //We have a wall.{PaintWall(x*TILEXSIZE,y*TILEYSIZE);}}}PaintWall() takes screen co-ordinates where you want the section of wall to be displayed.   ;  To represent a multi-dimensional array that is rectangular but not of known-ahead-of-time size, use boost::multi_array.To compare std::string instances, don't bother with .compare() except for very specialized purposes (almost never applicable); instead, just use its operator== overload.Don't hide code in macros like 'RED;'. Call a function. And don't repeat the colour-checking logic; do it inside the function. Actually, don't use strings for that purpose, either; use an enumeration to specify one of a finite, predetermined set of values.It is possible in C++ to pass arrays by reference, which gives you a little better type-checking.I suspect that you can't just call glGenLists once and use successive values after that. The function is doing more than giving you an integer handle; it's allocating memory behind the scenes.And for heavens' sake, don't repeat code when you can use a simple looping construct.So for example:enum Colour { RED, BLUE, YELLOW };// The parentheses around the '&' here cause the type to be interpreted as// a reference to an array, instead of an array of references (which is// illegal anyway; you'd think they'd have made it simpler... anyway)void DisplayList::Render_Food(Colour (&) FoodCol[3], float Diameter) {float coordinates[3][2] = {{0.0, 0.0}, {0.0, 0.0}, {10.0, -10.0}};// Did you really mean for the first two to be the same?for (int i = 0; i < 3; ++i) {cFood.dListIDFd = glGenLists(3);glNewList(cFood.dListIDFd,GL_COMPILE);doColorLogicFor(FoodCol);glPointSize(Diameter);glBegin(GL_POINTS);glVertex2f(coordinates[0], coordinates[1]);glEnd();glEndList();}};Quote:Original post by tnuttyI have hoping to finish this pacman clone before I smash and burn my computer.So -- how much time is that? (^_^)Sorry, couldn't resist.;Quote:Original post by Tom SloperQuote:Original post by tnuttyI have hoping to finish this pacman clone before I smash and burn my computer.So -- how much time is that? (^_^)Sorry, couldn't resist.ROFL!   