pacman eat

Started by
0 comments, last by randrace 19 years, 10 months ago
hi, im working on a pacman clone at the moment and having some trouble getting him to eat. Here is my loadMap function. Im reading 15 X 20 map from a text file and basically if there is not a tile then im going to draw a pellet instead void Map::loadMap(){ fin.open("data/map.txt"); int t, x, y; for(x = 0; x < 15; x++){ for(y = 0; y < 20; y++){ fin >> mapArray[x][y]; t = mapArray[x][y]; if (t != 0) { if (t == 1) tiles[x][y].solid = true; tiles[x][y].block = &blocks[t]; } else { pelts[x][y].dot = &dots pelts[x][y].show = true; } } } cout << "map loaded... " << endl; fin.close(); } my drawMap function just reads from the arrays and draws the proper image. void Map::draw() { int x, y; for(x = 0; x < 20; x++){ for(y = 0; y < 15; y++){ if(tiles[y][x].block != NULL) { tiles[y][x].block->setXY(x*32, y*32); tiles[y][x].block->draw(); } else if (pelts[y][x].show == true) { pelts[y][x].dot->setXY(x*32+12,y*32+12); pelts[y][x].x = x*32+12; pelts[y][x].y = y*32+12; pelts[y][x].dot->draw(); } } } } This all works fine. My problem is with the collision detection. this is what i have at the moment: void collide() { double left1, left2; double right1, right2; double top1, top2; double bottom1, bottom2; for(int x = 0; x < 20; x++){ for(int y = 0; y < 15; y++){ if (pelts[y][x].dot != NULL) { left1 = player.getX(); left2 = pelts[y][x].x; top1 = player.getY(); top2 = pelts[y][x].y; right1 = player.getX()+25; right2 = pelts[y][x].x+8; bottom1 = player.getY()+25; bottom2 = pelts[y][x].y+8; if (bottom1 < top2)return; if (top1 > bottom2)return; if (right1 < left2)return; if (left1 > right2)return; pelts[y][x].show = false; } } } } if i specify a pellet to check for(ex: pelts[2][2]) it will work fine, but trying to check them all with a for loop doesnt work. Any ideas? thanks
Advertisement
Excuse me dude, but you should try checking the pellets that you Mr. Pacman dude is at. Checking all of them at once is a waste of time. Think about it dud; you don’t need to check collision for a pellet that is on the other side of the screen. Unless there is some telepathy or ESP in this game that you are not telling us about
Take back the internet with the most awsome browser around, FireFox

This topic is closed to new replies.

Advertisement