azalea.avapose.com

.NET/Java PDF, Tiff, Barcode SDK Library

The flow controller is injected with a flow executor. This is a component that knows how to initialize and load the flow information from the flow registry (see Listing 6-18).

winforms pdf 417 reader, winforms qr code reader, winforms upc-a reader, winforms data matrix reader, winforms gs1 128, winforms ean 13 reader, itextsharp remove text from pdf c#, replace text in pdf using itextsharp in c#, winforms code 39 reader, itextsharp remove text from pdf c#,

To allow the unit to receive damage, you ll create the ReceiveDamage method, which receives the damage intensity as a parameter. The code for the ReceiveDamage method follows: public virtual void ReceiveDamage(int damageValue) { life = Math.Max(0, life - damageValue); if (life == 0) isDead = true; } When the unit s hit points reach zero, the isDead flag is marked as true. In this case, you can avoid updating this unit. The ReceiveDamage method should be virtual, allowing the units that extend the TerrainUnit class to override this method and, for example, play a death animation for the unit.

Listing 6-18. Configuring the Flow Executor <flow:executor id="flowExecutor" registry-ref="flowRegistry"/>

During the game, every time a unit changes its current action (or state), you need to change its animation. For example, the animation used when the unit is idle is different from the animation used when the unit is running. The unit s animated model (AnimatedModel class) has an array that stores all the unit s animations. You can change the unit s animation manually, but to do that, you need to go over all its animations, searching for the desired animation. This is necessary because you don t know which animations the unit has, or in which order they were stored. To ease the swap between animations, you can create an enumeration for the unit s animations inside each class that extends the TerrainUnit, where each enumeration lists the available animations of the unit s animated model in the order they were stored. For example, the Player class has an enumeration called PlayerAnimations and the Enemy class has an enumeration called EnemyAnimations, as shown in the following code: public enum PlayerAnimations { Idle = 0, Run, Aim, Shoot } public enum EnemyAnimations { Idle = 0, Run, Bite, TakeDamage, Die }

These beans are configured by using a custom schema and are normally mapped to the flow: namespace prefix. The appropriate XML namespace entries are shown in bold in Listing 6-19.

You use these enumerations to change the current animation of the model. To change the unit s animation, you create the SetAnimation method in the TerrainUnit class. In the SetAnimation method, you set the model s current animation using an integer value, which is the index of the animation inside the animation s array, stored inside the AnimatedModel class. However, because you don t know the index of the animations, this method is protected so only the classes that extend the TerrainUnit class (Player and Enemy) can use it. Then, in the Player and Enemy classes, you can change the model animation using the PlayerAnimations and EnemyAnimations enumerations. Following is the code for the SetAnimation method of the TerrainUnit class: protected void SetAnimation(int animationId, bool reset, bool enableLoop, bool waitFinish) { if (reset || currentAnimationId != animationId) { if (waitFinish && !AnimatedModel.IsAnimationFinished) return; AnimatedModel.ActiveAnimation = AnimatedModel.Animations[animationId]; AnimatedModel.EnableAnimationLoop = enableLoop; currentAnimationId = animationId; } } The other parameters of the SetAnimation method allow the animation to be reset or looped, or prevent it from being changed before it has finished. Whenever an animation is set, its identifier is stored in the currentAnimationId variable and is used to prevent the current animation from being reset, unless you desire that, by setting the reset parameter to true. Following is the code for the SetAnimation method of the Player class: // Player class public class Player : TerrainUnit { ... public void SetAnimation(PlayerAnimations animation, bool reset, bool enableLoop, bool waitFinish) { SetAnimation((int)animation, reset, enableLoop, waitFinish); } } And following is the code for the SetAnimation method of the Enemy class: // Enemy class public class Enemy : TerrainUnit { ...

public void SetAnimation(EnemyAnimations animation, bool reset, bool enableLoop, bool waitFinish) { SetAnimation((int)animation, reset, enableLoop, waitFinish); } } The SetAnimation methods defined in the Player and Enemy classes allow the unit s animation to be easily switched and guarantee that a valid animation will always be set. The following code example illustrates how you would change the animation in the Player and Enemy classes: player.SetAnimation(PlayerAnimations.Idle, false, true, false); enemy.SetAnimation(EnemyAnimations.Run, false, true, false);

   Copyright 2020.