// Update is called once per frame
    void Update()
    {
        UpdateState();
        if (stateStack.Count > 0)
        {
            currentState = stateStack.Peek();
            switch (currentState)
            {
            case EVillagerState.idle:
                Idle();
                break;

            case EVillagerState.moving:
                Move();
                break;

            case EVillagerState.woodCutting:
                break;

            default:
                break;
            }
        }
        else
        {
            stateStack.Push(EVillagerState.idle);
        }
    }
    public void UpdateState()
    {
        currentTimeBtwStateChange -= Time.deltaTime;
        if (currentTimeBtwStateChange <= 0 || (newPosition - rb.position).magnitude < 0.2 || CanChangeSate)
        {
            CanChangeSate = false;

            currentState = (EVillagerState)Random.Range(0, sizeof(EVillagerState) - 1);
            ChangeState(currentState);

            switch (currentState)
            {
            case EVillagerState.idle:
                break;

            case EVillagerState.moving:
                GetNewPosition();
                break;

            case EVillagerState.woodCutting:
                break;

            default:
                break;
            }

            currentTimeBtwStateChange = Random.Range(0.5f, 1.5f) * timeBTWStateChange;
        }
    }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        rb          = transform.GetComponent <Rigidbody2D>();
        rb.velocity = Vector2.zero;

        sr   = transform.GetChild(0).GetComponent <SpriteRenderer>();
        anim = transform.GetChild(0).GetComponent <Animator>();

        currentTimeBTWPosChange = 0f;
        initPosition            = transform.position;
        GetNewPosition();

        currentState = EVillagerState.idle;

        stateStack.Push(currentState);
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        currentState = stateStack.Peek();

        UpdateNewPosition();

        switch (currentState)
        {
        case EVillagerState.idle:
            ChangeState(EVillagerState.moving);
            break;

        case EVillagerState.moving:
            Move();
            break;

        case EVillagerState.woodCutting:
            break;

        default:
            break;
        }
    }
Ejemplo n.º 5
0
 public void ChangeState(EVillagerState newState)
 {
     stateStack.Pop();
     stateStack.Push(newState);
     justChangedStates = true;
 }
Ejemplo n.º 6
0
    public void HandleBeingKilled()
    {
		GetComponent<AudioSource>().Stop();

		CurrentState = EVillagerState.Dying;
		villagerAnimations.AnimationDie();

		GameController.Instance.PlayerCharacter.RemoveVillagerFromColliding(this);
    }
Ejemplo n.º 7
0
	public void HandleBeingDroppedAsCultist(PrayerSpot prayerSpot)
	{
		CurrentState = EVillagerState.Praying;
		this.transform.SetParent(prayerSpot.transform);
		//this.transform.localPosition = prayerSpot.CultistSpot.localPosition;
		this.transform.localPosition = new Vector3(0f, -0.5f, 0f);

		if(GameController.Instance.Altar.transform.position.x > this.transform.position.x)
		{
			Vector3 newScale = this.transform.localScale;
			newScale.x = 1f;
			this.transform.localScale = newScale;
		}
		else
		{
			Vector3 newScale = this.transform.localScale;
			newScale.x = -1f;
			this.transform.localScale = newScale;
		}

		GetComponent<AudioSource>().Play();

		villagerAnimations.AnimationPray();

		if(GameController.Instance.PlayerCharacter != null)
			GameController.Instance.PlayerCharacter.RemoveVillagerFromColliding(this);
	}
Ejemplo n.º 8
0
	public void HandleBeingDroppedAsSacrifice()
	{

		CurrentState = EVillagerState.Dying;
		this.transform.SetParent(GameController.Instance.Altar.SacrificeSpot);
		//this.transform.localPosition = GameController.Instance.Altar.SacrificeSpot.position;
		this.transform.localPosition = new Vector3(0f, -0.35f, 0f);
		villagerAnimations.AnimationDie();

		GameController.Instance.PlayerCharacter.RemoveVillagerFromColliding(this);
	}
Ejemplo n.º 9
0
	public void HandleBeingDropped()
	{
		CurrentState = EVillagerState.Idle;
		this.transform.SetParent(GameController.Instance.PlayerCharacter.transform.parent);
		this.transform.localPosition = GameController.Instance.PlayerCharacter.transform.localPosition;
		villagerAnimations.AnimationIdle();
	}
Ejemplo n.º 10
0
	public void HandleBeingPickedUp()
	{
		CurrentState = EVillagerState.PickedUp;

		this.transform.SetParent(GameController.Instance.PlayerCharacter.PickablePoint);
		DOTween.To(() => this.transform.localPosition, (pos) => this.transform.localPosition = pos, Vector3.zero, 1.2f);

		//this.transform.localPosition = Vector3.zero;
		villagerAnimations.AnimationCarried();		
	}
Ejemplo n.º 11
0
    void ChooseVillagerMovementDirection()
    {
        movementRandomSeed = Random.Range(0f, maximumRollForRandomSeed);
        if (movementRandomSeed <= 2f)
        {
            CurrentState = EVillagerState.Idle;
			villagerAnimations.AnimationIdle();
        }
        else if (movementRandomSeed <= 2.5f)
        {
            CurrentState = EVillagerState.WalkingLeft;
			Vector3 newScale = this.transform.localScale;
			newScale.x = -1f;
			this.transform.localScale = newScale;
			villagerAnimations.AnimationMove();
        }
        else
        {
            CurrentState = EVillagerState.WalkingRight;
			Vector3 newScale = this.transform.localScale;
			newScale.x = 1f;
			this.transform.localScale = newScale;
			villagerAnimations.AnimationMove();
        }
    }