Exemplo n.º 1
0
        protected void AddEnemy()
        {
            // create the animation object
            Animation enemyAnimation = new Animation();

            // Init the animation with the correct
            // animation information
            enemyAnimation.Initialize(enemyTexture,
                                      Vector2.Zero,
                                      47,
                                      61,
                                      8,
                                      30,
                                      Color.White,
                                      1f,
                                      true);

            // randomly generate the postion of the enemy
            Vector2 position = new Vector2(
                GraphicsDevice.Viewport.Width + enemyTexture.Width / 2,
                random.Next(100, GraphicsDevice.Viewport.Height - 100));

            // create an enemy
            Enemy enemy = new Enemy();

            var m = new LinearMovement(position, new Vector2(-1f, 0f));

            m.MoveSpeed = 10f;

            // Add the enemy to the active enemies list
            enemies.Add().Initialize(this, enemyAnimation, m);
        }
Exemplo n.º 2
0
 public override void SetSpeed(Vector3 s)
 {
     this._speed = s;
     _imovement  = new LinearMovement(
         ((Vector2)s).magnitude * Mathf.Cos(Mathf.Deg2Rad * _degree),
         ((Vector2)s).magnitude * Mathf.Sin(Mathf.Deg2Rad * _degree),
         _speed.z);
 }
Exemplo n.º 3
0
    // Use this for initialization
    protected override void Start()
    {
        base.Start();

        // Chọn kiểu di chuyển.
        _imovement   = new LinearMovement(_speed.x, _speed.y, _speed.z);
        _hitbyplayer = new GoompaHitByPlayer();
    }
        public void TestHorizontalLine()
        {
            LinearMovement t = new LinearMovement(Vector2.Zero, new Vector2(10, 0));

            Assert.AreEqual(new Vector2(0, 0), t.GetPosition(0));
            Assert.AreEqual(new Vector2(10, 0), t.GetPosition(1));
            Assert.AreEqual(new Vector2(5, 0), t.GetPosition(.5f));
        }
        public void TestVerticalLine()
        {
            LinearMovement t = new LinearMovement(Vector2.Zero, new Vector2(0, 10));

            Assert.AreEqual(new Vector2(0, 0), t.GetPosition(0));
            Assert.AreEqual(new Vector2(0, 10), t.GetPosition(1));
            Assert.AreEqual(new Vector2(0, 5), t.GetPosition(.5f));
        }
Exemplo n.º 6
0
    private void InstantiateEnemy(Vector2 pos)
    {
        GameObject obj = Instantiate(enemyPrefab, pos, Quaternion.identity);

        LinearMovement move = obj.GetComponent <LinearMovement>();

        move.direction = movementDirection;

        move.speed = RandomFloat(speed);
    }
Exemplo n.º 7
0
 public LinearMovement(int defaultCount = 64)
 {
     self       = this;
     taa        = new TransformAccessArray(defaultCount);
     targets    = new NativeArray <Vector3>(defaultCount, Allocator.Persistent);
     speeds     = new NativeArray <float>(defaultCount, Allocator.Persistent);
     terminated = new NativeArray <byte>(defaultCount, Allocator.Persistent);
     callbacks  = new List <Action>(defaultCount);
     to_remove  = new List <int>();
 }
Exemplo n.º 8
0
    protected override void OnEnable()
    {
        base.OnEnable();
        linear           = GetComponent <LinearMovement>();
        numHitsRemaining = numHits;

        if (range > 0)
        {
            StartCoroutine(RecycleAfterOutOfRange());
        }
    }
Exemplo n.º 9
0
    protected override IEnumerator TransitionToDream(Nightmatrix nightmatrix)
    {
        yield return(base.TransitionToDream(nightmatrix));

        LinearMovement lm = shooterPhase.GetComponent <LinearMovement>();

        if (lm && lm.enabled)
        {
            platformerBirdie.AttackIntoDirection(movement.normalized);
        }
    }
Exemplo n.º 10
0
    public override void Use()
    {
        GameObject arrow = pool.GetObject();

        if (arrow == null)
        {
            return;
        }
        LinearMovement lm = arrow.GetComponent <LinearMovement>();

        lm.StartMovement(arrowSpawn.position, arrowSpawn.position + arrowSpawn.forward * range);
    }
Exemplo n.º 11
0
    public void RandomDogsPosition()
    {
        var newPositions = new Vector3[currentDogsByScenes[0].Dogs.Count];

        for (int i = 0; i < newPositions.Length; i++)
        {
            newPositions[i] = GetNewDogRandomPosition();
        }

        foreach (var dogsByScene in currentDogsByScenes)
        {
            var dogIndex = 0;
            foreach (var dog in dogsByScene.Dogs)
            {
                var positionAssigned = false;
                var counter          = 0;
                while (!positionAssigned && counter < RETRIES)
                {
                    var dogInitialPos = newPositions[dogIndex];
                    dog.transform.position     = dogInitialPos;
                    Physics.autoSyncTransforms = true;
                    Physics.SyncTransforms();
                    if (PositionIsSafe(dog, objectAssigned))
                    {
                        objectAssigned.Add(dog);
                        positionAssigned = true;
                    }
                    else
                    {
                        newPositions[dogIndex] = GetNewDogRandomPosition();
                    }

                    counter++;
                }


                LinearMovement linear = dog.GetComponent <LinearMovement>();
                if (linear != null)
                {
                    linear.SetNewStartPosition(dog.transform.position);
                }

                CircularMovement circularMovement = dog.GetComponent <CircularMovement>();
                if (circularMovement != null)
                {
                    circularMovement.Reset();
                }

                dogIndex++;
            }
        }
    }
Exemplo n.º 12
0
        protected override void Spawn(Vector2 spawnPosition)
        {
            Vector2 dif = mPlayer.Position - spawnPosition;

            dif.Normalize();

            var p = new LinearMovement(spawnPosition, spawnPosition + dif * 2000);

            //var b = new Bullet(this.Sprite, new LifeTimeMovement(5, p));
            var b = new Bullet(Sprite, new LinearVectorMovement(spawnPosition, mPlayer.Position, (float)Speed));

            bulletList.Add(b);
        }
Exemplo n.º 13
0
        public void VerifyIterationsFor70Degrees(int directionX, int directionY, int expectedX, int expectedY)
        {
            // Given
            const int Degree   = 70;
            IMovement movement = new LinearMovement(0, Degree, new Vector2(0, 0), new Vector2(directionX, directionY));

            // Then
            bool result = Move(movement, Iterations, out Vector2 position);

            // When
            Assert.IsTrue(result);
            Assert.AreEqual(expectedX, position.X);
            Assert.AreEqual(expectedY, position.Y);
        }
Exemplo n.º 14
0
        public void VerifyReverseIterationsFor45Degrees(int directionX, int directionY)
        {
            // Given
            const int Degree   = 45;
            IMovement movement = new LinearMovement(Iterations, Degree, new Vector2(0, 0), new Vector2(directionX, directionY));

            // Then
            bool result = ReverseMove(movement, Iterations, out Vector2 position);

            // When
            Assert.IsTrue(result);
            Assert.AreEqual(0, position.X);
            Assert.AreEqual(0, position.Y);
        }
Exemplo n.º 15
0
    protected override void Start()
    {
        base.Start();

        _imovement = new LinearMovement(_speed.x, _speed.y, _speed.z);
        //_hitbyplayer = new TroopaHitByPlayer();
        if ((_imovement as LinearMovement).Xspeed > 0)
        {
            _aniamtor.SetBool("left", false);
        }
        else
        {
            _aniamtor.SetBool("left", true);
        }
    }
Exemplo n.º 16
0
    // Use this for initialization
    protected override void Start()
    {
        base.Start();

        _imovement = new LinearMovement(_speed.x, _speed.y, _speed.z);
        //_hitbyplayer = new TroopaHitByPlayer();
        if ((_imovement as LinearMovement).Xspeed > 0)
        {
            this.flipLeft(false);
        }
        else
        {
            this.flipLeft(true);
        }
    }
Exemplo n.º 17
0
    protected void Fire()
    {
        LinearMovement bullet = ObjectRecycler.Singleton.GetObject <LinearMovement>(0);

        bullet.speed           = 25;
        bullet.initialPosition = playerCharacter.transform.position;
        bullet.orientation     = playerCharacter.transform.parent.GetComponentInChildren <MouseIndicator>().GetAttackDirection();

        bullet.GetComponent <Bullet>().isFriendly     = true;
        bullet.GetComponent <Bullet>().Bounce         = true;
        bullet.GetComponent <Bullet>().bounceRatio    = 1.5f;
        bullet.GetComponent <Bullet>().maxBounceTimes = 3;
        bullet.transform.right = bullet.orientation;

        bullet.gameObject.SetActive(true);
    }
Exemplo n.º 18
0
    public override void Use()
    {
        if (Ready)
        {
            GameObject bullet = pool.GetObject();
            if (bullet == null)
            {
                return;
            }
            bullet.SetActive(true);
            LinearMovement lm = bullet.GetComponent <LinearMovement>();
            lm.StartMovement(spawnPoint.position, spawnPoint.position + spawnPoint.forward * maximumDistance);

            base.Use();
        }
    }
Exemplo n.º 19
0
    protected virtual void Fire(RangedWeaponConfiguration firingConfiguration)
    {
        Bullet bullet = ObjectRecycler.Singleton.GetObject <Bullet>(firingConfiguration.BulletID);

        bullet.hit.source = enemy;
        bullet.isFriendly = false;


        LinearMovement bulletMovement = bullet.GetComponent <LinearMovement>();

        bulletMovement.speed           = firingConfiguration.BulletSpeed;
        bulletMovement.initialPosition = firingConfiguration.Muzzle ? firingConfiguration.Muzzle.position : enemy.transform.position;
        bulletMovement.orientation     = (enemy.currentTarget.transform.position - bulletMovement.initialPosition).normalized;
        bulletMovement.GetComponent <Bullet>().isFriendly = false;
        bulletMovement.transform.right = bulletMovement.orientation;
        bulletMovement.gameObject.SetActive(true);
    }
Exemplo n.º 20
0
    public void Fire(Vector3 position, bool hasDeviation = true)
    {
        Vector3 aimDirection = Aim(position);


        Bullet bullet = ObjectRecycler.Singleton.GetObject <Bullet>(patrolFiringConfiguration.BulletID);

        bullet.hit.source = this;
        bullet.isFriendly = false;

        LinearMovement bulletMovement = bullet.GetComponent <LinearMovement>();

        bulletMovement.speed           = patrolFiringConfiguration.BulletSpeed;
        bulletMovement.initialPosition = patrolFiringConfiguration.Muzzle ? patrolFiringConfiguration.Muzzle.position : transform.position;
        bulletMovement.orientation     = hasDeviation ? GetDeviatedBulletDirection(patrolFiringConfiguration.MinDeviationAngle, patrolFiringConfiguration.MaxDeviationAngle) : aimDirection;
        bulletMovement.transform.right = bulletMovement.orientation;
        bulletMovement.gameObject.SetActive(true);
    }
Exemplo n.º 21
0
    private void OnSceneGUI()
    {
        LinearMovement line            = target as LinearMovement;
        Transform      handleTransform = line.transform;
        Quaternion     handleRotation  = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity;
        Vector3        p0           = handleTransform.position;
        Transform      parent_trans = line.transform.parent;
        Vector3        p1           = parent_trans == null ? handleTransform.localPosition + line.m_point_b : parent_trans.TransformPoint(handleTransform.localPosition + line.m_point_b);

        Handles.color = Color.white;
        Handles.DrawLine(p0, p1);
        EditorGUI.BeginChangeCheck();
        p1 = Handles.DoPositionHandle(p1, handleRotation);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(line, "Move Point");
            EditorUtility.SetDirty(line);
            line.m_point_b = (parent_trans == null ? p1 : parent_trans.InverseTransformPoint(p1)) - handleTransform.localPosition;
        }
    }
Exemplo n.º 22
0
    private void InitializePool()
    {
        pool = new ObjectPool(vfxNumber);
        for (int i = 0; i < vfxNumber; i++)
        {
            //shot gets a shot prefab that needs to be instantiated
            GameObject bullet = Instantiate(vfx);
            bullet.SetActive(false);
            //rigidbody is needed to perform collision detection
            //as we might re-use the bullet prefab for other purposes
            //the rigidbody is added dynamically
            Rigidbody rb = bullet.AddComponent <Rigidbody>();
            //disable gravity as the shot should fly straight forward
            rb.useGravity = false;

            //prepare collision handler
            TargetSelectionOnCollision collisionSelection = bullet.AddComponent <TargetSelectionOnCollision>();
            //add the set up target selection methods and impact effects
            //references to the lists are passed as content changes are
            //propagated immediately
            collisionSelection.Selectors = targetSelectors;
            collisionSelection.Effects   = impactEffects;

            collisionSelection.CollisionLayer = collisionLayer;

            //straight forward movement
            LinearMovement movement = bullet.AddComponent <LinearMovement>();
            //stop movement on hit
            collisionSelection.onHitOccured += movement.StopMovement;

            //if skill can level
            if (skillExperience != null)
            {
                //get experience on successful hit
                collisionSelection.onHitOccured += GainExperience;
            }
            pool.AddObject(bullet);
        }
        skillExperience.onLevelChanged += LevelUpHandler;
    }
Exemplo n.º 23
0
    protected override void Fire(RangedWeaponConfiguration firingConfiguration)
    {
        Bullet bullet = ObjectRecycler.Singleton.GetObject <Bullet>(firingConfiguration.BulletID);

        bullet.hit.source = enemy;
        bullet.isFriendly = false;


        LinearMovement bulletMovement = bullet.GetComponent <LinearMovement>();

        bulletMovement.speed           = firingConfiguration.BulletSpeed;
        bulletMovement.initialPosition = firingConfiguration.Muzzle ? firingConfiguration.Muzzle.position : enemy.transform.position;
        bulletMovement.orientation     = enemy.GetDeviatedBulletDirection(firingConfiguration.MinDeviationAngle, firingConfiguration.MaxDeviationAngle);
        bulletMovement.transform.right = bulletMovement.orientation;
        bulletMovement.gameObject.SetActive(true);


        enemy.isGunCharging = false;


        gunAnimator.Play("L2Drone_Gun_Idle");

        AudioManager.Singleton.PlayOnce("LaserBullet");
    }
Exemplo n.º 24
0
    public void EmitShockwave(int objectID, Vector3 direction, bool cameraShake = true)
    {
        LinearMovement shockwaveMovement = ObjectRecycler.Singleton.GetObject <LinearMovement>(objectID);

        shockwaveMovement.initialPosition = transform.position + new Vector3(1, 0, 0);
        shockwaveMovement.orientation     = direction.x > 0 ? Vector3.right : Vector3.left;


        HitBox shockwaveHitbox = shockwaveMovement.GetComponent <HitBox>();

        if (shockwaveHitbox)
        {
            shockwaveHitbox.hit.source = this;
        }


        shockwaveMovement.gameObject.SetActive(true);


        if (cameraShake)
        {
            CameraManager.Instance.Shaking(0.2f, 0.2f);
        }
    }
Exemplo n.º 25
0
 private void Awake()
 {
     //this.difficulty = FindObjectOfType<DIfficultyIncrease>();
     this.linearMovement = GetComponent <LinearMovement>();
 }