Esempio n. 1
0
    public static void DualShot(GameObjectPool enemyBulletPool, int enemyType, Vector3 shooterPosition)
    {
        GameObject bullet = enemyBulletPool.Borrow();

        bullet.GetComponent <EnemyBullet>().SetType(enemyType);
        bullet.GetComponent <EnemyBullet>().Spawn(shooterPosition - new Vector3(-0.2f, 0f, 0f), new Vector3(0f, 1f, 0));
        bullet.SetActive(true);

        bullet = enemyBulletPool.Borrow();
        bullet.GetComponent <EnemyBullet>().SetType(enemyType);
        bullet.GetComponent <EnemyBullet>().Spawn(shooterPosition - new Vector3(0.2f, 0f, 0f), new Vector3(0f, 1f, 0));
        bullet.SetActive(true);
    }
        private void Spawn()
        {
            if (ballPool.IsPoolEmpty)
            {
                if (spawnedBalls.Count == 0)
                {
                    Debug.LogError("No balls available to spawn.");
                    return;
                }
                else
                {
                    Ball oldBall = spawnedBalls[0];
                    ReturnBall(oldBall);
                }
            }

            GameObject ballObject = ballPool.Borrow();

            ballObject.transform.SetParent(transform, false);
            ballObject.transform.localPosition = Vector3.zero;
            ballObject.transform.localRotation = Quaternion.identity;

            currentBall           = ballObject.GetComponent <Ball>();
            currentBall.OnThrown += OnBallThrown;
            spawnedBalls.Add(currentBall);

            currentBall.PlaySpawnAnimation();
        }
Esempio n. 3
0
        public override List <IStateful> GetAllTargets(GoapAgent agent)
        {
            if (!targetPositions.ContainsKey(agent))
            {
                targetPositions[agent]   = null;
                previousPositions[agent] = agent.transform.position;
            }

            WanderPosition targetPosition = targetPositions[agent];

            if (targetPosition == null || !targetPosition.gameObject.activeInHierarchy)
            {
                targetPositions[agent]            = wanderPool.Borrow <WanderPosition>();
                targetPosition                    = targetPositions[agent];
                targetPosition.transform.position = GetRandomPosition(agent.transform.position,
                                                                      wanderingMaxDistance);
                previousPositions[agent] = agent.transform.position;
            }
            else if (Vector3.Distance(previousPositions[agent], agent.transform.position) > wanderingMaxDistance)
            {
                // Used in case the agent moved and is now away from the original wander position
                targetPositions[agent].transform.position = GetRandomPosition(agent.transform.position,
                                                                              wanderingMaxDistance);
            }

            return(new List <IStateful> {
                targetPosition
            });
        }
Esempio n. 4
0
        public override List <IStateful> GetAllTargets(GoapAgent agent)
        {
            if (!agentPositions.ContainsKey(agent))
            {
                agentPositions[agent] = wanderPool.Borrow <WanderPosition>();
            }

            WanderPosition wanderPos = agentPositions[agent];

            DangerSensor     dangerSensor = agent.GetComponent <DangerSensor>();
            SightSensor      sightSensor  = agent.GetComponent <SightSensor>();
            List <IStateful> threats      = dangerSensor.GetThreats();

            //Vector3 targetPosition = Vector3.zero;

            //foreach (IStateful threat in threats) {
            //    Component threatComp = threat as Component;
            //    targetPosition = targetPosition + (agent.transform.position - threatComp.transform.position);
            //}

            //targetPosition = (agent.transform.position + targetPosition) * runAwayDistance;
            //wanderPos.transform.position = sightSensor.GetRandomPosition(runAwayDistance, targetPosition);
            wanderPos.transform.position = sightSensor.GetRandomPosition(runAwayDistance, agent.transform.position);

            return(new List <IStateful> {
                wanderPos
            });
        }
Esempio n. 5
0
    private void DefaultShoot(Vector3 origin, GameObjectPool pool)
    {
        GameObject bullet = playerBulletPool.Borrow();

        bullet.GetComponent <PlayerBullet>().SetType(0);
        bullet.GetComponent <PlayerBullet>().Spawn(transform.position);
        bullet.SetActive(true);
    }
Esempio n. 6
0
    // shoot single bullets at a time, straight down
    public static void SingleStraightDown(GameObjectPool enemyBulletPool, int enemyType, Vector3 shooterPosition)
    {
        GameObject bullet = enemyBulletPool.Borrow();

        bullet.GetComponent <EnemyBullet>().SetType(enemyType);
        bullet.GetComponent <EnemyBullet>().Spawn(shooterPosition, new Vector3(0f, 1f, 0));

        bullet.SetActive(true);
    }
Esempio n. 7
0
    private void FixedUpdate()
    {
        if (playerScore >= nextPowerupSpawnScore)
        {
            // generate a new spawn score
            nextPowerupSpawnScore = NewPowerupSpawnScore();

            // spawn a powerup
            GameObject powerup = powerupPool.Borrow();
            powerup.GetComponent <Powerup>().Spawn();
            powerup.SetActive(true);
        }
    }
Esempio n. 8
0
        private FileSelectorTile AddTile(GameObject prefab, string poolName)
        {
            GameObjectPool pool       = GetPool(prefab, poolName);
            GameObject     tileObject = pool.Borrow();

            tileObject.transform.SetParent(layoutGroup.transform, false);
            tileObject.transform.SetSiblingIndex(tiles.Count);

            FileSelectorTile tile = tileObject.GetComponent <FileSelectorTile>();

            Assert.IsNotNull(tile);
            tiles.Add(tile);
            MarkTilesDirty();
            return(tile);
        }
Esempio n. 9
0
    public static void TriFanUp_Shoot(Vector3 origin, GameObjectPool bulletPool)
    {
        GameObject[] bullets = bulletPool.Borrow(3);
        PlayerBullet currentBullet;

        for (int i = 0; i < 3; i++)
        {
            currentBullet = bullets[i].GetComponent <PlayerBullet>();
            float angle = 75 + 15 * i;
            currentBullet.SetRotation(angle);

            Vector3 moveDirection = new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle), 0f);
            currentBullet.Spawn(origin, moveDirection);
            bullets[i].SetActive(true);
        }
    }
Esempio n. 10
0
    public static void TriFanDown(GameObjectPool enemyBulletPool, int enemyType, Vector3 shooterPosition)
    {
        GameObject[] bullets = enemyBulletPool.Borrow(3);
        EnemyBullet  currentBullet;

        for (int i = 0; i < 3; i++)
        {
            currentBullet = bullets[i].GetComponent <EnemyBullet>();
            currentBullet.SetType(enemyType);
            float angle = 65 + 25 * i;
            currentBullet.SetRotation(angle);

            Vector3 moveDirection = new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle), 0f);
            currentBullet.Spawn(shooterPosition, moveDirection);
            bullets[i].SetActive(true);
        }
    }
Esempio n. 11
0
        protected void Start()
        {
            // Create all spaceships.
            var secondaryColorIndex = 0;
            var type2colors         = new Dictionary <SpaceshipBody.Type, HashSet <Color> >();
            var nameCount           = new Dictionary <string, int>();

            foreach (var spaceshipName in spaceshipNames)
            {
                var brain      = BrainFactory.GetBrain(spaceshipName);
                var spawnPoint = Space.GetSpawnPoint();
                var angle      = UnityEngine.Random.Range(1, 360 / Spaceship.ROTATION_PER_ACTION) * Spaceship.ROTATION_PER_ACTION;
                var body       = spaceshipBodiesPool.Borrow <SpaceshipBody>(spawnPoint, angle, space, brain);

                // Check for duplicate type and color.
                var bodyType = body.spaceshipType;
                var color    = body.primaryColor;
                if (!type2colors.ContainsKey(bodyType))
                {
                    type2colors[bodyType] = new HashSet <Color>();
                    type2colors[bodyType].Add(color);
                }
                else if (type2colors[bodyType].Contains(color))
                {
                    // Color clash! Set secondary color.
                    body.SetSecondaryColor(secondaryColors[secondaryColorIndex++]);
                }
                else
                {
                    type2colors[bodyType].Add(color);
                }

                if (nameCount.ContainsKey(brain.DefaultName))
                {
                    ++nameCount[brain.DefaultName];
                    brain.Name = brain.DefaultName + " " + nameCount[brain.DefaultName];
                }
                else
                {
                    nameCount[brain.DefaultName] = 1;
                }

                // Register to score board.
                scoreBoard.Add(brain.Name, color, body.secondaryColor);
            }
        }
Esempio n. 12
0
    // spray out in a circle
    public static void Circular(GameObjectPool enemyBulletPool, int enemyType, Vector3 shooterPosition)
    {
        int bulletCount = 5;

        GameObject[] bullets = enemyBulletPool.Borrow(bulletCount);
        EnemyBullet  currentBullet;

        float angleIncrement = 360 / bulletCount;

        for (int i = 0; i < bulletCount; i++)
        {
            currentBullet = bullets[i].GetComponent <EnemyBullet>();
            currentBullet.SetType(enemyType);

            float angle = angleIncrement + angleIncrement * i;
            currentBullet.SetRotation(angle);
            Vector3 moveDirection = new Vector3(Mathf.Cos(Mathf.Deg2Rad * angle), Mathf.Sin(Mathf.Deg2Rad * angle), 0f);
            currentBullet.Spawn(shooterPosition, moveDirection);
            bullets[i].SetActive(true);
        }
    }
Esempio n. 13
0
        private int _RasterizeNextChunk(int lastPointIndex)
        {
            DebugUtils.Assert(lastPointIndex < Game.instance.terrainPoints.Count, "Last point index out of bounds");
            var startPoint = Game.instance.terrainPoints[lastPointIndex];

            if (lastPointIndex + 2 >= Game.instance.terrainPoints.Count)
            {
                DebugUtils.Log("Not enough points to rasterize");
                return(lastPointIndex);
            }
            var endPoint  = Game.instance.terrainPoints[lastPointIndex + 1];
            var nextPoint = Game.instance.terrainPoints[lastPointIndex + 2];

            // Create ceiling points.
            var ceilingPoints = GetPoints(true, startPoint, endPoint, nextPoint);
            var floorPoints   = GetPoints(false, startPoint, endPoint, nextPoint);

            var chunk = terrainPool.Borrow <TerrainChunk>(ceilingPoints, floorPoints);

            DebugUtils.Log("Rasterized chunk " + chunk.name);
            return(lastPointIndex + 1);
        }
Esempio n. 14
0
    private void CreateEnemyWave()
    {
        if (BossWaveActive)
        {
            return;
        }
        int waveSize      = Random.Range(Balance.ENEMY_WAVE_MIN_SIZE, Balance.ENEMY_WAVE_MAX_SIZE);
        int waveTypeIndex = Random.Range(0, EnemyWaves.WaveTypes.Length);

        print("spawning wave");
        print("available pool size: " + enemyPool.Available.Count);
        print("inuse pool size: " + enemyPool.InUse.Count);

        GameObject[] enemies = enemyPool.Borrow(waveSize);

        for (int i = 0; i < waveSize; i++)
        {
            enemies[i].GetComponent <Enemy>().SetSpawnPosition(EnemyWaves.WaveTypes[waveTypeIndex].GetSpawnPoint(i, waveSize));
            enemies[i].GetComponent <Enemy>().SetWaveType(waveTypeIndex);
        }

        StartCoroutine(SpawnEnemyWave(enemies, EnemyWaves.WaveTypes[waveTypeIndex]._delayBetweenSpawns));
    }