Exemple #1
0
        public GridItem RemoveItem(Vector2 position, List <GridItem> items)
        {
            GridItem toDelete = null;
            GridItem temp     = null;

            if ((int)Math.Floor((position.X - Position.X) / 48) >= 0 && (int)Math.Floor((position.X - Position.X) / 48) < GridHolder.GetLength(0))
            {
                if ((int)Math.Floor((position.Y - Position.Y) / 48) >= 0 && (int)Math.Floor((position.Y - Position.Y) / 48) < GridHolder.GetLength(0))
                {
                    toDelete = GridHolder[(int)Math.Floor((position.X - Position.X) / 48), (int)Math.Floor((position.Y - Position.Y) / 48)];
                }
            }

            for (int y = 0; y < GridHolder.GetLength(0); y++)
            {
                for (int x = 0; x < GridHolder.GetLength(0); x++)
                {
                    if (GridHolder[x, y] != null && GridHolder[x, y] == toDelete)
                    {
                        if (items.Contains(GridHolder[x, y]))
                        {
                            temp = GridHolder[x, y];
                            items.Remove(GridHolder[x, y]);
                        }
                        GridHolder[x, y] = null;
                    }
                }
            }

            return(temp);
        }
Exemple #2
0
    public static List <Cell> GetNeighbours(Cell cell)
    {
        List <Cell> neighbours = new List <Cell>();

        foreach (var direction in ORTHOGONAL)
        {
            Vector3Int center          = cell.AsVector3Int();
            Vector3Int directionVector = Vector3Int.right * direction.x + Vector3Int.up * direction.y;
            Cell       neighbour       = GridHolder.GetCell(center + directionVector) as Cell;
            if (neighbour != null)
            {
                neighbours.Add(neighbour);
            }
        }

        if (selectedStyle == Style.Diagonal || selectedStyle == Style.Euclidian)
        {
            foreach (var direction in DIAGONALS)
            {
                Vector3Int center          = cell.AsVector3Int();
                Vector3Int directionVector = Vector3Int.right * direction.x + Vector3Int.up * direction.y;
                Cell       neighbour       = GridHolder.GetCell(center + directionVector) as Cell;
                if (neighbour != null)
                {
                    neighbours.Add(neighbour);
                }
            }
        }

        return(neighbours.Count > 0 ? neighbours : null);
    }
    public void CreateGrid(int x, int y)
    {
        List<List<GameObject>> grid = new List<List<GameObject>>();

        Vector3 tileSize = _tileSpriteRenderer.bounds.size;
        Vector3 tilePosition = new Vector3(0, 0, 0);

        for(int xRow = 0; xRow < x; xRow++)
        {
            grid.Add(new List<GameObject>());

            for(int yRow = 0; yRow < y; yRow++)
            {
                tilePosition = new Vector3(-((x * tileSize.x) / 2) + xRow * tileSize.x,
                                           -((y * tileSize.y) / 2) + yRow * tileSize.y,
                                           0);

                Instantiate(tile, tilePosition, Quaternion.identity);
                tile.GetComponent<Tile>().SetTile(xRow, yRow);
                grid[xRow].Add(tile);

                totalTiles = (x * y);
            }
        }

        _gridHolder = new GridHolder(grid);
    }
Exemple #4
0
        private void BuildGrid1()
        {
            gridHolder = new GridHolder <int>();

            var shape = gridShapeGraph.shape1Graph.GetShape();

            gridHolder.SetGrid(new Grid1 <TCell>(shape));

            var spaceMap = spaceMapGraph.GetMap();
            var roundMap = MakeRoundMap <int>();
            var gridMap  = new GridMap <int>(spaceMap, roundMap);

            gridHolder.SetMap(gridMap);

            if (cellStorage != null)
            {
                if (!cellStorage.IsEmpty())
                {
                    RelinkCells(gridHolder.GetGrid <int>());
                    return;
                }
            }

            MakeCells(gridHolder.GetGrid <int>(), gridHolder.GetMap <int>());
        }
Exemple #5
0
        public Player()
        {
            GridHolder = Object.FindObjectOfType <GridHolder>();
            GridHolder.CreateGrid();
            Grid = GridHolder.Grid;

            TurretMarket = new TurretMarket(Game.CurrentLevel.TurretMarketAsset);
        }
Exemple #6
0
 public Player()
 {
     GridHolder = Object.FindObjectOfType <GridHolder>();
     GridHolder.CreateGrid();
     Grid         = GridHolder.Grid;
     TurretMarket = new TurretMarket();
     m_Health     = Game.CurrentLevel.StartHealth;
 }
Exemple #7
0
        //public readonly EnemySearch EnemySearch;

        public Player()
        {
            GridHolder = Object.FindObjectOfType <GridHolder>();
            GridHolder.CreateGrid();
            Grid = GridHolder.Grid;

            TurretMarket = new TurretMarket(Game.CurrentLevel.TurretMarketAsset);

            //EnemySearch = new EnemySearch(m_EnemyDatas);
        }
Exemple #8
0
        public Player()
        {
            GridHolder = Object.FindObjectOfType <GridHolder>();
            GridHolder.CreateGrid();
            Grid = GridHolder.Grid;



            //EnemySearch = new EnemySearch(m_EnemyDatas);
        }
 public void NewWorld()
 {
     Pathfinding.SetUp();
     GridHolder.GenerateGrid();
     WorldPainter.RemoveWorld();
     WorldPainter.PaintWorld();
     Pathfinding.SwitchToManhattan();
     NewWorldCreated?.Invoke();
     FindObjectOfType <FollowCam>().enabled = true;
     SetGameState(GameState.play);
 }
Exemple #10
0
    protected virtual void RefreshForNewWorld()
    {
        if (GetComponent <iTween>())
        {
            ServiceLocator.GetDebugProvider().Log("remove itween");
            Destroy(GetComponent <iTween>());
        }
        Cell newCell = GridHolder.GetRandomWalkableCell();

        newCell.walkable        = false;
        pos.x                   = newCell.GetX();
        pos.y                   = newCell.GetY();
        this.transform.position = new Vector3(pos.x, 0, pos.y);
    }
Exemple #11
0
    public virtual void MoveAlongDirection(Direction direction, float _speed)
    {
        Vector3Int toAdd = Vector3Int.zero;

        switch (direction)
        {
        case Direction.Up:
            toAdd += new Vector3Int(0, 0, 1);
            break;

        case Direction.Down:
            toAdd += new Vector3Int(0, 0, -1);
            break;

        case Direction.Left:
            toAdd += new Vector3Int(-1, 0, 0);
            break;

        case Direction.Right:
            toAdd += new Vector3Int(1, 0, 0);
            break;

        default:
            break;
        }

        if (GridHolder.IsWalkable(pos.x + toAdd.x, pos.y + toAdd.z) == false)
        {
            return;
        }

        MakeCurrentCellWalkable();
        if (GetComponent <iTween>())
        {
            Destroy(GetComponent <iTween>());
            this.transform.position = pos.GetAsBoardAlignedVector3Int();
        }
        pos.x += toAdd.x;
        pos.y += toAdd.z;

        iTween.MoveTo(this.gameObject, iTween.Hash(
                          "position", new Vector3(pos.x, this.transform.position.y, pos.y),
                          "time", _speed,
                          "easeType", iTween.EaseType.linear
                          ));


        RotateToFaceDirection(direction);
        MakeCurrentCellNotWalkable();
    }
Exemple #12
0
 private Cell LookForPlayer()
 {
     if (Vector3.Distance(transform.position, player.gameObject.transform.position) <= ruleSet.LIGHT_RADIUS)
     {
         if (Physics.Linecast(transform.position, player.transform.position, out hit, searchMask))
         {
             if (hit.collider.gameObject == player.gameObject)
             {
                 return(GridHolder.GetCell(player.pos.GetAsVector3Int()));
             }
         }
     }
     return(null);
 }
    /// <summary>
    /// Creates a new room.
    /// </summary>
    private void CreateNewRoom(GridHolder gridHolder, Tile startingTile, int roomSize)
    {
        int roomTileSet = 0;
        List<Tile> roomTiles = new List<Tile>();
        List<Tile> currentTileNeighbors = GetNeighbors(gridHolder, startingTile);
        Tile currentNeighbor;

        while(roomTileSet < roomSize)
        {
            for(int i = 0; i < currentTileNeighbors.Count; i++)
            {
                currentNeighbor = currentTileNeighbors[i];
                print("looping through.");
            }
        }
    }
Exemple #14
0
        private void OnValidate()
        {
            if (stateMachine == null)
            {
                stateMachine = FindObjectOfType <GameStateMachine>();
            }

            if (levelManager == null)
            {
                levelManager = FindObjectOfType <LevelManager>();
            }

            if (audioManager == null)
            {
                audioManager = FindObjectOfType <AudioManager>();
            }

            if (gridHolder == null)
            {
                gridHolder = FindObjectOfType <GridHolder>();
            }

            if (uiManager == null)
            {
                uiManager = FindObjectOfType <UiManager>();
            }

            if (towerManager == null)
            {
                towerManager = FindObjectOfType <TowerManager>();
            }

            if (enemyManager == null)
            {
                enemyManager = FindObjectOfType <EnemyManager>();
            }

            if (selectionManager == null)
            {
                selectionManager = FindObjectOfType <SelectionManager>();
            }

            if (cameraController == null)
            {
                cameraController = FindObjectOfType <CameraController>();
            }
        }
Exemple #15
0
    private void ChangeMode(Modes newMode)
    {
        currentMode = newMode;
        flame.ChangeMode(currentMode);
        switch (currentMode)
        {
        case Modes.Search:
            animator.SetBool("FoundPlayer", false);
            animator.SetBool("Moving", true);
            newSearchPointTimer = ruleSet.MONSTER_SEARCH_TIMER.GetRandomValue();
            searchCell          = GridHolder.GetRandomWalkableCell();
            timeBetweenSteps    = ruleSet.MONSTER_MOVEMENT_TICK_SEARCH;
            break;

        case Modes.Hunt:
            animator.SetBool("FoundPlayer", true);
            animator.SetBool("Moving", true);
            ServiceLocator.GetAudioProvider().PlaySoundEvent("Inhale");
            timeBetweenSteps = ruleSet.MONSTER_MOVEMENT_TICK_HUNT;
            timeSinceSpotted = 0;
            break;

        case Modes.Happy:
            animator.SetBool("FoundPlayer", true);
            animator.SetBool("Moving", false);
            timeBetweenSteps = int.MaxValue;
            happyTimer       = ruleSet.MONSTER_WAIT_TIME;
            lastKnownCell    = null;
            searchCell       = null;
            break;

        case Modes.Dead:
            animator.SetBool("FoundPlayer", false);
            animator.SetBool("Moving", false);
            timeBetweenSteps = int.MaxValue;
            if (GetComponent <iTween>())
            {
                ServiceLocator.GetDebugProvider().Log("remove itween");
                Destroy(GetComponent <iTween>());
            }
            Instantiate(Resources.Load <GameObject>("Prefabs/Poof/Poof"), this.transform.position, Quaternion.identity);
            this.transform.position = Vector3.one * 5000;
            break;
        }
    }
Exemple #16
0
        public void Draw(List <GridItem> items)
        {
            for (int y = 0; y < GridHolder.GetLength(1); y++)
            {
                for (int x = 0; x < GridHolder.GetLength(0); x++)
                {
                    if (GridHolder[x, y] == null)
                    {
                        Game1.SpriteBatchGlobal.Draw(Game1.Textures["SlotBackground"], new Vector2(x * 48, y * 48) + Position);
                    }
                }
            }

            foreach (GridItem item in items)
            {
                Game1.SpriteBatchGlobal.Draw(item.Texture, new Vector2(item.Index.X * 48, item.Index.Y * 48) + Position, origin: new Vector2(192 / 2), rotation: item.Rotation);
            }
        }
Exemple #17
0
    private void Start()
    {
        jump     = GetComponentInChildren <Jump>();
        animator = GetComponentInChildren <Animator>();
        animator.SetTrigger("Idle");
        prevPos      = transform.position;
        curPos       = prevPos;
        lightChecker = GetComponent <InLightChecker>();
        InputManager.INSTANCE.DirectionInput += MoveAlongDirection;
        Cell randomStartPosition = GridHolder.GetRandomWalkableCell();

        pos.x = randomStartPosition.pos.x;
        pos.y = randomStartPosition.pos.y;
        if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameFinish)
        {
            //new pos
            this.transform.position = startPosition;
        }
        else
        {
            //new pos
            this.transform.position = new Vector3(pos.x, 0, pos.y);
        }
        hp        = new Health();
        hp.myUnit = this;
        hp.SetMaxHealth(ruleSet.PLAYER_HEALTH);
        hp.SetCurrentHealth(ruleSet.PLAYER_HEALTH);
        hp.IsDead += GameManager.INSTANCE.GameOver;
        hp.IsDead += SavePlayerPos;

        healthSlider          = GameObject.FindWithTag("HealthSlider").GetComponent <Slider>();
        healthSlider.maxValue = hp.GetMaxHealth();
        healthSlider.minValue = 0;
        healthSlider.value    = hp.GetCurrentHealth();

        hp.HpChanged += UpdateHealthSlider;



        GameManager.INSTANCE.NewWorldCreated += RefreshForNewWorld;
    }
Exemple #18
0
    void Start()
    {
        animator = GetComponentInChildren <Animator>();
        light    = GetComponentInChildren <MonsterLight>();
        flame    = GetComponentInChildren <MonsterFlame>();
        Cell randomStartPosition = GridHolder.GetRandomWalkableCell();

        pos.x = randomStartPosition.pos.x;
        pos.y = randomStartPosition.pos.y;
        // pos.x = 5;
        // pos.y = 5;
        if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameFinish)
        {
            //player previous pos
            monsterGrowth           = ruleSet.MONSTER_GROWTH_FACTOR;
            this.transform.position = startPosition;
        }
        else
        {
            //new pos
            monsterGrowth           = 0;
            this.transform.position = new Vector3(pos.x, 0, pos.y);
        }

        moveTimer  = 3f;
        player     = GameObject.FindWithTag("Player").GetComponent <Player>();
        actionWait = ruleSet.MONSTER_MOVEMENT_TICK_SEARCH - monsterGrowth;
        hp         = new Health();
        hp.SetMaxHealth(ruleSet.MONSTER_HEALTH + monsterGrowth);
        hp.SetCurrentHealth(ruleSet.MONSTER_HEALTH + monsterGrowth);

        hp.IsDead += GameManager.INSTANCE.GameFinished;
        hp.IsDead += GetPlayerPosition;

        GridHolder.BranchSnap += TargetSteppedOnBranch;

        GameManager.INSTANCE.NewWorldCreated += RefreshForNewWorld;

        ChangeMode(Modes.Search);
    }
 private void OnDrawGizmos()
 {
     if (Application.isPlaying == false)
     {
         return;
     }
     if (GridHolder.GetGrid() == null)
     {
         return;
     }
     foreach (Cell cell in GridHolder.GetGrid())
     {
         if (cell.walkable)
         {
             Gizmos.color = Color.green;
         }
         else
         {
             Gizmos.color = Color.red;
         }
         Gizmos.DrawSphere(cell.AsBoardOrientedVector3Int(), 0.1f);
     }
 }
Exemple #20
0
    public override void MoveAlongDirection(InputManager.Direction direction, float _speed)
    {
        _speed = ruleSet.PLAYER_MOVEMENT_TICK;
        if (isBurning)
        {
            _speed = _speed / (ruleSet.PLAYER_BURNING_EXTRA_SPEED_PERCENTAGE);
        }
        base.MoveAlongDirection(direction, _speed);


        GridHolder.CheckForBranch(pos.GetAsVector3Int());
        if (stepSFXList == null || stepSFXList.Count == 0)
        {
            ServiceLocator.GetDebugProvider().Log("step sfx is null");
            return;
        }
        if (everyOtherStep == 2)
        {
            everyOtherStep = 0;
            ServiceLocator.GetAudioProvider().PlaySoundEvent(stepSFXList.GetRandom(), volume: 0.6f);
        }
        everyOtherStep++;
    }
    public void Awake()
    {
        if (INSTANCE == null)
        {
            INSTANCE = this;
        }
        else
        {
            if (INSTANCE != this)
            {
                Destroy(this.gameObject);
            }
        }

        ServiceLocator.SetDebugProvider(new NullDebugProvider());
        ServiceLocator.SetAudioProvider(new RealAudioProvider());
        ServiceLocator.GetAudioProvider().PlaySoundEvent("Ambience", true);
        FindObjectOfType <Rules>().SetRules();
        ruleSet = ruleSet.CreateClone();
        GridHolder.GenerateGrid();
        WorldPainter.PaintWorld();
        Pathfinding.SwitchToManhattan();
        SetGameState(GameState.play);
    }
Exemple #22
0
 public DeskRaycastController(GridHolder mGridHolder)
 {
     m_GridHolder = mGridHolder;
 }
Exemple #23
0
        public bool AddItem(Vector2 origin, List <GridItem> selfItems, float rotation)
        {
            if (MouseItem.Item != null)
            {
                int Left   = 3;
                int Right  = 0;
                int Top    = 3;
                int Bottom = 0;

                for (int y = 0; y < 4; y++)
                {
                    for (int x = 0; x < 4; x++)
                    {
                        if (MouseItem.Item.ItemBounds[x, y] == 1 && x < Left)
                        {
                            Left = x;
                        }
                        if (MouseItem.Item.ItemBounds[x, y] == 1 && x > Right)
                        {
                            Right = x;
                        }
                        if (MouseItem.Item.ItemBounds[x, y] == 1 && y < Top)
                        {
                            Top = y;
                        }
                        if (MouseItem.Item.ItemBounds[x, y] == 1 && y > Bottom)
                        {
                            Bottom = y;
                        }
                    }
                }

                Right  = 3 - Right;
                Bottom = 3 - Bottom;

                for (int y = 0 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48); y < 4 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48); y++)
                {
                    for (int x = 0 + (int)Math.Floor((origin.X - Position.X - 72) / 48); x < 4 + (int)Math.Floor((origin.X - Position.X - 72) / 48); x++)
                    {
                        if (0 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48) < -Top || 4 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48) > GridHolder.GetLength(1) + Bottom)
                        {
                            return(false);
                        }
                        if (0 + (int)Math.Floor((origin.X - Position.X - 72) / 48) < -Left || 4 + (int)Math.Floor((origin.X - Position.X - 72) / 48) > GridHolder.GetLength(0) + Right)
                        {
                            return(false);
                        }
                    }
                }

                GridItem item = new GridItem(MouseItem.Item.Rotation, new Point((int)(origin.X - Position.X + 24) / 48, (int)(origin.Y - Position.Y + 24) / 48), MouseItem.Item.Type);

                for (int y = 0 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48); y < 4 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48); y++)
                {
                    for (int x = 0 + (int)Math.Floor((origin.X - Position.X - 72) / 48); x < 4 + (int)Math.Floor((origin.X - Position.X - 72) / 48); x++)
                    {
                        if (MouseItem.Item.ItemBounds[x - (int)Math.Floor((origin.X - Position.X - 72) / 48), y - (int)Math.Floor((origin.Y - Position.Y - 72) / 48)] == 1)
                        {
                            if (GridHolder[x, y] == null)
                            {
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }

                for (int y = 0 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48); y < 4 + (int)Math.Floor((origin.Y - Position.Y - 72) / 48); y++)
                {
                    for (int x = 0 + (int)Math.Floor((origin.X - Position.X - 72) / 48); x < 4 + (int)Math.Floor((origin.X - Position.X - 72) / 48); x++)
                    {
                        if (MouseItem.Item.ItemBounds[x - (int)Math.Floor((origin.X - Position.X - 72) / 48), y - (int)Math.Floor((origin.Y - Position.Y - 72) / 48)] == 1)
                        {
                            GridHolder[x, y] = item;
                            if (selfItems.Contains(item) == false)
                            {
                                selfItems.Add(item);
                            }
                        }
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
    /// <summary>
    /// Gets the neighbors of a tile.
    /// </summary>
    /// <returns>The neighbors.</returns>
    /// <param name="gridHolder">Grid holder.</param>
    /// <param name="tile">Tile.</param>
    private List<Tile> GetNeighbors(GridHolder gridHolder, Tile tile)
    {
        List<Tile> returningNeighbor = new List<Tile>();

        int x = (int)tile.gridPosition.x;
        int y = (int)tile.gridPosition.y;

        if(gridHolder.GetTile(x - 1, y) != null)
            returningNeighbor.Add(gridHolder.GetTile(x - 1, y));

        if(gridHolder.GetTile(x + 1, y) != null)
            returningNeighbor.Add(gridHolder.GetTile(x + 1, y));

        if(gridHolder.GetTile(x, y - 1) != null)
            returningNeighbor.Add(gridHolder.GetTile(x, y - 1));

        if(gridHolder.GetTile(x, y + 1) != null)
            returningNeighbor.Add(gridHolder.GetTile(x, y + 1));

        return returningNeighbor;
    }
        private void ShowDialog(int holderId, GravityFlags gravity, bool showHeader, bool showFooter, bool expanded)
        {
            bool isGrid;

            Com.Orhanobut.Dialogplus.IHolder holder;
            switch (holderId)
            {
            case Resource.Id.basic_holder_radio_button:
                holder = new ViewHolder(Resource.Layout.content);
                isGrid = false;
                break;

            case Resource.Id.list_holder_radio_button:
                holder = new ListHolder();
                isGrid = false;
                break;

            default:
                holder = new GridHolder(3);
                isGrid = true;
                break;
            }

            OnClickListener clickListener = new OnClickListener()
            {
                ClickAction = (s, v) =>
                {
                }
            };

            OnItemClickListener itemClickListener = new OnItemClickListener()
            {
                ItemClick = (d, i, v, p) =>
                {
                    TextView textView       = v.FindViewById <TextView>(Resource.Id.text_view);
                    string   clickedAppName = textView.Text;
                    Toast.MakeText(this, clickedAppName + "Clicked", ToastLength.Short).Show();
                }
            };

            OnDismissListener dismissListener = new OnDismissListener()
            {
                Dimissed = (d) =>
                {
                    Toast.MakeText(this, "dismiss listener invoked!", ToastLength.Short).Show();
                }
            };

            OnCancelListener cancelListener = new OnCancelListener()
            {
                Canceled = (d) =>
                {
                    Toast.MakeText(this, "cancel listener invoked!", ToastLength.Short).Show();
                }
            };

            DialogPlusQs.Views.SimpleAdapter adapter = new DialogPlusQs.Views.SimpleAdapter(this, isGrid);

            if (showHeader && showFooter)
            {
                ShowCompleteDialog(holder, gravity, adapter, clickListener, itemClickListener, dismissListener, cancelListener,
                                   expanded);
                return;
            }

            if (showHeader && !showFooter)
            {
                ShowNoFooterDialog(holder, gravity, adapter, clickListener, itemClickListener, dismissListener, cancelListener,
                                   expanded);
                return;
            }

            if (!showHeader && showFooter)
            {
                ShowNoHeaderDialog(holder, gravity, adapter, clickListener, itemClickListener, dismissListener, cancelListener,
                                   expanded);
                return;
            }

            ShowOnlyContentDialog(holder, gravity, adapter, itemClickListener, dismissListener, cancelListener, expanded);
        }
Exemple #26
0
 public static List <Cell> PathfindBetween(Vector3Int start, Vector3Int goal)
 {
     return(PathfindBetween(GridHolder.GetCell(start), GridHolder.GetCell(goal)));
 }
Exemple #27
0
 public void TargetSteppedOnBranch(Vector3Int pos)
 {
     ChangeMode(Modes.Hunt);
     searchCell       = GridHolder.GetCell(pos);
     timeSinceSpotted = 0;
 }
Exemple #28
0
    void Update()
    {
        if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.pause)
        {
            return;
        }
        if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameOver)
        {
            return;
        }
        if (GameManager.INSTANCE.GetGameState() == GameManager.GameState.gameFinish)
        {
            return;
        }

        if (currentMode == Modes.Dead)
        {
            return;
        }

        light.UpdateColor(hp.GetCurrentHealth(), hp.GetMaxHealth());

        hp.TakeDamage(ruleSet.MONSTER_HEALTH_LOSS_RATE * Time.deltaTime);


        if (hp.GetCurrentHealth() <= 0 && currentMode != Modes.Dead)
        {
            ChangeMode(Modes.Dead);
        }

        if (currentMode == Modes.Dead)
        {
            return;
        }

        switch (currentMode)
        {
        case Modes.Search:

            if (LookForPlayer() != null)
            {
                ChangeMode(Modes.Hunt);
                moveTimer = 0.25f;
                return;
            }

            newSearchPointTimer -= Time.deltaTime;
            if (newSearchPointTimer <= 0)
            {
                newSearchPointTimer = ruleSet.MONSTER_SEARCH_TIMER.GetRandomValue();
                searchCell          = GridHolder.GetRandomWalkableCell();
            }

            moveTimer -= Time.deltaTime;
            if (moveTimer <= 0)
            {
                moveTimer = timeBetweenSteps;
                Direction direction = Pathfinding.GetNextStepDirection(this.pos.GetAsVector3Int(), searchCell.pos.GetAsVector3Int());
                if (direction != Direction.NONE)
                {
                    MoveAlongDirection(direction, ruleSet.MONSTER_MOVEMENT_TICK_SEARCH);
                }
            }


            break;

        case Modes.Hunt:



            Cell prevCell      = searchCell;
            Cell LookingAtCell = LookForPlayer();
            if (LookingAtCell != null)
            {
                searchCell       = LookingAtCell;
                timeSinceSpotted = 0;
            }

            if (prevCell == searchCell)
            {
                timeSinceSpotted += Time.deltaTime;
                if (timeSinceSpotted > 1)
                {
                    ChangeMode(Modes.Search);
                }
            }

            moveTimer -= Time.deltaTime;
            if (moveTimer <= 0)
            {
                moveTimer = timeBetweenSteps;
                Direction direction = Pathfinding.GetNextStepDirection(this.pos.GetAsVector3Int(), searchCell.AsVector3Int());
                if (direction != Direction.NONE)
                {
                    MoveAlongDirection(direction, ruleSet.MONSTER_MOVEMENT_TICK_HUNT);
                }
                else
                {
                    if (NextToPlayer())
                    {
                        AttackPlayer();
                        ChangeMode(Modes.Happy);
                        return;
                    }
                }
            }
            break;

        case Modes.Happy:
            happyTimer -= Time.deltaTime;
            if (happyTimer <= 0)
            {
                ChangeMode(Modes.Search);
            }
            break;

        case Modes.Dead:
            break;

        default:
            break;
        }
    }
Exemple #29
0
 private void MakeCurrentCellWalkable()
 {
     GridHolder.SetWalkableCell(pos.x, pos.y, true);
 }
Exemple #30
0
 private void MakeCurrentCellNotWalkable()
 {
     GridHolder.SetWalkableCell(pos.x, pos.y, false);
 }
Exemple #31
0
 void Awake()
 {
     GridHolder = GetComponent <GridHolder>();
 }