Esempio n. 1
0
 public Meteor(MeteorType meteorType, Point initialLocation)
 {
     IsActive = true;
     _meteorSprite = new Sprite();
     _meteorType = meteorType;
     CreateMeteor(initialLocation);
 }
    // 各パラメータの初期化
    // Note: 本当はtypeを渡す必要はないが,typeに依存していることを明示するために引数にしています
    void InitParameters(MeteorType type)
    {
        // 種類依存のパラメータ
        speed = speeds[(int)type];
        var scale = scales[(int)type];

        transform.localScale = new Vector3(scale, scale, 0);
        // TODO: Spriteを変更する
        switch (type)
        {
        case MeteorType.SMALL:
            GetComponent <SpriteRenderer>().sprite = SmallSprite;
            break;

        case MeteorType.MEDIUM:
            GetComponent <SpriteRenderer>().sprite = MediumSprite;
            break;

        case MeteorType.BIG:
            GetComponent <SpriteRenderer>().sprite = BigSprite;
            break;
        }

        // 位置・角度
        // 中心から見て,どの角度に隕石が発生するかをランダムで決定
        var   PI         = Mathf.PI;
        float baseRadian = Random.Range(PI / 3, (2 + 2 / 3) * PI);

        // baseRadianを元に位置と角度を初期化
        transform.position = getInitFirstPos(baseRadian);
        angle = getInitAngle(baseRadian);
    }
Esempio n. 3
0
        /// <summary>
        /// Creates a new meteor entity with a random linear and rotation velocity.
        /// </summary>
        /// <param name="type">The type of the new meteor</param>
        /// <param name="position">The position of the new meteor</param>
        /// <param name="direction">The direction of the new meteor</param>
        /// <param name="inject">Whether the meteor should be injected into the entity manager.</param>
        /// <returns>The new meteor entity.</returns>
        public Meteor CreateMeteor(MeteorType type, Vector2 position, Vector2 direction, bool inject)
        {
            float linearVelocity   = _random.Next(100, 200);
            float rotationVelocity = _random.Next(90, 360);

            return(CreateMeteor(type, position, direction, linearVelocity, rotationVelocity, inject));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a meteor entity with a random position, direction, linear and rotation velocity.
        /// </summary>
        /// <param name="type">Type of the meteor.</param>
        /// <param name="inject">Whether the meteor should be injected into the entity manager.</param>
        /// <returns>Th new meteor entity.</returns>
        public Meteor CreateMeteor(MeteorType type, bool inject)
        {
            Vector2 randomPosition  = new Vector2(_random.Next(0, _gameSize.ScreenWidth), _random.Next(0, _gameSize.ScreenHeight));
            Vector2 randomDirection = VectorHelper.AngleToVector((float)(_random.NextDouble() * Math.PI * 2));

            return(CreateMeteor(type, randomPosition, randomDirection, inject));
        }
Esempio n. 5
0
    public void MeteorCollided(Vector3 position, Vector3 normal, MeteorType type)
    {
#if UNITY_EDITOR
        if (debugCollisions)
        {
            Debug.Log("Meteor(" + type + ") collision at: " + position);
        }
        if (drawCollisionRays)
        {
            Debug.DrawRay(position, normal, Color.red, 5f);
        }
#endif
    }
    void Start()
    {
        // Manager取得
        parent = GameObject.Find("Manager");

        // ランダムで種類を決定
        type = GetRandomType();

        // パラメータを初期化
        InitParameters(type);

        // 寿命設定
        Destroy(gameObject, lifeTime);
    }
Esempio n. 7
0
        public Meteor(MeteorType type)
        {
            Type = type;

            switch (Type)
            {
            case MeteorType.Big:
                Radius         = 120;
                ExplosionScale = 1.0f;
                break;

            case MeteorType.Medium:
                Radius         = 80;
                ExplosionScale = 0.5f;
                break;

            case MeteorType.Small:
                Radius         = 40;
                ExplosionScale = 0.2f;
                break;
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new meteor entity.
        /// </summary>
        /// <param name="type">The type of the new meteor</param>
        /// <param name="position">The position of the new meteor</param>
        /// <param name="direction">The direction of the new meteor</param>
        /// <param name="linearVelocity">The linear velocity of the new meteor</param>
        /// <param name="rotationVelocity">The rotation velocity of the new meteor</param>
        ///
        /// <returns>The new meteor entity.</returns>
        public Meteor CreateMeteor(MeteorType type, Vector2 position, Vector2 direction, float linearVelocity, float rotationVelocity, bool inject)
        {
            Meteor newMeteor = null;

            switch (type)
            {
            case MeteorType.TINY: newMeteor = new TinyMeteor(position, direction, linearVelocity, rotationVelocity); break;

            case MeteorType.SMALL: newMeteor = new SmallMeteor(position, direction, linearVelocity, rotationVelocity); break;

            case MeteorType.MEDIUM: newMeteor = new MediumMeteor(position, direction, linearVelocity, rotationVelocity); break;

            case MeteorType.BIG: newMeteor = new BigMeteor(position, direction, linearVelocity, rotationVelocity); break;
            }

            if (inject)
            {
                _entityManager.AddEntity(newMeteor);
            }

            return(newMeteor);
        }
Esempio n. 9
0
 public MeteorDestroyedNotificationArguments(MeteorType meteorType, Vector2 position)
 {
     MeteorType = meteorType;
     Position   = position;
 }