void FixedUpdate()
    {
        // Gravity
        if(lastJump == dir.up) movement.y += gravity*Time.fixedDeltaTime;
        else if(lastJump == dir.down) movement.y -= gravity*Time.fixedDeltaTime;
        else if (transform.position.y > center.y) movement.y += gravity*Time.fixedDeltaTime;
        else movement.y -= gravity*Time.fixedDeltaTime;

        // Crossing the middle
        if (transform.position.y > center.y && transform.position.y + movement.y*Time.deltaTime < center.y && lastJump == dir.up
            || transform.position.y < center.y && transform.position.y + movement.y*Time.deltaTime > center.y && lastJump == dir.down) {
            lastJump = dir.none;
            cutGravity = true;
        }
        if (transform.position.y > center.y && transform.position.y + movement.y*Time.deltaTime < center.y && cutGravity
            || transform.position.y < center.y && transform.position.y + movement.y*Time.deltaTime > center.y && cutGravity) {
            movement.y *= 0.6f;
        }

        // Speed
        GetComponent<Rigidbody2D>().velocity = movement;

        // jump Rotation
        float distance = Mathf.Abs(transform.position.y - center.y);
        float jumpRotation = 360 + 180 - Mathf.Rad2Deg * Mathf.Atan2(movement.y,(movement.x-obstacleSpeed));
        if(distance < 0.05 && (((jumpRotation%360) < 10) || ((jumpRotation%360) > 350))){
            jumpRotation = 0;
        }
        transform.rotation = Quaternion.Euler(new Vector3(0,0,jumpRotation));
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!_dead)
        {
            //Debug.Log(_body.velocity.z);
            if (_body.velocity.z <= _maxSpeed)
            {
                _body.AddForce(new Vector3(0, 0, _speed * Time.deltaTime), ForceMode.Acceleration);
            }

            if (_body.velocity.z > _maxSpeed + 50f)
            {
                _body.velocity *= 0.9f;

            }

            if (_addedForce)
            {
                switch (impulse)
                {
                    case dir.left:
                        xPos = Mathf.Lerp(xPos, xPos - _travelDist, Time.deltaTime);

                        if (transform.position.x <= (_lastPos.x - _travelDist))
                        {
                            _addedForce = false;
                            float x = Mathf.Floor(xPos);
                            if(x == 0 || x == -1)
                            {
                                xPos = 0f;
                            }
                            else
                            {
                                xPos = -_travelDist;
                            }
                        }
                        break;
                    case dir.right:
                        xPos = Mathf.Lerp(xPos, xPos + _travelDist, Time.deltaTime * 2f);
                        if (transform.position.x >= (_lastPos.x + _travelDist))
                        {
                            _addedForce = false;
                            float x = Mathf.Floor(xPos);
                            if (x == 0 || x == -1 )
                            {
                                xPos = 0f;
                            }
                            else
                            {
                                xPos = _travelDist;
                            }
                        }
                        break;
                }

            }

            if (Input.GetKeyDown(KeyCode.A) && transform.position.x > (_startPos.x - _travelDist) && !_addedForce)
            {
                _addedForce = true;
                _lastPos = transform.position;
                impulse = dir.left;
            }
            if (Input.GetKeyDown(KeyCode.D) && transform.position.x < (_startPos.x + _travelDist) && !_addedForce)
            {
                _addedForce = true;
                _lastPos = transform.position;
                impulse = dir.right;
            }

            if(Input.GetKey(KeyCode.S))
            {
                _body.AddForce(new Vector3(0f, -3f, 0f), ForceMode.Impulse);
            }

            if (Input.GetKeyDown(KeyCode.W))
            {
                Debug.Log("Fire the lazer");
            }

            if (Input.GetKeyDown(KeyCode.Space) && OnGround())
            {
                _body.AddForce(new Vector3(0, 5f, 0), ForceMode.Impulse);
                Sounds.OneShot(Sounds.Instance._sounds._jump);
            }

            Vector3 pos = transform.position;
            pos.x = xPos;
            transform.position = pos;

            if (CheckOutofBounds())
                Kill();

            if(_body.velocity.z <= 0)
            {
                Kill();
            }
        }
        if (_dead)
        {
            _body.velocity = new Vector3(0, 0, 0);
        }
    }
Exemplo n.º 3
0
			return GetWebConfigFileName (dir);
Exemplo n.º 4
0
        public void MoveUp()
        {
            direction = dir.Up;
            this.Animate();
            clsGame.GameForm.Invalidate();

            if (clsGame.physics.Allow(dir.Up))
            {
                clsEvent.CheckEncounter(clsGame.player.TilePosition, clsGame.player.direction);
                if (!inmotion)
                {
                    inmotion = true;

                    for (int x = 1; x <= (clsGame.tileheight * multiplier); x++)
                    {
                        //move up one tile
                        position.Y -= (1 / multiplier);
                        this.Animate();
                        //Check for keypress and refresh form
                        System.Windows.Forms.Application.DoEvents();
                        clsGame.GameForm.Invalidate();
                    }
                    inmotion = false;
                }
            }
        }
Exemplo n.º 5
0
    //curves to turn down
    void CurveDown()
    {
        if (curveInt < CurveCount)
        {
            if (turn == TurnDirection.left)
            {
                transform.Rotate(0f, 0f, CurveAngle);
            }
            else if (turn == TurnDirection.right)
            {
                transform.Rotate(0f, 0f, -CurveAngle);
            }
            transform.position += (CurveMult * (transform.right * CurveSpeed)) * Time.deltaTime;
            curveInt++;
        }
        else if (curveInt == CurveCount)
        {
            currentDirection = dir.down;
        }

    }
Exemplo n.º 6
0
 void MoveStraight()
 {
     if (currentDirection == dir.down)
     {
         transform.position -= new Vector3(0f, (float)speed, 0f) * Time.deltaTime;
     }
     else if (currentDirection == dir.up)
     {
         transform.position += new Vector3(0f, (float)speed, 0f) * Time.deltaTime;
     }
     if (CheckForPass())
     {
         if (currentDirection == dir.up)
         {
             currentDirection = dir.arcDown;
             AssignCircle();
         }
         if (currentDirection == dir.down)
         {
             currentDirection = dir.arcUp;
             AssignCircle();
         }
     }
 }
    void Update()
    {
        if (transform.position.x + GetComponent<Renderer>().bounds.size.x/2 <  -19f/2) {
            Destroy(gameObject);
        }
        // jump!
        if (obstacles.Count != 0 && timeToCollision() < jumptime && lastJump == dir.none) {
            int inputY = 0;

            if (obstacle.tag == "Up") {
                inputY = 1;
                lastJump = dir.up;
            }
            else if (obstacle.tag == "Down") {
                inputY = -1;
                lastJump = dir.down;
            }
            else {
                inputY = Random.Range(0,2);
                if (inputY == 1) lastJump = dir.up;
                else {
                    inputY = -1;
                    lastJump = dir.down;
                }
            }
            if (inputY != 0) {
                // xf = 1/2 a * tº2 + v*t + xi    xi -> centre + dist   xf -> centre.y +- pos.y
                // a = (xf - xi)* factor    factor = 1/ (1/2*t_2)
                float factor = 2f/(jumptime * jumptime); //inversa de   1/2 * temps al quadrat
                gravity = factor * (transform.position.y - (center.y + inputY*dist));
                movement.y = - gravity * jumptime;
                gravity *= inputY;
                cutGravity = false;
                obstacles.Remove(obstacle);
                obstacle = null;
            }
        }
    }
    void FixedUpdate()
    {
        movement = GetComponent<Rigidbody2D>().velocity;

        // Gravity
        if(lastJump == dir.up) movement.y += gravity*Time.fixedDeltaTime;
        else if(lastJump == dir.down) movement.y -= gravity*Time.fixedDeltaTime;
        else if (transform.position.y > center.y) movement.y += gravity*Time.fixedDeltaTime;
        else movement.y -= gravity*Time.fixedDeltaTime;

        // Crossing the middle
        if (transform.position.y > center.y && transform.position.y + movement.y*Time.deltaTime < center.y && lastJump == dir.up
            || transform.position.y < center.y && transform.position.y + movement.y*Time.deltaTime > center.y && lastJump == dir.down) {
            lastJump = dir.none;
            cutGravity = true;
        }
        if (transform.position.y > center.y && transform.position.y + movement.y*Time.deltaTime < center.y && cutGravity
            || transform.position.y < center.y && transform.position.y + movement.y*Time.deltaTime > center.y && cutGravity) {
            movement.y *= 0.6f;
        }

        // Horizontal Speed
        if (!collisioning) movement.x = center.x - transform.position.x;
        collisioning = false;
        // Speed
        GetComponent<Rigidbody2D>().velocity = movement;

        // Agular
        /*float angularDirection;
        angularDirection = transform.rotation.z;
        if (transform.rotation.z > 0) angularDirection = Mathf.Max (0.2f, Mathf.Min(0.6f ,angularDirection));
        else angularDirection = Mathf.Min (-0.2f, Mathf.Max( -0.6f, angularDirection));
        angularDirection = - Mathf.Pow(angularDirection*100,2) * Mathf.Sign(angularDirection);
        */

        // jump Rotation
        float distance = Mathf.Abs(transform.position.y - center.y);
        float jumpRotation = 360 + 180 - Mathf.Rad2Deg * Mathf.Atan2(movement.y,(movement.x-obstacleSpeed));
        float diff = 0;
        if(distance < 0.05 && (((jumpRotation%360) < 10) || ((jumpRotation%360) > 350))){
            jumpRotation = 0;
            if (!collisioning) GetComponent<Rigidbody2D>().angularVelocity = 0;
        }
        else {
            float aux = jumpRotation % 360;

            //Debug.Log("Diff " +diff);
            if (lastRotation > 180 && aux < 180) {
                //Debug.Log("aux " + aux + " last " + lastRotation + " diff " + (360 - lastRotation + aux));
                diff = 360 - lastRotation + aux;
            }
            else if (lastRotation < 180 && aux > 180 ) {
                //Debug.Log("aux " + aux + " last " + lastRotation + " diff " + (-360 - lastRotation + aux));
                diff = -360 - lastRotation + aux;
            }
            else {
                //Debug.Log("aux " + aux + " last " + lastRotation + " diff " + (aux - lastRotation));
                diff = aux - lastRotation;
            }

            diff = Mathf.Min(10,Mathf.Max(-10,diff));
        }
        //if (diff != 0) lastRotation = (lastRotation + diff) % 360;
        //else
        lastRotation = (jumpRotation) % 360;
        if (!collisioning) transform.rotation = Quaternion.Euler(new Vector3(0,0,lastRotation));
    }
    // Update is called once per frame
    void Update()
    {
        //Rumble Thing
        #if UNITY_STANDALONE || UNITY_WEBPLAYER
        if (!playerIndexSet || !state.IsConnected) getPlayerIndex();
        if (state.IsConnected) {
            rumbleCount -= Time.deltaTime;
            if (rumbleCount < 0) GamePad.SetVibration(playerIndex,0,0);
        }
        #endif
        // Is dead?
        //print("trnas " + transform.position.x + " bounds " + GetComponent<Renderer>().bounds.size.x + " screen " + Screen.width);
        if (canDie && Mathf.Abs( transform.position.x) - GetComponent<Renderer>().bounds.size.x/2 >  19f/2) {
            Destroy(gameObject);
        }

        // jump!
        if (lastJump == dir.none) {
            int inputY = 0;
            float verticalInput = 0.0f;

            #if UNITY_STANDALONE || UNITY_WEBPLAYER
            if (Input.GetKey(up)) verticalInput = 1;
            else if (Input.GetKey(down)) verticalInput = -1;
            //verticalInput = Input.GetAxis("Vertical");
            else if (Input.GetButton("Fire1")) {
                verticalInput = 1;
            }
            else if (Input.GetButton("Fire2")) {
                verticalInput = -1;
            }
            #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
            if(Input.touchCount > 0) {
                Touch myTouch = Input.touches[0];

                if(myTouch.phase == TouchPhase.Began){
                    float position = myTouch.position.y;
                    if(touchTypeHorizontal) {
                        if (position >= Screen.width/2) verticalInput = 1;
                        else verticalInput = -1;
                    }
                    else {
                        if (position <= Screen.height/2) verticalInput = 1;
                        else verticalInput = -1;
                    }
                }
            }
            #endif

            if (verticalInput > 0) {
                inputY = 1;
                lastJump = dir.up;
            }
            else if (verticalInput < 0) {
                inputY = -1;
                lastJump = dir.down;
            }
            if (inputY != 0) {
                // xf = 1/2 a * tº2 + v*t + xi    xi -> centre + dist   xf -> centre.y +- pos.y
                // a = (xf - xi)* factor    factor = 1/ (1/2*t_2)
                float factor = 2f/(jumptime * jumptime); //inversa de   1/2 * temps al quadrat
                gravity = factor * (transform.position.y - (center.y + inputY*dist));
                movement.y = - gravity * jumptime;
                GetComponent<Rigidbody2D>().velocity = movement;
                gravity *= inputY;
                cutGravity = false;

                // Tracking things
                ++numberOfJumps;
                PlayerPrefs.SetInt("trackJumps",numberOfJumps);

                #if UNITY_STANDALONE || UNITY_WEBPLAYER
                //Rumble Thing
                state = GamePad.GetState(playerIndex);
                if (state.IsConnected) {
                    GamePad.SetVibration(playerIndex,1,1);
                    rumbleCount = rumbleTime;
                }
                #endif
            }

        }

        //PARTICLES STUFFS
        if(   transform.position.y > center.y+0.8 && movement.y < 0
           || transform.position.y < center.y-0.8 && movement.y > 0 ){
            GetComponentInChildren<ParticleSystem>().emissionRate = 0;
        }
        else {
            GetComponentInChildren<ParticleSystem>().emissionRate = 80;
        }

        if (transform.position.y > center.y && lastJump == dir.down && movement.y > 0) { // Too high
            Debug.LogWarning("The penguin was going up");
            Debug.LogWarning("y: " + transform.position.y + " dir: " + lastJump + " speed: " + movement.y);
            lastJump = dir.up;
        }
        else if (transform.position.y < center.y && lastJump == dir.up && movement.y < 0) { // Too low
            Debug.LogWarning("The penguin was going down");
            Debug.LogWarning("y: " + transform.position.y + " dir: " + lastJump + " speed: " + movement.y);
            lastJump = dir.down;
        }
    }