Jump to content
• Advertisement

Public Group

#### Archived

This topic is now archived and is closed to further replies.

# pacman eat

This topic is 5275 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5
• Advertisement

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011259
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!