private void MakeBullet(BulletDirection bulletDirection, int bulletNum) { for (int i = 0; i < bulletNum; i++) { Bullet bullet = bulletPool.GetItem(); Vector3 dir = Vector3.one; switch (bulletDirection) { case BulletDirection.Up: dir = Vector3.up; break; case BulletDirection.Down: dir = Vector3.down; break; case BulletDirection.Left: dir = Vector3.left; break; case BulletDirection.Right: dir = Vector3.right; break; } bullet.Initialize(this.transform.position, dir, i * 0.3f, BulletType.EnemyBullet, 1f, 1, 999f); bullet.SetMoveLifetime(1f); bullet.SetDestroyByCollision(false); allBulletList.Add(bullet); } }
public void Use(GameObject user) { Enemy_AI aI = GameObject.Find("Enemy").GetComponent <Enemy_AI>(); CoolDownManager aiCDMaganger = GameObject.Find("Enemy").GetComponent <CoolDownManager>(); Skill ba = new BasicAttack(); if (user == GameObject.Find("Player") && !Skill_Handler.isBroken && skill_Handler.QSlot.cdEnd && skill_Handler.state == Skill_Handler.ButtonState.qActive) { playerShot = true; BulletDirection thisBullet = Instantiate(Bullet, firepoint.position, Quaternion.identity); thisBullet.gameObject.name = "PlayerBullet"; skill_Handler.QSlot.CoolDownCounter(CreatePlayer.chosenShip.QSkill, skill_Handler.qSkillSlot); } if (user == GameObject.Find("Enemy") && !aI.isBroken && cdEnd) { BulletDirection thisBullet = (BulletDirection)Instantiate(Bullet, firepoint.position, Quaternion.identity); thisBullet.transform.rotation = Quaternion.Euler(0, 180f, 0); thisBullet.gameObject.name = "EnemyBullet"; thisBullet.EnemyShot(); if (Circle_Move_Behaviour.enemyCircleMove) { ba.SkillCoolDown = 1; } StartCoroutine(SimpleCoolDown(CreateEnemy.EnemyShip.QSkill.SkillCoolDown)); } }
/// <summary> /// Creates a new shotgun bullet /// </summary> /// <param name="content">A ContentManager to load content from</param> /// <param name="position">The starting position of the bullet</param> /// <param name="bulletDirection"></param> public ShotgunBullet(uint id, ContentManager content, Vector2 position, BulletDirection bulletDirection) : base(id) { this.spriteSheet = content.Load<Texture2D>("Spritesheets/newsh(.shp.000000"); direction = bulletDirection; this.spriteBounds = new Rectangle(146, 99, 7, 13); // Sets the velocity based on the direction the bullet should be headed in if (bulletDirection == BulletDirection.Right) this.velocity = new Vector2(100, -500); else if (bulletDirection == BulletDirection.Left) this.velocity = new Vector2(-100, -500); else if (bulletDirection == BulletDirection.HardLeft) this.velocity = new Vector2(-200, -400); else if (bulletDirection == BulletDirection.HardRight) this.velocity = new Vector2(200, -400); else this.velocity = new Vector2(0, -600); this.position = position; }
public override void InitBullet(Vector3 _positionStart, BulletDirection _direction) { //Khởi tạo ban đầu của đạn gồm một số thông số: // + Hướng di chuyển của đạn // + Rotate hình // + Thay đổi giá trị tốc độ di chuyển của đạn gameObject.transform.parent.localPosition = _positionStart; direction = _direction; //Rotate(90); switch (direction) { case BulletDirection.LEFT: { speedCurrent = -speed; FlipHorizontal(180); break; } case BulletDirection.RIGHT: { speedCurrent = speed; FlipHorizontal(0); break; } case BulletDirection.NONE: { speedCurrent = 0; FlipHorizontal(0); break; } } // Rotate(-90); rangeBullet.enemyInBoxs.Clear(); }
public void CreateBullet(Vector3 startingPosition, BulletDirection bulletDirection) { GameObject go = Utility.InstantiatePrefab(prefab, content, startingPosition); BulletGUI bulletGUI = go.GetComponent <BulletGUI>(); bulletGUI.Initialize(bulletDirection); }
public virtual void InitBullet() { //Khởi tạo ban đầu của đạn gồm một số thông số: // + Hướng di chuyển của đạn // + Rotate hình // + Thay đổi giá trị tốc độ di chuyển của đạn isCritDamge = false; direction = BulletDirection.LEFT; gameObject.transform.localPosition = Vector3.zero; switch (direction) { case BulletDirection.LEFT: { speedCurrent = -speed; FlipHorizontal(0); break; } case BulletDirection.RIGHT: { speedCurrent = speed; FlipHorizontal(-180); break; } case BulletDirection.NONE: { speedCurrent = 0; FlipHorizontal(0); break; } } }
public void Gravitate() { colliders = Physics2D.OverlapCircleAll(this.transform.position, 100); foreach (Collider2D hit in colliders) { switch (PlayerShot) { case true: if (hit.gameObject.name == "EnemyBullet") { thisBullet = hit.GetComponent <BulletDirection>(); if (holeDestroyed) { thisBullet.DestroyWithHole(); } thisBullet.lighningOnce = true; // prevent Electric Charge hit applyForce(thisBullet.gameObject); } if (hit.gameObject.name == "EnemyMissile") { thisMissile = hit.GetComponent <Missile>(); thisMissile.lighningOnce = true; if (holeDestroyed) { thisMissile.DestroyWithHole(); } applyForce(thisMissile.gameObject); } break; case false: if (hit.gameObject.name == "PlayerBullet") { thisBullet = hit.GetComponent <BulletDirection>(); if (holeDestroyed) { thisBullet.DestroyWithHole(); } thisBullet.lighningOnce = true; applyForce(thisBullet.gameObject); } if (hit.gameObject.name == "PlayerMissile") { thisMissile = hit.GetComponent <Missile>(); thisMissile.lighningOnce = true; if (holeDestroyed) { thisMissile.DestroyWithHole(); } applyForce(thisMissile.gameObject); } break; } } }
private IEnumerator ShootSecond(float t, GameObject user) { yield return(new WaitForSecondsRealtime(t)); BulletDirection Bullet2 = Instantiate(thisBullet, transform.position, Quaternion.identity); if (user == Enemy) { Bullet2.EnemyShot(); } }
public override void SetSpeed(int isRight) { base.SetSpeed(isRight); if(isRight == 1) { bulletDirection = BulletDirection.RIGHT; } else { bulletDirection = BulletDirection.LEFT; } }
public PlayerBullet(Vector2 position, BulletDirection direction) : base(position) { texture = Engine.Instance.Content.Load <Texture2D>("Bullet"); this.Tag((int)GameTags.Bullet); this.Collider = new Hitbox(10, 10); this.Visible = true; this.direction = direction; }
public virtual void CreateBullet(Vector3 _positionStart, BulletDirection _direction) { //Kiem tra sung con dan khong //Neu sung het dan tihi khoa lai va goi ham thay dan /*if (numberBulletMax <= 0) { Debug.Log("Vao 1"); return 0; //Dung ban, da het dan //Doi sang sung khac }/* else if (numberBulletCurrent <= 0 && !this.isInsteadOfBullet ) { this.isInsteadOfBullet = true; Debug.Log("Vao 2"); Invoke("InsteadOfBullets", timeInsteadOfBullets); return 1; } else */ if(this.isShoot && this.enableGun) { GameObject bulletObject = PoolObject.Instance.SpawnObject(bulletPrefab, "Bullet"); Bullet bullet = bulletObject.GetComponent<Bullet>(); bullet.InitBullet(_positionStart, _direction); bullet.ResetProperties(); //bullet.SetDamge(this.damge); float _damge = RandomCritDamge(bullet); bullet.SetDamge(_damge); switch (gunOfObjectType) { case GunOfObjectType.PLAYER: bullet.SetBulletOfObjectType(BulletOfObjectType.PLAYER); break; case GunOfObjectType.ENEMIES: bullet.SetBulletOfObjectType(BulletOfObjectType.ENEMIES); break; case GunOfObjectType.TOWER: bullet.SetBulletOfObjectType(BulletOfObjectType.TOWER); break; case GunOfObjectType.BOSS: break; case GunOfObjectType.OTHER: break; default: break; } this.isShoot = false; this.numberBulletCurrent -= 1; Invoke("AllowShoot", timeRespawnShoot); } }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { var data = new BulletOrigin { origin = math.float3(transform.position) }; dstManager.AddComponentData(entity, data); var data2 = new BulletDirection { direction = math.float3(direction) }; dstManager.AddComponentData(entity, data2); }
void SetBulletDirection() { dir = (BulletDirection)Random.Range(0, 2); if (dir == BulletDirection.LEFT) { startBullet = new Vector3(gameObject.transform.position.x - gameObject.GetComponent <Collider>().bounds.size.x / 2 - 1, 0.0f, gameObject.transform.position.z); changeDir = false; } else if (dir == BulletDirection.RIGHT) { startBullet = new Vector3(gameObject.transform.position.x + gameObject.GetComponent <Collider>().bounds.size.x / 2 + 1, 0.0f, gameObject.transform.position.z); changeDir = true; // Bullet.MirrorSpeed(true); } shoted = false; }
/// <summary> /// Starts the bullet moving in the given direction /// </summary> /// <param name="direction">movement direction</param> public void StartMoving(BulletDirection direction) { // apply impulse force to get projectile moving int forceSignal = 1; Vector3 forceVector = defaultForceVector; switch (direction) { case BulletDirection.Up: forceVector = Quaternion.AngleAxis(90, Vector3.forward) * forceVector; break; case BulletDirection.Down: forceVector = Quaternion.AngleAxis(-90, Vector3.forward) * forceVector; break; case BulletDirection.Random: forceVector = Quaternion.AngleAxis(Random.Range(-120, -60), Vector3.forward) * forceVector; break; case BulletDirection.UpLeftLayer1: forceVector = Quaternion.AngleAxis(105, Vector3.forward) * forceVector; changeDirectionLayer1Timer.Run(); break; case BulletDirection.UpLeftLayer2: forceVector = Quaternion.AngleAxis(120, Vector3.forward) * forceVector; changeDirectionLayer2Timer.Run(); break; case BulletDirection.UpRightLayer1: forceVector = Quaternion.AngleAxis(75, Vector3.forward) * forceVector; changeDirectionLayer1Timer.Run(); break; case BulletDirection.UpRightLayer2: forceVector = Quaternion.AngleAxis(60, Vector3.forward) * forceVector; changeDirectionLayer2Timer.Run(); break; default: break; } bulletSprite.flipX = forceSignal == -1; rb2d.AddForce(forceVector * forceSignal, ForceMode2D.Impulse); }
Vector3 rotation(BulletDirection dir) { Vector3 rotationAngle = Vector3.zero; if (dir == BulletDirection.Up) { rotationAngle.z = 90; } else if (dir == BulletDirection.Left) { rotationAngle.z = 180; } else if (dir == BulletDirection.Down) { rotationAngle.z = 270; } return(rotationAngle); }
public MissileEntity(float x, float y, BulletDirection bulletDirection) { _bulletDirection = bulletDirection; var projectilePath = (bulletDirection == BulletDirection.Up) ? @".\Assets\Graphics\PlayerProjectile256.png" : @".\Assets\Graphics\AlienProjectile256.png"; var animation = new Spritemap<string>(projectilePath, 256, 256); animation.Add("firing", new[] { 0, 1 }, new[] { 5f, 5f }); animation.Play("firing"); SetGraphic(animation); SetCollider(_hitBox); animation.OriginX = 0; animation.OriginY = 0; X = x; Y = y; }
public void Initialize(BulletDirection direction) { gameObject.SetActive(true); destroyTime = Utility.gameManager.getBulletDestroyTime(); if (direction == BulletDirection.Right) { yMultiplier = 0; } if (direction == BulletDirection.TopRight) { yMultiplier = 1; } if (direction == BulletDirection.BottomRight) { yMultiplier = -1; } Destroy(gameObject, destroyTime); }
private void Shoot() { if (state == State.shooting) { if (!playerShot) { BulletDirection Bullet1 = Instantiate(thisBullet, transform.position, Quaternion.Euler(0, 180, 0)); Missile newMissile = Instantiate(thisMissile, this.transform.position, Quaternion.Euler(0, 180, 0)); Bullet1.EnemyShot(); StartCoroutine(ShootSecond(1, Enemy)); newMissile.EnemyShot(); StartCoroutine(newMissile.GetOutState(Player)); } else { BulletDirection newBullet = Instantiate(thisBullet, transform.position, Quaternion.identity); Missile newMissile = Instantiate(thisMissile, this.transform.position, Quaternion.identity); StartCoroutine(ShootSecond(1, Player)); StartCoroutine(newMissile.GetOutState(Enemy)); } state = State.wait; } }
/// <summary> /// Creates a new shotgun bullet /// </summary> /// <param name="content">A ContentManager to load content from</param> /// <param name="position">The starting position of the bullet</param> /// <param name="bulletDirection"></param> public BlimpShotgun(uint id, ContentManager content, Vector2 position, BulletDirection bulletDirection) : base(id) { this.spriteSheet = content.Load <Texture2D>("Spritesheets/newsh(.shp.000000"); direction = bulletDirection; this.spriteBounds = new Rectangle(146, 99, 7, 13); // Sets the velocity based on the direction the bullet should be headed in if (bulletDirection == BulletDirection.Right) { this.velocity = new Vector2(-100, 500); } else if (bulletDirection == BulletDirection.Left) { this.velocity = new Vector2(100, 500); } else if (bulletDirection == BulletDirection.HardLeft) { this.velocity = new Vector2(200, 400); } else if (bulletDirection == BulletDirection.HardRight) { this.velocity = new Vector2(-200, 400); } else { this.velocity = new Vector2(0, 600); } this.position = position; }
/// <summary> /// Конструктор /// </summary> /// <param name="pos">Позиция пули</param> /// <param name="dir">Направление\Скорость полета пули</param> /// <param name="size">Размер пули</param> /// <param name="D">Направление полета объекта</param> /// <param name="col">Цвет пули</param> public Bullet(Point pos, Point dir, Size size, BulletDirection D, Color col) : base(pos, dir, size) { Direction = dir; CurrentDirection = D; color = col; }
/// <summary> /// Shoots bullets depending on the bulletLevel of the ship /// </summary> void ShootBullet() { GameObject[] bullets = null; Vector2[] bulletPos = null; BulletDirection[] bulletDirection = null; //Prepares the necessary variables switch (bulletLevel) { case 0: //Creates the bullet vector bullets = ObjectPool.GetPlayerBullets(1); //Positions the bullets at the right places bulletPos = new Vector2[bullets.Length]; bulletPos[0] = gameObject.transform.position; bulletPos[0] += GameConstants.ShipBulletOffset["Central1"]; //Sets the shooting direction bulletDirection = new BulletDirection[bullets.Length]; bulletDirection[0] = BulletDirection.Up; break; case 1: //Creates the bullet vector bullets = ObjectPool.GetPlayerBullets(3); //Positions the bullets at the right places bulletPos = new Vector2[bullets.Length]; bulletPos[0] = gameObject.transform.position; bulletPos[0] += GameConstants.ShipBulletOffset["Central1"]; bulletPos[1] = gameObject.transform.position; bulletPos[1] += GameConstants.ShipBulletOffset["Central2"]; bulletPos[2] = gameObject.transform.position; bulletPos[2] += GameConstants.ShipBulletOffset["Central3"]; //Sets the shooting direction bulletDirection = new BulletDirection[bullets.Length]; bulletDirection[0] = BulletDirection.Up; bulletDirection[1] = BulletDirection.Up; bulletDirection[2] = BulletDirection.Up; break; case 2: //Creates the bullet vector bullets = ObjectPool.GetPlayerBullets(5); //Positions the bullets at the right places bulletPos = new Vector2[bullets.Length]; bulletPos[0] = gameObject.transform.position; bulletPos[0] += GameConstants.ShipBulletOffset["Central1"]; bulletPos[1] = gameObject.transform.position; bulletPos[1] += GameConstants.ShipBulletOffset["Central2"]; bulletPos[2] = gameObject.transform.position; bulletPos[2] += GameConstants.ShipBulletOffset["Central3"]; bulletPos[3] = gameObject.transform.position; bulletPos[3] += GameConstants.ShipBulletOffset["CentralLayer1Left"]; bulletPos[4] = gameObject.transform.position; bulletPos[4] += GameConstants.ShipBulletOffset["CentralLayer1Right"]; //Sets the shooting direction bulletDirection = new BulletDirection[bullets.Length]; bulletDirection[0] = BulletDirection.Up; bulletDirection[1] = BulletDirection.Up; bulletDirection[2] = BulletDirection.Up; bulletDirection[3] = BulletDirection.UpLeftLayer1; bulletDirection[4] = BulletDirection.UpRightLayer1; break; case 3: //Creates the bullet vector bullets = ObjectPool.GetPlayerBullets(7); //Positions the bullets at the right places bulletPos = new Vector2[bullets.Length]; bulletPos[0] = gameObject.transform.position; bulletPos[0] += GameConstants.ShipBulletOffset["Central1"]; bulletPos[1] = gameObject.transform.position; bulletPos[1] += GameConstants.ShipBulletOffset["Central2"]; bulletPos[2] = gameObject.transform.position; bulletPos[2] += GameConstants.ShipBulletOffset["Central3"]; bulletPos[3] = gameObject.transform.position; bulletPos[3] += GameConstants.ShipBulletOffset["CentralLayer1Left"]; bulletPos[4] = gameObject.transform.position; bulletPos[4] += GameConstants.ShipBulletOffset["CentralLayer1Right"]; bulletPos[5] = gameObject.transform.position; bulletPos[5] += GameConstants.ShipBulletOffset["CentralLayer2Left"]; bulletPos[6] = gameObject.transform.position; bulletPos[6] += GameConstants.ShipBulletOffset["CentralLayer2Right"]; //Sets the shooting direction bulletDirection = new BulletDirection[bullets.Length]; bulletDirection[0] = BulletDirection.Up; bulletDirection[1] = BulletDirection.Up; bulletDirection[2] = BulletDirection.Up; bulletDirection[3] = BulletDirection.UpLeftLayer1; bulletDirection[4] = BulletDirection.UpRightLayer1; bulletDirection[5] = BulletDirection.UpLeftLayer2; bulletDirection[6] = BulletDirection.UpRightLayer2; break; default: break; } //Shoot bullets for (int i = 0; i < bullets.Length; i++) { bullets[i].GetComponent <Bullet>().StopMoving(); bullets[i].transform.position = bulletPos[i]; bullets[i].SetActive(true); bullets[i].GetComponent <Bullet>().StartMoving(bulletDirection[i]); } }
public SPAddBullet(short entityID, short creatorID, BulletDirection direction) { EntityID = entityID; CreatorID = creatorID; Direction = direction; }