Hi I'm trying to write a pacman game for a cellphone (
Java 2D J2ME ). I am fairly new to java and I am trying to brain storm ideas on how to structure this program without any repetitive code.
I have a tiled background for the layout. I want the ghosts to travel in random directions on their own. First off I'm organizing the program like this. I have an abstract Character class. Then underneath that I have a PacmanCharacter, GhostCharacter, and FruitCharacter class. Now back to my initial question... There are many locations on the background where I want the ghost to have to make a decision whether it be keep going straight or make a turn I was going to do this by just randomly selecting a direction at each intersection however in order to do this I would have to have an array of variables that contains the information on each pixel location where a turn is possible, and which direction it is possible to turn in. Then I would have to write a for loop and scroll through all of this information every time the game updates. As you can see this is a ton of unnecessary code that will no doubt slow down my game. SO! My next idea is to have a a track line through the paths the (Sprite) ghost can travel on. Any just make it so the ghost can not leave this track line. Then for each level all I would have to do is create a new track line and not have to set all new variables... (As you can see I'm quite new so these solutions arent coming to me naturally yet) I was wondering, Is this latest idea the best way of going about something like this? And if so, how would I implement it? I don't even know where to begin. Thanks in advance.