private bool CanShoot() { int numberOfAmmunition = ammunition; if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { numberOfAmmunition += ammunitionLeft; } return Time.time - lastShootTime > shootTimeInterval && numberOfAmmunition != GunsConstants.EmptyMagazine(); }
private void CreateGuns() { Gun Pistol = new Gun(); Pistol.Type = GunType.Pistol; Pistol.AmmunitionLeft = GunsConstants.InfinityAmmunition();; Pistol.Ammunition = 7; Gun Submachinegun = new Gun(); Submachinegun.Type = GunType.SubMachinegun; Submachinegun.AmmunitionLeft = GunsConstants.EmptyMagazine(); Submachinegun.Ammunition = GunsConstants.EmptyMagazine(); Gun Machinegun = new Gun(); Machinegun.Type = GunType.Machinegun; Machinegun.AmmunitionLeft = GunsConstants.EmptyMagazine(); Machinegun.Ammunition = GunsConstants.EmptyMagazine(); guns = new Gun[3]; guns[GunsConstants.PistolGunType()] = Pistol; guns[GunsConstants.SubmachinegunGunType()] = Submachinegun; guns[GunsConstants.MachinegunGunType()] = Machinegun; }
public bool HasAmmoLeft() { int numberOfAmmunition = ammunition; if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { numberOfAmmunition += ammunitionLeft; } return numberOfAmmunition == GunsConstants.EmptyMagazine() ? false : true; }
public void AddMachinegunAmmo() { if (guns[GunsConstants.MachinegunGunType()].AmmunitionLeft == GunsConstants.EmptyMagazine() && guns[GunsConstants.MachinegunGunType()].Ammunition == GunsConstants.EmptyMagazine()) { guns[GunsConstants.MachinegunGunType()].Ammunition = GunsConstants.MachinegunMagazineCapacity(); guns[GunsConstants.MachinegunGunType()].AmmunitionLeft = GunsConstants.MachineStartAmmunitionLeftQuantity(); } else if (guns[GunsConstants.MachinegunGunType()].Ammunition == GunsConstants.EmptyMagazine()) { guns[GunsConstants.MachinegunGunType()].Ammunition += GunsConstants.MachinegunMagazineCapacity(); guns[GunsConstants.MachinegunGunType()].AmmunitionLeft += GunsConstants.MachinegunMagazineCapacity(); } else { guns[GunsConstants.MachinegunGunType()].AmmunitionLeft += GunsConstants.MachineStartAmmunitionLeftQuantity(); } if (guns[GunsConstants.MachinegunGunType()].Ammunition > GunsConstants.MachinegunMagazineCapacity()) { guns[GunsConstants.MachinegunGunType()].Ammunition = GunsConstants.MachinegunMagazineCapacity(); } if (guns[GunsConstants.MachinegunGunType()].AmmunitionLeft > GunsConstants.MachinegunTotalAmmunitionCapacity()) { guns[GunsConstants.MachinegunGunType()].AmmunitionLeft = GunsConstants.MachinegunTotalAmmunitionCapacity(); } }
public void BasicEnemyGun () { ammunition = 7; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 5; // seconds lastShootTime = 0; shootTimeInterval = 1.5f; isReloading = false; reloadingTime = 0.1f; owner = GunOwner.Enemy; }
public void MediumEnemyGun () { magazineCapacity = 20; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 8; // seconds lastShootTime = 0; shootTimeInterval = 1.2f; isReloading = false; reloadingTime = 0.1f; owner = GunOwner.Enemy; }
public void PistolGun () { magazineCapacity = 7; ammunition = magazineCapacity; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 1.6f; // seconds lastShootTime = 0; shootTimeInterval = 0.7f; isReloading = false; owner = GunOwner.Player; }
public void SuperEnemyGun() { magazineCapacity = 30; ammunition = magazineCapacity; ammunitionLeft = GunsConstants.InfinityAmmunition(); reloadingTime = 5; // seconds lastShootTime = 0; shootTimeInterval = 0.9f; isReloading = false; reloadingTime = 0.1f; owner = GunOwner.Enemy; }
public void Reload() { if ( Time.time - startReloadingTime > reloadingTime) { ammunition = magazineCapacity; if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { ammunitionLeft -= ammunition; } isReloading = false; if (owner == GunOwner.Player) { GameHUDManager.instance.HideReloadingText(); GameHUDManager.instance.SetAmmoText(Ammunition, AmmunitionLeft); } } }
void Start () { isReloading = false; if (owner == GunOwner.Player) { GameHUDManager.instance.HideReloadingText(); } if (Ammunition == GunsConstants.EmptyMagazine()) { isReloading = true; startReloadingTime = Time.time; Reload(); } audio.clip = audioClip; }
public void Restart() { if (guns == null || guns.Length == 0) { CreateGuns(); } guns[GunsConstants.PistolGunType()].Ammunition = 7; guns[GunsConstants.SubmachinegunGunType()].AmmunitionLeft = GunsConstants.EmptyMagazine(); guns[GunsConstants.SubmachinegunGunType()].Ammunition = GunsConstants.EmptyMagazine(); guns[GunsConstants.MachinegunGunType()].AmmunitionLeft = GunsConstants.EmptyMagazine(); guns[GunsConstants.MachinegunGunType()].Ammunition = GunsConstants.EmptyMagazine(); playerLives = 1; }
public Gun CurrentGun() { if (guns[GunsConstants.MachinegunGunType()].AmmunitionLeft + guns[GunsConstants.MachinegunGunType()].Ammunition > GunsConstants.EmptyMagazine()) { return(guns[GunsConstants.MachinegunGunType()]); } else if (guns[GunsConstants.SubmachinegunGunType()].AmmunitionLeft + guns[GunsConstants.SubmachinegunGunType()].Ammunition > GunsConstants.EmptyMagazine()) { return(guns[GunsConstants.SubmachinegunGunType()]); } else { return(guns[GunsConstants.PistolGunType()]); } }
public override void TakeDamage(int damage) { health--; if (health <= 0) { if (gunType == GunsConstants.BossGunType()) { GameManager.instance.AddBonusPoints(); GameManager.instance.FinishGame(); } else { Die(); GameManager.instance.AddScore(); } } }
public void Shoot(int direction, string tag) { if (!isReloading) { if (CanShoot()) { Vector3 spawnPosition = spawnPoint.transform.position; Bullet firedBullet; firedBullet = (Instantiate(bullet, spawnPosition, Quaternion.identity) as Bullet); firedBullet.Shoot(direction); firedBullet.tag = tag; ammunition--; lastShootTime = Time.time; audio.Play(); if (ammunition == GunsConstants.EmptyMagazine()) { isReloading = true; startReloadingTime = Time.time; if (owner == GunOwner.Player) { GameHUDManager.instance.ShowReloadingText(); } Reload(); } } } }
private void LoadGunController() { gunController = carriedGun.GetComponent <GunController>(); if (gunType == GunsConstants.SubmachinegunGunType()) { health = 2; gunController.MediumEnemyGun(); } else if (gunType == GunsConstants.MachinegunGunType()) { health = 3; gunController.SuperEnemyGun(); } else if (gunType == GunsConstants.BossGunType()) { health = 6; gunController.SuperEnemyGun(); } else { health = 1; gunController.BasicEnemyGun(); } }
public void SpawnGun(int gunType, Vector3 position) { int type = gunType == GunsConstants.BossGunType() ? GunsConstants.MachinegunGunType() : gunType; Instantiate(guns[type], position, Quaternion.Euler(new Vector3(0, 90, 0))); }
public void SetAmmoText(int ammo, int ammunitionLeft) { string ammoString = ammunitionLeft == GunsConstants.InfinityAmmunition() ? string.Format("{0}/∞", ammo) : string.Format("{0}/{1}", ammo, ammunitionLeft); ammoText.text = ammoString; }
public void AddAmmo(int ammo){ if (ammunitionLeft != GunsConstants.InfinityAmmunition()) { ammunitionLeft += ammo; } }
void Update() { if (playerPhysics.movementStopped) { targetSpeed = 0; currentSpeed = 0; } animationSpeed = IncrementTowards(animationSpeed, Mathf.Abs(targetSpeed), accelerationSpeed); animator.SetFloat(ANIMATOR_SPEED, animationSpeed); //Input targetSpeed = Input.GetAxisRaw(HORIZONTAL_KEYS) * runSpeed; currentSpeed = IncrementTowards(currentSpeed, targetSpeed, accelerationSpeed); if (playerPhysics.grounded) { amountToMove.y = 0; //Landed if (jumping) { jumping = false; animator.SetBool(ANIMATOR_JUMPING, false); } //Jump if (Input.GetButtonDown(JUMP_KEY)) { amountToMove.y = jumpHeight; jumping = true; animator.SetBool(ANIMATOR_JUMPING, true); } } amountToMove.x = currentSpeed; amountToMove.y -= gravity * Time.deltaTime; playerPhysics.Move(amountToMove * Time.deltaTime); //Face direction float moveDirection = Input.GetAxisRaw(HORIZONTAL_KEYS); if (moveDirection != 0) { transform.eulerAngles = moveDirection > 0 ? Vector3.up * 180: Vector3.zero; direction = moveDirection > 0 ? Directions.Right() : Directions.Left(); } //Shot if (Input.GetButtonDown(FIRE_KEY)) { gunController.Shoot(direction, Tags.PlayerBulletTag()); if (!gunController.HasAmmoLeft() && gunController.AmmunitionLeft != GunsConstants.InfinityAmmunition()) { HandleNoAmmunition(); } else { Gun gun = PlayerManager.instance.CurrentGun(); gun.Ammunition = gunController.Ammunition; gun.AmmunitionLeft = gunController.AmmunitionLeft; Debug.Log(gun.Ammunition); } } GameHUDManager.instance.SetAmmoText(gunController.Ammunition, gunController.AmmunitionLeft); }