Computer Science Canada

Complex Process Functions Replicated in Procedures?

Author:  Zampano [ Fri Nov 30, 2007 9:52 am ]
Post subject:  Complex Process Functions Replicated in Procedures?

I've heard a lot of talk in this forum about how processes will mess your program up, and how everything that is usually done with a process (except music) can be done with a procedure.
you've said how to do simple process tasks in a procedure, like shooting while moving. But how about more complex tasks, such as having an enemy move in a predictable pattern (walk south a bit, turn around 180 degrees, walk the same distance north, turn 180 again, and repeat).
To my knowledge this cannot be done in a procedure without making the program horribly long and needlessly complicated while the same can be done in a process.
Is there a remedy available to such a problem?

Author:  Dan [ Fri Nov 30, 2007 11:39 am ]
Post subject:  RE:Complex Process Functions Replicated in Procedures?

This case is aucatly not that complex at all. Take the fallowing pesodo code for example:

code:

Load enemy objects in to array enemies
Load one instance of the class MyChar in to mainChar
..........

Main Loop
      mainChar.move();

      for enemies.length do
                 enemies[i].move();
      end
...........
end

................

Classs Enemy
..........
    Method move
            code to move enemy in some pateren
    end
........
end

Class MyChar
........
    Method move
              code to move main char
    end
......
end


Note: you do not need clases at all and it could all be done with procudes instened, but clases just make it look better and easyer to use.


: