2016년 9월 5일 월요일

3)ActionFighter's State design





When I first making this, the hardest thing was how Making various character’s action. And the hardest thing in making action is keeping independency on each action.

I’ve searched, and I found state pattern and I use it.

Simply state pattern mean making each character’s state (move, attack, damaged etc.) to object.

I’ll explain state pattern more with BitmapWorld.



- AFstate


In BitmapWorld, all state inheritance AFstate. AFstate do not use itself but it has some functions that all state share.




Let’s see variable.
 


ownerRef: reference of AF having this. When state initiate, it connected.

state: structure having essential variables for expressing AF’s state.





 

And having information about other variable used in functions and reference of nextState.


AFstate has some functions to realize state.



Initiate: called when object created. by this function, state initiate.

Update: called on every tick. by this function, state realize continual action.
  • update charge time and atk, next slot image needed to change by charge rate.
  • change Stamina according as staminaUse.
  • check curSkillMap with Essential SkillMap and if wrong, change state to IdelState.
*SkillMap: Object saving state can called by AF's input. by mouse left or right click, you can call each different skillMap.
Enter: called one time when enter this state.
  • if this state cause damage to target, calculate finalDamage by preChargeRate of pre state. target take final damage.
  • change AF's sprite to state's motion.
  • create slotComponents and draw def, pre slot image.

Leave: like enter, it called one time when leave state.
  • reset chargeTime to 0.
  • clean slot data.
  • return chargeRate to nextState.

InputSlot: called when receive AF's input.
  • if state's nextSlot data and input Slot data is same and state have nextState, change state to next state. in this action, when real object of nextState is not exist, create one and if exist object of nextState, use this.

Damaged: called when AF take damage.
  • receive causer's finalDamage and check it succeed blocking by damage's atkDirection match with state's defSlot.
  • if it fail to block, change Hp and Stamina by damage formula.

*damage formula
BitmapWorld have damage formula related with Hp and Stamina both.
this is Damage structure.



if attackDirection avoid defSlot and succeed attack, damage caused by 3 type of damage.

damage = pureDamage+(normalDamage - stamina / 2) and deal to stamina after deal Hp.
after taking damage, if stamina is 0, AF changeState to down and if Hp is 0, AF dead.



ChangeState: it used for change state. in this function, enter and leave realizate.

All state changing work by this function.

most of state add it's own logic to AFstate's function. some special state change all function but purpose of function call never change.


nextTime, I'll introduce how ActionFighter work including this State.

댓글 없음:

댓글 쓰기