I am writing a RPG game and am finding there is far more background functionality that the user ever sees.
I have a battle class. this holds instances of the enemies the background picture and deals with choosing which enemies are in the battle.
I have developed several global functions to calculate and display gauges like hp and mp. and another to move the timer bar so battle progresses. but I am wondering if these should be in the battle class as with all the other functions I for see it will grow far larger than any other class ?
Also i know drawing should be separated from other code so right now i have global functions that loop through all the active stuff and draw it after the process code has finished, but would it be better to put a draw function inside each class and loop through them instead or keep it all separate ?
The other thing that has been bothering me is I am implementing attacks and was thinking of giving the creature class four attack class instances. this would work but would create waste if there were two or more creatures in the battle that used the same attack. I thought about making one instance of every attack type somewhere and having each creature store four pointers to the applicable attack instances. Are either of these options a good idea or are the better ways to implement this?
I think you should have a look on the finite state machines which usually the base mechanism for games. That would give you a broad idea how your code should be organized in order to keep everything easily editable and easy to browse.
I think your choice of class extraction is kind of weird. The "battle" in it self does not qualify for a class since it has no resemblance to any "object" which is at the heart of OOP. I mean, yeah, you can collect your functions in to a specific class, but then it make more sense to identify first the states you are dealing with and then build a state machine around them, so if as you progress, a new set of states arise, you can easily build a new class for that functionality.
I'm sure that FSM is the thing you're looking for...
To give an idea: Simple but generic FSM implementation in C++ Game design with FSM tutorial
精彩评论