// Update is called once per frame void Update() { #region MouseClick if (Input.GetMouseButton(0)) { if (Time.time - lastShootTime > getObjectById(selectedBullet).coolTime) { //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); Transform bullet = Instantiate(BulletProto); bullet.position = mainActor.position + mainActor.forward; bullet.GetComponent <Rigidbody>().velocity = ray.direction.normalized * getObjectById(selectedBullet).speed; bullet.tag = "Bullet"; bullet.name = selectedBullet.ToString(); bullet.localScale = getObjectById(selectedBullet).size; lastShootTime = Time.time; //Debug.Log(Tools.getMapIndexByPosition(mainActor.transform.position)); //mainActor.GetComponent<Rigidbody>().AddForce(-1 * mainActor.transform.forward * getObjectById(selectedBullet).recoil); //Bullets.Add(bullet); } } if (Input.GetMouseButton(1)) { /* * if (toolbox.isSelected() && Time.time - lastClickTime > 0.5) { * Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); * RaycastHit rch; * if (Physics.Raycast(ray, out rch)) { * Vector3 target = rch.point + rch.normal / 2; * target.x = Mathf.Round(target.x); * target.y = Mathf.Round(target.y); * target.z = Mathf.Round(target.z); * ground.instantiateItem(toolbox.deleteSeletedItem(), target); * } * lastClickTime = Time.time; * }*/ } if (Mathf.Abs(Input.GetAxis("Mouse ScrollWheel")) > 0f) { selectedBullet -= (int)Input.mouseScrollDelta.y; selectedBullet = (BulletType)((int)selectedBullet % numWeapon); if (selectedBullet < 0) { selectedBullet += numWeapon; } GameMsgControllor.showMsg(selectedBullet.ToString()); StartCoroutine("timer_2s"); } #endregion }
public static List <Bounding> InitaliseBounding(Point2D point, BulletColour bulletColour, BulletType bulletType) { List <Bounding> result = new List <Bounding>(); result.Add(new Bounding(new Point2D[] { new Point2D(point.X + (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Width / 2), point.Y - (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Height / 2)), new Point2D(point.X - (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Width / 2), point.Y - (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Height / 2)), new Point2D(point.X - (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Width / 2), point.Y + (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Height / 2)), new Point2D(point.X + (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Width / 2), point.Y + (GameResources.GameImage(bulletType.ToString() + bulletColour.ToString()).Height / 2)) })); return(result); }
public void takeBulletType(BulletType type, int count) { bullet = type.ToString(); if (count != 999) { bullet += (" Ammo:" + count); } }
string GetBulletPrefabPath(BulletType _type) { if (mapBulletPrefabPath.ContainsKey(_type) == false) { string name = _type.ToString(); mapBulletPrefabPath.Add(_type, name); } return(mapBulletPrefabPath[_type]); }
public IBullet CreateBullet(BulletType bulletType, Position position) { Type typeOfBullet = Assembly.GetExecutingAssembly().GetTypes(). FirstOrDefault(v => v.Name == bulletType.ToString()); IBullet bullet = (IBullet)Activator.CreateInstance(typeOfBullet, position); return(bullet); }
private void ShootBullet() { var bullet = _objectPooler.GetFromPool(_bulletType.ToString(), firePoint.transform.position, firePoint.rotation); var bulletRigidbody = bullet.GetComponent <Rigidbody2D>(); bulletRigidbody.velocity = Vector2.zero; bulletRigidbody.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse); bullet.GetComponent <Bullet>().StartDeactivation(); }
public void Refresh() { while (bulletsToRemoveStack.Count > 0) { Bullet toRemove = bulletsToRemoveStack.Pop(); BulletType bulletType = toRemove.bulletType; if (!bulletDict.ContainsKey(bulletType) || !bulletDict[bulletType].Contains(toRemove)) { Debug.LogError("Stack tried to remove element of type: " + bulletType.ToString() + " but was not found in dictionary?"); } else { bulletDict[bulletType].Remove(toRemove); ObjectPool.Instance.AddToPool(toRemove.bulletType.ToString(), toRemove); if (bulletDict[bulletType].Count == 0) { bulletDict.Remove(bulletType); } } } //Add Bullets to the dictionary from the "toAdd stack" while (bulletsToAddStack.Count > 0) { Bullet toAdd = bulletsToAddStack.Pop(); BulletType bulletType = toAdd.bulletType; if (!bulletDict.ContainsKey(bulletType)) // || !bulletDict[kv.Key].Contains(kv.Value)) { bulletDict.Add(bulletType, new List <Bullet>() { toAdd }); } else if (!bulletDict[bulletType].Contains(toAdd)) { bulletDict[bulletType].Add(toAdd); } else { //Spotting an error where the same monster is being initialized twice is almost impossible sometimes Debug.LogError("The bullet you are trying to add is already in the bullet dict"); } } foreach (KeyValuePair <BulletType, List <Bullet> > kv in bulletDict) { foreach (Bullet b in kv.Value) { b.Refresh(); } } }
public void SetSprite(BulletType bt) { foreach (Sprite sp in BulletSprites) { if (sp.name.Equals(bt.ToString())) { _spriteRenderer.sprite = sp; } } }
/// <summary> /// Constructs bullet entity. /// </summary> /// <param name="bulletColour">Colour of bullet.</param> /// <param name="bulletType">Type of bullet.</param> /// <param name="owner">Owner of bullet.</param> /// <param name="position">Spawn position of bullet.</param> /// <param name="trajectory">Trajectory of bullet.</param> public BulletEntity(BulletColour bulletColour, BulletType bulletType, Entity owner, Point position, Vector trajectory) : base(bulletType.ToString() + bulletColour.ToString(), InitBounding(bulletType, position, trajectory), 1) { _bulletColour = bulletColour; _bulletType = bulletType; _owner = owner; _trajectory = trajectory; _grazed = false; _movement = new Linear(trajectory); }
public void Spawn(Vector3 spawnLocation, Transform targetTransform) { if (!bulletPrefab) { return; } GameObject bullet = Instantiate(bulletPrefab, spawnLocation, Quaternion.identity); BulletControl control = bullet.GetComponent <BulletControl>(); control.ConfigureTarget(targetTransform, this); bullet.name = bulletType.ToString(); }
public void StartSpecialBehavior(BulletType BehaviorType) { StopAllCoroutines(); switch(BehaviorType){ case BulletType.Normal: break; case BulletType.SpiralIn: StartCoroutine(SpiralIn()); break; default: print("Please write special behavior code for " + BehaviorType.ToString() + "."); break; } }
public void StartSpecialBehavior(BulletType BehaviorType) { StopAllCoroutines(); switch (BehaviorType) { case BulletType.Normal: break; case BulletType.SpiralIn: StartCoroutine(SpiralIn()); break; default: print("Please write special behavior code for " + BehaviorType.ToString() + "."); break; } }
void CreateBullet(BulletType bulletType, BulletBehaviourType bulletBehaviourType, GameObject shootPosition, Team aim, float damage, Vector3 nextPos = new Vector3()) { foreach (IBullet bullet in _objectStorage.Bullets[bulletType.ToString()]) { if (!bullet.GameObject.activeSelf) { bullet.GameObject.SetActive(true); bullet.GameObject.transform.position = shootPosition.transform.position; bullet.Aim = aim; bullet.Damage = damage; bullet.BulletBehaviourType = bulletBehaviourType; bullet.Behaviour.NextPos = nextPos; bullet.Behaviour.StartPos = shootPosition.transform.position; return; } } }
void SetAppropriateBulletPool() { switch (bulletType) { case BulletType.SLOW: bulletPool = SimpleBulletPool.GetPool(SimpleBulletPool.BulletPoolType.ENEMY_SLOW); break; case BulletType.NORMAL: bulletPool = SimpleBulletPool.GetPool(SimpleBulletPool.BulletPoolType.ENEMY_NORMAL); break; case BulletType.FAST: bulletPool = SimpleBulletPool.GetPool(SimpleBulletPool.BulletPoolType.ENEMY_FAST); break; default: throw new UnityException("unknown bullet type " + bulletType.ToString()); } }
public Bullet CreateBullet(BulletType bulletType, Vector3 originPoint) { Bullet res; GameObject resObj; IPoolable poolable = ObjectPool.Instance.RetrieveFromPool(bulletType.ToString()); if (poolable != null) { resObj = poolable.GetGameObject; res = resObj.GetComponent <Bullet>(); } else { res = _CreateBullet(bulletType); resObj = res.gameObject; } resObj.transform.position = originPoint; return(res); }
public BaseBullent CreateBullet(BulletType _type) { GameObject bullet = null; switch (_type) { case BulletType.none: break; default: string name = _type.ToString(); // GameObject prefab = Resources.Load<GameObject>(GetBulletPrefabPath(_type)); bullet = poolManager.Spawn(GetBulletPrefabPath(_type)).gameObject; // GameObject.Instantiate(prefab); break; } if (bullet != null) { return(bullet.GetComponent <BaseBullent>()); } return(null); }
private void OnDisable() { UpdateHandler.UpdateOccurred -= ShootByIntervals; Debug.Log(extraBulletCount + " extra " + bulletType.ToString() + "bullet(s) instantiated"); shootState = false; }
public static Bullet GetBullet(Vector2 position, BulletType bulletType) { Queue <Bullet> availableBullets = BulletsFactory.Instance.availableBulletsByType[bulletType]; Bullet bullet = null; if (availableBullets.Count > 0) { bullet = availableBullets.Dequeue(); } if (bullet == null) { // Instantiate a new bullet. bullet = InstantiateBullet(bulletType); Debug.Log("Number of bullet instantiated = " + BulletsFactory.Instance.bulletCount + "\n" + bulletType.ToString()); } bullet.Position = position; bullet.gameObject.SetActive(true); return(bullet); }
public void Initialize(BulletType bulletType, int bulletDamage, float Velocity, float size, float Lifetime, Color bulletColor, int playerNum, Character character) { type = bulletType; damage = bulletDamage; reflectiveShot = false; transform.localScale = new Vector3(size, size, size); gameObject.tag = bulletType.ToString(); velocity = Velocity * velocityMultiplier; playerPathString = string.Concat(character.ToString(), playerNum == 0 ? "" : "Alt"); if (velocity == 0) { velocity = 5f; } Vector3 tempVector = Quaternion.AngleAxis(gameObject.transform.rotation.eulerAngles.z, Vector3.forward) * new Vector3(velocity, 0, 0); travelVector = new Vector2(tempVector.x, tempVector.y); lifetime = Lifetime; gameObject.layer = 8 + playerNum; myCollidersObj = GameObject.Find("BulletColliders"); myPolys = myCollidersObj.GetComponents <PolygonCollider2D>(); switch (type) { case BulletType.Boomerang: if (character == Character.Bastet) { bulletFunction = StraightLogic; transform.Rotate(new Vector3(0f, 0f, -90f)); travelVector *= -1; } else if (character == Character.Loholt) { bulletFunction = StraightLogic; reflectiveShot = true; travelVector *= -1; Lifetime = 100; // add custom collider, gameObject.GetComponent <CircleCollider2D>().enabled = false; myPoly = gameObject.GetComponent <PolygonCollider2D>(); myPoly.points = myPolys[2].points; myPoly.isTrigger = true; myPoly.enabled = true; } else { bulletFunction = IndirectLogic; } // add custom collider, if (character == Character.Orpheus) { gameObject.GetComponent <CircleCollider2D>().enabled = false; myPoly = gameObject.GetComponent <PolygonCollider2D>(); myPoly.points = myPolys[3].points; myPoly.isTrigger = true; myPoly.enabled = true; } // add custom collider, if (character == Character.Hiruko) { gameObject.GetComponent <CircleCollider2D>().enabled = false; myPoly = gameObject.GetComponent <PolygonCollider2D>(); myPoly.points = myPolys[4].points; myPoly.isTrigger = true; myPoly.enabled = true; } // add custom collider, if (character == Character.Bastet) { gameObject.GetComponent <CircleCollider2D>().enabled = false; myPoly = gameObject.GetComponent <PolygonCollider2D>(); myPoly.points = myPolys[5].points; myPoly.isTrigger = true; myPoly.enabled = true; } sprite = Resources.Load <Sprite>(string.Concat("sprites/weapons/", playerPathString, "/Boomerang")); headingTime = 0f; //indirectHomingLimit = 10f; // how long it tracks foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player")) { if (player.layer != gameObject.layer) { target = player.transform; } } break; case BulletType.Knife: sprite = Resources.Load <Sprite>(string.Concat("sprites/weapons/", playerPathString, "/Knife")); // TODO: change this transform.Rotate(new Vector3(0f, 0f, -90f)); //transform.rotation = new Vector3(0f, 0f, -90.0f); bulletFunction = StraightLogic; if (character == Character.Loholt) // add custom collider { //Destroy(gameObject.GetComponent<Collider2D>()); gameObject.GetComponent <CircleCollider2D>().enabled = false; myPoly = gameObject.GetComponent <PolygonCollider2D>(); myPoly.points = myCollidersObj.GetComponent <PolygonCollider2D>().points; myPoly.isTrigger = true; myPoly.enabled = true; } //Debug.Log("in here"); break; // Shield situation default: sprite = Resources.Load <Sprite>(string.Concat("sprites/weapons/", playerPathString, "/Shield")); bulletFunction = SlowShotLogic; GetComponent <CircleCollider2D>().radius = 0.5f; lifetime = Lifetime / 1.5f; //lifetime = Lifetime / 0.25f; tempVector = Quaternion.AngleAxis(gameObject.transform.rotation.eulerAngles.z, Vector3.forward) * new Vector3(velocity, 0, 0); travelVector = new Vector2(tempVector.x, tempVector.y); //create polygon colider if (character == Character.Loholt) // add custom collider, trying it on loholt { gameObject.GetComponent <CircleCollider2D>().enabled = false; myPoly = gameObject.GetComponent <PolygonCollider2D>(); myPoly.points = myPolys[1].points; myPoly.isTrigger = true; myPoly.enabled = true; } break; } //renderer.sprite = sprite; GetComponentInChildren <SpriteRenderer>().sprite = sprite; }
/// <summary> /// Constructor for bullet class. /// </summary> /// <param name="position">Inital position of the bullet.</param> /// <param name="velocity">Inital velosity of the bullet.</param> /// <param name="drawDirection">Direction to draw the bullet.</param> /// <param name="bulletColour">Colour of the bullet</param> /// <param name="bulletType">Type of the bullet</param> /// <param name="owner">Owner of the bullet</param> public BulletEntity(Point2D position, Velocity2D velocity, double drawDirection, BulletColour bulletColour, BulletType bulletType, Entity owner) : base(position, InitaliseBounding(position, bulletColour, bulletType), 1, bulletType.ToString() + bulletColour.ToString()) { _owner = owner; _drawDirection = drawDirection; _bulletColour = bulletColour; _bulletType = bulletType; _movement = new VectorMovement(velocity); }
public void SetNumberingFormat(int numberingId, int levelIndex, BulletType bulletType) { if (IsOutsideOfListNumberingId(numberingId)) { throw new InvalidOperationException("Outside of the list."); } if (levelIndex < 0) { throw new ArgumentOutOfRangeException(nameof(levelIndex), levelIndex, "The level index is must be greater than equal 0."); } var oxmlLevel = GetLevelElement(numberingId, levelIndex); switch (bulletType) { case BulletType.Ordered: oxmlLevel.NumberingFormat.Val.Value = NumberFormatValues.Decimal; oxmlLevel.LevelText.Val.Value = "%1."; oxmlLevel.NumberingSymbolRunProperties.RunFonts.Ascii = null; oxmlLevel.NumberingSymbolRunProperties.RunFonts.HighAnsi = null; oxmlLevel.NumberingSymbolRunProperties.RunFonts.ComplexScript = null; break; case BulletType.Unordered: // Use default values. break; default: throw new NotImplementedException(string.Format("Unknown bullet type: {0}", bulletType.ToString())); } }
public void takeBulletType(BulletType type, int count) { bullet = type.ToString(); if (count != 999) bullet += (" Ammo:" + count); }
protected void SetLayer() { this.gameObject.layer = LayerMask.NameToLayer(bulletType.ToString()); }
public Bullet CreateBullet(BulletType type, Vector3 pos, Vector3 direction) { contents.CreateInstance <Bullet>(type.ToString()).Init(pos, direction); return(null); }