コード例 #1
0
        public override Dictionary <string, object> SaveToDict()
        {
            var dict = new Dictionary <string, object>();

            dict.Add(GDMConstants.SchemaKey, "Enemy");

            dict.Merge(true, ID.ToGDEDict(IDKey));
            dict.Merge(true, MaxHP.ToGDEDict(MaxHPKey));
            dict.Merge(true, MoveVec.ToGDEDict(MoveVecKey));
            dict.Merge(true, AlertRange.ToGDEDict(AlertRangeKey));
            dict.Merge(true, AtkRange.ToGDEDict(AtkRangeKey));
            dict.Merge(true, AtkInterval.ToGDEDict(AtkIntervalKey));
            dict.Merge(true, HurtProtect.ToGDEDict(HurtProtectKey));
            dict.Merge(true, Mass.ToGDEDict(MassKey));
            dict.Merge(true, PrefabPath.ToGDEDict(PrefabPathKey));
            return(dict);
        }
コード例 #2
0
        public override Dictionary <string, object> SaveToDict()
        {
            var dict = new Dictionary <string, object>();

            dict.Add(GDMConstants.SchemaKey, "Hero");

            dict.Merge(true, ID.ToGDEDict(IDKey));
            dict.Merge(true, MaxHP.ToGDEDict(MaxHPKey));
            dict.Merge(true, MaxShieldVal.ToGDEDict(MaxShieldValKey));
            dict.Merge(true, ShieldRestoreVec.ToGDEDict(ShieldRestoreVecKey));
            dict.Merge(true, MoveVec.ToGDEDict(MoveVecKey));
            dict.Merge(true, HurtProtect.ToGDEDict(HurtProtectKey));
            dict.Merge(true, Mass.ToGDEDict(MassKey));
            dict.Merge(true, ShieldRestoreInterval.ToGDEDict(ShieldRestoreIntervalKey));
            dict.Merge(true, ShieldRestoreBreak.ToGDEDict(ShieldRestoreBreakKey));
            dict.Merge(true, PrefabPath.ToGDEDict(PrefabPathKey));
            return(dict);
        }
コード例 #3
0
    public override void _Process(float delta)
    {
        base._Process(delta);

        if (CurrentState == State.Spawning || CurrentState == State.Dead)
        {
            return;
        }

        if (path.Count == 0)
        {
            CurrentState = State.Idle;
            ShootTimer.Stop();
            RecalculatePath();
            return;
        }

        if (GlobalPosition.DistanceTo(path[0]) < NextPathPoint || (IsInstanceValid(target) && GlobalPosition.DistanceTo(path[0]) < 32 && path[0].DistanceTo(target.GlobalPosition) > GlobalPosition.DistanceTo(target.GlobalPosition)))
        {
            path.RemoveAt(0);

            if (path.Count == 0)
            {
                return;
            }
        }

        MoveVec = GlobalPosition.DirectionTo(path[0]);

        Array overlappingBodies = TargetArea.GetOverlappingBodies();

        if (overlappingBodies.Count == 0)
        {
            CurrentState = State.Sprint;
            ShootTimer.Stop();
        }
        else if (PriorityTargetArea.GetOverlappingBodies().Contains(target))
        {
            CurrentState = State.Idle;
            if (ShootTimer.IsStopped())
            {
                ShootTimer.Start();
            }
        }
        else
        {
            CurrentState = State.Move;
            if (ShootTimer.IsStopped())
            {
                ShootTimer.Start();
            }
        }

        float rotateTarget;

        switch (CurrentState)
        {
        case State.Spawning:
            return;

        case State.Idle:
            AnimationPlayer.Play("Idle");
            rotateTarget = target.GlobalPosition.AngleToPoint(RotateGroup.GlobalPosition);
            Rotate(delta, rotateTarget);
            break;

        case State.Move:
            AnimationPlayer.Play("Move");
            var   closest         = (PhysicsBody2D)overlappingBodies[0];
            float closestDistance = GlobalPosition.DistanceTo(closest.GlobalPosition);
            foreach (PhysicsBody2D body in overlappingBodies)
            {
                float dist = GlobalPosition.DistanceTo(body.GlobalPosition);
                if (dist < closestDistance)
                {
                    closest         = body;
                    closestDistance = dist;
                }
            }
            rotateTarget = closest.GlobalPosition.AngleToPoint(RotateGroup.GlobalPosition);
            Rotate(delta, rotateTarget);

            break;

        case State.Sprint:
            AnimationPlayer.Play("Sprint");
            rotateTarget = MoveVec.Angle();
            Rotate(delta, rotateTarget);
            break;
        }
    }
コード例 #4
0
    public override void _Process(float delta)
    {
        base._Process(delta);

        // Get Input
        MoveVec    = Vector2.Zero;
        MoveVec.x += Input.GetActionStrength("right");
        MoveVec.x -= Input.GetActionStrength("left");
        MoveVec.y += Input.GetActionStrength("down");
        MoveVec.y -= Input.GetActionStrength("up");
        MoveVec    = MoveVec.Normalized();

        // Rotate To Mouse
        float target = GetGlobalMousePosition().AngleToPoint(RotateGroup.GlobalPosition);

        Rotate(delta, target);

        switch (CurrentState)
        {
        case State.Spawning:
            return;

        case State.Idle:
            AnimationPlayer.Play("Idle");

            break;

        case State.Move:
            AnimationPlayer.Play("Move");

            // Offset Camera
            Camera.Position = MoveVec * CameraForwardMult;

            break;

        case State.Sprint:
            AnimationPlayer.Play("Sprint");

            // Offset Camera
            Camera.Position = MoveVec * CameraForwardMult * SprintMult;

            break;
        }

        Vector2 rotationalVec = MoveVec;

        rotationalVec.y *= -1;
        rotationalVec    = rotationalVec.Rotated(target);

        if (MoveVec == Vector2.Zero)
        {
            CurrentState = State.Idle;
        }
        else if (Input.IsActionPressed("sprint") && rotationalVec.x > .3f)
        {
            CurrentState = State.Sprint;
        }
        else
        {
            CurrentState = State.Move;
        }
    }