Inheritance: MonoBehaviour
Ejemplo n.º 1
0
 public void SetDefaultTile(int u, int v, int w, int h, int dx = 0, int dy = 0)
 {
     this.defaultTile                        = new _Tile();
     this.defaultTile.tileSprite             = new Sprite(this.tileset);
     this.defaultTile.tileSprite.TextureRect = new IntRect(u, v, w, h);
     this.defaultTile.tileSprite.Scale       = new Vector2f(this.TileScale, this.TileScale);
     // CellWidth and CellHeight are already scaled
     this.defaultTile.tileSprite.Position = new Vector2f(0f, 0f);
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        _Tile[,] tiles = _LevelController.instance.tiles;

        for (int i = 0; i < tiles.GetLength(0); i++)
        {
            for (int j = 0; j < tiles.GetLength(1); j++)
            {
                _Tile tile = tiles[i, j];
                if (tile == null)
                {
                    continue;
                }

                if (Vector2.Distance(Snap(transform.position), tile.transform.position) < viewRadius)
                {
                    //scale = visible;
                    tile.discovered      = true;
                    tile.fogMask.enabled = false;
                }
                else if (tile.discovered)
                {
                    //scale = remembered;
                    tile.fogMask.enabled = true;
                    tile.fogMask.sprite  = _LevelController.instance.discoveredFogMask;
                }
                else
                {
                    //scale = undiscovered;
                    tile.fogMask.enabled = true;
                    tile.fogMask.sprite  = _LevelController.instance.undiscoveredFogMask;
                }


                /*
                 * SpriteRenderer[] renderers = tiles[i, j].GetComponentsInChildren<SpriteRenderer>();
                 *
                 * foreach( var renderer in renderers)
                 * {
                 * renderer.color = new Color(1f, 1f, 1f, scale);
                 * }
                 *
                 *
                 *
                 * try
                 * {
                 * Floor floor = tiles[i, j] as Floor;
                 * floor.agent.GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, scale != visible ? 0f : visible );
                 * floor.thing.GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, scale);
                 *
                 * }
                 * catch (Exception) { }*/
            }
        }
    }
Ejemplo n.º 3
0
 protected void RandomTileTarget()
 {
     _from.Set(X, Y);
     while (true)
     {
         _Tile[,] tempTiles = _LevelController.instance.tiles;
         _Tile targetTile = tempTiles[UnityEngine.Random.Range(0, tempTiles.GetLength(0)), UnityEngine.Random.Range(0, tempTiles.GetLength(1))];
         if (targetTile is Floor)
         {
             _to.Set(targetTile.X, targetTile.Y);
             path = PathFind.Pathfinding.FindPath(grid, _from, _to);
             if (path.Count != 0)
             {
                 ExtrapolatePath(path);
                 break;
             }
         }
     }
 }
Ejemplo n.º 4
0
 public void SetTile(int x, int y, int u, int v, int w, int h, int dx = 0, int dy = 0)
 {
     try {
         var t = new _Tile();
         t.tileSprite             = new Sprite(this.tileset);
         t.tileSprite.TextureRect = new IntRect(u, v, w, h);
         t.tileSprite.Scale       = new Vector2f(this.TileScale, this.TileScale);
         // CellWidth and CellHeight are already scaled
         t.tileSprite.Position = new Vector2f(
             //x * this.cellSize.X + dx * this.TileScale,
             //y * this.cellSize.Y + dy * this.TileScale
             dx * this.TileScale,
             dy * this.TileScale
             );             // XXX no longer useful
         t.dx = dx;
         t.dy = dy;
         this.maskMap [y, x] = t;
     } catch {
         Logger.Warning("TiledLayer", "SetTile", "Out of bounds " + x.ToString() + "," + y.ToString());
     }
 }
Ejemplo n.º 5
0
    private bool beginAttack; //set to true once random position around the dragon has been found

    #endregion Fields

    #region Methods

    void Move()
    {
        gameObject.GetComponentInChildren<_EnemyAnimation>().ChangeState(_EnemyAnimation.animationState.walk);
        //speeds up slowed down enemy at end of effect's duration
        if (slowed && slowTimer < Time.time)
        {
            moveSpeed += modifyMoveSpeed;
            slowed = false;
            ice.Stop();
        }

        //allows enemy to be shocked again
        if (shocked && shockTimer < Time.time)
        {
            shocked = false;
            shock.Stop();
        }

        if (targetTile.endOfLine)
        {
            goingForward = false;
        }

        if (targetTile.goldStash)
        {
            if (_Overlord.gold > gold && !hasGold)
            {
                _Overlord.gold -= gold;
                gold *= 2;
                hasGold = true;
                attacking = false;
            }
            else if (_Overlord.gold > 0 && !hasGold)
            {
                int goldTaken = _Overlord.gold;
                _Overlord.gold -= goldTaken;
                gold += goldTaken;
                hasGold = true;
                attacking = false;
            }
            if (_Overlord.gold <= 0 && !attacking && !hasGold)
            {
                //gold is the "damage" the enemy does
                attacking = true;
                nextTarget = new Vector3(Random.Range(attackBox.leftX, attackBox.rightX), targetTile.transform.position.y, Random.Range(attackBox.topZ, attackBox.bottomZ));
                beginAttack = false;
            }
        }

        if (targetTile.exit)
        {
            Destroy(gameObject);
        }

        if (!attacking)
        {
            //new rotation
            Vector3 target = targetTile.transform.position - transform.position;
            Quaternion targetRotation = Quaternion.LookRotation(target);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
            //end of new rotation

            //new movement
            float distanceCheckX = 10000;
            float distanceCheckZ = 10000;

            distanceCheckX = Mathf.Abs(nextTarget.x - this.transform.position.x);
            distanceCheckZ = Mathf.Abs(nextTarget.z - this.transform.position.z);
            distanceCheckDisplay1 = distanceCheckX;
            distanceCheckDisplay2 = distanceCheckZ;

            if (distanceCheckX < 0.1 && distanceCheckZ < 0.1)
            {
                targetTile = targetTile.nextTile;
                nextTarget = targetTile.transform.position;
                distanceTravelled++;
            }
            else
                transform.Translate(0, 0, moveSpeed * Time.deltaTime);
            //end of new movement
        }
        else
        {
            //enemy is attacking
            if (!beginAttack)
            {
                attackTimer += Time.deltaTime;

                Vector3 target = nextTarget - transform.position;
                Quaternion targetRotation = Quaternion.LookRotation(target);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);

                float distanceCheckX = 10000;
                float distanceCheckZ = 10000;

                distanceCheckX = Mathf.Abs(nextTarget.x - this.transform.position.x);
                distanceCheckZ = Mathf.Abs(nextTarget.z - this.transform.position.z);
                distanceCheckDisplay1 = distanceCheckX;
                distanceCheckDisplay2 = distanceCheckZ;

                if ((distanceCheckX < 0.1 && distanceCheckZ < 0.1) || attackTimer > 2)
                {
                    beginAttack = true;
                    attackTimer = 0;
                }
                else
                {
                    transform.Translate(0, 0, moveSpeed * 2 * Time.deltaTime);
                }
            }
            else
            {
                //rotate to face the dragon //Nate addition 5/28
                Vector3 target = dragonPositionTile.transform.position - transform.position;
                target.Normalize();
                Quaternion targetRotation = Quaternion.LookRotation(target);
                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
                //end of new rotation

                gameObject.GetComponentInChildren<_EnemyAnimation>().ChangeState(_EnemyAnimation.animationState.attack);
                attackTimer -= Time.deltaTime;
                if (attackTimer <= 0)
                {
                    _Overlord.wyrmHealth--;
                    this.health--;
                    attackTimer = 1;
                }
            }
        }
    }
Ejemplo n.º 6
0
    private void Awake()
    {
        Time.timeScale = 1;
        player         = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>();
        // ==========================
        // Singleton initialization
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        // ==========================

        StartTimer();

        // Generating current level bounds dynamically **********************
        int maxX = 0, maxY = 0;

        foreach (_GridElement element in FindObjectsOfType <_GridElement>())
        {
            maxX = (maxX < element.X ? element.X : maxX);
            maxY = (maxY < element.Y ? element.Y : maxY);
        }
        // *****************************************************************

        // Array storing every tile on the map
        tiles = new _Tile[maxX + 1, maxY + 1];

        // Filling the tiles array *****************************************
        foreach (_Tile tile in FindObjectsOfType <_Tile>())
        {
            if (tiles[tile.X, tile.Y] == null)
            {
                tiles[tile.X, tile.Y] = tile;
            }
            else
            {
                throw new DuplicatedTile(tiles[tile.X, tile.Y], tile);
            }
        }
        // ******************************************************************

        // Filling inital tile informations (entities) **********************
        foreach (_Entity obj in FindObjectsOfType <_Entity>())
        {
            _Tile tile = tiles[obj.X, obj.Y];
            try
            {
                if (obj is _Agent && tile is Floor)
                {
                    (tile as Floor).agent = obj as _Agent;

                    if (obj is Knight)
                    {
                        knights.Add(obj as Knight);
                    }
                    else if (obj is Monster)
                    {
                        monsters.Add(obj as Monster);
                    }
                }

                else if (obj is Thing && tile is Floor)
                {
                    (tile as Floor).thing = obj as Thing;
                }
            }
            catch (NullReferenceException)
            {
                throw new InvalidGridObjectPosition(obj);
            }
        }
        // ********************************************************************



        // Creating knights and monsters arrays
        knightsTilemap  = new bool[maxX + 1, maxY + 1];
        monstersTilemap = new bool[maxX + 1, maxY + 1];

        for (int i = 0; i < knightsTilemap.GetLength(0); i++)
        {
            for (int j = 0; j < knightsTilemap.GetLength(1); j++)
            {
                // Getting info from tile data
                if (tiles[i, j] is Wall)
                {
                    knightsTilemap[i, j]  = false;
                    monstersTilemap[i, j] = false;
                }
                else if (tiles[i, j] is Floor)
                {
                    knightsTilemap[i, j]  = true;
                    monstersTilemap[i, j] = true;
                }
                else if (tiles[i, j] is Door)
                {
                    knightsTilemap[i, j]  = true;
                    monstersTilemap[i, j] = (tiles[i, j] as Door).Walkable;
                }
            }
        }
    }