測試用敵人
상속: NetworkBehaviour
예제 #1
0
    public System.Collections.IEnumerator CreateNewObjectWhenPoolEmpty()
    {
        const int limit = 3;

        var     objectToSpawn = TestEnemy.Create(0);
        Spawner spawner       = Spawner.Create(
            typeof(Crasher), limit, 0, 0, 10, 0);

        Spawnable.Pool <Crasher> .Instance.Populate(objectToSpawn, limit);

        spawner.StartSpawning();
        yield return(new UnityEngine.WaitWhile(() => spawner.IsSpawning));

        spawner.StartSpawning(typeof(Crasher), 1, 0, 0, 0, 10);
        yield return(new UnityEngine.WaitWhile(() => spawner.IsSpawning));

        int expectedValue = limit + 1;

        /* Normal Destroy does not destroy the object before the assertion happens.
         * Using DestroyImmediate instead. */
        UnityEngine.Object.DestroyImmediate(objectToSpawn.gameObject);
        int actualValue = UnityEngine.Object.FindObjectsOfType <TestEnemy>().Length;

        Assert.AreEqual(expectedValue, actualValue,
                        $"Expected {expectedValue} spawned objects but got {actualValue}.");
    }
예제 #2
0
    public IEnumerator SpawnersHaveAGlobalSpawningLimit()
    {
        int limit = 100;            // Should be used only for the following check

        // and assigning spawnLimit.
        Assert.Less(Spawnable.GLOBAL_SPAWN_LIMIT, limit,
                    $"Test is not set up correctly:\n" +
                    $"The spawner's limit ({limit}) is lower than the " +
                    $"global spawn limit ({Spawnable.GLOBAL_SPAWN_LIMIT})."
                    );

        Spawner spawner = Spawner.Create(
            objectToSpawn: TestEnemy.Create(),
            spawnLimit: limit,
            initialDelay: 0f,
            spawnRate: 0f,
            maxDistanceToSpawn: 100f,
            minDistanceToSpawn: 0f
            );

        spawner.StartSpawning();
        yield return(new WaitUntil(
                         () => spawner.SpawnCount == Spawnable.GLOBAL_SPAWN_LIMIT));

        yield return(new WaitForSecondsRealtime(.5f));

        Assert.That(spawner.IsSpawning, "Spawner should not stop spawning.");
        Assert.LessOrEqual(spawner.SpawnCount, Spawnable.GLOBAL_SPAWN_LIMIT,
                           "Spawners must respect the global spawn limit."
                           );
    }
예제 #3
0
    public override void Mode_Start(Charactor _obj)
    {
        TestEnemy _enemy = _obj.GetComponent <TestEnemy>();


        player = GameObject.Find("TestPlayer");
        //Vector3 v;

        //プレイヤーの向きに応じて向きを変える
        //プレイヤーのほうが右にいるなら
        if (player.transform.position.x > _obj.transform.position.x)
        {
            _obj.transform.localScale = new Vector2(_obj.BaseScale_x, _obj.transform.localScale.y);
        }
        else
        {
            _obj.transform.localScale = new Vector2(-_obj.BaseScale_x, _obj.transform.localScale.y);
            //_obj.transform.localScale = new Vector2(-_obj.transform.localScale.x, _obj.transform.localScale.y);
        }

        base.Mode_Start(_obj);

        //ひとつだけプレハブから攻撃オブジェクトを作成
        _obj.hitbox[0] = GameObject.Instantiate(Attack[0], _obj.transform.position, Quaternion.identity) as GameObject;
        _obj.hitbox[0].transform.parent = _obj.transform;
    }
예제 #4
0
    public IEnumerator ObjectsAreSpawnedInsideTheDesignatedArea()
    {
        /* This test is based on luck, making it pretty much unreliable.
         * I feel confident enough that things workout, though.*/

        var     prefab  = TestEnemy.Create();
        Spawner spawner = Spawner.Create(prefab, 20, 0f, 0f, 5f, 3f);

        spawner.StartSpawning();
        yield return(new WaitWhile(() => spawner.IsSpawning));

        Object.Destroy(prefab.gameObject);
        Enemy[] enemies = Object.FindObjectsOfType <Enemy>();
        foreach (var enemy in enemies)
        {
            if (enemy == spawner.ObjectToSpawn)
            {
                continue;
            }

            var distance = enemy.transform.position.magnitude;
            Assert.GreaterOrEqual(distance, spawner.MinDistanceToSpawn,
                                  "Objects should not be spawned below the minimum distance.");
            Assert.LessOrEqual(distance, spawner.MaxDistanceToSpawn,
                               "Objects should not be spawned past the maximum distance.");
        }
    }
예제 #5
0
 private void OnCollisionEnter(Collision collision)
 {
     if (ProjectileBehaviour == Type.FirstPerson)
     {
         TestEnemy enemyHit = collision.collider.GetComponent <TestEnemy>();
         if (enemyHit)
         {
             if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie == Bounces)
             {
                 enemyHit.Die();
             }
             else
             if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie > Bounces)
             {
                 Die();
             }
             else
             if (enemyHit.DiesFromDamage)
             {
                 enemyHit.TakeDamage(Damage);
             }
         }
         Vector3 bounceDirection = Vector3.Reflect(transform.forward, collision.contacts[0].normal);
         Bounces++;
         Instantiate(HitSmoke, transform.position + Vector3.forward * .5f, Random.rotation);
         transform.forward = bounceDirection;
     }
 }
예제 #6
0
    public IEnumerator UseLastShotToKillLastEnemy()
    {
        GameState gameState = GameState.Create(0);
        Camera    camera    = new GameObject("Camera").AddComponent <Camera>();
        Player    player    = Player.Create(
            health: Player.MAXIMUM_HEALTH,
            camera: camera,
            bullet: Bullet.Create(100f),
            ammo: 1,
            gameState: gameState);
        TestEnemy enemy = TestEnemy.Create(0, 0, 0, 10, 10, 10, gameState);

        GameManager.Create(player, gameState);

        yield return(null);         //without this, firedBullet will be null

        camera.transform.LookAt(enemy.transform);
        var firedBullet = player.Shoot();

        firedBullet.gameObject.SetActive(true);

        yield return(new WaitUntil(() => gameState.RoundWon));

        Assert.False(gameState.GameOver,
                     "The game must not end if the last enemy dies by the last bullet.");
        Assert.True(gameState.RoundWon,
                    "The round should be won when the last enemy dies by the last bullet.");
    }
예제 #7
0
        private DemoScene()
        {
            // set up camera
            Camera = new Camera
            {
                //Zoom = 2,
                Origin   = new Vector2(320, 180),
                Position = new Vector2(200, 400)
            };

            map    = new DemoMap();
            player = new Player(Camera);
            TestEnemy enemy = new TestEnemy(new Vector2(200, 600), player);

            enemy2 = new WalkingEnemy(new Vector2(295, 365), player);
            //enemy2 = new WalkingEnemy(new Vector2(250, 400), player);
            Item item = new Item(player, new Vector2(100, 500));

            children.Add(map);
            children.Add(player);
            //children.Add(enemy);
            children.Add(enemy2);
            children.Add(item);

            physical = new PhysicsGroup(PhysicsGroupType.Physical);
            physical.Add(map);
            physical.Add(player);
            //physical.Add(enemy);
            physical.Add(enemy2);

            writer = new FragmentWriter("Fonts/TooMuchInk", new Rectangle(100, 450, 200, 200), Color.White);
            writer.SetText(Fragment.Parse(example));
        }
예제 #8
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        TestEnemy enemy = collision.gameObject.GetComponent <TestEnemy>();

        enemy.take_damage(Config.Instance.gun_damage);
        enemy.update_health();
        Destroy(gameObject);
    }
 public override void EnterLevel(int fromLevelNum)
 {
     base.EnterLevel(fromLevelNum);
     selector = new TestEnemy(new Vector2(0, 0));
     enemyList.addSpriteReuse(selector);
     menuSelector    = 0;
     notSelected     = true;
     Game1.TimeScore = 0;
 }
 public override void SpawnTargets()
 {
     enemyList = new SpriteList();
     for (int i = 0; i < targetSpawnPositions.Count; i++)
     {
         TestEnemy currentTestEnemy = new TestEnemy(targetSpawnPositions[i]);
         currentTestEnemy.canRespawn = true;
         enemyList.addSprite(currentTestEnemy);
     }
 }
예제 #11
0
파일: Arm.cs 프로젝트: matsumoto36/Hasamu
    void OnCollisionEnter(Collision other)
    {
        Debug.Log(other.collider.tag);
        Debug.Log("Hit");
        state = ArmState.Hit;

        if (other.collider.tag == "Enemy")
        {
            TestEnemy en = other.collider.GetComponent <TestEnemy>();
            en.isFree = false;
            en.GetComponent <Collider>().enabled = false;
            enemyList.Add(en);
            enemyOffset.Add(trackPoint.position - en.transform.position);

            state = ArmState.Push;
            return;
        }

        //引かなくてよいかチェック
        foreach (Transform p in checkPoints)
        {
            float length = transform.localScale.x + 1;
            Ray   ray    = new Ray(p.position, p.right);
            Debug.DrawLine(p.position, p.position + (p.right * length), Color.red, 1f);

            if (Physics.Raycast(ray, length))
            {
                Debug.Log("Col > pull");

                //Armなら角度で引くスピードを上げる
                if (other.collider.tag == "Arm")
                {
                    Arm   otherArm = other.collider.GetComponent <Arm>();
                    float dir      = GetArmDir(otherArm);
                    if (dir < 90.0f && otherArm.state != ArmState.Pull)
                    {
                        Debug.Log("SpeedUp");
                        pullSpeed *= 6 * (1 - (dir / 90.0f)) + 1;
                    }
                }

                //押している敵を倒す
                foreach (TestEnemy en in enemyList)
                {
                    en.Death();
                }
                enemyList   = new List <TestEnemy>();
                enemyOffset = new List <Vector3>();

                return;
            }
        }

        state = ArmState.Push;
    }
예제 #12
0
 // Update is called once per frame
 void Update()
 {
     if (enemy == null && UI.TargetObject != null)
     {
         enemy = UI.TargetObject.GetComponent <TestEnemy>();
     }
     if (enemy != null)
     {
         text.text = "HP:" + enemy.status.HP.ToString();
     }
 }
예제 #13
0
 // Update is called once per frame
 void Update()
 {
     if (enemy == null && UI.TargetObject != null)
     {
         enemy = UI.TargetObject.GetComponent <TestEnemy>();
     }
     if (enemy != null)
     {
         text.text = enemy.name;
     }
 }
예제 #14
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (!Parent)
     {
         Debug.Log("Find Parent");
         Parent = animator.GetComponent <TestEnemy> ( );
         Parent.OnTriggerStay += TriggerStay;
         this.testValue        = 2;
     }
     Debug.Log("StateEnter");
 }
예제 #15
0
    private void Update()
    {
        //time check
        if (DeathByTime)
        {
            timer += Time.deltaTime;
            if (timer >= LifeTime)
            {
                Die();
            }
        }

        //movement
        transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);

        //raycast for topdown
        if (ProjectileBehaviour == Type.TopDown)
        {
            Ray        ray = new Ray(transform.position, transform.forward);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Time.deltaTime * MoveSpeed + .2f, collisionMask))
            {
                TestEnemy enemyHit = hit.collider.GetComponent <TestEnemy>();
                if (enemyHit)
                {
                    if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie == Bounces)
                    {
                        enemyHit.Die();
                    }
                    else
                    if (enemyHit.DiesFromBounces && enemyHit.BouncesNeededToDie > Bounces)
                    {
                        Die();
                    }
                    else
                    if (enemyHit.DiesFromDamage && enemyHit.Health == Damage)
                    {
                        enemyHit.TakeDamage(Damage);
                        return;
                    }
                }
                Vector3 bounceDirection = Vector3.Reflect(ray.direction, hit.normal);
                float   rot             = 90 - Mathf.Atan2(bounceDirection.z, bounceDirection.x) * Mathf.Rad2Deg;
                transform.eulerAngles = new Vector3(0, rot, 0);
                if (DeathByBounces)
                {
                    Bounces++;
                    Instantiate(HitSmoke, transform.position + Vector3.forward * .5f, Random.rotation);
                }
            }
        }
    }
예제 #16
0
    public void ObjectReturnsToPool()
    {
        Spawnable.Pool <Crasher> .Instance.Populate(TestEnemy.Create(0), 1);

        TestEnemy testObject = Spawnable.Pool <Crasher> .Instance.RequestObject() as TestEnemy;

        testObject.ReturnToPool <Crasher>();

        Assert.AreEqual(1, Spawnable.Pool <Crasher> .Instance.Count,
                        "No object available in the pool.");
        Assert.IsNotNull(Spawnable.Pool <Crasher> .Instance.RequestObject(),
                         "No object available to return.");
    }
예제 #17
0
    public IEnumerator SpawnerStopsSpawningAtGameOver()
    {
        GameState gameState = GameState.Create(0);
        Spawner   spawner   = Spawner.Create(TestEnemy.Create(), 99, 0f, 1f, 5f, 3f, gameState);

        spawner.StartSpawning();
        yield return(new WaitUntil(() => spawner.SpawnCount == 3));

        gameState.GameOver = true;
        yield return(new WaitWhile(() => spawner.IsSpawning));

        Assert.AreEqual(3, spawner.SpawnCount,
                        "Spawner should stop spawning at game over.");
    }
    // public TestEnemy testEnemy;
    private void OnTriggerEnter2D(Collider2D col)
    {
        TestEnemy Enemy = col.GetComponent <TestEnemy>();

        // if(col.isTrigger != true && col.CompareTag("Enemy")){
        if (Enemy != null)
        {
            // col.SendMessageUpwards("Damageee", damage);
            // Enemy.Damageee(damage);
            // testEnemy = GameObject.FindGameObjectWithTag("Enemy").GetComponent<TestEnemy>();
            // testEnemy.Damage(damage);
            // player.trigger.enabled = false;
        }
    }
예제 #19
0
    public void NoAvailableObjectToFetch()
    {
        const int limit = 3;

        Spawnable.Pool <Crasher> .Instance.Populate(TestEnemy.Create(0), limit);

        for (int i = 0; i < limit; i++)
        {
            Spawnable.Pool <Crasher> .Instance.RequestObject();
        }

        Assert.IsNull(Spawnable.Pool <Crasher> .Instance.RequestObject(),
                      "A null reference should have been returned.");
    }
    public IEnumerator MoveFromPointAToPointB()
    {
        TestEnemy hamster = TestEnemy.Create(2f);

        hamster.AiEnabled = false;
        hamster.gameObject.SetActive(true);

        MovementTestPoint testPoint = MovementTestPoint.Create(new Vector3(10f, 10f, 10f));

        hamster.MoveTo(testPoint.transform.position);
        yield return(new WaitWhile(() => hamster.IsMoving));

        Assert.That(testPoint.reached,
                    "Test object must move to the designated test point.");
    }
예제 #21
0
    public override void Mode_Update(Charactor _obj)
    {
        TestEnemy _enemy = _obj.GetComponent <TestEnemy>();

        _enemy.Move(dash_speed);
        base.Mode_Update(_obj);

        /*
         * //プレイヤーとの距離が一定以下なら
         * if (Vector3.Distance(_obj.transform.position, player.transform.position) < AttackRange)
         * {
         *  //_obj.ChangeMode(4);
         * }
         */
    }
예제 #22
0
 // Use this for initialization
 void Start()
 {
     facingRight  = true;
     myRigidbody  = GetComponent <Rigidbody2D>();
     myAnimator   = GetComponent <Animator>();
     ourHealth    = maxHealth;
     gm           = GameObject.FindGameObjectWithTag("gamemaster").GetComponent <Gamemaster>();
     soundManager = GameObject.FindGameObjectWithTag("Sounds").GetComponent <SoundManager>();
     at           = GameObject.FindGameObjectWithTag("attri").GetComponent <AttackPlayer>();
     te           = GameObject.FindGameObjectWithTag("Enemy").GetComponent <TestEnemy>();
     eyybd        = GameObject.FindGameObjectWithTag("Enemy1").GetComponent <EnemyyBlood>();
     // ob = GameObject.FindGameObjectWithTag("Oc").GetComponent<OcBlood>();
     // ns = GameObject.FindGameObjectWithTag("Nhim").GetComponent<NhimScrips>();
     dead = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <DeadUI>();
 }
예제 #23
0
    public override void Mode_Update(Charactor _obj)
    {
        base.Mode_Update(_obj);
        //一定時間でオブジェクトを消去
        if (_obj.modetime > 0.01)
        {
            //MPを増やす
            TestPlayer p = GameObject.Find("TestPlayer").GetComponent <TestPlayer>();
            TestEnemy  e = _obj.GetComponent <TestEnemy>();

            p.status.MP += e.MP;
            _obj.audioPlayer.Play(14);
            _obj.Delete();
        }
    }
    public IEnumerator MoveAroundPlayer()
    {
        TestEnemy hamster = TestEnemy.Create(5f, 0, 0, -5f);

        hamster.AiEnabled = false;
        hamster.gameObject.SetActive(true);

        Player.Create();

        MovementTestPoint endPoint = MovementTestPoint.Create(-hamster.transform.position);

        hamster.MoveTo(endPoint.transform.position);
        yield return(new WaitWhile(() => hamster.IsMoving));

        Assert.True(endPoint.reached);
    }
    public IEnumerator EveryoneMovesToTheSameSpot()
    {
        TestEnemy[] hamsters = new TestEnemy[15];
        hamsters[0]  = TestEnemy.Create(3f, 0, 0, -4f, 0f, 5f);
        hamsters[1]  = TestEnemy.Create(3f, 0, 0, -2f, 0f, 5f);
        hamsters[2]  = TestEnemy.Create(3f, 0, 0, 0f, 0f, 5f);
        hamsters[3]  = TestEnemy.Create(3f, 0, 0, 2f, 0f, 5f);
        hamsters[4]  = TestEnemy.Create(3f, 0, 0, 4f, 0f, 5f);
        hamsters[5]  = TestEnemy.Create(3f, 0, 0, -4f, 2f, 5f);
        hamsters[6]  = TestEnemy.Create(3f, 0, 0, -2f, 2f, 5f);
        hamsters[7]  = TestEnemy.Create(3f, 0, 0, 0f, 2f, 5f);
        hamsters[8]  = TestEnemy.Create(3f, 0, 0, 2f, 2f, 5f);
        hamsters[9]  = TestEnemy.Create(3f, 0, 0, 4f, 2f, 5f);
        hamsters[10] = TestEnemy.Create(3f, 0, 0, -4f, 4f, 5f);
        hamsters[11] = TestEnemy.Create(3f, 0, 0, -2f, 4f, 5f);
        hamsters[12] = TestEnemy.Create(3f, 0, 0, 0f, 4f, 5f);
        hamsters[13] = TestEnemy.Create(3f, 0, 0, 2f, 4f, 5f);
        hamsters[14] = TestEnemy.Create(3f, 0, 0, 4f, 4f, 5f);

        MovementTestPoint gatheringPoint = MovementTestPoint.Create();

        foreach (var hamster in hamsters)
        {
            hamster.gameObject.SetActive(true);
            hamster.AiEnabled = false;
            hamster.MoveTo(gatheringPoint.transform.position);
        }

        yield return(new WaitForSecondsRealtime(3f));

        bool allMovementStoped;

        do
        {
            allMovementStoped = false;
            foreach (var hamster in hamsters)
            {
                if (hamster.IsMoving)
                {
                    allMovementStoped = true;
                    break;
                }
            }
            yield return(new WaitForFixedUpdate());
        } while (allMovementStoped && gatheringPoint.reached);
    }
예제 #26
0
    public IEnumerator SpawnerStopsWhenLimitReached()
    {
        Spawner spawner = Spawner.Create(
            objectToSpawn: TestEnemy.Create(),
            spawnLimit: 5,
            spawnRate: 1,
            maxDistanceToSpawn: 10f,
            minDistanceToSpawn: 3f,
            initialDelay: 0f
            );

        spawner.StartSpawning();
        yield return(new WaitUntil(() => spawner.SpawnCount == spawner.SpawnLimit));

        Assert.That(!spawner.IsSpawning,
                    "Spawner should stop spawining when the spawn limit is reached.");
    }
    public IEnumerator MoveToPointBSkippingA()
    {
        MovementTestPoint pointA = MovementTestPoint.Create(new Vector3(5f, 5f, 5f));
        MovementTestPoint pointB = MovementTestPoint.Create(2 * pointA.transform.position);

        TestEnemy hamster = TestEnemy.Create(5f);

        hamster.AiEnabled = false;
        hamster.gameObject.SetActive(true);

        hamster.MoveTo(pointA.transform.position);
        hamster.MoveTo(pointB.transform.position);
        yield return(new WaitWhile(() => hamster.IsMoving));

        Assert.True(pointA.reached, "Object did not pass through point A");
        Assert.True(pointB.reached, "Object did not reach the end.");
    }
예제 #28
0
    public override void Mode_Start(Charactor _obj)
    {
        _enemy = _obj.GetComponent <TestEnemy>();
        Vector3 v;

        if (!_obj.IsRight)
        {
            v = new Vector3(attack_offset.x * -1, attack_offset.y, attack_offset.z);
        }
        else
        {
            v = attack_offset;
        }
        base.Mode_Start(_obj);
        //ひとつだけプレハブから攻撃オブジェクトを作成
        _obj.hitbox[0] = GameObject.Instantiate(Attack[0], _obj.transform.position + v, Quaternion.identity) as GameObject;
        _obj.hitbox[0].transform.parent = _obj.transform;
    }
예제 #29
0
    public IEnumerator SpawnerSpawnsTheCorrectNumberOfObjects()
    {
        Spawner spawner = Spawner.Create(
            objectToSpawn: TestEnemy.Create(),
            spawnLimit: 5,
            spawnRate: 1,
            maxDistanceToSpawn: 10f,
            minDistanceToSpawn: 3f,
            initialDelay: 0f
            );

        spawner.StartSpawning();
        yield return(new WaitWhile(() => spawner.IsSpawning));

        int numberOfSpawned = Object.FindObjectsOfType <TestEnemy>().Length - 1;

        Assert.AreEqual(5, numberOfSpawned, "Should spawn 5 objects.");
    }
예제 #30
0
 private void SelectObject(GameObject obj)
 {
     if (obj != null)        // check to ensure object has not been destroyed
     {
         Vector3 diff        = obj.transform.position - transform.position;
         float   curDistance = diff.sqrMagnitude;
         if (curDistance < maxTargetDist * maxTargetDist && IsInView(this.gameObject, obj))             // have to muliply by itselft because curDistance is the is a sqrMagnitude
         {
             //print("Within target distance");
             selectedObject = obj;
             enemy          = selectedObject.GetComponent <TestEnemy>();
         }
         else
         {
             //print("Either not within range or not visible.");
             ClearSelection();
         }
     }
 }