예제 #1
0
    void Spawn()
    {
        //暂停模式下直接返回
        EnemyController enemyController = GetComponent <EnemyController>();

        if (enemyController.IsGamePaused)
        {
            return;
        }
        //主角死亡直接返回
        if (playerHealth.currentHealth <= 0f)
        {
            return;
        }
        // 设置出生点并初始化敌人
        int        spawnPointIndex = Random.Range(0, spawnPoints.Length);
        GameObject newEnemy        = Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation) as GameObject;

        // 低概率设置巡逻敌人
        if (Random.Range(0, 10) > 7)
        {
            newEnemy.GetComponent <EnemyAttack>().SetPatrol();
            newEnemy.GetComponent <EnemyMovement>().SetPatrol(patrolPoints.ToList());
        }
        enemyController.AddEnemy(newEnemy);
    }
예제 #2
0
    void SpawnEnemy()
    {
        GameObject enemy = Instantiate(enemyPrefab, transform.position, transform.rotation);

        lastSpawnedEnemy = enemy;
        enemyController.AddEnemy(enemy);
    }
예제 #3
0
 void Start()
 {
     currentBehaviour = defaultBehaviour;
     if (controller != null)
     {
         controller.AddEnemy(this);
     }
 }
예제 #4
0
    private void GenerateEnemies()
    {
        var tiles = Grid.GetTiles();

        foreach (var enemyScript in Enemy)
        {
            for (int i = 0; i < Enemies; i++)
            {
                var tile = tiles[Random.Range(0, tiles.Count)];
                if (tile != null && tile.gameObject.transform.position.x > XMin + 2 && tile.gameObject.transform.position.x < XMax - 2 &&
                    tile.gameObject.transform.position.z > ZMin + 2 && tile.gameObject.transform.position.x < XMax - 2)
                {
                    var position = tile.transform.position;
                    var enemy    = enemyScript.GetComponent <EnemyScript>().Initialize(position.x, position.z, position.y + 1.5f, tile.transform);
                    EnemyController.AddEnemy(enemy.GetComponent <EnemyScript>());
                }
            }
        }
    }
예제 #5
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            int multiplier = 1;

            Utilities.CliRenderer.view = Enumerable.Repeat(string.Empty.PadLeft((int)Enums.Ratio.Width), (int)Enums.Ratio.Height).ToArray();

            if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.O))
            {
                ShopState shop = new ShopState();
                shop.showShop();
            }

            if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.W) && Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.S))
            {
                UpOrDown = 1;
            }
            else if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.W))
            {
                UpOrDown = 2;
            }
            else if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.S))
            {
                UpOrDown = 0;
            }

            if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.D) && Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.A))
            {
                UpOrDown = 1;
            }
            else if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.D))
            {
                LeftOrRight = 2;
            }
            else if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.A))
            {
                LeftOrRight = 0;
            }

            if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.O))
            {
                Score = 74;
            }

            if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.Space))
            {
                Shoot = true;
            }

            if (Utilities.Keyboard.IsKeyDown(Utilities.KeyCode.Shift))
            {
                multiplier = 2;
            }
            else
            {
                multiplier = 1;
            }

            if (Shoot)
            {
                if (Ammo != 0)
                {
                    bullet.Shoot();
                }
                Shoot = false;
            }
            if (UpOrDown == 0)
            {
                UpOrDown = 1;

                if (spaceship.Y <= (int)Enums.Ratio.Height - spaceship.ship.Length - 3)
                {
                    spaceship.Y += (1 * multiplier);
                }
            }
            if (UpOrDown == 2)
            {
                UpOrDown = 1;

                if (spaceship.Y >= 2)
                {
                    spaceship.Y -= (1 * multiplier);
                }
            }
            if (LeftOrRight == 0)
            {
                LeftOrRight = 1;

                if (spaceship.X >= 5)
                {
                    spaceship.X -= (2 * multiplier);
                }
            }
            if (LeftOrRight == 2)
            {
                LeftOrRight = 1;
                if (spaceship.X <= (int)Enums.Ratio.Width - spaceship.ship[1].Length - 5)
                {
                    spaceship.X += (2 * multiplier);
                }
            }



            if (Score % 75 == 0 && Score != 0)
            {
                Bossfight = true;
            }

            stars.AddStar();
            stars.DownAllStars();
            stars.DrawStar();

            bullet.UpAllBullets();
            bullet.DrawBullets();


            if (Bossfight)
            {
                if (Invincible == 0)
                {
                    spaceship.DrawShip();
                }
                else if (Invincible % 2 != 0)
                {
                    spaceship.DrawShip();
                    if (Invincible >= InvincibleDuration)
                    {
                        Invincible = 0;
                    }
                }
                else
                {
                }

                bossfight.RunBossScript();
            }

            enemies.Shoot();
            enemies.DrawBullets();
            enemies.DownAllBullets();
            enemies.DownAllEnemies();

            if (Invincible == 0)
            {
                spaceship.DrawShip();
            }
            else if (Invincible % 2 != 0)
            {
                spaceship.DrawShip();
                Invincible++;
                if (Invincible >= InvincibleDuration)
                {
                    Invincible = 0;
                }
            }
            else
            {
                Invincible++;
            }



            if (!Bossfight)
            {
                boxes.AddBox();
            }
            boxes.DownAllBoxes();
            boxes.DrawBox();

            if (Meteors == 0)
            {
                if (!Bossfight)
                {
                    meteor.AddMeteor();
                    meteor.DownAllMeteors();
                }
                meteor.DrawMeteor();
            }
            else
            {
                Meteors++;
                if (Meteors >= MeteorDuration)
                {
                    Meteors = 0;
                }
            }

            if (bullet.ShootDelay != 0)
            {
                bullet.ShootDelay++;
                if (bullet.ShootDelay >= 15)
                {
                    bullet.ShootDelay = 0;
                }
            }

            if (SpecialGun != 0)
            {
                SpecialGun++;
                if (SpecialGun >= SpecialGunDuration)
                {
                    SpecialGun = 0;
                    bullet.Bullets.Clear();
                }
            }


            if (!Bossfight)
            {
                enemies.AddEnemy();
            }
            enemies.AI();
            enemies.DrawEnemies();

            string scoreboard = "Score: " + Score + "    Ammo: " + Ammo + "     Health: ";

            for (int z = 0; z <= Health - 1; z++)
            {
                scoreboard += "[]";
            }

            if (Bossfight)
            {
                scoreboard += "    Boss HP: " + bossfight.BossHealth;
            }

            if (Invincible != 0)
            {
                scoreboard += "    Invincibility";
            }
            if (Meteors != 0)
            {
                scoreboard += "    Meteor Free";
            }
            if (SpecialGun != 0)
            {
                scoreboard += "    Laser Activated";
            }

            if (Health <= 0)
            {
                alive = false;
            }

            StringBuilder sb = new StringBuilder(Utilities.CliRenderer.view[0]);

            for (int z = 0; z <= scoreboard.Length - 1; z++)
            {
                sb[z] = scoreboard.ToCharArray()[z];
            }

            Utilities.CliRenderer.view[0] = sb.ToString();

            Utilities.CliRenderer.Render();

            if (!alive)
            {
                timer.Stop();
                Main.highscore = new HighscoreState();
                Main.highscore.Input();

                timer.Stop();
                Utilities.CliRenderer.view = Enumerable.Repeat(string.Empty.PadLeft((int)Enums.Ratio.Width), (int)Enums.Ratio.Height).ToArray();
                Utilities.CliRenderer.Render();

                Main.menu = new MenuState();

                Main.menu.ShowMenu();
            }
        }
예제 #6
0
 //register with enemy controller on awake
 void Awake()
 {
     enemyController = FindObjectOfType <EnemyController>();
     enemyController.AddEnemy(this);
     enemyTransform = GetComponentInChildren <RectTransform>();
 }