コード例 #1
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	private bool CanShoot() {
		int numberOfAmmunition = ammunition;
		if (ammunitionLeft != GunsConstants.InfinityAmmunition()) {
			numberOfAmmunition += ammunitionLeft;
		}
		return Time.time - lastShootTime > shootTimeInterval && numberOfAmmunition != GunsConstants.EmptyMagazine();
	}
コード例 #2
0
ファイル: PlayerManager.cs プロジェクト: jmirota/jm-vmk
    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;
    }
コード例 #3
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	public bool HasAmmoLeft() {
		int numberOfAmmunition = ammunition;
		if (ammunitionLeft != GunsConstants.InfinityAmmunition()) {
			numberOfAmmunition += ammunitionLeft;
		}
		return numberOfAmmunition == GunsConstants.EmptyMagazine() ? false : true;
	}
コード例 #4
0
ファイル: PlayerManager.cs プロジェクト: jmirota/jm-vmk
    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();
        }
    }
コード例 #5
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	public void BasicEnemyGun () {
		ammunition = 7;
		ammunitionLeft = GunsConstants.InfinityAmmunition();
		reloadingTime = 5; // seconds
		lastShootTime = 0;
		shootTimeInterval = 1.5f;
		isReloading = false;
		reloadingTime = 0.1f;
		owner = GunOwner.Enemy;
	}
コード例 #6
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	public void MediumEnemyGun () {
		magazineCapacity = 20;
		ammunitionLeft = GunsConstants.InfinityAmmunition();
		reloadingTime = 8; // seconds
		lastShootTime = 0;
		shootTimeInterval = 1.2f;
		isReloading = false;
		reloadingTime = 0.1f;
		owner = GunOwner.Enemy;
	}
コード例 #7
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	public void PistolGun () {
		magazineCapacity = 7;
		ammunition = magazineCapacity;
		ammunitionLeft = GunsConstants.InfinityAmmunition();
		reloadingTime = 1.6f; // seconds
		lastShootTime = 0;
		shootTimeInterval = 0.7f;
		isReloading = false;
		owner = GunOwner.Player;
	}
コード例 #8
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	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;
	}
コード例 #9
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	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);
			}
		}
	}
コード例 #10
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	void Start () {
		isReloading = false;
		if (owner == GunOwner.Player) {
			GameHUDManager.instance.HideReloadingText();
		}

		if (Ammunition == GunsConstants.EmptyMagazine()) {
			isReloading = true;
			startReloadingTime = Time.time;
			Reload();
		}

		audio.clip = audioClip;
	}
コード例 #11
0
ファイル: PlayerManager.cs プロジェクト: jmirota/jm-vmk
    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;
    }
コード例 #12
0
ファイル: PlayerManager.cs プロジェクト: jmirota/jm-vmk
 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()]);
     }
 }
コード例 #13
0
 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();
         }
     }
 }
コード例 #14
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	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();
				} 
			}
		}
	}
コード例 #15
0
 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();
     }
 }
コード例 #16
0
ファイル: GameManager.cs プロジェクト: jmirota/jm-vmk
    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)));
    }
コード例 #17
0
ファイル: HUDCanvasController.cs プロジェクト: jmirota/jm-vmk
    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;
    }
コード例 #18
0
ファイル: GunController.cs プロジェクト: jmirota/jm-vmk
	public void AddAmmo(int ammo){
		if (ammunitionLeft != GunsConstants.InfinityAmmunition()) {
			ammunitionLeft += ammo;
		}
	}
コード例 #19
0
    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);
    }