Exemplo n.º 1
0
 public ActorDrawTracker(Actor actor)
 {
     this.actor = actor;
     tweener    = new ActorTweener(actor);
     jitterer   = new JitterHandler();
     leaner     = new ActorLeaner(actor);
     renderer   = new ActorRenderer(actor);
     ui         = new ActorUIOverlay(actor);
 }
Exemplo n.º 2
0
        public override void OnUpdate()
        {
            base.OnUpdate();
            ActorRenderer sprite    = this.GameObj.GetComponent <ActorRenderer>();
            Transform     transform = this.GameObj.Transform;

            Vector2 moveVec = transform.Vel.Xy;
            float   moveDir = moveVec.Angle;

            if (moveVec.Length <= 0.75f)
            {
                sprite.AnimFirstFrame = 0;
            }
            else if (MathF.CircularDist(moveDir, 0.0f) <= MathF.RadAngle45)
            {
                sprite.AnimFirstFrame = 9;
            }
            else if (MathF.CircularDist(moveDir, MathF.RadAngle90) <= MathF.RadAngle45)
            {
                sprite.AnimFirstFrame = 6;
            }
            else if (MathF.CircularDist(moveDir, MathF.RadAngle270) <= MathF.RadAngle45)
            {
                sprite.AnimFirstFrame = 3;
            }
            else
            {
                sprite.AnimFirstFrame = 0;
            }

            this.lifeTimeMs += Time.TimeMult * Time.MsPFMult;
            if (this.lifeTimeMs > 500.0f)
            {
                this.Energy -= (Time.MsPFMult / (50.0f)) * Time.TimeMult;
                if (this.Energy + this.TransferEnergy <= 0.0f)
                {
                    this.GameObj.Dispose();
                }
                this.HurtCharacters();
            }

            if (this.fireLoopInstance != null && this.fireLoopInstance.Disposed)
            {
                this.fireLoopInstance = null;
            }
            if (this.fireLoopInstance == null)
            {
                float scale = this.GetScale(this.Energy);
                if (scale > 0.05f && this.fireLoopSound != null)
                {
                    this.fireLoopInstance        = DualityApp.Sound.PlaySound3D(this.fireLoopSound, this.GameObj);
                    this.fireLoopInstance.Looped = true;
                    this.fireLoopInstance.Volume = scale;
                }
            }
        }
Exemplo n.º 3
0
    public void Destroy()
    {
        if (renderer != null)
        {
            renderer.BeforeDestroy();

            renderer.Destroy();
            renderer = null;
        }
    }
Exemplo n.º 4
0
        private void RefreshAnimation()
        {
            GraphicResource resource = (currentTransitionState != AnimState.Idle ? currentTransition : currentAnimation);

            if (renderer == null)
            {
                renderer = AddComponent <ActorRenderer>();
                renderer.AnimationFinished = OnAnimationFinished;
                renderer.AlignToPixelGrid  = true;
                renderer.Offset            = -2000;
                renderer.Flip = (isFacingLeft ? SpriteRenderer.FlipMode.Horizontal : SpriteRenderer.FlipMode.None);
            }

            renderer.SharedMaterial     = resource.Material;
            renderer.FrameConfiguration = resource.Base.FrameConfiguration;

            if (float.IsInfinity(resource.FrameDuration))
            {
                if (resource.FrameCount > 1)
                {
                    renderer.AnimFirstFrame = resource.FrameOffset + MathF.Rnd.Next(resource.FrameCount);
                }
                else
                {
                    renderer.AnimFirstFrame = resource.FrameOffset;
                }

                renderer.AnimLoopMode = ActorRenderer.LoopMode.FixedSingle;
            }
            else
            {
                renderer.AnimFirstFrame = resource.FrameOffset;

                renderer.AnimLoopMode = (resource.OnlyOnce ? ActorRenderer.LoopMode.Once : ActorRenderer.LoopMode.Loop);
            }

            renderer.AnimFrameCount = resource.FrameCount;
            renderer.AnimDuration   = resource.FrameDuration;
            renderer.Rect           = new Rect(
                -resource.Base.Hotspot.X,
                -resource.Base.Hotspot.Y,
                resource.Base.FrameDimensions.X,
                resource.Base.FrameDimensions.Y
                );

            renderer.AnimTime = 0;

            OnAnimationStarted();

            if ((collisionFlags & CollisionFlags.SkipPerPixelCollisions) == 0)
            {
                // ToDo: Workaround for refresh of AABB
                Transform.Pos = Transform.Pos;
            }
        }
Exemplo n.º 5
0
    public void Init(string resName, ActorType type, int id)
    {
        ID = id;

        if (type == ActorType.Sprite)
        {
            renderer = new ActorRendererSprite();
        }
        else if (type == ActorType.Skin)
        {
            renderer = new ActorRendererSkin();
        }

        renderer.Init(resName, this);
        renderer.AfterInit();
    }
Exemplo n.º 6
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;
            }
        }