Newbie starting out on Pacman

Started by
5 comments, last by LostSource 17 years, 1 month ago
Hi all, I am new to game development and I just graduated from college so I am quite inexperienced programmer I would say. At the moment, I am working on a Pacman clone and I am stuck on the how the interaction between the dots, pills, ghost and pacman should be done. I have two designs now, one is to have a centralized control called Game class which will handle all the events (e.g. eating of dots and pills) and updating the score and modifying the pacman according. For example eating of pill would be coded as below inside Game class: if(mazeLocation(pacman->x(), pacman->y()) == PILL) { addScore(10); pacman->setInvincible(); } The other design is to have a base class called Edible and children classes called Dot and Pill. So eating of dots and pills is handled as below inside Game class: Edible e = getMazeEntityAt(pacman->x(), pacman->y()); if( e ) { e.eaten(pacman, this); } void Pill:eaten(Pacman *p, Game *g) { p->setInvincible(); g->addScore(10); } Wondering which is the prefered way and why. The first method obviously will get ugly if we start introducing more edibles. But the second approach means each edible needs to be aware of Pacman and Game class. If we were to change Pacman or Game class, we might have to update every single edible class. Is there actually a better way to do this? Hope someone can advice on this. Thanks. Thuan Seah Tan
Advertisement
Moving you to For Beginners.

- Jason Astle-Adams

I can't be of much help but you need to do a collision of some sort. When PacMan touches the pill it vanishes and if a ghost touches PacMan he dies, ect... Collision is something I've been having a hard time for over 5 years and still run into problems. Another way would be to make a Tile Map, have each movable spot have it's own square, for example see the picture I made below.

http://img412.imageshack.us/img412/2339/expyo8.png

What you need to do is have it check for the next tile, this can be done with an Array. Now the colored Tiles are walls so it checks for the walls (You need to map this in an Array with 1 for example as walls and 2 for movable spots.) However you will still need some kind of Collision. I hope this helps and gives a general idea on what you can do.
____________________VB/C++/C# Programmer
In my pacman game, I used a tilemap to represent the level. With a tilemap,
if pacman collided with a DOT tile, we could just remove it from the tilemap,
and add the ponts, check for win, etc.

You can use an enumeration to represent different tile types, and use
a Tile class, if you want.
Quote:Original post by tts1980
The other design is to have a base class called Edible and children classes called Dot and Pill. So eating of dots and pills is handled as below inside Game class:

Edible e = getMazeEntityAt(pacman->x(), pacman->y());
if( e ) {
e.eaten(pacman, this);
}

void Pill:eaten(Pacman *p, Game *g) {
p->setInvincible();
g->addScore(10);
}


This seems to be a good way. I, personally would go with this, at least for the moment. You should first get it working, and then if you have a better design, re-write it.

The re-writing might be a lot of work, but it will really help in your understanding of your own code, because you'll have coded the app to work in a particular way, and then you'll be coding it to work a completely different way, but to have the same end result.

Anyway, the answer is this: this is one of your first games, so it doesn't matter, as long as it works.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Quote:Original post by tts1980
Edible e = getMazeEntityAt(pacman->x(), pacman->y());
if( e ) {
e.eaten(pacman, this);
}

void Pill:eaten(Pacman *p, Game *g) {
p->setInvincible();
g->addScore(10);
}


I would recommend this method. You should make Game a singleton though aswell. That way you dont need to pass it around everywhere. Representing the world, i guess a tiled map would be best. Just an enum of tile types, wall, pill, blank.

For moving pacman about, i would also recommend to move him about with physics. So he has position, velocity, acceleration. Then if the play moves forward, check the tile infront, and adjust he acceleration only. To stop him, take his velocitySquared, negate it, scale it, and adjust the acceleration with that vector and it will slow him down.

I'm only recommending the last bit, because i made the mistake to not do it that way as my 'leaving uni project'.
I would suggest creating a AABB class and giving each dynamic object an AABB and using this do a collision test against two AABB's:

if PILLs AABB collides with PacMans AABB
then: Pacman eats the pill

if nothing is within a curtain radius of Pacmans position
then don't do a AABB collision detection for Pacman

Good luck on your Pacman game.

This topic is closed to new replies.

Advertisement