// this creates a GameObject with a corresponding Trap on it, and stores it inside of the trapPositionalData
    public void SetTrap(Vector2Int position, TrapType trap, Unit source, UnitAbility ability)
    {
        // parse the spawn location and spawn a new object there
        Vector3    pos     = MapMath.MapToWorld(position.x, position.y);
        GameObject shell   = new GameObject();
        GameObject newTrap = Instantiate(shell, pos, Quaternion.identity);

        Destroy(shell);

        // add the correct inherited member of Trap to the object
        Trap newTrapComponent = null;

        switch (trap)
        {
        case TrapType.Claymore:
            newTrapComponent = newTrap.AddComponent <ClaymoreTrap>() as ClaymoreTrap;
            break;

        default:
            break;
        }

        newTrapComponent.mapPosition    = position;
        newTrapComponent.sourceUnit     = source;
        newTrapComponent.placingAbility = ability;
        newTrap.AddComponent <SpriteRenderer>();
        Sprite newSprite = Resources.Load <Sprite>(newTrapComponent.GetResourcePath());

        newTrap.GetComponent <SpriteRenderer>().sprite       = newSprite;
        newTrap.GetComponent <SpriteRenderer>().sortingOrder = 98;
        trapPositionalData.AddTrap(position, newTrapComponent);
    }
Exemplo n.º 2
0
    private IEnumerator SpawnUnit(int unit, Vector2Int position)
    {
        // parse the spawn location and spawn a new object there
        Vector3    playerPos = MapMath.MapToWorld(position.x, position.y);
        GameObject shell     = new GameObject();
        GameObject newUnit   = Instantiate(shell, playerPos, Quaternion.identity);

        Destroy(shell);
        newUnit.AddComponent <SpriteRenderer>();
        newUnit.GetComponent <SpriteRenderer>().enabled = false;
        Unit newUnitComponent = newUnit.AddComponent <EnemyUnit>() as EnemyUnit;

        newUnitComponent.StartData            = units[unit];
        newUnitComponent.globalPositionalData = TurnController.instance.globalPositionalData;
        newUnitComponent.LoadData();
        newUnitComponent.SetHealth(0);

        EventsManager.instance.AddEvent("spawning");

        CameraController.instance.targetPos = playerPos;
        yield return(new WaitForSecondsRealtime(0.5f));

        Graveyard.NewEnemiesEvent.Invoke(new List <Unit> {
            newUnitComponent
        });
        yield return(new WaitForSecondsRealtime(0.5f));

        EventsManager.instance.RemoveEvent("spawning");
    }
Exemplo n.º 3
0
    private void createLimits()
    {
        // Super inefficient, but it'll only get called once.
        // also singletons lmao.
        Vector3 left  = MapMath.MapToWorld(MapController.instance.mostWest, MapController.instance.mostSouth);
        Vector3 right = MapMath.MapToWorld(MapController.instance.mostEast, MapController.instance.mostNorth);
        Vector3 up    = MapMath.MapToWorld(MapController.instance.mostEast, MapController.instance.mostSouth);
        Vector3 down  = MapMath.MapToWorld(MapController.instance.mostWest, MapController.instance.mostNorth);

        // the extra space is twice as big in the y direction, but thats fine.
        negativeLimit = new Vector2(left.x - 0.5f, down.y) - Vector2.one * EXTRA_SPACE;
        positiveLimit = new Vector2(right.x - 0.5f, up.y) + Vector2.one * EXTRA_SPACE;
    }
Exemplo n.º 4
0
 // This takes a 'dead' unit and gets it back in the world
 // refreshes stats, health to full, etc
 // NOT DONE
 public virtual void Revive(Vector2Int position)
 {
     //if (globalPositionalData.SearchLocation(position) != null || )
     health   = StartData.health;
     hasMoved = false;
     hasActed = false;
     this.gameObject.GetComponent <SpriteRenderer>().enabled = true;
     this.gameObject.transform.position = MapMath.MapToWorld(position);
     globalPositionalData.AddUnit(position, this);
     tile = (TileWeight)MapController.instance.weightedMap[position];
     MapController.instance.weightedMap[position] = (int)TileWeight.OBSTRUCTED;
     SetDirection(Direction.S);
 }
    // Update is called once per frame
    void Update()
    {
        ray            = Camera.main.ScreenPointToRay(Input.mousePosition);
        cursorPosition = MapMath.WorldToMap(ray.origin * -10f / ray.origin.z);
        //Debug.Log("Cursor Position(World Pos): " + ray.origin);
        //Debug.Log("Cursor Position(Grid Pos): " + MapController.instance.walkableTiles.WorldToCell(ray.origin));

        /*
         * if(MapMath.InMapBounds(cursorPosition))
         *  debugText.text = "Cursor Position(Map Pos): " + cursorPosition + "Weight: " + MapController.instance.weightedMap[cursorPosition];
         * else
         *  debugText.text = "Cursor Position(Map Pos): " + cursorPosition + "Weight: NULL";
         */
        if (MapController.instance.walkableTiles.GetTile(MapMath.MapToGrid(cursorPosition)) != null)
        {
            tileSelector.transform.position = MapMath.MapToWorld(cursorPosition);
        }
    }
    // Parses unitSpawnData, instantiates and initializes Units
    // adds the newly instantiated Units to units list
    protected void LoadUnits()
    {
        for (int i = 0; i < unitSpawnData.Count; i++)
        {
            // parse the spawn location and spawn a new object there
            Vector3    playerPos = MapMath.MapToWorld(unitSpawnData[i].spawnPosition.x, unitSpawnData[i].spawnPosition.y);
            GameObject shell     = new GameObject();
            GameObject newUnit   = Instantiate(shell, playerPos, Quaternion.identity);
            Destroy(shell);

            newUnit.AddComponent <SpriteRenderer>();

            // add the correct inherited member of Unit to the object
            Unit newUnitComponent = null;
            switch (unitSpawnData[i].data.unitType)
            {
            case UnitType.AlliedUnit:
                newUnitComponent = newUnit.AddComponent <AlliedUnit>() as AlliedUnit;
                break;

            case UnitType.EnemyUnit:
                newUnitComponent = newUnit.AddComponent <EnemyUnit>() as EnemyUnit;
                break;

            case UnitType.Civilian:
                break;

            default:
                newUnitComponent = newUnit.AddComponent <AlliedUnit>() as AlliedUnit;
                break;
            }
            // give this new Unit the raw data for creating it, set its direction
            newUnitComponent.StartData = unitSpawnData[i].data;
            newUnitComponent.SetDirection(Direction.S);
            newUnitComponent.globalPositionalData = this.globalPositionalData;
            newUnitComponent.globalPositionalData.AddUnit(unitSpawnData[i].spawnPosition, newUnitComponent);

            // i've given you the data you need to make yourself. now make yourself, please
            newUnitComponent.LoadData();

            // add the brand-spankin-new and created unit to your units list
            units.Add(newUnit.GetComponent <Unit>());
        }
    }
Exemplo n.º 7
0
    public override void Update()
    {
        // if it's not currently this controller's turn, the controller has no Units, or there are active events, it's not allowed to do anything
        if (!myTurn || units.Count == 0 || EventsManager.instance.EventsExist())
        {
            return;
        }

        AlliedUnit theUnit = units[activeUnit] as AlliedUnit;

        //left click to choose unit
        if (Input.GetMouseButtonDown(0))
        {
            Vector2Int selectedLoc   = MapUIController.instance.cursorPosition;
            int?       selectedIndex = FindUnit(selectedLoc);
            if (selectedIndex != null)
            {
                ClearSpotlight();
                SelectUnit((int)selectedIndex);
            }
        }

        //check for tab input
        //select next unit
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            GetNextUnit();

            return;
        }

        if (theUnit.hasMoved && !theUnit.hasPivoted)
        {
            Vector2Int unitPosition = units[activeUnit].GetMapPosition();
            //Vector3 truePosition = MapMath.MapToWorld(unitPosition);
            directionSelector.transform.position = MapMath.MapToWorld(unitPosition);
            directionSelector.transform.position = new Vector3(directionSelector.transform.position.x, directionSelector.transform.position.y + 1.506f, directionSelector.transform.position.z);
            directionSelector.SetActive(true);
            theUnit.ChooseDirection();
            return;
        }

        // if the current unit has moved but hasn't attacked, it needs to select an ability
        if (theUnit.hasMoved && theUnit.hasPivoted && !theUnit.hasActed)
        {
            directionSelector.SetActive(false);
            abilityPanel.SetActive(true);
            theUnit.ChooseAbility();
            return;
        }
        else
        {
            abilityPanel.SetActive(false);
        }


        // if the current unit has moved and attacked, get the next unit
        if (theUnit.hasMoved && theUnit.hasPivoted && theUnit.hasActed)
        {
            abilityPanel.SetActive(false);
            GetNextUnit();
            return;
        }
        //Only process if the unit has not moved
        if (!theUnit.hasMoved)
        {
            // ----Do Movement----
            Vector2Int dest = MapUIController.instance.cursorPosition;

            if (Input.GetMouseButtonDown(0))
            {
                if (theUnit.plannedPath.Contains(dest)) // Commit to the path
                {
                    Queue <Vector2Int> movementPath = new Queue <Vector2Int>();
                    for (int i = 0; i < theUnit.plannedPath.Count; i++)
                    {
                        movementPath.Enqueue(theUnit.plannedPath[i]);
                        if (theUnit.plannedPath[i] == dest)
                        {
                            break;
                        }
                    }
                    StartCoroutine(theUnit.Move(movementPath, MovementType.WALK));
                    ClearSpotlight();
                }
                else
                {
                    theUnit.DisplayShortestPath(dest);
                }
            }
        }
    }
Exemplo n.º 8
0
    public IEnumerator Move(Queue <Vector2Int> path, MovementType type)
    {
        // I am moving. do not let any controllers do anything
        EventsManager.instance.AddEvent("move");

        if (moveSoundEvent.isValid())
        {
            if (this is AlliedUnit)
            {
                moveSoundEvent.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
                MapUIController.instance.ClearPathHighlight();
                MapUIController.instance.ClearRangeHighlight();
                (this as AlliedUnit).plannedPath.Clear();
            }
            moveSoundEvent.start();
        }

        attackBuffed = false;

        Vector2Int currentTile = GetMapPosition();

        while (path.Count > 0)
        {
            // have the camera look here
            CameraController.instance.targetPos = this.transform.position;

            // get the next tile to move to
            currentTile = path.Dequeue();

            // remove old coordinates from globalPositionalData
            globalPositionalData.RemoveUnit(mapPosition);
            // restore old tilevalue
            MapController.instance.weightedMap[mapPosition] = (int)tile;
            // set new coordinates
            mapPosition = currentTile;
            // update the globalPositionalData
            globalPositionalData.AddUnit(mapPosition, this);
            // remember the weight of the tile being occupied
            tile = (TileWeight)MapController.instance.weightedMap[mapPosition];
            // set the occupied tile to OBSTRUCTED
            MapController.instance.weightedMap[mapPosition] = (int)TileWeight.OBSTRUCTED;

            // visualize the movement made from one tile to another, based on the type of movement
            switch (type)
            {
            case MovementType.DASH:
                this.transform.position = MapMath.MapToWorld(currentTile);
                yield return(new WaitForSecondsRealtime(0.1f));

                break;

            case MovementType.KNOCKBACK:
                this.transform.position = MapMath.MapToWorld(currentTile);
                yield return(new WaitForSecondsRealtime(0.01f));

                break;

            case MovementType.TELEPORT:
                this.transform.position             = MapMath.MapToWorld(currentTile);
                CameraController.instance.targetPos = this.transform.position;
                yield return(new WaitForSecondsRealtime(0.1f));

                break;

            case MovementType.WALK:
                this.transform.position             = MapMath.MapToWorld(currentTile);
                CameraController.instance.targetPos = this.transform.position;
                yield return(new WaitForSecondsRealtime(0.1f));

                break;

            default:
                this.transform.position             = MapMath.MapToWorld(currentTile);
                CameraController.instance.targetPos = this.transform.position;
                yield return(new WaitForSecondsRealtime(0.1f));

                break;
            }

            if (TurnController.instance != null)
            {
                TurnController.instance.trapPositionalData.CheckTraps();
            }
        }

        this.transform.position = MapMath.MapToWorld(currentTile);
        hasMoved = true;
        EventsManager.instance.RemoveEvent("move");
    }