Take a look at my Loderunner clone in the Showcase forum. I use polymorphism for moving. There is a base (Super) class called Human which implements stuff common to Enemies and Players, namely how to move based on it's direction and speed. Now that code is used by both enemies and players. Then there is an abstract method that use used to decide on where to move. All humans need to decide where to move, it's just that Enemies and Players do it differently. Players get their input from the keyboard, Enemies need to think about where to move, and in my Loderunner clone, that means they use A* to find a path. The results of the movement decision is a set of "state" that all humans share telling the human where to try to move to. Then in the actual move part, any common stuff is handled (Banging into sides, being able to walk up or down, moving along the bar, falling etc) and then specialisations of movement for the specific Humans. For instance, enemies when they've fallen into a hole, must not fall throgh it and wait. Humans can fall through holes if there is nothing below them.
OO is a paradigm, you can implement a lot of it with procedural functions, just passing in objects to the functions, but once you understand and use it a bit you see that it's very helpful in keeping your code together.
Inheritance is nice, because you can have methods, functions etc that take base class types and know how to handle derived classes automatically. As Mikkel said if you were using procedure stuff, you might have to do something like:
Select object.type
case enemy
MoveEnemy(object)
case human
MoveHuman(object)
End Select
With OO you would just go
object.move()
Another example in my Loderunner stuff is that I have a distance function type that knows how to calculate distances between two 'positions'. Now my AStar stuff just knows about that base type and calls a method for getting distance, but I can now derive different functions and ways of finding distances, and my AStar code doesn't have to change - at all cause I just pass it in a different function to use, as an object.
Aaron
OO is a paradigm, you can implement a lot of it with procedural functions, just passing in objects to the functions, but once you understand and use it a bit you see that it's very helpful in keeping your code together.
Inheritance is nice, because you can have methods, functions etc that take base class types and know how to handle derived classes automatically. As Mikkel said if you were using procedure stuff, you might have to do something like:
Select object.type
case enemy
MoveEnemy(object)
case human
MoveHuman(object)
End Select
With OO you would just go
object.move()
Another example in my Loderunner stuff is that I have a distance function type that knows how to calculate distances between two 'positions'. Now my AStar stuff just knows about that base type and calls a method for getting distance, but I can now derive different functions and ways of finding distances, and my AStar code doesn't have to change - at all cause I just pass it in a different function to use, as an object.
Aaron