Exemple #1
0
        static void Main(string[] args)
        {
            var gameState    = GameState.Create();
            var currentPhase = MovementPhase.Create();

            while (currentPhase != null)
            {
                Console.WriteLine($"{currentPhase.Id}: {currentPhase.Description}");
                var actions = currentPhase.PossibleActions.ToList();
                int i       = 1;
                actions.ForEach(act => Console.WriteLine($"{i++}: {act.Description}"));
                int selectIdx = -1;
                while (selectIdx < 0)
                {
                    Console.Write($"Choice(1-{actions.Count})?: ");
                    string data = Console.ReadLine();
                    if (int.TryParse(data, out int value))
                    {
                        int actIdx = value - 1;
                        if (actIdx >= 0 && actIdx < actions.Count)
                        {
                            selectIdx = actIdx;
                        }
                    }
                }
                currentPhase = actions[selectIdx].Execute(gameState);
            }
        }
Exemple #2
0
 public void MoveTo(Func <float2> position, Func <float2> velocity, Action onFinish = null)
 {
     TargetPosition  = position;
     TargetVelocity  = velocity;
     MatchVelocity   = true;
     _movementPhase  = MovementPhase.Locomotion;
     Moving          = true;
     _onFinishMoving = onFinish;
 }
Exemple #3
0
 public void MoveTo(float2 position, bool matchVelocity = true, Action onFinish = null)
 {
     TargetPosition  = () => position;
     TargetVelocity  = () => float2.zero;
     MatchVelocity   = matchVelocity;
     _movementPhase  = MovementPhase.Locomotion;
     Moving          = true;
     _onFinishMoving = onFinish;
 }
Exemple #4
0
 public void MoveTo(Entity entity, bool matchVelocity = true, Action onFinish = null)
 {
     TargetPosition  = () => entity.Position;
     TargetVelocity  = () => entity.Velocity;
     MatchVelocity   = matchVelocity;
     _movementPhase  = MovementPhase.Locomotion;
     Moving          = true;
     _onFinishMoving = onFinish;
 }
 public void SetRotationTarget(Vector3 target)
 {
     rotateTarget  = target;
     movementPhase = MovementPhase.ROTATE;
     if (Neutral)
     {
         Neutral = false;
     }
 }
        public void RegisterMovementEngine(MovementPhase phase, IMovementEngine engine)
        {
            if (engines.ContainsKey(phase))
            {
                throw new InvalidOperationException("please add a new MovementPhase in the enum and use it.");
            }

            engines[phase]      = engine;
            enginesFasterAccess = engines.OrderBy(x => x.Key).Select(x => x.Value).ToArray();
        }
Exemple #7
0
 void Awake()
 {
     teamChecker       = this.GetComponent <TeamChecker> ();
     countryManagement = this.GetComponent <CountryManagement> ();
     targetingNetwork  = this.GetComponent <TargetingNetwork> ();
     attack            = this.GetComponent <Attack> ();
     globalFunctions   = this.GetComponent <GlobalFunctions> ();
     phases            = this.GetComponent <Phases> ();
     movementPhase     = this.GetComponent <MovementPhase> ();
 }
 public void SetWalkTarget(Vector3 target)
 {
     walkTarget             = target;
     agent.speed            = walkSpeed;
     agent.stoppingDistance = surveyDistance;
     agent.SetDestination(target); // Set the walk target as our NavMesh Agent's target, this will have the agent moving of its own accord.
     movementPhase = MovementPhase.WALK;
     if (Neutral)
     {
         Neutral = false;
     }
 }
    public override void Hit(int damage, string guid)
    {
        if (guid == NodeGuid.ToString())
        {
            if (HitCoolDownTimer <= 0.0f)
            {
                Health -= damage;

                var hud = this.GetParent().GetNode <HUD>("HUD");
                hud.SetBossHealthBarPercent(((float)Health) / ((float)TotalHealth));

                Phase = MovementPhase.Hit;

                if (Health > 0)
                {
                    HitAnimationTimer = 0.2f;
                    HitCoolDownTimer  = 0.5f;
                    DamageToTake      = damage;
                    this.GetNode <AudioStreamPlayer2D>("HitSound").Play();
                }
                else
                {
                    var    explosion         = (PackedScene)ResourceLoader.Load("res://Components/Explosion.tscn");
                    Node2D explosionInstance = (Node2D)explosion.Instance();
                    var    position          = this.GlobalPosition;
                    explosionInstance.Position = position;
                    this.GetParent().AddChild(explosionInstance);

                    var  coin         = (PackedScene)ResourceLoader.Load("res://Components/Coin.tscn");
                    Coin coinInstance = (Coin)coin.Instance();
                    coinInstance.Position = position;

                    if (Rnd.NextDouble() < 0.90)
                    {
                        coinInstance.SetValue(1);
                        hud.AddCoin(1);
                    }
                    else
                    {
                        coinInstance.SetValue(5);
                        hud.AddCoin(5);
                    }

                    this.GetParent().AddChild(coinInstance);

                    EmitSignal(nameof(BossDefeated));

                    CallDeferred("free");
                }
            }
        }
    }
    // SURVEY - This method will be rather simple for now.
    private void SurveyArea()
    {
        if (agent.hasPath)
        {
            agent.ResetPath();
        }

        // If the enemy sees nothing of interest in the disturbance zone, his movement will return to neutral after 3 seconds.
        if (tm.TimeCount(3))
        {
            movementPhase = MovementPhase.NEUTRAL;
        }
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Invoke Unsuccessful Hit
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public void InvokeUnsuccessfulHit()
    {
        SprRend.sprite = m_sprMissedSprite;
        AudioSourceManager.PlayAudioClip(m_acMissedSound);

        if (!TutorialManager_Base.TutorialOpened)
        {
            m_rChallengeModeInfo.ChallengeScore -= 0.01f;
            m_rChallengeModeInfo.Score          -= 0.01f;
            m_rChallengeModeInfo.VisibleScore   -= 0.01f;
            m_rChallengeModeInfo.RemoveNote(this);
        }

        m_eMovementPhase = MovementPhase.MISS;
        m_fMissedTime    = Random.Range(0.0f, 10.0f);
    }
    void Start()
    {
        #region Obtain variables from the scripts we require.
        AI = GetComponent <EnemyController>(); // Get our EC script and the variables we need.
        //POV_GO = AI.POV_GO;
        //surveyPoints = AI.surveyPoints;
        walkSpeed        = AI.WalkSpeed * AI.GravMultiplier;
        runSpeed         = walkSpeed * AI.RunMultiplier;
        turningSpeed     = AI.TurningSpeed;
        surveyTime       = AI.SurveyTime;
        agent            = GetComponent <NavMeshAgent>(); // Get our NavMesh Agent script and the variables we need.
        stoppingDistance = agent.stoppingDistance;
        surveyDistance   = stoppingDistance + VIEW_DISTANCE;
        attackDistance   = AI.AlertDistance;
        #endregion

        movementPhase = MovementPhase.NEUTRAL; // Enemies will initially have no independent movement outside their patrol/post.
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Update Unsuccessful Hit~
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private void UpdateUnsuccessfulHit()
    {
        if (m_ttMissedMovementTracker.Update())
        {
            SprRend.color    = new Color(1.0f, 1.0f, 1.0f, 0.0f);
            m_eMovementPhase = MovementPhase.IDLE;
        }
        else
        {
            float timeAdjustment = Time.deltaTime * 10.0f;
            m_fMissedTime += timeAdjustment;
            float xAdjustment = Mathf.Cos(m_fMissedTime) * 0.01f;

            float newX = m_rChallengeModeInfo.targetLocation.x + xAdjustment;                   // Gradually Moving Left to Right
            float newY = LocalPosition.y - 0.1f * Time.deltaTime;                               // Gradually falling

            transform.localPosition = new Vector3(newX, newY, transform.localPosition.z);
            SprRend.color           = new Color(1.0f, 1.0f, 1.0f, 1.0f - m_ttMissedMovementTracker.GetCompletionPercentage());
        }
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Invoke Successful Hit
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public void InvokeSuccessfulHit()
    {
        SprRend.sprite = m_sprSuccessSprite;
        AudioSourceManager.PlayAudioClip(m_acHitSound);

        m_rChallengeModeInfo.Score += m_rChallengeModeInfo.NoteScore;
        m_rChallengeModeInfo.RemoveNote(this);
        // !!!Change the Score During Success Animation!!! //

        m_eSuccessAnimationPhase = SuccessAnimationPhase.TO_SCORE;

        if (m_eMovementPhase == MovementPhase.AUTO_PLAY)
        {
            LocalPosition.x = m_rChallengeModeInfo.victoryLocation.x;
        }
        m_arToScoreAnimation[0].m_vStartingPosition = LocalPosition;

        m_eMovementPhase           = MovementPhase.SUCCESS;
        m_iCurrentAnimationElement = 0;
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Update Successful Hit!
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    private void UpdateSuccessfulHit()
    {
        if (m_eSuccessAnimationPhase == SuccessAnimationPhase.TO_SCORE)
        {
            if (m_arToScoreAnimation[m_iCurrentAnimationElement].UpdateAnimation())
            {
                m_iCurrentAnimationElement += 1;
                if (m_iCurrentAnimationElement >= m_arToScoreAnimation.Length)
                {
                    m_iCurrentAnimationElement = 0;
                    m_eSuccessAnimationPhase   = SuccessAnimationPhase.TO_BAG;

                    // Update Score
                    m_rChallengeModeInfo.IncrementScore();

                    // Reset Animations
                    for (int i = 0; i < m_arToScoreAnimation.Length; ++i)
                    {
                        m_arToScoreAnimation[i].Reset();
                    }
                }
            }
        }
        else
        {
            if (m_arIntoBagAnimation[m_iCurrentAnimationElement].UpdateAnimation())
            {
                m_iCurrentAnimationElement += 1;
                if (m_iCurrentAnimationElement >= m_arIntoBagAnimation.Length)
                {
                    m_eMovementPhase = MovementPhase.IDLE;

                    // Reset Animations
                    for (int i = 0; i < m_arIntoBagAnimation.Length; ++i)
                    {
                        m_arIntoBagAnimation[i].Reset();
                    }
                }
            }
        }
    }
    public void SetRunTarget(Vector3 target)
    {
        //if (!alerted) alerted = true;
        if (movementPhase != MovementPhase.ATTACK)
        {
            runTarget              = target;
            agent.speed            = runSpeed;
            agent.stoppingDistance = attackDistance;
        }

        if (!AI.PlayerTracker.LineOfSight.enabled)
        {
            agent.stoppingDistance = surveyDistance;
        }


        //agent.SetDestination(target); // Set the walk target as our NavMesh Agent's target, this will have the agent moving of its own accord.
        movementPhase = MovementPhase.RUN;
        if (Neutral)
        {
            Neutral = false;
        }
    }
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //	* New Method: Reset
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public void Reset()
    {
        m_eMovementPhase   = MovementPhase.IDLE;
        m_fCurrentBeatLine = m_fBeatPos;
        SprRend.sprite     = m_sprNormalSprite;


        SpriteRenderer sprRend = GetComponent <SpriteRenderer>();

        if (sprRend != null)
        {
            sprRend.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
        }

        if (m_vStartPosition != Vector3.zero)
        {
            transform.localPosition = m_vStartPosition;
        }

        if (m_ttMissedMovementTracker != null)
        {
            m_ttMissedMovementTracker.Reset();
        }
    }
 // Methode called by InputLogigScript to set movemten in dependence to input
 public void SetMovementPhase(MovementPhase movementPhase)
 {
     switch (movementPhase)
     {
         case MovementPhase.Jump:
             // Set new buffer time and start waiting to true
             jumpBufferTime = Time.time;
             jump = true;
             break;
         case MovementPhase.HighJump:
             highjump = true;
             break;
         case MovementPhase.Slide:
             // Set new buffer time and start waiting to true
             slideBufferTime = Time.time;
             slide = true;
             break;
         case MovementPhase.Shoot:
             Rigidbody missleInstance;
             missleInstance = Instantiate(missle, missleStartPosition.position, missleStartPosition.rotation) as Rigidbody;
             missleInstance.AddForce(missleStartPosition.right * misslePower);
             break;
     }
 }
Exemple #19
0
 public static Scene Create() =>
 new MovementScene(GameState.Create(), MovementPhase.Create());
Exemple #20
0
        private void Update()
        {
            if (MinigameManager.IsPaused || !m_miniGame.GameLogic.IsGameInProgress || !m_isBattleInProgress)
            {
                return;
            }
            Vector3 position;

            switch (m_currentMovementPhase)
            {
            case MovementPhase.APPROACH:
                position    = base.transform.position;
                position.x -= 3.8f * Time.deltaTime;
                base.transform.position = position;
                if (!m_hasAppearanceSoundPlayed && position.x < m_miniGame.VisibleWorldBounds.max.x)
                {
                    m_miniGame.PlaySFX(mg_jr_Sound.BOSS_KLUTZY_LOOP.ClipName());
                    m_hasAppearanceSoundPlayed = true;
                }
                if (m_klutzySprite.bounds.max.x < m_miniGame.VisibleWorldBounds.max.x)
                {
                    int num = (int)(m_targetFlightPath = (FlightPath)Random.Range(0, 3));
                    switch (m_targetFlightPath)
                    {
                    case FlightPath.TOP:
                        m_currentVerticalMovementDirection = 1f;
                        break;

                    case FlightPath.MIDDLE:
                        m_currentVerticalMovementDirection = 0f;
                        break;

                    case FlightPath.BOTTOM:
                        m_currentVerticalMovementDirection = -1f;
                        break;

                    default:
                        Assert.IsTrue(condition: false, "Invalid flight path");
                        break;
                    }
                    m_currentMovementPhase = MovementPhase.WAITING;
                }
                break;

            case MovementPhase.WAITING:
                m_timeWaiting += Time.deltaTime;
                if (m_timeWaiting > 0.5f && Random.value > 0.5f)
                {
                    m_miniGame.PlaySFX(mg_jr_Sound.BOSS_KLUTZY_LAUGH.ClipName());
                    m_currentMovementPhase = MovementPhase.NORMAL;
                }
                break;

            case MovementPhase.NORMAL:
                position    = base.transform.position;
                position.x -= 3.8f * Time.deltaTime;
                position.y += 1.8f * Time.deltaTime * m_currentVerticalMovementDirection;
                if (position.y > 3f)
                {
                    position.y = 3f;
                    m_currentVerticalMovementDirection = -1f;
                    m_currentMovementPhase             = MovementPhase.WAITING;
                }
                if (position.y < -1f)
                {
                    position.y = -1f;
                    m_currentVerticalMovementDirection = 1f;
                    m_currentMovementPhase             = MovementPhase.WAITING;
                }
                base.transform.position = position;
                if (position.x < m_miniGame.VisibleWorldBounds.min.x && !m_miniGame.VisibleWorldBounds.Intersects(m_reactorRingsRight.bounds))
                {
                    if (m_bossCompleteCallback != null)
                    {
                        m_bossCompleteCallback();
                    }
                    m_miniGame.StopSFX(mg_jr_Sound.BOSS_KLUTZY_LOOP.ClipName());
                    m_isBattleInProgress = false;
                    m_miniGame.Resources.ReturnPooledResource(base.gameObject);
                }
                break;

            default:
                Assert.IsTrue(condition: false, "Unknown movement phase");
                break;
            }
        }
    public override void _Process(float delta)
    {
        switch (Phase)
        {
        // Slide down from the top.
        case MovementPhase.JustEntered:
            if (this.Position.y < 100)
            {
                this.Translate(positionDifference * moveSpeed * delta);
                moveSpeed -= 0.005f;
            }
            else
            {
                oldPosition = this.Position;
                moveSpeed   = game.Boss1MoveSpeed;
                Phase       = MovementPhase.MovingInCircle;
            }
            break;

        // Move in increasingly smaller circles.
        case MovementPhase.MovingInCircle:
            var newPoint = PointOnCircle(currentRadius, currentAngle, playerPosition);

            // FIXME - get this to work
            //LookAt(PointOnCircle(currentRadius, currentAngle - 10, playerPosition));

            Translate((newPoint - oldPosition));

            // Continue to move in a circle.
            currentAngle += movingClockwise ?
                            moveSpeed * delta :
                            moveSpeed * delta * -1;

            // And shrink the circle based on how long we've been in this phase.
            if (currentRadius > minimumRadiusLimit)
            {
                currentRadius -= shrinkSpeed * delta;
            }

            // Count up and then shoot fly's at the player!
            if (shootProjectileTimer < game.Boss1ShootStartingTimer)
            {
                shootProjectileTimer += delta;
            }
            else
            {
                if (shootProjectileLimit > game.Boss1ShootMinimumTime)
                {
                    shootProjectileLimit -= 0.3f;
                }

                shootProjectileTimer = 0.0f;

                var aSprite = this.GetNode <AnimatedSprite>("Sprite");
                aSprite.Play("attacking2");
                aSprite.Playing = true;

                var dae = (PackedScene)ResourceLoader.Load("res://Components/DirectAttackEnemy.tscn");
                DirectAttackEnemy daeInstance = (DirectAttackEnemy)dae.Instance();
                this.GetParent().AddChild(daeInstance);
                var temp = this.Position;
                daeInstance.SetStartingPosition(temp);
                daeInstance.SetVariety(3);
            }

            oldPosition = newPoint;
            break;

        // Back up and change direction.
        case MovementPhase.Hit:
            currentRadius = originalRadius;

            newPoint = PointOnCircle(currentRadius, currentAngle, playerPosition);
            Translate((newPoint - oldPosition));

            oldPosition     = newPoint;
            movingClockwise = !movingClockwise;

            shootProjectileTimer = 0.0f;
            DamageToTake         = 0;
            moveSpeed           += 4.0f;

            Phase = MovementPhase.MovingInCircle;
            break;
        }


        if (HitCoolDownTimer > 0.0f)
        {
            HitCoolDownTimer -= delta;
        }
        else
        {
            if ((Area.GetOverlappingAreas().Count) > 0 && (DamageToTake > 0))
            {
                Phase = MovementPhase.Hit;
            }
        }

        if (HitAnimationTimer > 0.0f)
        {
            var sprite = this.GetNode <AnimatedSprite>("Sprite");
            sprite.SelfModulate = new Color(0.5f - HitAnimationTimer, 0.5f - HitAnimationTimer, 0.5f - HitAnimationTimer);

            HitAnimationTimer -= delta;
        }
        else
        {
            HitAnimationTimer = 0.0f;
            var sprite = this.GetNode <AnimatedSprite>("Sprite");
            sprite.SelfModulate = new Color(1, 1, 1);
        }
    }
 public void RegisterMovementEngine(MovementPhase phase, IMovementEngine engine)
 {
 }
    void Update()
    {
        if (AI.DebugMode)
        {
            Debug.Log("Movement walk speed:" + walkSpeed);
            Debug.Log("Movement run speed:" + runSpeed);
        }
        switch (movementPhase)
        {
        case MovementPhase.WALK:
            if (DestinationReached())
            {
                movementPhase = MovementPhase.SURVEY;
            }
            break;

        case MovementPhase.RUN:
            if (DestinationReached())
            {
                movementPhase = MovementPhase.ATTACK;
            }
            break;

        case MovementPhase.ROTATE:
            RotateTowards("Enemy", rotateTarget);
            break;

        case MovementPhase.SURVEY:
            SurveyArea();
            break;

        case MovementPhase.ATTACK:
            agent.stoppingDistance = attackDistance;
            if (tm.TimeCount(AI.ShootCooldown))
            {
                AI.Shoot();
            }

            if (PlayerInAttackRange())
            {
                RotateTowards("Enemy", AI.Player.transform.position);
            }

            if (!PlayerInAttackRange())
            {
                SetRunTarget(AI.Player.transform.position);
            }
            break;

        case MovementPhase.NEUTRAL:
            if (!Neutral)
            {
                Neutral = true;
            }
            if (AI.Alerted)
            {
                AI.Alerted = false;
                AI.EnableBackupCall(false);     // This should disable the enemy's backup call zone.
            }
            break;
        }
    }
Exemple #24
0
    public bool Update(float delta)
    {
        if (Available)
        {
            // No task is assigned and we're at home, do nothing!
            if (_entity.Parent == HomeEntity)
            {
                return(false);
            }

            // No task is assigned, but we're not home, go home!
            if (!Moving)
            {
                GoHome();
            }
        }

        if (Waiting)
        {
            _waitTime -= delta;
            if (_waitTime < 0)
            {
                Waiting = false;
                _onFinishWaiting?.Invoke();
            }

            return(true);
        }

        if (Moving)
        {
            if (_entity.Parent != Guid.Empty)
            {
                _context.RemoveParent(_entity);
            }

            var targetPosition = TargetPosition();
            var distance       = length(targetPosition - _entity.Position);
            if (MatchVelocity)
            {
                var targetVelocity = TargetVelocity();
                VelocityMatch.TargetVelocity = targetVelocity;
                if (_movementPhase == MovementPhase.Locomotion)
                {
                    var matchDistanceTime = VelocityMatch.MatchDistanceTime;
                    Locomotion.Objective = targetPosition + targetVelocity * matchDistanceTime.y;
                    Locomotion.Update(delta);

                    if (distance < matchDistanceTime.x)
                    {
                        _movementPhase = MovementPhase.Slowdown;
                        //_context.Log($"Controller {_entity.Name} has entered slowdown phase.");
                        VelocityMatch.Clear();
                        VelocityMatch.OnMatch += () =>
                        {
                            Moving = false;
                            _onFinishMoving?.Invoke();
                        };
                    }
                }
                else
                {
                    VelocityMatch.TargetVelocity = targetVelocity;
                    VelocityMatch.Update(delta);
                }
            }
            else
            {
                Locomotion.Objective = TargetPosition();
                Locomotion.Update(delta);
                if (distance < _controllerData.TargetDistance)
                {
                    Moving = false;
                    _onFinishMoving();
                }
            }
        }

        return(true);
    }
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //	* New Methods: Begin Movement
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 public void BeginMovement()
 {
     SprRend.sprite   = m_sprNormalSprite;
     m_eMovementPhase = MovementPhase.MOVEMENT;
 }
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //	* New Method: Begin AutoPlay
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 public void BeginAutoPlay()
 {
     m_eMovementPhase = MovementPhase.AUTO_PLAY;
 }