Esempio n. 1
0
    /// <summary>
    /// 从对象池中or新创建enemyBase
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    protected EnemyBase NewEnemy(eEnemyType type)
    {
        Stack <EnemyBase> stack;
        EnemyBase         enemy = null;

        if (_enemiesPool.TryGetValue(type, out stack))
        {
            if (stack.Count > 0)
            {
                enemy = stack.Pop();
            }
        }
        else
        {
            stack = new Stack <EnemyBase>();
            _enemiesPool.Add(type, stack);
        }
        if (enemy == null)
        {
            switch (type)
            {
            case eEnemyType.NormalEnemy:
                enemy = new NormalEnemy();
                break;

            case eEnemyType.Boss:
                enemy = new Boss();
                break;
            }
        }
        return(enemy);
    }
Esempio n. 2
0
    public EnemyBase CreateEnemyByType(eEnemyType type)
    {
        EnemyBase enemy = NewEnemy(type);

        RegisterEnemy(enemy);
        enemy.Init();
        return(enemy);
    }
 public void HandleEnemyShootsSounds(eEnemyType enemyType)
 {
     switch (enemyType)
     {
         case eEnemyType.Cop:
             PlayCopShoots();
             break;
         case eEnemyType.Solider:
             PlaySoldierShoots();
             break;
     }
 }
Esempio n. 4
0
 public GameObject GetEnemyPrefab(eEnemyType type)
 {
     if (DicEnemyPrefab.ContainsKey(type) == true)
     {
         return(DicEnemyPrefab[type]);
     }
     else
     {
         Debug.LogError(type.ToString() + " 타입의 적 프리팹이 없습니다.");
         return(null);
     }
 }
Esempio n. 5
0
        public Enemy(int levelNr, Vector2 location, eEnemyType type)
        {
            #region Assign velocity
            Velocity = 15f + levelNr * 3.0f;
            if (Velocity > 160.0f)
            {
                Velocity = 160.0f;
            }
            #endregion

            CollisionRect = new FRect(location, WIDTH, HEIGHT);

            #region Create enemy by type
            switch (type)
            {
            case eEnemyType.Top:
                Texture     = Common.str2Tex("Enemies/enemy01");
                HP          = 2;
                ScoreValue  = 30;
                ShootChance = 4 + levelNr / 2;
                if (ShootChance > 25)
                {
                    ShootChance = 25;
                }
                break;

            case eEnemyType.Mid:
                Texture     = Common.str2Tex("Enemies/enemy02");
                ScoreValue  = 20;
                HP          = 1;
                ShootChance = 2 + levelNr / 2;
                if (ShootChance > 15)
                {
                    ShootChance = 15;
                }
                break;

            case eEnemyType.Bottom:
                Texture     = Common.str2Tex("Enemies/enemy03");
                ScoreValue  = 10;
                HP          = 1;
                ShootChance = 1 + levelNr / 2;
                if (ShootChance > 10)
                {
                    ShootChance = 10;
                }
                break;
            }
            #endregion
        }
 public void HandleEnemyDeathSounds(eEnemyType enemyType)
 {
     switch (enemyType)
     {
         case eEnemyType.Citizen:
             PlayCitizenScreams();
             break;
         case eEnemyType.Cop:
             PlayCopScreams();
             break;
         case eEnemyType.Solider:
             PlaySoldierScreams();
             break;
     }
 }
    /// <summary>
    /// spawns Enemeys
    /// </summary>
    public void SpawnEnemy(eEnemyType enemyType, int row)
    {
        // initate new enemy
        Transform newEnemy = Instantiate(enemiesPrefab) as Transform;

        newEnemy.GetComponent<Enemy>().type = enemyType;

        // generate a start posision
        Vector3 startPosition = GenertaeStartPosision(row, enemyType);
        // set enemy position randomly between the six rows
        newEnemy.position = (startPosition);
        SpriteRenderer spriteRenderer = newEnemy.gameObject.GetComponent<SpriteRenderer>();
        // set enemy layer
        spriteRenderer.sortingLayerName = Utilities.SortingLayerNames[row];
        spriteRenderer.sortingOrder = 1;
    }
Esempio n. 8
0
 public MotherShip(Game i_Game, Color i_TintColor)
     : base(i_Game, k_AssetName)
 {
     m_SoundManager         = this.Game.Services.GetService(typeof(ISoundManager)) as ISoundManager;
     this.AssetName         = k_AssetName;
     this.TintColor         = i_TintColor;
     this.Velocity          = new Vector2(k_Velocity * this.Direction.X, 0);
     m_TimeSinceLastShow    = 0;
     m_IsTimestampSaved     = false;
     m_RandomWaitTime       = 0;
     m_Random               = new Random();
     this.Team              = eTeam.Enemy;
     m_EnemyType            = eEnemyType.MotherShip;
     this.ScalingTimeToZero = 2.6f;
     this.BlinkingPerSecond = 10f;
 }
Esempio n. 9
0
 private void setEnemySpaceShipProperties(int i_Index)
 {
     if (i_Index == 0)
     {
         m_EnemySpaceShipColor = Color.LightPink;
         m_EnemyType           = eEnemyType.HardEnemy;
     }
     else if (i_Index == 1 || i_Index == 2)
     {
         m_EnemySpaceShipColor = Color.LightBlue;
         m_EnemyType           = eEnemyType.MediumEnemy;
     }
     else
     {
         m_EnemySpaceShipColor = Color.LightYellow;
         m_EnemyType           = eEnemyType.EasyEnemy;
     }
 }
Esempio n. 10
0
    public void RestoreEnemyToPool(EnemyBase enemy)
    {
        if (enemy == null)
        {
            return;
        }
        eEnemyType        enemyType = enemy.GetEnemyType();
        Stack <EnemyBase> stack;

        if (_enemiesPool.TryGetValue(enemyType, out stack))
        {
            enemy.Clear();
            stack.Push(enemy);
        }
        else
        {
            Logger.Log("Restore Enemy Fail!Reason : stack of type " + enemyType + " is not found!");
        }
    }
Esempio n. 11
0
 public static List <ICreature> GetTargetList(bool is_team, eEnemyType enemy_type)
 {
     if (is_team == true)
     {
         if (enemy_type == eEnemyType.team)
         {
             return(BattleBase.Instance.characters.ToList());
         }
         return
             (BattleBase.Instance.enemies.ToList());
     }
     else
     {
         if (enemy_type == eEnemyType.team)
         {
             return(BattleBase.Instance.enemies.ToList());
         }
         return
             (BattleBase.Instance.characters.ToList());
     }
 }
Esempio n. 12
0
 public EnemySpaceShip(Game i_Game, Color i_TintColor, eEnemyType i_EnemyType, Point i_Index)
     : base(i_Game, k_AssetName)
 {
     m_SoundManager     = this.Game.Services.GetService(typeof(ISoundManager)) as ISoundManager;
     AssetName          = k_AssetName;
     TintColor          = i_TintColor;
     m_Index            = i_Index;
     m_TimeBetweenJumps = 0.25f;
     m_IsEnemyVisible   = true;
     m_TimeToNextShow   = 0;
     this.Direction     = new Vector2(-1, 0);
     m_PrevDirection    = -1;
     m_PrevX            = 0;
     m_NextXJump        = 0;
     Team                   = eTeam.Enemy;
     m_EnemyGun             = new EnemyGun(i_Game, this);
     m_EnemyType            = i_EnemyType;
     m_CurrentFrameIndex    = 0;
     this.IsDying           = false;
     this.ScalingTimeToZero = 1.8f;
     this.CyclesPerSecond   = 7f;
     setEnemyFrames();
     NotifyGameManagerAboutMe();
 }
 void Start()
 {
     this.type = transform.GetComponent<Enemy>().type;
 }
 private float positionOffset(eEnemyType type)
 {
     float offset = 0;
     switch (type)
     {
         case eEnemyType.Citizen:
             offset = 0;
             break;
         case eEnemyType.Cop:
             offset = -0.4f;
             break;
         case eEnemyType.Solider:
             offset = 0.3f;
             break;
     }
     return offset;
 }
 /// <summary>
 /// Generate a vector for the posistion for enemy spawn
 /// </summary>
 /// <param name="row"> the row the vector should be on</param>
 /// <returns></returns>
 private Vector3 GenertaeStartPosision(int row, eEnemyType enemyType)
 {
     return new Vector3(9.4f, -2.4f + row + positionOffset(enemyType), 0f);
 }