Ejemplo n.º 1
0
    // Update is called once per frame
    void Update () {
		if (state == PigState.Jumping) {
			float duration = Time.time - jumpStartTime;
			float progress = duration / jumpDuration;
			Vector2 vertical = Vector2.up * Mathf.Sin (Mathf.PI * progress) * jumpHeight;
			transform.position = Vector2.Lerp (startPos, target, duration / jumpDuration) + vertical;
			if (duration > jumpDuration) {
				state = PigState.Idle;
				ScheduleJump ();
			}
		}
        UpdateScaredOf();
        
	}
Ejemplo n.º 2
0
 // Use this for initialization
 void Start () {
     sr = transform.FindChild("Graphics").GetComponent<SpriteRenderer>();
     sprite = 0;
     sr.sprite = sprites[sprite].leftSprite;
     state = PigState.Idle;
     ScheduleJump();
         poopCoroutine = StartCoroutine(PoopSometimes());
         starveCoroutine = StartCoroutine(Starve());
         randomInfectCoroutine = StartCoroutine(RandomlyInfectSometime());
         
         if (infectious) {
             sprites = infectedSprites;
             UpdateSprite();
         }
 }
Ejemplo n.º 3
0
	/* Delays by a random amount
	 * and then jump
	 */
	IEnumerator JumpWithDelay(float delay) {
		yield return new WaitForSeconds(delay);
        jumpDuration = (Scared) ? JUMP_DUR / 3f : JUMP_DUR;
        targetObj = null;
        if (infectious && followPigsWhenInfected) {
            TargetCleanPig();
        } else if (!infectious && Scared) {
            RunAway();
        } else if (!infectious) {
            TargetGrassIfHungry();
        }
        if (targetObj == null) {
            target = Map.Inst.Bound(Random.insideUnitCircle * jumpRange
                    + (Vector2)transform.position);
        } else {
            Vector3 vecToTarget = targetObj.transform.position
                    - transform.position;
            vecToTarget = Vector3.ClampMagnitude(vecToTarget, jumpRange);
            float extra = (Scared) ? 0.7f : 0.1f;
            vecToTarget += Random.insideUnitSphere * jumpRange * extra;
            target = Map.Inst.Bound(transform.position + vecToTarget);
        }

		startPos = transform.position;
		if (target.x > transform.position.x) {
            left = false;
		} else {
            left = true;
		}
        UpdateSprite();
		state = PigState.Jumping;
		jumpStartTime = Time.time;
	}