Exemplo n.º 1
0
    //Clamps particles from the collisions module inside the borders
    private void ClampParticles()
    {
        //GameObject.Find looks in the scene view for a gameobject with name ("NAME")
        GameObject BorderLeft   = GameObject.Find("BorderLeft");
        GameObject BorderRight  = GameObject.Find("BorderRight");
        GameObject BorderTop    = GameObject.Find("BorderTop");
        GameObject BorderBottom = GameObject.Find("BorderBottom");

        //buffer which changes the border size of the confines
        float buffer = 0.01f;

        foreach (newParticle particle in newParticle.ParticleInstances)
        {
            Vector3 newPosition = particle.MyGameObject.transform.position + particle.currentVelocity * deltaT;
            //Clamps the particles position to inside of the borders
            float diameter = particle.diameter;

            float minX = BorderLeft.transform.position.x + diameter / 2 + (BorderLeft.GetComponent <Renderer>().bounds.size.x / 2) - buffer;
            float maxX = BorderRight.transform.position.x - diameter / 2 - (BorderRight.GetComponent <Renderer>().bounds.size.x / 2) + buffer;

            float minY = BorderBottom.transform.position.y + diameter / 2 + (BorderBottom.GetComponent <Renderer>().bounds.size.y / 2) - buffer;
            float maxY = BorderTop.transform.position.y - diameter / 2 - (BorderTop.GetComponent <Renderer>().bounds.size.y / 2) + buffer;

            //Clamps position to be inside of the border objects
            newPosition.x = MyMaths.Clamp(newPosition.x, minX, maxX);
            newPosition.y = MyMaths.Clamp(newPosition.y, minY, maxY);
            particle.MyGameObject.transform.position = newPosition;
        }
    }
        // Walk horizontaly
        public override void WalkHorizontal(float targetSpeed)
        {
            // lerp the sprite scale (prob wont keep)
            imageScale = MyMaths.Lerp(imageScale,
                                      Math.Sign(targetSpeed),
                                      .25f * GahameController.GameSpeed * (GameInput.ControllerMode && !GahameController.CutScene ? Math.Abs(GameInput.AbsLeftStickX) : 1));

            // keeps it from memeing maxSpeed
            targetSpeed = MyMaths.Clamp(targetSpeed, -maxSpeed, maxSpeed);

            // Approach the target speed
            physics.Velocity.X = MyMaths.Approach(physics.Velocity.X, targetSpeed,
                                                  GahameController.GameSpeed * (physics.Grounded ? accelerationSpeed : airAccelerationSpeed));

            // Sprite things
            if (spriteManager.CurrentSprite != "Moving")
            {
                spriteManager.ChangeSprite("Moving");
                spriteManager.GetSprite("Moving").CurrentImage = 0;
            }
            spriteManager.GetSprite("Moving").ImageSpeed = .1f * Math.Abs(physics.Velocity.X / maxSpeed);

            // You be walking
            WalkingHorizontal = true;
        }
Exemplo n.º 3
0
    //Controls the zoom of the camera
    private void ControlZoom()
    {
        // 1 for positive , 0 for no input , -1 for negative input
        float input = Input.GetAxis("Mouse ScrollWheel");

        if (input != 0)
        {
            float sign = -Mathf.Sign(input);                             //minus so backwards is zoom out while inwards is zoom in
            currentZoom += sign * zoomMod;
            currentZoom  = MyMaths.Clamp(currentZoom, minZoom, maxZoom); //Clamps the currentZoom between minZoom and maxZoom
            Camera.main.orthographicSize = currentZoom;                  // Updates zoom
        }
    }
Exemplo n.º 4
0
    //Ran when user hovers and clicks over a collider
    private void OnMouseDrag()
    {
        int   index    = gameObject.GetComponent <newCollisionsController>().particleIndex;
        float diameter = newParticle.ParticleInstances[index].diameter;

        Vector3 mousePosition = new Vector3(
            Input.mousePosition.x,
            Input.mousePosition.y,
            distance);
        Vector3 objectPosition = Camera.main.ScreenToWorldPoint(mousePosition);
        //changes object position but restricts the position to be inside of the borders
        float minX = BorderLeft.transform.position.x + diameter / 2 + (BorderLeft.GetComponent <Renderer>().bounds.size.x / 2);
        float maxX = BorderRight.transform.position.x - diameter / 2 - (BorderRight.GetComponent <Renderer>().bounds.size.x / 2);

        float minY = BorderBottom.transform.position.y + diameter / 2 + (BorderBottom.GetComponent <Renderer>().bounds.size.y / 2);
        float maxY = BorderTop.transform.position.y - diameter / 2 - (BorderTop.GetComponent <Renderer>().bounds.size.y / 2);

        objectPosition.x   = MyMaths.Clamp(objectPosition.x, minX, maxX);
        objectPosition.y   = MyMaths.Clamp(objectPosition.y, minY, maxY);
        transform.position = objectPosition;
    }