예제 #1
0
    void Update()
    {
        Vector3 point = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (GameplayManager.Instance.CanBuildArea)
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }
            selectedTile = tilemp.WorldToCell(point);
            // Will show an error cursor over unbuildable areas
            if (!tilemp.ContainsTile(tilemp.GetTile(selectedTile)))
            {
                ArtManager.Instance.SwapCursor(ArtManager.CursorToUse.ERROR);
            }
            if (Input.GetMouseButtonDown(0))
            {
                if (tilemp.ContainsTile(tilemp.GetTile(selectedTile)) && tilemp.GetTile(selectedTile) != builtTile)
                {
                    GameplayManager.Instance.ScrapCollected   -= GameplayManager.Instance.ScrapCostToBuild;
                    GameplayManager.Instance.ScrapCostToBuild += 25;
                    tilemp.SetTile(selectedTile, builtTile);
                    Instantiate(build, new Vector2(selectedTile.x + .5f, selectedTile.y + .5f), Quaternion.identity);
                    GameplayManager.Instance.CanBuildArea = false;
                    hudCUI.buildAreaToggle.isOn           = false;
                }
            }
        }
    }
예제 #2
0
    void SearchForSpawners(Tilemap tileMap, SpawnableObjectBehaviour[] spawnableObjects)
    {
        if (spawnableGameBojects.Length > 0)
        {
            foreach (SpawnableObjectBehaviour spawner in spawnableObjects)
            {
                Debug.Log("Objekte vom Typ " + spawner.nameOfEntity + " werden gesucht ...");

                if (spawnMap.ContainsTile(spawner.spawnerTile))
                {
                    Debug.Log("Objekte vom Typ " + spawner.nameOfEntity + " wurden gefunden!");
                    BoundsInt  bounds   = tileMap.cellBounds;
                    TileBase[] allTiles = tileMap.GetTilesBlock(bounds);

                    for (int x = 0; x < bounds.size.x; x++)
                    {
                        for (int y = 0; y < bounds.size.y; y++)
                        {
                            TileBase tile = allTiles[x + y * bounds.size.x];
                            if (tile != null)
                            {
                                if (tile == spawner.spawnerTile)
                                {
                                    Debug.Log("x:" + x + " y:" + y + " Objekt: " + spawner.nameOfEntity);
                                    Instantiate(spawner.spawnableGameObject, new Vector3(tileMap.origin.x + x + 0.5f, tileMap.origin.y + y + 0.5f, 0f), Quaternion.identity);
                                }
                            }
                        }
                    }
                }
            }
            spawnMap.ClearAllTiles();
        }
    }
예제 #3
0
    private void Awake()
    {
        FireTilemap = GetComponent <Tilemap>();
        _maxBorder  = PlacingTurret.tilemap.cellBounds.max;
        _minBorder  = PlacingTurret.tilemap.cellBounds.min;
        if (FireTilemap.ContainsTile(tileBase))
        {
            var origin    = FireTilemap.origin;
            var fireTiles = new List <Vector3Int>();
            for (var i = 0; i < FireTilemap.size.x; i++)
            {
                for (var e = 0; e < FireTilemap.size.y; e++)
                {
                    var tile = FireTilemap.GetTile(new Vector3Int(origin.x + i, origin.y + e, 0));
                    if (tile == null || tile != tileBase)
                    {
                        continue;
                    }
                    fireTiles.Add(new Vector3Int(origin.x + i, origin.y + e, 0));
                }
            }

            foreach (var fireTile in fireTiles)
            {
                var fire = Instantiate(fireGameObject, transform);
                fire.transform.position = FireTilemap.CellToWorld(fireTile) + new Vector3(0.5f, 0.5f, 0);
            }
        }
    }
예제 #4
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Vector3 hitPosition = Vector3.zero;

        foreach (ContactPoint2D hit in collision.contacts)
        {
            hitPosition.x = hit.point.x - 0.1f;
            hitPosition.y = hit.point.y - 0.1f;
            Vector3Int cell = new Vector3Int((int)hitPosition.x, (int)hitPosition.y, 0);
            tiles.SetTile(tiles.WorldToCell(hitPosition), null);
            GameManagerTS.score += 10;
            if (!tiles.ContainsTile(uwuCoin))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            }
        }
    }
예제 #5
0
    private void FixedUpdate()
    {
        if (_tick % spreadRate == 0 && FireTilemap.ContainsTile(tileBase))
        {
            var origin    = FireTilemap.origin;
            var fireTiles = new List <Vector3Int>();
            for (var i = 0; i < FireTilemap.size.x; i++)
            {
                for (var e = 0; e < FireTilemap.size.y; e++)
                {
                    var tile = FireTilemap.GetTile(new Vector3Int(origin.x + i, origin.y + e, 0));
                    if (tile == null || tile != tileBase)
                    {
                        continue;
                    }
                    fireTiles.Add(new Vector3Int(origin.x + i, origin.y + e, 0));
                }
            }

            if (fireTiles.Count == 0)
            {
                FindObjectOfType <Win>(true).gameObject.SetActive(true);
                FindObjectOfType <Win>().DisplayHighScore();
                var gamePlayMusics = FindObjectsOfType <GamePlayMusic>();
                foreach (var music in gamePlayMusics)
                {
                    music.gameObject.SetActive(false);
                }
                Time.timeScale = 0;
                FindObjectOfType <Pause>().cantPause = true;
            }

            foreach (var fireTile in fireTiles)
            {
                var location = new Vector3Int();
                if (Random.Range(0f, 1f) < chanceToSpread / Mathf.Pow(fireTiles.Count, spreadToFireBias))
                {
                    if (!OneAvailableAround(fireTile))
                    {
                        continue;
                    }
                    do
                    {
                        location = new Vector3Int(Random.Range(fireTile.x - 1, fireTile.x + 2),
                                                  Random.Range(fireTile.y - 1, fireTile.y + 2), fireTile.z);
                    } while (!CanSpawn(location) || location.x != fireTile.x && location.y != fireTile.y || !IsAvailable(FireTilemap.GetTile(location), PlacingTurret.tilemap.GetTile(location)));

                    if (IsDamageAble(FireTilemap.GetTile(location)))
                    {
                        var grid        = FindObjectOfType <Grid>();
                        var position    = FireTilemap.CellToWorld(location);
                        var damageAbles = grid.GetComponentsInChildren <IDamageAble>();
                        if (damageAbles.Where(damageable => position + new Vector3(0.5f, 0.5f, 0) == damageable.GetPos()).Any(damageable => !damageable.TakeDamage(damage)))
                        {
                            continue;
                        }
                    }

                    FireTilemap.SetTile(location, tileBase);
                    var fire = Instantiate(fireGameObject, transform);
                    fire.transform.position = FireTilemap.CellToWorld(location) + new Vector3(0.5f, 0.5f, 0);
                }
            }
        }
        _tick++;
    }
예제 #6
0
    private void Update()
    {
        if (Time.timeScale > 0)
        {
            t += Time.deltaTime;
            //El booleano done aumenta la eficiencia del script (muy a menudo no se ejecutará ningún if debido a él)
            if (!done && Input.GetKey(GameManager.areaKey)) //Si no está representada el área y se pulsa el espacio se crea el círculo
            {
                line.positionCount = segments + 1;
                CreatePoints();
                done = true;
            }

            else if (done && !Input.GetKey(GameManager.areaKey)) //Si ya está representada y se deja de pulsar el espacio se borra
            {
                line.positionCount = 0;
                done = false;
            }

            if (Input.GetKey(KeyCode.Mouse1) && Input.GetKey(GameManager.areaKey))
            {
                Ray   ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                float enter = 0f;

                if (plane.Raycast(ray, out enter))
                {
                    Vector3Int hit = Vector3Int.FloorToInt(ray.GetPoint(enter));

                    if (tilemap.ContainsTile(tilemap.GetTile(hit)))
                    {
                        //Distancia entre posiciones
                        distance = new Vector2(Mathf.Abs(hit.x - transform.position.x), Mathf.Abs(hit.y - transform.position.y));

                        if (distance.magnitude <= GameManager.playerRange && t > .5) //Si se está a rango
                        {
                            Vector3 poshit = new Vector3(hit.x + 0.5f, hit.y + 0.5f, hit.z - 1);

                            //Se compara poshit con los elementos en el vector que guarda las posiciones usadas
                            //Si no se ha usado todavía, se construye una torreta
                            bool used = false;
                            int  i    = 0;
                            while (!used && placedTurrets[i] != null && placedTurrets[i].transform.position != Vector3.zero)
                            {
                                if (placedTurrets[i].transform.position == poshit)
                                {
                                    used = true;
                                }

                                else
                                {
                                    i++;
                                }
                            }

                            if (!used && GameManager.instance.RetMoney() >= costPlacement)
                            {
                                //Se construye una pared en el tile en cuestión y se añade poshit al vector usedTiles
                                t = 0;
                                placedTurrets[ind] = Instantiate(turretPref, poshit, Quaternion.identity);
                                ind++;
                                source.clip = placingSound;
                                source.Play();
                                GameManager.instance.GanaDinero(-costPlacement);

                                //Feedback Dinero
                                TextManager.instance.CreateText(new Vector3(this.transform.position.x, this.transform.position.y + offset, this.transform.position.z), "-" + costPlacement + "$");
                            }

                            else
                            {
                                int level = placedTurrets[i].GetComponent <TurretShooting>().RetLevel();
                                switch (level)
                                {
                                case 1:
                                    //Si se tiene dinero, se está a rango y no está a nivel máximo
                                    if (GameManager.instance.RetMoney() >= first.cost && level < 3)
                                    {
                                        placedTurrets[i].GetComponent <TurretShooting>().TurretUpgrade(first.damage, first.fireRate);
                                        GameManager.instance.GanaDinero(-first.cost);
                                        //Feedback Dinero
                                        TextManager.instance.CreateText(new Vector3(this.transform.position.x, this.transform.position.y + offset, this.transform.position.z), "-" + first.cost + "$");
                                        placedTurrets[i].GetComponent <SpriteRenderer>().sprite = n1;
                                    }
                                    break;

                                case 2:
                                    if (GameManager.instance.RetMoney() >= second.cost && level < 3)
                                    {
                                        placedTurrets[i].GetComponent <TurretShooting>().TurretUpgrade(second.damage, second.fireRate);
                                        GameManager.instance.GanaDinero(-second.cost);
                                        //Feedback Dinero
                                        TextManager.instance.CreateText(new Vector3(this.transform.position.x, this.transform.position.y + offset, this.transform.position.z), "-" + second.cost + "$");
                                        placedTurrets[i].GetComponent <SpriteRenderer>().sprite = n2;
                                    }
                                    break;
                                }

                                t           = 0;
                                source.clip = upgradeSound;
                                source.Play();
                            }
                        }
                    }
                }
            }
        }
    }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        SuperTile tile;

        superTileset.TryGetTile(1, out tile); // pellet
        if (!tilemap.ContainsTile(tile))
        {
            for (int i = 0; i < Ghosts.Count; i++)
            {
                Ghosts[i].moveSpeed          *= 1.1f;
                Ghosts[i].moveLogic.moveSpeed = Ghosts[i].moveSpeed;
            }
            Pacman.moveSpeed          *= 1.1f;
            Pacman.moveLogic.moveSpeed = Pacman.moveSpeed;
            RestartLevel();
        }

        for (int i = 0; i < Ghosts.Count; i++)
        {
            if (Ghosts[i].moveLogic.GetCurrentCell() == Pacman.moveLogic.GetCurrentCell() && !player_dead)
            {
                if (!frightTimer.IsNull() && !frightTimer.isDone)
                {
                    if (!Ghosts[i].wasEatenRecently && Ghosts[i].state != State.Spirit)
                    {
                        Ghosts[i].state = State.Spirit;

                        Ghosts[i].UpdateState();

                        switch (ghost_eaten)
                        {
                        case 0:
                            Pacman.score += 200;
                            ghost_eaten++;
                            break;

                        case 1:
                            Pacman.score += 400;
                            ghost_eaten++;
                            break;

                        case 2:
                            Pacman.score += 800;
                            ghost_eaten++;
                            break;

                        case 3:
                            Pacman.score += 1600;
                            ghost_eaten++;
                            break;

                        default:
                            ghost_eaten = 0;
                            Timer.Cancel(frightTimer);
                            WaveUpdate();
                            break;
                        }
                    }

                    if (Ghosts[i].wasEatenRecently && Ghosts[i].state != State.Spirit)
                    {
                        player_dead   = true;
                        waveState     = State.Idle;
                        Pacman.paused = true;
                        StartCoroutine(Pacman.animPlayer.PlayAndWaitForAnim("Base Layer.Death", RestartLevel));
                    }
                    return;
                }


                player_dead   = true;
                waveState     = State.Idle;
                Pacman.paused = true;
                StartCoroutine(Pacman.animPlayer.PlayAndWaitForAnim("Base Layer.Death", RestartLevel));
            }
        }
    }
예제 #8
0
    void SearchForSpawners(Tilemap tileMap, SpawnableObjectBehaviour[] spawnableObjects)
    {
        // Are spawnable scripted objects added to the array in the inspector?
        if (spawnableGameObjects.Length > 0)
        {
            foreach (SpawnableObjectBehaviour spawner in spawnableObjects)
            {
                // Skip empty entries
                if (spawner != null)
                {
                    // validate basic spanwer values
                    if (spawner.NameOfEntity == "" ||
                        spawner.spawnableGameObject == null ||
                        spawner.spawnerTile == null ||
                        spawner.MoveSpeed < 0f)
                    {
                        Debug.LogWarning("Spawner \"" + spawner.NameOfEntity + "\" übersprungen, fehlerhafte Einträge im Inspector!");
                        continue;
                    }

                    // Everything ok with the spawner values
                    int countTiles = 0;
                    //Debug.Log("Objekte vom Typ " + spawner.NameOfEntity + " werden gesucht ...");

                    if (tileMap != null && spawner != null)
                    {
                        // check if tilemap has tiles of the spawner type
                        if (tileMap.ContainsTile(spawner.spawnerTile))
                        {
                            //Instanciate one parent GameObject to sort all spawned children
                            GameObject tmpParent = new GameObject
                            {
                                name = spawner.name + "Container"
                            };

                            BoundsInt  bounds   = tileMap.cellBounds;
                            TileBase[] allTiles = tileMap.GetTilesBlock(bounds);

                            for (int x = 0; x < bounds.size.x; x++)
                            {
                                for (int y = 0; y < bounds.size.y; y++)
                                {
                                    TileBase tile = allTiles[x + y * bounds.size.x];
                                    if (tile != null)
                                    {
                                        if (tile == spawner.spawnerTile)
                                        {
                                            countTiles++;
                                            //Debug.Log("x:" + x + " y:" + y + " Objekt: " + spawner.nameOfEntity);
                                            GameObject tmpChild = Instantiate(spawner.spawnableGameObject, new Vector3(tileMap.origin.x + x + tileMap.tileAnchor.x, tileMap.origin.y + y + tileMap.tileAnchor.y, 0f), Quaternion.identity);
                                            tmpChild.name = spawner.name + countTiles;

                                            // Set spawner properties to instance properties
                                            if (tmpChild.GetComponent <ObjectGridInteraction>())
                                            {
                                                ObjectGridInteraction tmpGridInteraction = tmpChild.GetComponent <ObjectGridInteraction>();
                                                tmpGridInteraction.Data = new SpawnableObjectBehaviour.PublicProperties(
                                                    spawner.NameOfEntity.Replace(" ", ""),
                                                    spawner.MoveSpeed,
                                                    spawner.IsPlayable,
                                                    spawner.IsVulnerable,
                                                    spawner.IsPushable,
                                                    spawner.IsHeavy,
                                                    spawner.IsHole,
                                                    spawner.IsTrigger);
                                            }

                                            // Add child object to parent
                                            tmpChild.transform.parent = tmpParent.transform;
                                        }
                                    }
                                }
                            }
                            // normal (ignore maximum spawn value, you can add as many spawners as you like)
                            if (spawner.minimumSpawners >= 0 && spawner.maximumSpawners == 0)
                            {
                                if (countTiles >= spawner.minimumSpawners)
                                {
                                    //Debug.Log(countTiles + "x " + spawner.NameOfEntity + " gespawnt");
                                }
                            }
                            // spawn count has to be specific (e.g. start tile)
                            else if (spawner.minimumSpawners > 0 && spawner.maximumSpawners > 0)
                            {
                                // Nothing is ok
                                if (countTiles < spawner.minimumSpawners || countTiles > spawner.maximumSpawners)
                                {
                                    Debug.LogError(countTiles + "x " + spawner.NameOfEntity + " gespawnt, erlaubt sind Min "
                                                   + spawner.minimumSpawners + "x und Max " + spawner.maximumSpawners);
                                }
                                // Everything is ok
                                else if (countTiles >= spawner.minimumSpawners && countTiles <= spawner.maximumSpawners)
                                {
                                    //Debug.Log(countTiles + "x " + spawner.NameOfEntity + " gespawnt");
                                }
                            }
                        }
                    }
                    else if (spawner == null)
                    {
                        Debug.LogError("Spawner existiert nicht!");
                    }
                    else if (tileMap == null)
                    {
                        Debug.LogError("Tilemap existiert nicht!");
                    }
                }
            }
            Debug.Log("Spawner-Suche beendet");
            spawnMap.ClearAllTiles();
            EventManager.current.SpawnerFinished();
            EventManager.current.EnablePlayerMovement();
        }
        else
        {
            Debug.LogError("Keine Einträge für Spawner im Level Approver gefunden. Bitte ergänzen!");
        }
    }
    void Update()
    {
        if (Time.timeScale > 0)
        {
            //Cambiando el color se marca en modo construcción qué paredes permiten la construcción de barricadas
            if (Input.GetKey("space") && Time.timeScale > 0)
            {
                tilemap.color = Color.magenta;
            }

            else
            {
                tilemap.color = Color.white;
            }

            t += Time.deltaTime;
            //El booleano done aumenta la eficiencia del script (muy a menudo no se ejecutará ningún if debido a él)

            if (Input.GetKey(KeyCode.Mouse1) && Input.GetKey(GameManager.areaKey))
            {
                Ray   ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                float enter = 0f;

                if (plane.Raycast(ray, out enter))
                {
                    Vector3Int hit = Vector3Int.FloorToInt(ray.GetPoint(enter));

                    if (tilemap.ContainsTile(tilemap.GetTile(hit)))
                    {
                        //Distancia entre posiciones
                        distance = new Vector2(Mathf.Abs(hit.x - transform.position.x), Mathf.Abs(hit.y - transform.position.y));

                        if (distance.magnitude <= GameManager.playerRange && t > .5 && GameManager.instance.RetMoney() >= cost) //Si se está a rango y se tiene el dinero
                        {
                            Vector3 poshit = new Vector3(hit.x + 0.5f, hit.y + 0.5f, hit.z - 1);

                            //Se compara poshit con los elementos en el vector que guarda las posiciones usadas
                            //Si no se ha usado todavía, se construye una torreta
                            bool used = false;
                            int  i    = 0;
                            while (!used && usedTiles[i] != Vector3.zero)
                            {
                                if (usedTiles[i] == poshit)
                                {
                                    used = true;
                                }

                                i++;
                            }

                            if (!used)
                            {
                                //Se construye una pared en el tile en cuestión y se añade poshit al vector usedTiles
                                usedTiles[i] = poshit;
                                t            = 0;
                                source.clip  = sound;
                                source.Play();
                                GameObject barricade = Instantiate(barPref, poshit, Quaternion.identity);
                                barricade.transform.Rotate(0, 0, angle);
                                barricade.transform.GetChild(0).gameObject.GetComponent <Health>().Created(this);
                                GameManager.instance.GanaDinero(-cost);

                                //FeedBack del texto al colocar las barricadas
                                TextManager.instance.CreateText(new Vector3(this.transform.position.x, this.transform.position.y + offset, this.transform.position.z), "-" + cost + "$");
                            }
                        }
                    }
                }
            }
        }
    }
예제 #10
0
    void CheckForGrapplePoints()
    {
        // create a list of five empty grapple points
        for (int i = 0; i < 5; i++)
        {
            grappleOverlap [i] = null;
        }

        validPoint = false;

        // clear the lists
        for (int i = 0; i < positionList.Count; i++)
        {
            RaycastHit2D testGrapple;
            if (positionList.TryGetValue(lengthList[0], out testGrapple))
            {
                if (tileMap.HasTile(tileMap.WorldToCell(testGrapple.point)))
                {
                    tileMap.SetTile(tileMap.WorldToCell(testGrapple.point), tile);
                }
            }
        }
        positionList.Clear();
        lengthList.Clear();
        GetComponent <GrappleHook> ().grappled = false;
        // checks to see if there are grapples in range
        if (Physics2D.OverlapCircleNonAlloc(player.transform.position, distance, grappleOverlap, mask) > 0)
        {
            // gets the number of grapple points within the given distance
            int times = Physics2D.OverlapCircleNonAlloc(player.transform.position, distance, grappleOverlap, mask);

            for (int i = 0; i < times; i++)
            {
                Vector3 position = grappleOverlap [i].attachedRigidbody.transform.position;
                var     hit      = Physics2D.Linecast(player.transform.position, position, mask1);
                // find the position and the distance to the grapple point
                if (hit.collider == grappleOverlap [i])
                {
                    position = hit.point;
                    float length = Vector2.Distance(player.transform.position, position);

                    // adds the grapple points to the lists
                    if ((player.transform.position.x - position.x) * player.transform.localScale.x < 0)
                    {
                        validPoint = true;
                        lengthList.Add(length);
                        positionList.Add(length, hit);
                    }
                }
            }

            // sort the list of lengths
            lengthList.Sort();
            RaycastHit2D grapple;

            if (validPoint == true)
            {
                // get the value in the position list using the shortest length in the lenght list
                if (positionList.TryGetValue(lengthList [0], out grapple))
                {
                    grapplePoint = grapple.point;
                    tileMap.SetTile(tileMap.WorldToCell(grapplePoint), highlightTile);
                    GetComponent <GrappleHook> ().grapplePoint = grapplePoint;
                    Debug.DrawLine(transform.position, grapple.point);
                    GetComponent <GrappleHook> ().grappled = true;
                }
            }
        }
        else
        {
            if (tileMap.ContainsTile(highlightTile))
            {
                tileMap.SwapTile(highlightTile, tile);
            }
        }
    }