Beispiel #1
0
    /*
     * private void OnGUI()
     * {
     *  x_coord = gameObject.transform.position.x;
     *  y_coord = gameObject.transform.position.y;
     *  string s = String.Format("Coords: {0:F2}, {1:F2} \nSaves: {2} of {3}", x_coord, y_coord, saves_used, MAXSAVES);
     *  GUI.Label(new Rect(10, 10, 150, 50), s);
     * }*/

    public void Save()
    {
        saves_used += 1;
        if (saves_used > MAXSAVES)
        {
            saves_used -= 1;
            return;
        }
        //Make Vibration to add all the materials to the savedObjects list
        Vibration.Vibrator().MakeTimeVibration(RING_SIZE, (Vector2)powerScript.GetPosition(), gameObject);
        //Save every object in your inventory
        Inventory.instance.SaveInventory(this);
        //Save Game Statistics such as handIndex or HP
        GameManager.instance.SaveGameStatistics(this);

        /*
         * BinaryFormatter bf = new BinaryFormatter();
         * FileStream file;
         * if (!File.Exists(Application.persistentDataPath + "/playerinfo.dat"))
         * {
         *  file = File.Create(Application.persistentDataPath + "/playerinfo.dat");
         * } else
         * {
         *  file = File.Open(Application.persistentDataPath + "/playerinfo.dat", FileMode.Open);
         * }
         *
         * PlayerData data = new PlayerData();
         * data.x_coord = gameObject.transform.position.x;
         * data.y_coord = gameObject.transform.position.y;
         * data.saves_used = saves_used;
         * data.stamina = 100;
         *
         * bf.Serialize(file, data);
         * file.Close();*/
    }
Beispiel #2
0
    protected override void MakeVibration()
    {
        //Define Ring size so that walking causes a uniform speed, while running or crawling has double the effect
        int ringSize = (int)((speed * 2 - WALK_SPEED) / 3) * weight;

        //Create Vibration Ring
        Vibration.Vibrator().MakeVibration(ringSize, GetPosition(), this);
    }
Beispiel #3
0
 protected void MakeVibration(Collider2D collision)
 {
     //Make sure the object is touching the object the shadow touched. If not, the object is too high and is over the wall
     //This is too far to see or appreciate the vibration, so don't show it
     //Debug.Log(parentTransform.gameObject.GetComponent<Collider2D>().Distance(collision).isOverlapped + " and distance is " + parentTransform.gameObject.GetComponent<Collider2D>().Distance(collision).distance);
     if (parentTransform.gameObject.GetComponent <Collider2D>().Distance(collision).isOverlapped)
     {
         //Make Vibration
         Vibration.Vibrator().MakeVibration((int)(rb2d.velocity.magnitude * 100), (Vector2)parentTransform.position + rb2d.velocity * Time.deltaTime, this.gameObject, collision);
     }
 }
Beispiel #4
0
 private void FixedUpdate()
 {
     _horizRadius += _ringSpeed;
     _vertRadius  += _ringSpeed;
     time--;
     if (time > 0)
     {
         _line.startWidth = time * BEGINNING_THICKNESS / beginningTime;
         _line.endWidth   = time * BEGINNING_THICKNESS / beginningTime;
     }
     else
     {
         Vibration.Vibrator().RemoveVibration(gameObject);
     }
 }
Beispiel #5
0
    //Throw this object from x starting position to y target
    //This method is a coroutine
    public virtual IEnumerator <float> Throw(Vector2 target, int arcDegrees)
    {
        if (GameManager.activePlay)
        {
            beingThrown = true;
            //Ignore collisions between this object and the thrower for a short amount of time
            holderData.SetCollisionFlag(this, true);

            //Run-time variables
            float zRate = Mathf.Sqrt(9.8f * Vector2.Distance(GetPosition(), target));

            float arcRadians = arcDegrees * Mathf.PI / 180;
            float factor     = Mathf.Sin(arcRadians) / Mathf.Sin(Mathf.PI / 4);

            //Set object to be in front or behind player depending on direction thrown
            Vector2 distance = target - (Vector2)GetPosition();
            //Possessed Objects have no "holder", and so the throw object could be called without holder being defined
            myRenderer.sortingOrder = holderData.GetSortingOrder() + (int)(-distance.y / Mathf.Abs(distance.y));
            Drop();

            Debug.Log("factor is " + factor + ". deltaTime is " + Time.deltaTime);
            shadow.addVelocity((zRate + (4.9f * AVERAGE_DELTA_TIME)) * AVERAGE_DELTA_TIME * factor); //Arc is increased by a factor of 1/factor, multiplying distance by 1/factor
            distance = distance * (1f / factor);                                                     //By increasing distance by a multiple of inverse factor, the speed (and so distance) will be multiplied by factor
            //These two together cause distance to be the same; the distance to target, but it makes the speed and arc different
            shadow.PushDist(distance.normalized * distance.magnitude / (shadow.GetRigidbody().drag *(26f / 15)), ForceMode2D.Impulse);

            //Wait for the object to hit the ground again
            while (shadow.GetHeight() != 0 || shadow.GetHeightVelocity() > 0)
            {
                UpdatePosition(shadow.GetHeight());
                //When object has come to half its distance and started falling back down, continuously change sortingOrder
                if (shadow.GetHeightVelocity() < 0)
                {
                    myRenderer.sortingOrder = (int)(GetPosition().y *GlobalRegistry.SORTING_Y_MULTIPLIER());
                }
                yield return(Timing.WaitForOneFrame);
            }
            //Object has reached target, so make vibration
            Vibration.Vibrator().MakeVibration((int)((zRate) * FALL_VIBRATION_SIZE), (Vector2)GetPosition(), this);

            //Object may have crashed into other objects and hurt them, so empty the damagedList as well
            EmptyDamagedList();

            //Object is no longer attached to thrower, so let it be able to collide with thrower again
            holderData.SetCollisionFlag(this, false);
            beingThrown = false;
        }
    }
Beispiel #6
0
    public bool Load()
    {
        bool status = GameManager.instance.DrainCap(STAMINA_COST);

        if (status == true)
        {
            //Go through savedObject list and apply to each object
            foreach (Memento toRevert in savedObjects)
            {
                toRevert.Revert();
                //Destroy mementos
                if (toRevert)
                {
                    Destroy(toRevert.gameObject);
                }
            }
            //Get rid of all Vibrations
            Vibration.Vibrator().EraseVibrations();
            //Decrease saves_used
            saves_used--;
            savedObjects.Clear();
        }

        return(status);

        /*
         * try
         * {
         *  if (File.Exists(Application.persistentDataPath + "/playerinfo.dat"))
         *  {
         *      BinaryFormatter bf = new BinaryFormatter();
         *      FileStream file = File.Open(Application.persistentDataPath + "/playerinfo.dat", FileMode.Open);
         *      PlayerData data = (PlayerData)bf.Deserialize(file);
         *
         *      saves_used = data.saves_used - 1;
         *      x_coord = data.x_coord;
         *      y_coord = data.y_coord;
         *
         *      gameObject.transform.SetPositionAndRotation(new Vector2(x_coord, y_coord), new Quaternion(0,0,0,0));
         *  }
         * } catch (IOException e)
         * {
         *  Console.WriteLine("file does not exist: " + e);
         * }*/
    }