Exemplo n.º 1
0
    /**
     * Checks if movement is possible from current position in a direction
     * vector specified. Call this only when you are in a center of a labyrinth
     * cell.
     *
     * @param Vector3 newDirection - direction of movement suggested.
     *    Only one of x or y can be non zero. I.e. if x component non-zero then
     *    y must be equal to zero and vice versa.
     * @return bool
     *   - true if movement in suggested direction is possible from current position
     */
    bool IsMovementPossible(Vector3 newDirection)
    {
        Vector2 coords = GetCurrentCellCoords();

        int position_x = Mathf.RoundToInt(coords.x);
        int position_y = Mathf.RoundToInt(coords.y);
        int target_x   = position_x + Mathf.RoundToInt(newDirection.x);
        int target_y   = position_y + Mathf.RoundToInt(newDirection.y);

        LabyrinthController lc = labyrinth.GetComponent <LabyrinthController>();

        return(lc.CanMoveFromCell(position_x, position_y, target_x, target_y));
    }
Exemplo n.º 2
0
    /**
     * Called to init references to game level objects
     * after game started or level reloaded.
     * This locates relevant Game Objects and saves connections
     */
    void AwakeInit()
    {
        AdjustOrthoSize();

        if (SceneManager.GetActiveScene().name != "PlayLevel")
        {
            return;
        }

        // Connecting to game objects
        labyrinth = GameObject.Find("Labyrinth").GetComponent <LabyrinthController>();
        player    = GameObject.Find("Player").GetComponent <PlayerController>();

        // Connection to UI
        gameOverText  = GameObject.Find("Game over text").GetComponent <Text>();
        winnerText    = GameObject.Find("Winner text").GetComponent <Text>();
        restartText   = GameObject.Find("restart notification text").GetComponent <Text>();
        continueText  = GameObject.Find("Continue notification text").GetComponent <Text>();
        scoreText     = GameObject.Find("Points Text").GetComponent <Text>();
        collectedText = GameObject.Find("Collected text").GetComponent <Text>();
        backdrop      = GameObject.Find("Backdrop shadow").GetComponent <Image>();
        creditsScroll = GameObject.Find("Scroll View").GetComponent <ScrollRect>();
        creditsScroll.gameObject.SetActive(false);

        // Connection to UI volume control buttons
        // musicVolumeControlButton = GameObject.Find("Music Volume button").GetComponent<Button>();;
        // effectsVolumeControlButton = GameObject.Find("Effects Volume button").GetComponent<Button>();;
        // musicVolumeControlButton.image.overrideSprite = musicVolumeIcons[musicVolumeIndex];
        // musicVolumeControlButton.onClick.AddListener(OnMusicVolumeButton);
        // effectsVolumeControlButton.image.overrideSprite = effectsVolumeIcons[effectsVolumeIndex];
        // effectsVolumeControlButton.onClick.AddListener(OnEffectsVolumeButton);

        // Initializing
        if (score < 0)
        {
            score = 0;
        }
        cookiesCollected = 0;
        gameOver         = false;
        restart          = false;
        gameLost         = false;
        dirtyUI          = true;

        BroadcastMessage("GameNewLevel", null, SendMessageOptions.DontRequireReceiver);
        // musicBox.SwitchNewLevel();
    }
Exemplo n.º 3
0
    /**
     * Calculates coodinates of a cell we reside in in the labyrinth
     *
     * @return
     *      Vector2.zero - error / outside of labyrinth.
     *      (1 .. labyrinth.width, 1 .. labyrinth.height)
     */
    Vector2 GetCurrentCellCoords()
    {
        int x = Mathf.RoundToInt(transform.position.x);
        int y = Mathf.RoundToInt(transform.position.y);

        LabyrinthController lc = labyrinth.GetComponent <LabyrinthController>();

        // x is from 1 to lc.width (inclusive)
        // y is from 1 to lc.height (inclusive)
        if (y < 1 || x < 1 || x > (lc.width) || y > (lc.height))
        {
            return(Vector2.zero);
        }
        else
        {
            return(new Vector2(x, y));
        }
    }
 void Start()
 {
     labyrinth = GameObject.FindGameObjectWithTag("Labyrinth").GetComponent<LabyrinthController>();
     // create droid
     var free = labyrinth.GetRandomFreePosition();
     droid = Instantiate(droidPrefab);
     droid.transform.parent = transform;
     droid.transform.position = new Vector3(free.x + 0.5f, 1, free.z + 0.5f);
     droid.layer = 8; // Player
     droid.GetComponent<DroidSound>().PlayScream();
     // create target
     do
     {
         free = labyrinth.GetRandomFreePosition();
     } while (free == droid.transform.position);
     target = Instantiate(targetPrefab);
     target.transform.parent = transform;
     target.transform.position = new Vector3(free.x, 0f, free.z);
 }
Exemplo n.º 5
0
    void Awake()
    {
        // connect to the outer data
        labyrinth = GameObject.FindGameObjectWithTag("Labyrinth").GetComponent<LabyrinthController>();
        walls = labyrinth.GetMap();
        minimap = GameObject.FindGameObjectWithTag("Minimap").GetComponent<MinimapController>();

        // connect to subsystems
        laser = GetComponent<DroidLaser>();

        // create first particles, for 3*3 for each unit
        var length = labyrinth.length;
        var width = labyrinth.width;
        var particlesOnUnit = 1;
        var particlesShift = CreateParticlesShift(particlesOnUnit);
        var ls = new List<Particle>();
        for (var i = 0; i < length; i++)
        {
            for (var j = 0; j < width; j++)
            {
                if (walls[i, j] == 0)
                {
                    // nine particles for every unit
                    for (var k = 0; k < particlesOnUnit*particlesOnUnit; k++)
                    {
                        var particle = new Particle
                        {
                            probablity = 1,
                            position = new Vector3(i, 1f, j) + particlesShift[k]
                        };
                        ls.Add(particle);
                    }
                }
            }
        }

        // create particles map
        particlesMap = new ParticlesMap(ls);
        particlesMap.Normalize();
        StartCoroutine(minimap.ShowParticles(particlesMap.Particles));
    }
 void Awake()
 {
     labyrinth = GameObject.FindGameObjectWithTag("Labyrinth").GetComponent<LabyrinthController>();
 }