Beispiel #1
0
        private void DropItem(ItemKind aKind, Vector3 aPosition)
        {
            GameObject go = null;

            switch (aKind)
            {
            case ItemKind.Bomb:
                go = GameObject.Instantiate((GameObject)_gameCore.bombItemPrefab);
                break;

            case ItemKind.Gun:
                go = GameObject.Instantiate((GameObject)_gameCore.gunItemPrefab);
                break;

            case ItemKind.Ammo:
                go = GameObject.Instantiate((GameObject)_gameCore.ammoItemPrefab);
                break;

            case ItemKind.Heal:
                go = GameObject.Instantiate((GameObject)_gameCore.healItemPrefab);
                break;
            }

            if (go != null)
            {
                float   angle = AntMath.DegToRad(AntMath.RandomRangeFloat(-180, 180));
                Vector2 force = new Vector2();
                force.x = 0.5f * Mathf.Cos(angle);
                force.y = 0.5f * Mathf.Sin(angle);

                go.GetComponent <Transform>().position = aPosition;
                go.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse);
                Engine.AddEntity(go.GetComponent <AntEntity>());
            }
        }
Beispiel #2
0
        public void Move(float aDir, float aDeltaTime)
        {
            float   angle = AntMath.DegToRad(_t.rotation.eulerAngles.z);
            Vector2 force = new Vector2();

            force.x        = speed * aDir * Mathf.Cos(angle) * aDeltaTime * 50.0f;
            force.y        = speed * aDir * Mathf.Sin(angle) * aDeltaTime * 50.0f;
            _body.velocity = force;

            /*
             * // Старый код движения без физ тела.
             * Vector3 pos = _t.position;
             * pos.x += speed * aDir * Mathf.Cos(angle) * aDeltaTime;
             * pos.y += speed * aDir * Mathf.Sin(angle) * aDeltaTime;
             * _t.position = pos;//*/
        }
Beispiel #3
0
        private void Fire(MovementNode aNode)
        {
            if (aNode.TankControl.Tower.HasGun &&
                aNode.TankControl.Tower.HasAmmo)
            {
                Transform go  = GameObject.Instantiate((GameObject)aNode.TankControl.Tower.bulletPrefab).GetComponent <Transform>();
                float     ang = AntMath.DegToRad(aNode.TankControl.Tower.Angle);
                Vector3   p   = aNode.entity.Position3D;
                p.x        += aNode.TankControl.Tower.bulletPosition * Mathf.Cos(ang);
                p.y        += aNode.TankControl.Tower.bulletPosition * Mathf.Sin(ang);
                go.position = p;

                Vector2 force = new Vector2();
                force.x = aNode.TankControl.Tower.bulletSpeed * Mathf.Cos(ang);
                force.y = aNode.TankControl.Tower.bulletSpeed * Mathf.Sin(ang);
                go.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse);

                Quaternion q = Quaternion.AngleAxis(aNode.TankControl.Tower.Angle, Vector3.forward);
                go.rotation = q;

                aNode.TankControl.Tower.AmmoCount--;
            }
            else if (aNode.TankControl.Tower.HasBomb)
            {
                float      dist;
                HealthNode hpNode;
                for (int i = _healthNodes.Count - 1; i >= 0; i--)
                {
                    hpNode = _healthNodes[i];
                    dist   = AntMath.Distance(aNode.entity.Position, hpNode.entity.Position);
                    if (dist < 2.5f)
                    {
                        hpNode.Health.HP = 0.0f;
                    }
                }
            }
        }