public void RemoveBullet(IBullet deadBullet) { if (deadBullet is Mover myMover) { myMover.Used = false; } }
public Gun(float attack, float fireRate, float fireRange, IBullet bullet) : base(attack, fireRate, fireRange) { currentTime = fireRate; SetBullet(bullet); SetRemianBullet(maxBullet); SetReLoadingTime(0.5f); }
private void Handler_MakeShot(IMessage msg) { SolidBody BodyHolder = (Parent as Weapon).Owner?.Components?.GetComponent <SolidBody>(); if (BodyHolder == null) { return; } //получаем гранату IBullet grenadeBullet = magazin.GetBullet(); if (grenadeBullet == null) { return; } //получаем позицию игрока Vec2 position = (Vec2)BodyHolder.Body?.GetPosition(); //определяем импульс float dX = msg.Location.X - position.X; float dY = (msg.Location.Y - position.Y); //нельзя бросить дальше дальности броска if (System.Math.Sqrt(dX * dX + dY * dY) > strength) { return; } Vec2 impulse = new Vec2(dX, dY); //создаем объект гранаты var grenade = BuilderGameObject.CreateGrenade(Parent.Model, (Parent as Weapon).Owner.Components.GetComponent <SolidBody>().Shape.Location, impulse, grenadeBullet); }
public void Start() { debugInput.Initialize(); testStage = new TestStage(levelData); bulletFactory = new BulletFactory(originalBullet, levelData); // プレイヤー playerModel = new PlayerModel(testStage.LevelData, testStage); playerPresenter.Initialize(playerModel, debugInput, testStage); playerModel.OnAttackObservable.Subscribe(attacker => { // 弾生成 if (playerBullet == null) { playerBullet = bulletFactory.CreateBullet(attacker); playerBullet.OnDestroy.Subscribe(_ => { playerBullet = null; }).AddTo(this); } }).AddTo(this); // 敵 enemyArmy = new EnemyArmy(testStage); }
IEnumerator ZZShotgun() { for (int i = 0; i >= 0; i++) { Vector3 vec = new Vector3(0, 0, 1); int tj = Random.Range(-8, 20); for (int j = -8; j < 28; j++) { GameObject bullet; if (i % 2 == 1) { bullet = BulletUtil.LoadBullet("红边圆"); } else { bullet = BulletUtil.LoadBullet("蓝边圆"); } bullet.transform.position = shooter.GetPos(); bullet.transform.forward = Quaternion.AngleAxis(10 * j, Vector3.up) * vec; IBullet bulletInfo = bullet.GetComponent <IBullet>(); bulletInfo.shooter = shooter; bulletInfo.speed = 1.0f; bulletInfo.Fire(); } Vector3 flowerVec = new Vector3(0, 0, 1); flowerVec = Quaternion.AngleAxis(Random.Range(0, 36) * 10, Vector3.up) * vec; for (int j = 0; j < 7; j++) { GameObject bullet; if (i % 2 == 1) { bullet = BulletUtil.LoadBullet("红花"); } else { bullet = BulletUtil.LoadBullet("蓝花"); } bullet.transform.position = shooter.GetPos() + new Vector3(0, 0.3f, 0);; bullet.transform.forward = Quaternion.AngleAxis(10 * j, Vector3.up) * flowerVec; IBullet bulletInfo = bullet.GetComponent <IBullet>(); bulletInfo.shooter = shooter; bulletInfo.speed = 1.0f; bulletInfo.Fire(); } yield return(new WaitForSeconds(3.5f)); } }
IEnumerator ZZShotgun() { Vector3 vec = GetVec(); for (int i = -9; i < 36; i++) { GameObject bullet = BulletUtil.LoadBullet(shooter.GetBulletName()); bullet.transform.position = shooter.GetPos(); bullet.transform.forward = Quaternion.AngleAxis(20 * i, Vector3.up) * vec; IBullet bulletInfo = bullet.GetComponent <IBullet>(); bulletInfo.shooter = shooter; bulletInfo.speed = 5; bulletInfo.delay = 0; bulletInfo.Fire(); GameObject bullet2 = BulletUtil.LoadBullet(shooter.GetBulletName()); bullet2.transform.position = shooter.GetPos(); bullet2.transform.forward = Quaternion.AngleAxis(20 * i, Vector3.down) * vec; IBullet bulletInfo2 = bullet2.GetComponent <IBullet>(); bulletInfo2.shooter = shooter; bulletInfo2.speed = 5; bulletInfo2.delay = 0; bulletInfo2.Fire(); yield return(new WaitForSeconds(0.1f)); } }
public override bool OnHit(IBullet bullet) { if (brickState != BrickState.Full || bullet.CanDestroyConcrete) { DieBy(bullet); } else { switch (bullet.Direction) { case Direction.Down: SetBrickState(BrickState.Bottom); break; case Direction.Up: SetBrickState(BrickState.Top); break; case Direction.Left: SetBrickState(BrickState.Left); break; case Direction.Right: SetBrickState(BrickState.Right); break; } if (bullet.Group == GroupType.Players) { AudioManager.s_Instance.PlayFxClip(AudioManager.AudioClipType.TargetHit); } } return(true); }
public void OnBulletCollision(object sender, BulletCollisionEventArgs args) { IBullet bullet = args.Bullet; bullet.Clear(); bullets.Remove(bullet); }
private IEnumerator FireCoroutine(Transform target, GameObject bulletPrefab) { if (target != null && bulletPrefab != null) { if (anim != null && anim.runtimeAnimatorController != null) { foreach (AnimationClip clip in anim.runtimeAnimatorController.animationClips) { if (clip.name == "Attack") { anim.SetTrigger("attack"); break; } } } // Chờ hết thời gian chờ thì đánh tiếp yield return(new WaitForSeconds(fireDelay)); if (target != null) { GameObject arrow = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation); IBullet bullet = arrow.GetComponent <IBullet>(); bullet.SetDamage(damage); bullet.Fire(target); if (sfx != null && AudioManager.instance != null) { AudioManager.instance.PlayAttack(sfx); } } } }
public void InstantiateBullet(IBullet bullet) { bullet.GameObject = GameObject.Instantiate(_prefabs[bullet.BulletType.ToString()]); bullet.Collider2D = bullet.GameObject.GetComponent <Collider2D>() as Collider2D; bullet.RigidBody2D = bullet.GameObject.GetComponent <Rigidbody2D>() as Rigidbody2D; bullet.GameObject.SetActive(false); }
public void BulletRefresh(IBullet newBullet) { //Tip: When got bullet will be Avtive the Function. // And Init will call ones. this.mBullet = newBullet; }
void ZZShotgun() { IBullet[] bullets = new IBullet[40]; Vector3 vec = new Vector3(0, 0, 1); for (int i = 0; i < 18; i++) { GameObject bullet = BulletUtil.LoadBullet(shooter.GetBulletName()); bullet.transform.position = shooter.GetPos(); bullet.transform.forward = Quaternion.AngleAxis(20 * i, Vector3.up) * vec; IBullet bulletInfo = bullet.GetComponent <IBullet>(); bulletInfo.shooter = shooter; bulletInfo.Fire(); bullets[i] = bulletInfo; bulletInfo.speed = 5.0f; } if (count % 2 == 0) { for (int j = 0; j < 18; j++) { GameObject bullet = BulletUtil.LoadBullet("米粒"); bullet.transform.position = shooter.GetPos(); bullet.transform.forward = Quaternion.AngleAxis(20 * j, Vector3.up) * vec1; IBullet bulletInfo = bullet.GetComponent <IBullet>(); bulletInfo.shooter = shooter; bulletInfo.speed = 5; bulletInfo.Fire(); } vec1 = Quaternion.AngleAxis(10, Vector3.up) * vec1; } }
IEnumerator ZZShotgun() { for (int i = 0; i < 4; i++) { Vector3 vec = new Vector3(0, 0, 1); Vector3 flowerVec = new Vector3(0, 0, 1); flowerVec = Quaternion.AngleAxis(Random.Range(0, 36) * 10, Vector3.up) * vec; for (int j = 0; j < 7; j++) { GameObject bullet; bullet = BulletUtil.LoadBullet(shooter.GetBulletName()); bullet.transform.position = shooter.GetPos(); bullet.transform.forward = Quaternion.AngleAxis(10 * j, Vector3.up) * flowerVec; IBullet bulletInfo = bullet.GetComponent <IBullet>(); bulletInfo.shooter = shooter; bulletInfo.speed = 1.5f; bulletInfo.Fire(); } yield return(new WaitForSeconds(2.0f)); } }
private void HaveAttacked(SolidBody attacked, Vec2 position, float angle, IBullet bullet) { PointF locationObject = attacked.Shape.Location; ulong idParent = (Parent as Weapon).Owner.ID; float newDistance = VectorMethod.DefineDistance(position, new Vec2(locationObject.X, locationObject.Y)); Parent.Model.AddOutgoingMessage(new MakedShot(idParent, angle, newDistance)); if (attacked == null) { return; } var damageMsg = new GotDamage(idParent, bullet.Damage); attacked.Parent.Update(damageMsg); //определяем убили ли мы противника Healthy healthyAttacked = attacked.Parent.Components.GetComponent <Healthy>(); if (healthyAttacked == null) { return; } //если убили засчитываем фраг if (healthyAttacked.HP < bullet.Damage) { (Parent as Weapon).Owner.Update(new MakedKill(idParent)); } }
IEnumerator ZZShotgun() { Vector3[] bulletsPos = new Vector3[20]; float distance = 0.4f; Vector3 vec = new Vector3(0, 0, 1); for (int a = 0; a < 1; a++) { for (int i = 0; i < 20; i++) { bulletsPos[i] = shooter.GetPos() + Quaternion.AngleAxis(18 * i, Vector3.up) * vec * distance; distance += 0.2f; } for (int i = 0; i < 20; i++) { for (int j = -8; j < 29; j++) { GameObject bullet2 = BulletUtil.LoadBullet(shooter.GetBulletName()); bullet2.transform.position = bulletsPos[i]; bullet2.transform.forward = Quaternion.AngleAxis(10 * j, Vector3.up) * vec; IBullet bulletInfo2 = bullet2.GetComponent <IBullet>(); bulletInfo2.shooter = shooter; bulletInfo2.Fire(); bulletInfo2.speed = 3.0f; } yield return(new WaitForSeconds(0.1f)); } } }
private IBullet GetOrCreateBullet() { IBullet bullet = null; try { bullet = _bullets.Dequeue(); } catch (Exception) { // ignore } if (bullet != null) { return(bullet); } var bulletGameObject = UnityEngine.Object.Instantiate(_weaponData.BulletPrefab, Vector3.zero, Quaternion.identity); bullet = bulletGameObject.GetComponent <IBullet>(); bullet.BulletRecycle += OnBulletRecycle; return(bullet); }
public IBullet Spawn(Vector3 position, Quaternion rotation, IBullet prefab) { int key = prefab.GetHashCode(); bool hasKey = BulletPool.ContainsKey(key); List <IBullet> bullets = new List <IBullet>(); if (hasKey) { bullets = BulletPool[key]?.Where(b => b.gameObject.activeSelf == false).ToList(); } else { BulletPool.Add(key, bullets); } if (!hasKey || bullets.Count() == 0) { GameObject newBulletObject = Instantiate(prefab.gameObject, position, rotation); IBullet newBullet = newBulletObject.GetComponent <IBullet>(); BulletPool[key].Add(newBullet); return(newBullet); } IBullet bullet; bullet = bullets.First(); bullet.gameObject.SetActive(true); bullet.transform.position = position; bullet.transform.rotation = rotation; return(bullet); }
/// <summary> /// Removes the bullet from the SolarSystem. /// </summary> /// <param name="bullet">The removing SolarSystem.</param> public void RemoveIBullet(IBullet bullet) { if (bulletDict.ContainsKey(bullet.Name)) { bulletDict.Remove(bullet.Name); } }
protected override void AddBullets(Vector launchPosition) { IBullet bullet = Ammo.Create(launchPosition); ImbueBullet(bullet); BulletAdder(bullet); }
public IBullet GetBullet() { IBullet bulletToShoot = bulletManager.GetBullet(BulletID); bulletToShoot.gameObject.transform.position = ShootStartPosition.position; bulletToShoot.OnDestroy += OnBulletDestroy; return(bulletToShoot); }
private float AddShield(IBullet bullet) { if (bullet.bulletType == BulletType.bullet || bullet.bulletType == BulletType.bustBullet) { return(0); } return(bullet.damage * currentShildStats.damageResist); }
public string Fire(IBullet Bullet) { if (Bullet.Caliber == Caliber) { return(Bullet.Fire()); } return("improper caliber"); }
void RightDiagonalMoving(IBullet bullet) { Vector3 distanceUp = new Vector3(bullet.MoveSpeed * Time.fixedDeltaTime, bullet.MoveSpeed * Time.fixedDeltaTime, 0); Vector3 distanceDown = new Vector3(-bullet.MoveSpeed * Time.fixedDeltaTime, -bullet.MoveSpeed * Time.fixedDeltaTime, 0); Vector2 newBulletPosition = bullet.Aim == Team.Enemy ? bullet.GameObject.transform.position + distanceUp : bullet.GameObject.transform.position + distanceDown; bullet.RigidBody2D.MovePosition(Vector2.MoveTowards(bullet.GameObject.transform.position, newBulletPosition, 1f)); }
protected override void SetReferences() { transform = instance.transform; rigidbody2D = instance.GetComponent <Rigidbody2D>(); spriteRenderer = instance.GetComponent <SpriteRenderer>(); bullet = instance.GetComponent <IBullet>(); bullet.bulletPoolObject = this; }
private void OnBulletDestroy(IBullet bullet) { if (!BulletDestroyer) { return; } GameObject.Destroy(bullet.gameObject); }
public Clip(IBullet Bullet, int Capacity) { Bullets = new Stack <IBullet>(Capacity); for (int i = 0; i < Capacity; i++) { Bullets.Push(Bullet); } }
private void OnBulletDestroy(IBullet bullet) { if (!BulletDestroyer) { return; } bullet.DestroyBehaviour(); }
public void Fire() { animator.Play("fire"); IBullet bullet = BulletManager.Instance.Spawn(BarrelEnd.position, transform.rotation, bulletPrefab); bullet.Fire(); GunFireParticles.ForEach(p => p.Play()); }
/// <summary> /// Inserts the bullet to the SolarSystem. /// </summary> /// <param name="bullet">The inserting bullet.</param> public void AddIBullet(IBullet bullet) { if (!bulletDict.ContainsKey(bullet.Name)) { bulletDict.Add(bullet.Name, bullet); bullet.ChangeVisible(active); } }
public override bool OnHit(IBullet bullet) { if (bullet.Group == GroupType.Players) { AudioManager.s_Instance.PlayFxClip(AudioManager.AudioClipType.EnvironmentHit); } return(true); }
public BulletView(IBullet bullet, Texture2D texture) { if (bullet == null) throw new ArgumentNullException("bullet"); if (texture == null) throw new ArgumentNullException("texture"); _bullet = bullet; _bullet.Destroyed += BulletOnDestroyed; _texture = texture; _bodyTextureCenter = new Vector2(_texture.Width, _texture.Height) / 2; }
void Start() { mGui = guiMain; mKeyboardInput = kbInput; mPlayer = player; mBullet = bullet; mPlayer.BulletRefresh(mBullet); mPlayerCtrl = new PlayerCtrl(mPlayer, camera, Setting.PLAYER_SPEED); mEngine = new Engine(); mKeyboardInput.Init(mPlayerCtrl); mGui.Init(mPlayerCtrl, mEngine); }
private void OnShootted(IBullet e) { EventHandler<IBullet> handler = Shootted; if (handler != null) { handler(this, e); } }
public IView Create(IBullet bullet) { return new BulletView(bullet, _bulletTexture); }
/// <summary> /// Gets damage to hitted target from bullet. /// </summary> /// <param name="bullet">The bullet that hit the target.</param> /// <param name="hittedObject">The object that is hit.</param> public void BulletHit(IBullet bullet, IGameObject hittedObject) { hittedObject.TakeDamage(damageCounter.CountDamage(hittedObject, bullet)); }
/// <summary> /// Randomize bullet attack power and count real damage. The result is returned if it is greater than 0. When the result /// is lower then 0 so function returns 0 (attack cannot "heal"). /// </summary> /// <param name="gameObject">The object which defends itself.</param> /// <param name="bullet">The bullet that hit the object.</param> /// <returns>Calculated damage when it is greater then 0.</returns> public int CountDamage(IGameObject gameObject, IBullet bullet) { var damage = GetRandomizeAttack(bullet.Attack) - gameObject.DeffPower; return damage > 0 ? damage : 0; }