Ejemplo n.º 1
0
 void Awake()
 {
     _bodySpriteRenderer = GetComponentInChildren <SpriteRenderer>(true);
     _entityAnimator     = GetComponent <ActorAnimator>();
     UiPresenter         = GetComponent <EntityUiPresenter>();
 }
 public MovementFSM(TActor actor, ActorAnimator actorAnimator) : base(actor, actorAnimator)
 {
 }
Ejemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     if (actorAnimator == null) actorAnimator = this.GetComponent<ActorAnimator>();
     if (navMeshAgent == null) navMeshAgent = this.GetComponent<NavMeshAgent>();
 }
Ejemplo n.º 4
0
        void ICmpUpdatable.OnUpdate()
        {
            Transform           transform = this.GameObj.Transform;
            CharacterController character = this.GameObj.GetComponent <CharacterController>();

            // temp hack to test HitNotAnEnemy()
            if (DualityApp.Keyboard.KeyHit(Key.E))
            {
                HitNotAnEnemy();
            }

            // Find out which waypoint we're travelling to
            Transform waypoint = this.travelPath.Waypoints[this.waypointIndex];

            this.targetPos = waypoint.Pos.Xy;

            // Adjust walking speed
            this.walkSpeed += Time.TimeMult * 0.04f * MathF.Rnd.NextFloat(-1.0f, 1.0f);
            this.walkSpeed  = MathF.Clamp(this.walkSpeed, 0.5f, 1.0f);

            // Walk directly to the target
            Vector2 diffToTarget      = this.targetPos - transform.Pos.Xy;
            Vector2 directionToTarget = diffToTarget.Normalized;
            float   targetDistance    = diffToTarget.Length;
            float   movementSpeed     = this.walkSpeed * MathF.Clamp(targetDistance / 64.0f, 0.0f, 1.0f);
            Vector2 movementDirection = directionToTarget;

            // Raycast to see if there is someone in front of us
            Vector2     rayStart = transform.Pos.Xy;
            Vector2     rayEnd   = rayStart + directionToTarget * 64.0f;
            RayCastData rayFirstHit;
            bool        rayHitAnything = RigidBody.RayCast(rayStart, rayEnd, data => {
                if (data.GameObj == character.GameObj)
                {
                    return(-1);
                }
                if (data.Body.BodyType == BodyType.Static)
                {
                    return(-1);
                }
                if (data.Fraction < 0.5f)
                {
                    return(-1);
                }
                return(data.Fraction);
            }, out rayFirstHit);

            if (rayHitAnything)
            {
                Vector2 offset = (((int)Time.GameTimer.TotalSeconds / 5) % 2) == 0 ?
                                 movementDirection.PerpendicularLeft :
                                 movementDirection.PerpendicularRight;
                movementDirection = movementDirection + offset;
                movementDirection.Normalize();
                //VisualLog.Default.DrawConnection(new Vector3(rayStart, 0.0f), rayFirstHit.Pos).WithOffset(-100).WithColor(ColorRgba.Red);
            }
            else
            {
                //VisualLog.Default.DrawConnection(new Vector3(rayStart, 0.0f), rayEnd).WithOffset(-100);
            }

            // Switch to the next waypoint when arriving
            if (targetDistance < 16.0f)
            {
                if (this.walkBackwards)
                {
                    this.waypointIndex--;
                    if (this.waypointIndex < 0)
                    {
                        this.walkBackwards  = false;
                        this.carriesStuff   = true;
                        this.carryType      = MathF.Rnd.Next(1, 5);
                        this.waypointIndex += 2;
                    }
                }
                else
                {
                    this.waypointIndex++;
                    if (this.waypointIndex >= this.travelPath.Waypoints.Count)
                    {
                        this.Score(false);
                        this.walkBackwards  = true;
                        this.carriesStuff   = false;
                        this.waypointIndex -= 2;
                    }
                }
            }

            // Color the guy green
            ActorRenderer renderer = this.GameObj.GetComponent <ActorRenderer>();
            ActorAnimator animator = this.GameObj.GetComponent <ActorAnimator>();

            animator.Animations[1].DirectionMap[0].SpriteSheetIndex = this.carriesStuff ? 2 + this.carryType : 1;
            animator.Animations[1].DirectionMap[1].SpriteSheetIndex = this.carriesStuff ? 2 + this.carryType : 1;
            animator.Animations[1].DirectionMap[2].SpriteSheetIndex = this.carriesStuff ? 2 + this.carryType : 1;
            animator.Animations[1].DirectionMap[3].SpriteSheetIndex = this.carriesStuff ? 2 + this.carryType : 1;
            float redShift = MathF.Clamp(1.0f - (((float)Time.GameTimer.TotalSeconds - this.lastHitTime) / 0.5f), 0.0f, 1.0f);

            renderer.ColorTint = ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, redShift);

            character.TargetMovement = movementDirection * movementSpeed;

            // Hit Animation code
            if (hitAnimationStart + hitAnimationDuration > Time.GameTimer.TotalSeconds)
            {
                hitAnimationBlinkframes++;
                if (hitAnimationBlinkframes > hitAnimationBlinkrate)
                {
                    hitAnimationBlinkframes = 0;
                    if (renderer.Active == true)
                    {
                        renderer.Active = false;
                    }
                    else
                    {
                        renderer.Active = true;
                    }
                }
            }
            else
            {
                renderer.Active = true;
            }
        }
Ejemplo n.º 5
0
 public ActorActionFiniteStateMachine(TActor actor, ActorAnimator actorAnimator)
 {
     this.actor         = actor;
     this.actorAnimator = actorAnimator;
 }
Ejemplo n.º 6
0
 void Awake()
 {
     this.MyTransform  = this.transform;
     this.MyGameObject = this.gameObject;
     this.Animator     = this.MyGameObject.AddComponent <ActorAnimator>();
 }
Ejemplo n.º 7
0
 public ActionFSM(TActor actor, ActorAnimator actorAnimator) : base(actor, actorAnimator)
 {
 }
Ejemplo n.º 8
0
 private void PlayerAnimationStopped(ActorAnimator.AnimationData animation)
 {
 }