// Use this for initialization void Start() { attachedToPlayer = transform.parent.parent.name.Equals("Main Camera"); gunSounds = GetComponent <AudioSource>(); animations = transform.GetChild(0).GetComponent <Animation>(); ammoUI = GameObject.FindWithTag("Ammo UI").GetComponent <AmmoUIController>(); bulletTimerUI = GameObject.FindWithTag("Bullet Timer").GetComponent <BulletTimer>(); idlePosition = transform.GetChild(0).localPosition; idleRotation = transform.GetChild(0).localEulerAngles; idleScale = transform.GetChild(0).localScale; // Get the length of the animation clip for gunfire. // This code only works if the default clip in the Animation component is the gunshot animation. shotAnimationLength = animations.clip.length; currAmmoInClip = magazineSize; currSpareAmmo = initSpareAmmo; canFire = true; zoomedIn = false; nextFire = 0.0f; if (attachedToPlayer) { mainCamera = transform.parent.parent.GetComponent <Camera>(); initFOV = mainCamera.fieldOfView; } else { // Add a slight random extra delay to each turret such that they don't all shoot the same target. firePause *= (aiDelay + Random.Range(0.0f, 0.01f)); } }
private void BulletTimer_Tick(object sender, EventArgs e) { if (bullet.GetDirection() == (int)Directions.Up) { bullet.SetY(bullet.GetY() - 20); } if (bullet.GetDirection() == (int)Directions.Down) { bullet.SetY(bullet.GetY() + 20); } if (bullet.GetDirection() == (int)Directions.Left) { bullet.SetX(bullet.GetX() - 20); } if (bullet.GetDirection() == (int)Directions.Right) { bullet.SetX(bullet.GetX() + 20); } int i = (bullet.GetY() - 5) / 20; int j = (bullet.GetX() - 5) / 20; if (maze.GetMaze()[i, j] == 1) { bullet.SetImage(null); BulletTimer.Stop(); ShootOnce = false; } if (bullet.CheckHitGhost(RGhost)) { Pman.SetScore(Pman.GetScore() + 20); ResetRedLoc(); BulletTimer.Stop(); ShootOnce = false; } if (bullet.CheckHitGhost(YGhost)) { Pman.SetScore(Pman.GetScore() + 20); ResetYellowLoc(); BulletTimer.Stop(); ShootOnce = false; } if (bullet.CheckHitGhost(BGhost)) { Pman.SetScore(Pman.GetScore() + 20); ResetBlueLoc(); BulletTimer.Stop(); ShootOnce = false; } if (bullet.CheckHitGhost(PGhost)) { Pman.SetScore(Pman.GetScore() + 20); ResetPinkLoc(); BulletTimer.Stop(); ShootOnce = false; } }
// Use this for initialization void Start() { mainCamera = transform.Find("Main Camera").gameObject; ammoUI = GameObject.FindWithTag("Ammo UI").GetComponent <AmmoUIController>(); gameController = GameObject.FindWithTag("GameController").GetComponent <GameController>(); bulletTimerUI = GameObject.FindWithTag("Bullet Timer").GetComponent <BulletTimer>(); currWeaponSlotHeld = 1; gunController = mainCamera.transform.Find("Weapon Slot " + currWeaponSlotHeld).GetChild(0).GetComponent <GunController>(); ammoUI.setAmmoCount(gunController.currAmmoInClip, gunController.currSpareAmmo); }
void Start() { LifePickups = SinglePool.PickupsArr; PowerUps = SinglePool.PowerUpsArr; for (int i = 0; i < 2; i++) { PowerUps[i].transform.position = new Vector3(0, 2, 100 * (i + 1)); } DeathTrigger = SinglePool.DeathTriggerInstance; PlayerCon = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>(); BulletScript = GameObject.FindGameObjectWithTag("GameManager").GetComponent <BulletTimer>(); transform.position = new Vector3(0, 0, 350); }
private void GameForm_KeyDown(object sender, KeyEventArgs e) { int i = Pman.GetY() / 20; int j = Pman.GetX() / 20; if (Dead) { return; } if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.W)) { if (maze.GetMaze()[i - 1, j] != 1) { Pman.SetDirection((int)Directions.Up); } PacmanTimer.Start(); GhostTimer.Start(); } if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.S)) { if (maze.GetMaze()[i + 1, j] != 1) { Pman.SetDirection((int)Directions.Down); } PacmanTimer.Start(); GhostTimer.Start(); } if ((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.A)) { if (maze.GetMaze()[i, j - 1] != 1) { Pman.SetDirection((int)Directions.Left); } PacmanTimer.Start(); GhostTimer.Start(); } if ((e.KeyCode == Keys.Right) || (e.KeyCode == Keys.D)) { if (maze.GetMaze()[i, j + 1] != 1) { Pman.SetDirection((int)Directions.Right); } PacmanTimer.Start(); GhostTimer.Start(); } if (e.KeyCode != Keys.Space || Pman.GetAmmo() <= 0 || ShootOnce) { return; } bullet.SetImage(Properties.Resources.Bullet); Pman.ReduceAmmo(); bullet.SetX(Pman.GetX() + 5); bullet.SetY(Pman.GetY() + 5); ShootOnce = true; bullet.SetDirection(Pman.GetDirection()); bullet.RotateBullet(); BulletTimer.Start(); }