Beispiel #1
0
    void flip(lastKey last)
    {
        // send the last direction moved, which dictates the flip direction
        //Debug.Log ("flipping!");
        //Debug.Log(last);
        if (last == lastKey.up){
            charRB.AddRelativeTorque(transform.right * rotationForce, ForceMode.Impulse);
        }
        if (last == lastKey.down){
            charRB.AddRelativeTorque(transform.right * -rotationForce, ForceMode.Impulse);
        }
        if (last == lastKey.left && (gravity == physics.ground)){
            charRB.AddRelativeTorque(transform.forward * rotationForce, ForceMode.Impulse);
        }
        if (last == lastKey.right && (gravity == physics.ground)){
            charRB.AddRelativeTorque(transform.forward * -rotationForce, ForceMode.Impulse);
        }

        // Physics shift for on the wall
        if (last == lastKey.left && (gravity == physics.wall)){
            charRB.AddRelativeTorque(transform.up * -rotationForce, ForceMode.Impulse);
        }
        if (last == lastKey.right && (gravity == physics.wall)){
            charRB.AddRelativeTorque(transform.up * rotationForce, ForceMode.Impulse);
        }
    }
Beispiel #2
0
 private void MoveShip(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         if (gameOver)
         {
             startNew(null, null);
         }
     }
     if (e.KeyCode == Keys.Up)
     {
         if (lk != lastKey.Down)
         {
             ship.direction = "up";
             lk             = lastKey.Up;
         }
     }
     else if (e.KeyCode == Keys.Down)
     {
         if (lk != lastKey.Up)
         {
             ship.direction = "down";
             lk             = lastKey.Down;
         }
     }
     else if (e.KeyCode == Keys.Left)
     {
         if (lk != lastKey.Right)
         {
             ship.direction = "left";
             lk             = lastKey.Left;
         }
     }
     else if (e.KeyCode == Keys.Right)
     {
         if (lk != lastKey.Left)
         {
             ship.direction = "right";
             lk             = lastKey.Right;
         }
     }
 }
Beispiel #3
0
    private void startNew(object sender, EventArgs e)
    {
        B.Clear();

        ship.x         = 5;
        ship.y         = 4;
        ship.direction = "right";
        ship.life      = 100;
        lk             = lastKey.Right;

        level = 0;

        caps = new System.Collections.Generic.List <Energy>();

        timer.Start();
        timer2.Start();

        PlaySong(null, null);

        timer3.Start();
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        moveH = Input.GetAxis("Horizontal") * speed;
        moveV = Input.GetAxis("Vertical") * speed;

        if(Input.GetMouseButtonDown(0)){
            Debug.Log ("mouse clicked");
            //transform.rotation = Quaternion.identity;
            //transform.rotation = Quaternion.identity;
            //charRB.rotation = Quaternion.Euler(0, 0, 180);
        }

        // keep track of which direciton was last moved
        //Debug.Log(h + " " + v);

        // This keeps track of the last direction moved
        if (Mathf.Abs(moveH) > Mathf.Abs(moveV)) {
            if(moveH > 0) {
                last = lastKey.right;
            } else {
                last = lastKey.left;
            }
        } else if( moveV > 0 ) {
            last = lastKey.up;
        } else if( moveV < 0 ) {
            last = lastKey.down;
        }

        checkPhysics();

        // make disc jump
        if(Input.GetButtonDown("Jump")){
            // call jump function
            jump();
            // toggle 'jumped' state
            jumped = true;
            grounded = false;
            // start timer to check when to start the flip
            currTime = Time.time;
            charRB.freezeRotation = false;
            //Debug.Log ("space pressed!");
        }

        // FLIP
        // after jump, waits .5 seconds then flips
        if(jumped && (Time.time - currTime > .5)){
            flip (last);
            jumped = false;
        }

        //check if character is not moving, and re-orient itself
        //Debug.Log (transform.rotation.x + " "+  transform.rotation.y + " " + transform.rotation.z);

        /*

        if (grounded){
            charRB.freezeRotation = true;
            //charRB.angularVelocity = Vector3.zero;
            //Debug.Log(charTransform.rotation.eulerAngles);
            if (((charTransform.eulerAngles.z > 170) && (charTransform.eulerAngles.z < 190))){
                charTransform.rotation = Quaternion.Euler(0, 0, 180);
                Debug.Log("white side down");
                down = side.white;
            } else{
                charTransform.rotation = Quaternion.Euler(0, 0, 0);
                Debug.Log("black side down");
                down = side.black;
            }
            //transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, transform.rotation.z);
        }
        */
    }