예제 #1
0
    public float GetFactor(GravityAttracted attracted)
    {
        float distanceToSurface = (attracted.transform.position - transform.position).magnitude - planetBodyRadius;

        //		Dbg.Log (this, "radiuses", radius, planetBodyRadius);
        return(minFactor + (maxFactor - minFactor) * (atmosfearRadius - distanceToSurface) / atmosfearRadius);
    }
예제 #2
0
    void Start()
    {
        Dbg.Log(this, "Start");

        hero        = GameObject.FindGameObjectWithTag("Player");
        messageText = GameObject.Find("MessageText").GetComponent <Text> ();

        messageText.text = "\n\n\nSmall Worlds!\nMade by @damrem in 48h for #ld38.\n\n\nUse arrow keys to move.\nYou can 'multi-jump'.\n\n\nMusic by @Ynck_33.";

        heroControl = hero.GetComponent <HeroControl> ();
        heroControl.moved.AddListener(ClearMessage);

        heroGravityAttracted = hero.GetComponent <GravityAttracted> ();

        sfxSource = GetComponent <AudioSource> ();

        planets = GetComponentsInChildren <PlanetView> ();

        isOver = false;
    }
예제 #3
0
    void Orient()
    {
        foreach (GameObject attractedGameObject in attractedGameObjectList)
        {
            GravityAttracted gravityAttracted = attractedGameObject.GetComponent <GravityAttracted> ();

//			float[] gravities = gravityAttracted.attractorList.ToArray().Map(delegate(GameObject attractor){
//				return attractor.GetComponent<Gravity>().GetFactor(GetComponent<CircleCollider2D>().radius, (transform.position-gravityAttracted.transform.position).magnitude);
//			});
//			Dbg.Log (this, "gravities 0", gravities [0]);
//			if (gravities.Length > 1){
//				Dbg.Log (this, "gravities 1", gravities [1]);
//				Dbg.Log (this, "same", gravityAttracted.attractorList [0] == gravityAttracted.attractorList [1]);
//			}

            if (gravityAttracted.AttractorList.Count == 0 || gravityAttracted.AttractorList [0] != gameObject)
            {
                break;
            }

//			if (gravityAttracted.ignoreOrientation)
//				break;
            if (gravityAttracted.lastLand != planetBody.gameObject)
            {
                break;
            }

            Rigidbody2D attractedBody = attractedGameObject.GetComponent <Rigidbody2D> ();

            Vector2 delta  = (transform.position - attractedBody.transform.position);
            Vector2 normal = delta.GetNormal();

            Quaternion destRotation = Quaternion.LookRotation(normal.normalized, -delta.normalized);
            destRotation.x = 0;
            destRotation.y = 0;

            attractedBody.transform.rotation = destRotation;
//			StartCoroutine(SmoothRotate(attractedBody, destRotation));
        }
    }
예제 #4
0
    void Fall()
    {
        foreach (GameObject attractedGameObject in attractedGameObjectList)
        {
            GravityAttracted gravityAttracted = attractedGameObject.GetComponent <GravityAttracted> ();

            if (gravityAttracted.land != null && gravityAttracted.land != planetBody)
            {
                break;
            }
//			if (gravityAttracted.attractorList[0] != gameObject)
//				break;

            Rigidbody2D attractedBody = attractedGameObject.GetComponent <Rigidbody2D> ();

            Vector2 delta = (transform.position - attractedBody.transform.position);

            CircleCollider2D collider = GetComponent <CircleCollider2D> ();

            float radius = collider.radius * Mathf.Sqrt(transform.localScale.x * transform.localScale.x);

            if (delta.magnitude > radius)
            {
                return;
            }

            Vector2 attraction = delta.Normalized(radius - delta.magnitude);

//			float factor = GetFactor (radius, delta.magnitude);
            float factor = GetFactor(gravityAttracted);
            //float factor = (maxFactor - minFactor) * (radius - delta.magnitude) / radius;
            Dbg.Log(this, "factor", factor);

//			if (gravityAttracted.land != null)
//				factor *= 10;

            attractedBody.AddForce(attraction * factor);
        }
    }
예제 #5
0
 void Start()
 {
     attractedComponent = GetComponent <GravityAttracted> ();
     animator           = GetComponentInChildren <Animator> ();
 }