// Use this for initialization
    void Start()
    {
        _labelPos = LabelTransform.position;

        _labelPos.y = 0.0f;

        LabelTransform.position = _labelPos;

        CurrentEffectTime = 0.0f;

        _tilePos = new DJ_Point(0, 0);

        DJ_Util.GetTilePos(this.transform.position, _tilePos);

        LabelTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
        LabelTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);

        BGTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
        BGTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);

        _aspectRatio = TextTexture.width / TextTexture.height;

        //Quaternion _r = QuestionMark.rotation;
        //_r.y = LabelTransform.rotation.y;

        //QuestionMark.rotation = _r;

        SetupTextTexture();

        currQuestionAngle = (float)Random.Range(0.0f, Mathf.PI * 2.0f);
    }
Exemple #2
0
    public static DJ_Dir GetPreferredDirection(DJ_Point from, DJ_Point to)
    {
        DJ_Dir direction = DJ_Dir.NONE;

        float dx = to.X - from.X;
        float dy = to.Y - from.Y;

        if (Mathf.Abs(dx) > Mathf.Abs(dy))
        {
            if (dx < 0)
            {
                direction = DJ_Dir.LEFT;
            }
            if (dx > 0)
            {
                direction = DJ_Dir.RIGHT;
            }
        }
        else
        {
            if (dy < 0)
            {
                direction = DJ_Dir.UP;
            }
            if (dy > 0)
            {
                direction = DJ_Dir.DOWN;
            }
        }

        return(direction);
    }
    /// <summary>
    /// Accesses the tiles that are inside of DJ_LevelParser to instantiate tiles.
    /// </summary>
    /// <param name="_num">_num.</param>

    // Debug: Highlights adjacent tiles green.
    void getTilesNearLocation(DJ_Point playerTilePos)
    {
        //if the player has moved tiles, we need to update the closest ones
        if (!DJ_PlayerManager.prevPlayerTilePos.Equals(playerTilePos))
        {
            //reset the tile broke flag
            //tileBroke = false;

            DJ_PlayerManager.prevPlayerTilePos.X = playerTilePos.X;
            DJ_PlayerManager.prevPlayerTilePos.Y = playerTilePos.Y;

            //now get a ref to  the tiles around the  player
            //getNearbyTiles (playerTilePos, nearbyTiles, 1.0f);
            DJ_Util.GetNearbyTiles(playerTilePos, 1.0f, ref nearbyTiles);

            //Debugging view to see if tiles update correctly
            //			for (int i = 0; i < nearbyTiles.Count; ++i) {
            //				DJ_Point p = nearbyTiles [i];
            //				if (tileMap.ContainsKey (p)) {
            //					GameObject tile = tileMap [p];
            //					//(tile.GetComponentInChildren(typeof(MeshRenderer)) as MeshRenderer).material.color = Color.green;
            //				}
            //			}
            //(tileMap[playerTilePos].GetComponentInChildren(typeof(MeshRenderer)) as MeshRenderer).material.color = Color.red;
        }
    }
Exemple #4
0
 public TileNode(DJ_Point tilePos, ref GameObject tile)
 {
     neighbors = new TileNode[4];
     pos       = new DJ_Point(0, 0);
     pos.Set(tilePos);
     this.tile = tile;
 }
Exemple #5
0
    public void DeactivateTile(DJ_Point tilePos)
    {
        if (tileMap.ContainsKey(tilePos))
        {
            //remove from neighbors to tile
            for (int i = 0; i < tileMap[tilePos].neighbors.Length; ++i)
            {
                if (tileMap[tilePos].neighbors[i] != null)
                {
                    for (int t = 0; t < tileMap[tilePos].neighbors[i].neighbors.Length; ++t)
                    {
                        if (tileMap[tilePos].neighbors[i].neighbors[t] != null)
                        {
                            if (tileMap[tilePos].neighbors[i].neighbors[t].pos.Equals(tilePos))
                            {
                                tileMap[tilePos].neighbors[i].neighbors[t] = null;
                            }
                        }
                    }
                }
            }

            tileMap[tilePos].Deactivate();

            tilePool.Add(tileMap[tilePos]);
            tileMap.Remove(tilePos);
        }
    }
Exemple #6
0
    void LinkPossibleNeighbors(DJ_Point newPoint)
    {
        DJ_Point tempLeft  = new DJ_Point(newPoint.X - 1, newPoint.Y);
        DJ_Point tempRight = new DJ_Point(newPoint.X + 1, newPoint.Y);
        DJ_Point tempUp    = new DJ_Point(newPoint.X, newPoint.Y - 1);
        DJ_Point tempDown  = new DJ_Point(newPoint.X, newPoint.Y + 1);

        //make neighbor links within the graph
        if (tileMap.ContainsKey(tempLeft))
        {
            tileMap [tempLeft].neighbors [(int)DJ_Dir.RIGHT] = tileMap [newPoint];
            tileMap [newPoint].neighbors [(int)DJ_Dir.LEFT]  = tileMap [tempLeft];
        }
        if (tileMap.ContainsKey(tempRight))
        {
            tileMap [tempRight].neighbors [(int)DJ_Dir.LEFT] = tileMap [newPoint];
            tileMap [newPoint].neighbors [(int)DJ_Dir.RIGHT] = tileMap [tempRight];
        }
        if (tileMap.ContainsKey(tempUp))
        {
            tileMap [tempUp].neighbors [(int)DJ_Dir.DOWN] = tileMap [newPoint];
            tileMap [newPoint].neighbors [(int)DJ_Dir.UP] = tileMap [tempUp];
        }
        if (tileMap.ContainsKey(tempDown))
        {
            tileMap [tempDown].neighbors [(int)DJ_Dir.UP]   = tileMap [newPoint];
            tileMap [newPoint].neighbors [(int)DJ_Dir.DOWN] = tileMap [tempDown];
        }
    }
Exemple #7
0
 // Update is called once per frame
 void Update()
 {
     // spring activates on beat
     onBeat = DJ_Util.activateWithSound(gameObject.GetComponent <DJ_BeatActivation>());
     if (onBeat)
     {
         _flipper.Flip();
         DJ_Point tilePos = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
         if (DJ_TileManagerScript.tileMap.ContainsKey(tilePos))
         {
             if (DJ_PlayerManager.playerTilePos.X == tilePos.X && DJ_PlayerManager.playerTilePos.Y == tilePos.Y && !DJ_PlayerManager.player.GetComponent <DJ_Movement>().isLerping)
             {
                 DJ_PlayerManager.player.GetComponent <DJ_Movement>().heightOfHop     = height;
                 DJ_PlayerManager.player.GetComponent <DJ_Movement>().direction       = direction;
                 DJ_PlayerManager.player.GetComponent <DJ_Movement>().maxMoveDistance = distance;
                 DJ_PlayerManager.player.GetComponent <DJ_Movement>().canMove         = true;
             }
         }
         gameObject.GetComponentInChildren <MeshRenderer>().GetComponent <Renderer>().material = dangerShader;
     }
     else
     {
         gameObject.GetComponentInChildren <MeshRenderer>().GetComponent <Renderer>().material = safeShader;
     }
 }
    /// <summary>
    /// Checks to see if the player reaches a checkpoint tile. Sets the current checkpoint and next one.
    /// @author - Donnell Lu
    /// </summary>
    public void SaveCheckPoint()
    {
        if (DJ_LevelManager.currentLevel != -1)
        {
            for (int i = 0; i < DJ_TileManagerScript.checkpointList.Count; i++)
            {
                if (DJ_PlayerManager.player.GetComponent <DJ_Movement>().currentTilePos.Equals(DJ_TileManagerScript.checkpointList[i]))
                {
                    spawnPoint = DJ_TileManagerScript.checkpointList[i];
                }
            }
        }

        //debug draw of checkpoints

        /*
         * for (int i = 0; i < DJ_TileManagerScript.checkpointList.Count; ++i)
         * {
         * DJ_Point p = DJ_TileManagerScript.checkpointList[i];
         *      if(DJ_TileManagerScript.tileMap.ContainsKey(p))
         * DJ_TileManagerScript.tileMap[DJ_TileManagerScript.checkpointList[i]].tile.GetComponentInChildren<MeshRenderer>().material.color = Color.green;
         * }
         * if (DJ_TileManagerScript.tileMap.ContainsKey(DJ_TileManagerScript.exitPoint))
         * {
         * DJ_TileManagerScript.tileMap[DJ_TileManagerScript.exitPoint].tile.GetComponentInChildren<MeshRenderer>().material.color = Color.red;
         * }
         */
    }
    /// <summary>
    /// Creates the player gameObject, either Male or Female. Places them in the right location.
    /// </summary>
    public void createPlayer()
    {
        player   = (GameObject.Instantiate(m_playerPrefab) as GameObject);
        playerID = player.GetInstanceID();

        // This means you're on level select
        hashTablePosition = new DJ_Point(PlayerPrefs.GetInt("PlayerX"), PlayerPrefs.GetInt("PlayerY"));
        if (Application.loadedLevelName.Equals("levelSelectStage") && DJ_TileManagerScript.tileMap.ContainsKey(hashTablePosition))
        {
            //Debug.Log("Exists");
            player.transform.position = new Vector3(hashTablePosition.X, 0.0f, hashTablePosition.Y);
        }
        else
        {
            //Debug.Log("Spawn point spawn");
            player.transform.position = new Vector3(spawnPoint.X, 0.0f, spawnPoint.Y);
        }

        prevPlayerTilePos = new DJ_Point(int.MaxValue, int.MaxValue);

        playerTilePos = new DJ_Point(Mathf.RoundToInt(player.transform.position.x), Mathf.RoundToInt(player.transform.position.z));
        //Debug.Log("player tilePos in creation " + playerTilePos);

        player.transform.parent = transform;

        (player.GetComponent(typeof(DJ_Movement)) as DJ_Movement).currentTilePos  = playerTilePos;
        (player.GetComponent(typeof(DJ_Movement)) as DJ_Movement).targetTilePos   = playerTilePos;
        (player.GetComponent(typeof(DJ_Movement)) as DJ_Movement).prevTilePos     = playerTilePos;
        (player.GetComponent(typeof(DJ_Movement)) as DJ_Movement).prevPrevTilePos = playerTilePos;
    }
Exemple #10
0
    public static float GetDistance(DJ_Point start, DJ_Point end, DJ_Distance distanceType)
    {
        float dist = 0.0f;

        float distSquared = Mathf.Abs(end.X - start.X) + Mathf.Abs(end.Y - start.Y);

        switch (distanceType)
        {
        case DJ_Distance.EUCLIDEAN:
            dist = Mathf.Sqrt(distSquared);
            break;

        case DJ_Distance.PATH:
            dist = distSquared;
            break;

        case DJ_Distance.MANHATTAN:
            dist = distSquared;
            break;

        case DJ_Distance.TILE:
            dist = Mathf.Floor(distSquared);
            break;

        default:
            break;
        }

        return(dist);
    }
 // Use this for initialization
 void Start()
 {
     _startPos    = this.transform.position;
     StarAcquired = false;
     _angle       = 0.0f;
     _tilePos     = DJ_Util.GetTilePos(this.transform.position);
     _startRot    = this.transform.rotation;
 }
Exemple #12
0
 // Use this for initialization
 void Start()
 {
     state    = AnimationState.Hover;
     startPos = this.transform.localPosition;
     _tilePos = DJ_Util.GetTilePos(this.transform.parent.position);
     Beam.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
     Beam.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);
     _active        = false;
     _startRotation = this.transform.rotation;
     BlastOff       = false;
 }
    public void Awake()
    {
        m_parent   = null;
        m_children = new List <Transform>();

        tilePos   = new DJ_Point(0, 0);
        size      = new DJ_Point(0, 0);
        direction = DJ_Dir.NONE;

        //assign the sprite (the one assigned via the  inspector) to that of the Sprite Renderer component
        //that is attached to this entity
        //Debug.Log(m_texture);
    }
Exemple #14
0
    // Used this for initialization
    public void Start()
    {
        //DJ_Input.inputDir = DJ_Dir.NONE;
        isFalling    = false;
        afterFalling = false;
        prevCanMove  = false;
        canMove      = true;

        // Sets the positions based on the transform of the matrix.
        targetTilePos   = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
        currentTilePos  = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
        prevTilePos     = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
        prevPrevTilePos = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
    }
    // Use this for initialization
    void Start()
    {
        _labelPos = LabelTransform.position;

        _labelPos.y = 0.0f;

        LabelTransform.position = _labelPos;

        CurrentEffectTime = 0.0f;

        _tilePos = new DJ_Point(0, 0);

        DJ_Util.GetTilePos(this.transform.position, _tilePos);

        Vector3 _pos = PlayTransform.position;

        _pos += -PlayTransform.forward * .002f;
        PlayTransform.position = _pos;
        PlayTransform.tag      = "level_select_button";

        Stars = new GameObject[NumberOfStars];

        StarTimers = new float[NumberOfStars];

        PlayTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
        PlayTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);

        SpotlightTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
        SpotlightTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);

        LabelTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
        LabelTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);

        BGTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
        BGTransform.gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);

        for (int i = 0; i < Stars.Length; ++i)
        {
            Stars[i] = GameObject.Instantiate(StarGO) as GameObject;
            Stars[i].transform.parent = StarTransform;

            Stars[i].gameObject.GetComponent <Renderer>().material.SetFloat("_Alpha", 0.0f);
            Stars[i].gameObject.GetComponent <Renderer>().material.SetFloat("_GlowStrength", 0.0f);
        }

        SetupTextTexture();
    }
Exemple #16
0
    public static void GetNearbyTiles(DJ_Point tilePos, float depth, ref List <DJ_Point> nearbyTiles)
    {
        /*
         * for(int i = 0; i < nearbyTiles.Count; ++i)
         * {
         *      DJ_Point p = nearbyTiles[i];
         *
         *      if(DJ_TileManagerScript.tileMap.ContainsKey(p))
         *              DJ_TileManagerScript.tileMap[p].tile.GetComponentInChildren<MeshRenderer>().material.color = Color.white;
         * }
         */

        nearbyTiles.Clear();

        int numTilesPerDim = (int)(1 + 2 * depth);

        if (depth > 1)
        {
            numTilesPerDim = 3 * (int)Mathf.Pow(2.0f, depth - 1.0f) - 1;
        }

        DJ_Point startPoint = new DJ_Point(tilePos.X - Mathf.FloorToInt(numTilesPerDim / 2.0f), tilePos.Y - Mathf.FloorToInt(numTilesPerDim / 2.0f));

        DJ_Point currPoint = startPoint;

        for (int x = 0; x < numTilesPerDim; ++x)
        {
            for (int z = 0; z < numTilesPerDim; ++z)
            {
                DJ_Point newPoint = new DJ_Point(currPoint.X + x, currPoint.Y + z);

                //print ("Next tile pos = " + newPoint);
                nearbyTiles.Add(newPoint);
            }
        }

        //debug coloring of tiles
        ///*
//		for(int i = 0; i < nearbyTiles.Count; ++i)
//		{
//			DJ_Point p = nearbyTiles[i];
//			if(DJ_TileManagerScript.tileMap.ContainsKey(p))
//				DJ_TileManagerScript.tileMap[nearbyTiles[i]].tile.GetComponentInChildren<MeshRenderer>().material.color = Color.green;
//		}
        //*/
    }
Exemple #17
0
    /// <summary>
    /// Smooth lerp along trajectory. Used primarily for hopping between tiles.
    /// </summary>
    /// <param name="currPos">Curr position.</param>
    /// <param name="targetTilePos">Target tile position.</param>
    /// <param name="targetHeight">Target height.</param>
    /// <param name="animationTime">Animation time.</param>
    public static void LerpTrajectory(ref Vector3 currPos, DJ_Point prevTilePos, DJ_Point targetTilePos,
                                      float targetHeight, float currAnimationTime, float animationLength, float currHeight)
    {
        float dx = (targetTilePos.X - prevTilePos.X);
        float dz = (targetTilePos.Y - prevTilePos.Y);

        //if dx is 0, snap x to 0 to avoid errors
        if (dx == 0)
        {
            currPos.x = targetTilePos.X;
        }

        //if dz is 0, snap z to 0 to avoid errors
        if (dz == 0)
        {
            currPos.z = targetTilePos.Y;
        }


        float dxdt = (dx) / animationLength;
        float dzdt = (dz) / animationLength;

        /*
         * if (animationLength == 0)
         * {
         *  dxdt = dx;
         *  dzdt = dz;
         * }
         */


        if (dx == 0.0f && dz == 0.0f)
        {
            //clamp y
            currPos.y = currHeight;
        }
        else         //if( (Mathf.Abs(targetTilePos.X - currPos.x) < .5f && dz == 0.0f) || (dx == 0.0f && Mathf.Abs(targetTilePos.Y - currPos.z) < .5) )
        {
//			yDir = -1.0f;
//			height = targetHeight;
            currPos.y = targetHeight * Mathf.Sin(Mathf.PI * (currAnimationTime / animationLength));
        }

        currPos.x = prevTilePos.X + dxdt * currAnimationTime;
        currPos.z = prevTilePos.Y + dzdt * currAnimationTime;
    }
    // Update is called once per frame
    void Update()
    {
        // Used for instant teleporting in the level select
        if (instantTeleport)
        {
            DJ_Point tilePos = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
            if (DJ_TileManagerScript.tileMap.ContainsKey(tilePos))

            {
                if (DJ_PlayerManager.playerTilePos.X == tilePos.X && DJ_PlayerManager.playerTilePos.Y == tilePos.Y && !DJ_PlayerManager.player.GetComponent <DJ_Movement>().isLerping)
                {
                    if (!(DJ_PlayerManager.player.GetComponent <DJ_Movement>().prevPrevTilePos.X == teleporter.gameObject.transform.position.x &&
                          DJ_PlayerManager.player.GetComponent <DJ_Movement>().prevPrevTilePos.Y == teleporter.gameObject.transform.position.z))
                    {
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().direction       = DJ_Dir.TP;
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().targetTilePos.X = Mathf.RoundToInt(teleporter.gameObject.transform.position.x);
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().targetTilePos.Y = Mathf.RoundToInt(teleporter.gameObject.transform.position.z);
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().heightOfHop     = 14;
                    }
                }
            }
        }

        // Used for teleporting during gameplay
        else
        {
            onBeat = DJ_Util.activateWithSound(gameObject.GetComponent <DJ_BeatActivation>());
            if (onBeat)
            {
                DJ_Point tilePos = new DJ_Point(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.z));
                if (DJ_TileManagerScript.tileMap.ContainsKey(tilePos))
                {
                    if (DJ_PlayerManager.playerTilePos.X == tilePos.X && DJ_PlayerManager.playerTilePos.Y == tilePos.Y && !DJ_PlayerManager.player.GetComponent <DJ_Movement>().isLerping)
                    {
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().direction       = DJ_Dir.TP;
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().targetTilePos.X = Mathf.RoundToInt(teleporter.gameObject.transform.position.x);
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().targetTilePos.Y = Mathf.RoundToInt(teleporter.gameObject.transform.position.z);
                        DJ_PlayerManager.player.GetComponent <DJ_Movement>().heightOfHop     = 8;
                    }
                }
            }
        }
    }
Exemple #19
0
 public static void GetNeighboringTilePos(DJ_Point currTilePos, DJ_Dir direction, int dist, DJ_Point targetTilePos)
 {
     targetTilePos.Set(currTilePos);
     if (direction == DJ_Dir.DOWN)
     {
         targetTilePos.Y += dist;
     }
     else if (direction == DJ_Dir.UP)
     {
         targetTilePos.Y += -dist;
     }
     else if (direction == DJ_Dir.LEFT)
     {
         targetTilePos.X += -dist;
     }
     else if (direction == DJ_Dir.RIGHT)
     {
         targetTilePos.X += dist;
     }
 }
    // Use this for initialization
    public void Start()
    {
        teleporterTiles           = new Dictionary <int, List <GameObject> >();
        teleporterPads            = new Dictionary <int, GameObject>();
        receiverTile              = new Dictionary <int, GameObject>();
        levelSelectTeleporterTile = new Dictionary <int, List <GameObject> >();
//		MinX = float.MaxValue;
//		MinZ = float.MaxValue;
//		MaxX = float.MinValue;
//		MaxZ = float.MinValue;

        //this is only going tobe attached to an empty object but center
        //it at the origin anyway
        gameObject.transform.position = Vector3.zero;

        _recentlyVisitedTiles = new List <DJ_Point>();
        _tileGlowTimes        = new List <float>();

        _recentlyLaserVisitedTiles = new List <DJ_Point>();
        _tileLaserGlowTimes        = new Dictionary <DJ_Point, float>();

        _prevPlayerPos = new DJ_Point(int.MaxValue, int.MaxValue);

        tilePool = new Stack <TileNode>();
        tileMap  = new Dictionary <DJ_Point, TileNode>(DJ_PointComparer.Default);

        // Instantiate the checkpoint system
        checkpointList  = new List <DJ_Point>();
        exitPoint       = new DJ_Point(0, 0);
        levelselectList = new List <DJ_Point>();
        onBeat          = false;

        //Instantiate level select points
        tileGraph = new TileGraph(this.gameObject, m_tilePrefab);
        LinkTeleporters();
        LinkLevelSelectTeleporters();
        tileMap = tileGraph.tileMap;
        //print (tilegraph);
    }
Exemple #21
0
    public DJ_Dir GetNextMove(DJ_Point from, DJ_Point to, float maxDist, DJ_Distance distanceType)
    {
        tilesVisited.Clear();
        currentCosts.Clear();

        tilesVisited.Add(from);

        currentCosts.Add(0.0f);

        if (tileMap.ContainsKey(from))
        {
            DJ_Dir prefDir = DJ_Util.GetPreferredDirection(from, to);

            float currentCost = 0.0f;

            //immediately return none if the preferred direction
            //happens to be none. This either means the positions, from
            //and to, are the same or that there is no path from "from" to "to"
            if (prefDir == DJ_Dir.NONE)
            {
                return(prefDir);
            }

            //Debug.Log("the preferred direction is " + prefDir.ToString());

            int index;

            if (tileMap[from].neighbors[(int)prefDir] != null && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[(int)prefDir].pos))
            {
                //push info  onto queue
                tilesVisited.Add(tileMap[from].neighbors[(int)prefDir].pos);
                currentCosts.Add(currentCost);

                if (GetNextMove(tileMap[from].neighbors[(int)prefDir].pos, to, 0.0f, maxDist, distanceType, currentCost + 1.0f))
                {
                    return(prefDir);
                }

                //remove info from queue
                index = tilesVisited.IndexOf(tileMap[from].neighbors[(int)prefDir].pos);
                currentCosts.RemoveAt(index);
                tilesVisited.Remove(tileMap[from].neighbors[(int)prefDir].pos);
            }

            for (int i = 0; i < tileMap[from].neighbors.Length; ++i)
            {
                if (tileMap[from].neighbors[i] != null && i != (int)prefDir && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[i].pos))
                {
                    tilesVisited.Add(tileMap[from].neighbors[i].pos);
                    currentCosts.Add(currentCost);

                    if (GetNextMove(tileMap[from].neighbors[i].pos, to, 0.0f, maxDist, distanceType, currentCost + 1.0f))
                    {
                        return(DJ_Util.GetPreferredDirection(from, tileMap[from].neighbors[i].pos));
                    }

                    index = tilesVisited.IndexOf(tileMap[from].neighbors[i].pos);
                    currentCosts.RemoveAt(index);
                    tilesVisited.Remove(tileMap[from].neighbors[i].pos);
                }
            }
        }

        return(DJ_Dir.NONE);
    }
    // Update is called once per frame
    public void Update()
    {
        //get a ref to the player's tile position
        if (DJ_PlayerManager.player != null)
        {
            DJ_Point playerTilePos = (DJ_PlayerManager.player.GetComponent(typeof(DJ_Movement)) as DJ_Movement).currentTilePos;

//			if(DJ_PlayerManager.player.GetComponent<DJ_Movement>().justLanded)
//			{
//				if(tileMap.ContainsKey[playerTilePos])
//					tileMap [playerTilePos].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", 1.5f);
//			}

            DJ_Movement _movement = DJ_PlayerManager.player.GetComponent <DJ_Movement>();
            if (_movement.justLanded && DJ_PlayerManager.player.transform.position.y >= 0.0f)
            {
                if (tileMap.ContainsKey(playerTilePos))
                {
                    DJ_Point newPos = new DJ_Point(playerTilePos.X, playerTilePos.Y);

                    _recentlyVisitedTiles.Add(newPos);                     //set the time remaining of the effect
                    _tileGlowTimes.Add(1.5f);

                    _prevPlayerPos.X = playerTilePos.X;
                    _prevPlayerPos.Y = playerTilePos.Y;
                }
            }
        }

        for (int i = 0; i < _recentlyVisitedTiles.Count; ++i)
        {
            DJ_Point key = _recentlyVisitedTiles[i];

            if (_tileGlowTimes[i] < 0.0f)
            {
                if (tileMap.ContainsKey(key))
                {
                    tileMap[key].tile.transform.GetChild(0).GetComponent <Renderer>().material.SetFloat("_GlowStrength", .5f);
                }
                _recentlyVisitedTiles.RemoveAt(i);
                _tileGlowTimes.RemoveAt(i);
            }
            else
            {
                float _time = _tileGlowTimes[i];
                //Debug.Log("_time = " + _time);
                if (tileMap.ContainsKey(key))
                {
                    tileMap[key].tile.transform.GetChild(0).GetComponent <Renderer>().material.SetFloat("_GlowStrength", .5f + 5.5f * (_time / 1.5f));
                }
                //Debug.Log("_time = " + _time);
                _time            -= Time.deltaTime;
                _tileGlowTimes[i] = _time;
            }
        }

        /*
         * for (int j = 0; j < _recentlyLaserVisitedTiles.Count; ++j)
         * {
         *  DJ_Point key = _recentlyLaserVisitedTiles[j];
         *  if (_tileLaserGlowTimes.ContainsKey(key))
         *  {
         *      if (_tileLaserGlowTimes[key] < 0.0f)
         *      {
         *          if (tileMap.ContainsKey(key))
         *              tileMap[key].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", .5f);
         *          _recentlyLaserVisitedTiles.RemoveAt(j);
         *          _tileLaserGlowTimes.Remove(key);
         *      }
         *      else
         *      {
         *          float _time = _tileLaserGlowTimes[key];
         *          if (tileMap.ContainsKey(key))
         *              tileMap[key].tile.transform.GetChild(0).renderer.material.SetFloat("_GlowStrength", .5f + 5.5f * (_time / 1.5f));
         *
         *          _time -= Time.deltaTime;
         *          //Debug.Log("time is = " + _time);
         *          _tileLaserGlowTimes[key] = _time;
         *      }
         *  }
         * }
         */

        RespawnTile();

        //render debug data about the tile graph
        //tileGraph.Render();
    }
Exemple #23
0
    // Fills tile map with the current tiles in the scene
    void FillTileMap()
    {
        GameObject[] tileList;
        tileList = GameObject.FindGameObjectsWithTag("DJ_Tile");

        if (tileList.Length == 0)
        {
            Debug.Log("No game objects are tagged 'DJ_Tile'");
        }
        else
        {
            //Debug.Log("There are " + tileList.Length + " Objects tagged 'DJ_Tile'");
        }

        GameObject tempTile;

        //iterates though all the tiles with the tag DJ_Tile
        for (int i = 0; i < tileList.Length; i++)
        {
            //foreach( GameObject tile in tileList){
            tempTile = tileList[i];
            //ToDo: set parent to something

            Vector3 pos = tempTile.transform.position;

            //insert this DJ_Point and object into the map
            if (pos.y == 0)
            {
                DJ_Point newPoint = new DJ_Point((int)(pos.x), (int)(pos.z));


                //set the level dim values
                if (pos.x < DJ_TileManagerScript.MinX)
                {
                    DJ_TileManagerScript.MinX = tempTile.transform.position.x;
                }
                if (pos.x > DJ_TileManagerScript.MaxX)
                {
                    DJ_TileManagerScript.MaxX = tempTile.transform.position.x;
                }

                if (pos.z < DJ_TileManagerScript.MinZ)
                {
                    DJ_TileManagerScript.MinZ = tempTile.transform.position.z;
                }
                if (pos.z > DJ_TileManagerScript.MaxZ)
                {
                    DJ_TileManagerScript.MaxZ = tempTile.transform.position.z;
                }


                //checks to see two tiles are trying to occupy the same point
                if (tileMap.ContainsKey(newPoint))
                {
                    Debug.Log("Tile Exists already: " + newPoint.X + "," + newPoint.Y);
                }
                else
                {
                    //adds to the map that helps player movement

                    tileMap.Add(newPoint, new TileNode(newPoint, ref tempTile));

                    //create the links in the graph
                    LinkPossibleNeighbors(newPoint);
                    if (tempTile.GetComponent <DJ_TileScript>().checkpointTile)
                    {
                        DJ_TileManagerScript.checkpointList.Add(newPoint);
                        // checkpoint
                    }
                    else if (tempTile.GetComponent <DJ_TileScript>().spawnTile)
                    {
                        // spawn
                        DJ_TileManagerScript.checkpointList.Add(newPoint);
                        DJ_PlayerManager.spawnPoint = newPoint;
                    }
                    else if (tempTile.GetComponent <DJ_TileScript>().tutorialTile)
                    {
                        DJ_TileManagerScript.checkpointList.Add(newPoint);
                        DJ_PlayerManager.tutorialPoint = newPoint;
                    }
                    else if (tempTile.GetComponent <DJ_TileScript>().exitTile)
                    {
                        DJ_TileManagerScript.exitPoint = newPoint;
                    }
                    else if (tempTile.GetComponent <DJ_TileScript>().levelselectTile)
                    {
                        DJ_TileManagerScript.levelselectList.Add(newPoint);
                    }
                    else if (tempTile.GetComponent <DJ_TileScript>().teleportTile)
                    {
                        if (DJ_TileManagerScript.teleporterTiles.ContainsKey(tempTile.GetComponent <DJ_TeleporterTile>().teleporterPad))
                        {
                            DJ_TileManagerScript.teleporterTiles[tempTile.GetComponent <DJ_TeleporterTile>().teleporterPad].Add(tempTile);
                        }
                        else
                        {
                            List <GameObject> tempList = new List <GameObject>();
                            tempList.Add(tempTile);
                            DJ_TileManagerScript.teleporterTiles.Add(tempTile.GetComponent <DJ_TeleporterTile>().teleporterPad, tempList);
                        }
                    }
                    else if (tempTile.GetComponent <DJ_TileScript>().teleportPad)
                    {
                        DJ_TileManagerScript.teleporterPads.Add(tempTile.GetComponent <DJ_TeleporterPad>().teleportPadNumber, tempTile);
                    }
                    else
                    {
                        // normal
                    }
                    if (tempTile.GetComponent <DJ_TileScript>().fadingTile)
                    {
                        if (!tempTile.GetComponent <DJ_TileScript>().startVisible)
                        {
                            DJ_TileManagerScript.tilePool.Push(tileMap[new DJ_Point((int)tempTile.transform.position.x, (int)tempTile.transform.position.z)]);
                            tileMap.Remove(new DJ_Point((int)tempTile.transform.position.x, (int)tempTile.transform.position.z));
                            tempTile.gameObject.SetActive(false);
                        }
                    }
                    if (tempTile.GetComponent <DJ_TileScript>().recieverPad)
                    {
                        DJ_TileManagerScript.receiverTile.Add(tempTile.GetComponent <DJ_TileScript>().recieverNumber, tempTile);
                    }

                    if (tempTile.GetComponent <DJ_TileScript>().levelSelectTeleporterTile)
                    {
                        if (DJ_TileManagerScript.levelSelectTeleporterTile.ContainsKey(tempTile.GetComponent <DJ_LevelSelectTeleporter>().recieverNumber))
                        {
                            DJ_TileManagerScript.levelSelectTeleporterTile[tempTile.GetComponent <DJ_LevelSelectTeleporter>().recieverNumber].Add(tempTile);
                            //Debug.Log("adding levelSelect teleport tile to a created list");
                        }
                        else
                        {
                            //Debug.Log("adding levelSelect teleport tile by adding a list");
                            //Debug.Log("adding reciever number " + " = " + tempTile.GetComponent<DJ_LevelSelectTeleporter>().recieverNumber);
                            List <GameObject> tempList = new List <GameObject>();
                            tempList.Add(tempTile);
                            DJ_TileManagerScript.levelSelectTeleporterTile.Add(tempTile.GetComponent <DJ_LevelSelectTeleporter>().recieverNumber, tempList);
                        }
                    }
                }
            }
        }
    }
 //function for determining if tile exists
 public static bool isTileAvailable(DJ_Point pos)
 {
     return(tileMap.ContainsKey(pos));
 }
Exemple #25
0
 public static bool isTileAvailable(DJ_Point pos)
 {
     return(DJ_TileManagerScript.isTileAvailable(pos) && DJ_PlayerManager.isTileAvailable(pos));
 }
Exemple #26
0
    private bool GetNextMove(DJ_Point from, DJ_Point to, float currDist, float maxDist, DJ_Distance distanceType, float currentCost)
    {
        if (from.Equals(to))
        {
            return(true);
        }

        if (!tileMap.ContainsKey(to) && DJ_Util.GetDistance(from, to, DJ_Distance.EUCLIDEAN) <= 1)
        {
            return(false);
        }

        if (currDist > maxDist)
        {
            return(true);
        }

        if (tileMap.ContainsKey(from))
        {
            DJ_Dir prefDir = DJ_Util.GetPreferredDirection(from, to);

            int index;

            //immediately return none if the preferred direction
            //happens to be none. This either means the positions, from
            //and to, are the same or that there is no path from "from" to "to"
            if (prefDir == DJ_Dir.NONE)
            {
                return(true);
            }

            if (tileMap[from].neighbors[(int)prefDir] != null && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[(int)prefDir].pos))
            {
                if (!tilesVisited.Contains(tileMap[from].neighbors[(int)prefDir].pos))
                {
                    tilesVisited.Add(tileMap[from].neighbors[(int)prefDir].pos);
                    currentCosts.Add(currentCost);
                }
                else
                {
                    index = tilesVisited.IndexOf(tileMap[from].neighbors[(int)prefDir].pos);

                    float currCost = currentCosts[index];

                    if (currentCost < currCost)
                    {
                        tilesVisited.RemoveAt(index);
                        currentCosts.RemoveAt(index);

                        tilesVisited.Add(tileMap[from].neighbors[(int)prefDir].pos);
                        currentCosts.Add(currentCost);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (GetNextMove(tileMap[from].neighbors[(int)prefDir].pos, to, currDist + 1.0f, maxDist, distanceType, currentCost + 1.0f))
                {
                    return(true);
                }

                index = tilesVisited.IndexOf(tileMap[from].neighbors[(int)prefDir].pos);

                currentCosts.RemoveAt(index);
                tilesVisited.Remove(tileMap[from].neighbors[(int)prefDir].pos);
            }

            for (int i = 0; i < tileMap[from].neighbors.Length; ++i)
            {
                if (tileMap[from].neighbors[i] != null && i != (int)prefDir && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[i].pos))
                {
                    tilesVisited.Add(tileMap[from].neighbors[i].pos);
                    currentCosts.Add(currentCost);

                    if (GetNextMove(tileMap[from].neighbors[i].pos, to, currDist + 1.0f, maxDist, distanceType, currentCost + 1.0f))
                    {
                        return(true);
                    }

                    index = tilesVisited.IndexOf(tileMap[from].neighbors[i].pos);
                    currentCosts.RemoveAt(index);
                    tilesVisited.Remove(tileMap[from].neighbors[i].pos);
                }
            }
        }

        return(false);
    }
Exemple #27
0
    //created by Fernando
    public static DJ_Point GetTilePos(Vector3 position)
    {
        DJ_Point tilePos = new DJ_Point(Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.z));

        return(tilePos);
    }
Exemple #28
0
 public static void GetTilePos(Vector3 position, DJ_Point tilePos)
 {
     tilePos.X = (int)(position.x + .5f);
     tilePos.Y = (int)(position.z + .5f);
 }
Exemple #29
0
 public void Set(DJ_Point p)
 {
     X = p.X;
     Y = p.Y;
 }
Exemple #30
0
 public static void GetNeighboringTilePos(DJ_Point currTilePos, DJ_Dir direction, DJ_Point targetTilePos)
 {
     GetNeighboringTilePos(currTilePos, direction, 1, targetTilePos);
 }