public void Awake()
 {
     status      = NOT_STARTED;
     theOcean    = GameObject.Find("Ocean").GetComponent <OceanController>();
     movesAPIObj = GameObject.Find("MovesAPIRequests").GetComponent <MovesAPIRequests> ();
     jsonDataObj = GameObject.Find("JSONDataObject").GetComponent <JSONDataObject> ();
     dateObj     = GameObject.Find("DateObject").GetComponent <DateClass> ();
     startDate   = dateObj.getCurrentDateString();
 }
    private void OnEnable()
    {
        wave   = (Wave)target;
        parent = wave.transform.parent.GetComponent <OceanController>();

        amplitude  = wave.Amplitude;
        waveLength = wave.WaveLength;
        speed      = wave.Speed;
        steepness  = wave.Steepness;
    }
Exemple #3
0
    public void restartLevel()
    {
        myLoadScene(iLevel);
        OceanController oceanController = GameObject.Find("OceanController").gameObject.GetComponent <OceanController>();

        if (!oceanController)
        {
            throw new UnassignedReferenceException("Canoot find oceanController");
        }
        oceanController.Restart();
        EscapeMenuPanel.SetActive(false);
        escape            = false;
        gameOverText.text = "";
    }
    //enum Direction { Right, Up, Left, Down, Unassigned};

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            BoatController boatController = other.gameObject.GetComponent <BoatController>();

            GameObject oceanControllerObject = GameObject.Find("OceanController");
            if (oceanControllerObject != null)
            {
                oceanController = oceanControllerObject.GetComponent <OceanController>();
            }
            if (oceanController == null)
            {
                Debug.Log("Cannot find 'OceanController' script");
            }
            old_i = oceanController.iTile; old_j = oceanController.jTile;

            new_i = old_i + delta_i;
            new_j = old_j + delta_j;

            BoatController.Direction spawnSide = BoatController.Direction.Unassigned;
            if (delta_i == 1 & delta_j == 0)
            {
                spawnSide = BoatController.Direction.Left;
            }
            if (delta_i == 0 & delta_j == 1)
            {
                spawnSide = BoatController.Direction.Down;
            }
            if (delta_i == -1 & delta_j == 0)
            {
                spawnSide = BoatController.Direction.Right;
            }
            if (delta_i == 0 & delta_j == -1)
            {
                spawnSide = BoatController.Direction.Up;
            }

            bool movedToTile = boatController.MoveToTile(new_i, new_j, spawnSide);

            //If moving to tile is not successful there is no neighbor so explode boat and end game. Then return from OnTriggerEnter
            if (!movedToTile)
            {
                GameObject.Find("Boat").gameObject.GetComponent <BoatController>().Explode(); //also game over
                return;                                                                       //End OnTriggerEnter() because there is no tile to move to
            }
        }
    }
Exemple #5
0
 void Start()
 {
     OceanController = GameObject.Find("OceanController").GetComponent <OceanController>();
 }
Exemple #6
0
 public void Awake()
 {
     status   = NOT_STARTED;
     theOcean = GameObject.Find("Ocean").GetComponent <OceanController>();
 }
Exemple #7
0
 public void Awake()
 {
     theOcean = GameObject.Find("Ocean").GetComponent <OceanController> ();
 }
    /// <summary>
    /// Moves boat and sail til tile ij, on the spawnPosition side, fasinc the middle of the tile.
    /// iTile and jTile of oceanController is set.
    /// If tile ij is not found return false
    /// </summary>
    public bool MoveToTile(int i, int j, Direction spawnPosition)
    {
        GameObject tile_i_j = GameObject.Find("" + i + j);

        //If no tile is found explode boat and end game. Then return from OnTriggerEnter
        if (!tile_i_j)
        {
            Debug.Log("tileij not found");
            return(false);
        }

        Transform tileijTransform = tile_i_j.transform;

        if (!tileijTransform)
        {
            throw new UnassignedReferenceException("tileijTransform not found");
        }

        //Debug.Log("new_i = " + new_i + ", new_j = " + new_j);
        //oceanController.iTile = new_i; oceanController.jTile = new_j;
        //debugText.text = "new_i = " + new_i + ", new_j = " + new_j;

        OceanController oceanController = GameObject.Find("OceanController").gameObject.GetComponent <OceanController>();

        oceanController.Set_iTile_jTile(i, j);

        Vector3 unitVecDirSpawnPoint = new Vector3(0f, 0f, 0f);

        switch (spawnPosition)
        {
        case Direction.Right:
            unitVecDirSpawnPoint = Vector3.right;
            break;

        case Direction.Up:
            unitVecDirSpawnPoint = Vector3.up;
            break;

        case Direction.Left:
            unitVecDirSpawnPoint = Vector3.left;
            break;

        case Direction.Down:
            unitVecDirSpawnPoint = Vector3.down;
            break;

        case Direction.Unassigned:
            throw new UnassignedReferenceException("Direction.Unassigned");
            break;

        default:
            break;
        }

        Vector3 tilePos = tileijTransform.position;

        if (tileijTransform.localScale.x - tileijTransform.localScale.y > 0.05)
        {
            throw new System.Exception("Tile is not square, and here is an implementation that only work for square tiles!");
        }
        Transform backgroundTransform = tile_i_j.transform.Find("Background").gameObject.transform;

        float   tileHalfSideL = backgroundTransform.localScale.x / 2; //This way only works for Squre tiles
        Vector3 boatPos       = new Vector3(0f, 0f, 0f);              //To not refer to other objects

        boatPos += tilePos + unitVecDirSpawnPoint * tileHalfSideL - unitVecDirSpawnPoint * distanceFromSide;
        //boatPos = tilePos - new Vector3(1f, 0f, 0f) * delta_i * (backgroundHalfxSideL - distanceFromSide)
        //- new Vector3(0f, 1f, 0f) * delta_j * (backgroundHalfySideL - distanceFromSide)
        //+ 10 * Vector3.back; //This is not very elegant. Move background or use something else as reference?
        //float xBoat = delta_i * () + delta_j * (); //Explanation

        Quaternion boatQuaternion = Quaternion.identity;
        Quaternion sailQuaternion = Quaternion.identity;

        //Rotating boat
        switch (spawnPosition)
        {
        case Direction.Right:
            boatQuaternion = Quaternion.AngleAxis(180f, Vector3.back); sailQuaternion = Quaternion.AngleAxis(270, Vector3.back);
            break;

        case Direction.Up:
            boatQuaternion = Quaternion.AngleAxis(270f, Vector3.back); sailQuaternion = Quaternion.AngleAxis(0f, Vector3.back);
            break;

        case Direction.Left:
            boatQuaternion = Quaternion.AngleAxis(0f, Vector3.back); sailQuaternion = Quaternion.AngleAxis(90f, Vector3.back);
            break;

        case Direction.Down:
            boatQuaternion = Quaternion.AngleAxis(90f, Vector3.back); sailQuaternion = Quaternion.AngleAxis(180f, Vector3.back);
            break;

        case Direction.Unassigned:
            throw new UnassignedReferenceException("Direction unassigned!");

        //break; unreachble
        default:
            break;
        }

        //Moving camera
        GameObject camera = GameObject.Find("Camera");

        if (!camera)
        {
            throw new MissingReferenceException("Camera not found!");
        }
        Vector3 cameraPos = camera.transform.position;

        //cameraPos = new Vector3(tile_new_inew_j.transform.position.x, tile_new_inew_j.transform.position.y, -1f); //This works because tile_new_inew_j is found using new_i and new_j
        cameraPos.x = tile_i_j.transform.position.x; cameraPos.y = tile_i_j.transform.position.y;
        camera.transform.position = cameraPos;

        //GameObject sail = GameObject.Instantiate(SailPrefab, boatPos, boatQuaternion);
        //GameObject boat = GameObject.Instantiate(BoatPrefab, boatPos, boatQuaternion);
        this.transform.position = boatPos;
        this.GetComponent <BoatController>().speed = 0f;
        this.GetComponent <Rigidbody>().rotation   = boatQuaternion;

        //boatAngle = GetComponent<Rigidbody>().rotation.eulerAngles.z;

        sail.transform.position = boatPos;
        sail.GetComponent <Rigidbody>().rotation = sailQuaternion;

        return(true); //If this is reaced the metod call was successful
    }