I am a student with a mainly electronics background getting into programing. The more I get into it, the more I realize how bad I am at it.
I am trying to get better at OO design.
One thing I have been reading about is the use of Getters and Setters.
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1
http://typicalprogrammer.com/?p=23
Now I can see the point they are making here but I am still unable to see away around some simple problems. And this brings me to my question (finally). I am setting up a simple tower defense game in AS3 as a learning exercise. I want enemies to follow way points so I was going to make an array of way points, and make that a property of a map object. And a way point was to be an object with an x and a y property (more like a struct). Now I can see that this is exactly the sort of bad practice that the articles are discouraging but I can’t seem to think of a better way to do this. Any help from some of you guys with a bit more experience would be much appreciated.
Firstly generalise; whilst you are currently wanting enemies to follow waypoints it seems to me that what you have is a specific instance of the map determining where something moves.
Let’s call enemies an instance of “GameEntity” (possibly MoveableGameEntity).
What you should be doing is to tell the map to manage the relevant GameEntities, and then the Map can keep a list of these objects and move them as needed.
Code fragments.
The map will need to have a method get_new_position(MoveableGameEntity ge) which will determine the new posisiton and the enemies will only be told their new posistion via the positionNotify method.
The MoveableGameEntityList is an object that will tie together a game entity and it’s position. This way the game entity doesn’t contain any position information and this is managed by another object.