public void fire() { if ((state & GunState.SaffetyOn) == GunState.SaffetyOn) { return; } if (bullets == 1) { noAmmoTime = DateTime.Now; state &= ~GunState.Charged; } if (bullets > 0) { bullets--; precision -= 0.001; if (precision < 0.5) { state &= ~GunState.Working; } } else { NoAmmoExceptionArgs args = new NoAmmoExceptionArgs(noAmmoTime); throw new NoAmmoException(args); } }
/// <summary> /// Handles the Firing action when in the firing state /// </summary> private void Fire() { switch (_myBehaviourState) { case JetMinionBehaviourState.FIRE: if (_oldGunState == GunState.LEFT) { _myGunState = GunState.RIGHT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.JetMinionBullet, Position + (GunRightBarrel * SpriteScale)); _oldGunState = GunState.RIGHT; } else { _myGunState = GunState.LEFT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.JetMinionBullet, Position + (GunLeftBarrel * SpriteScale)); _oldGunState = GunState.LEFT; } break; } }
private void HandleInput() { if (Input.GetMouseButtonDown(0)) { gunState = GunState.Fire; chainFireNumber = 0; } // Forward if (Input.GetKey(KeyCode.W)) { rigidBody.AddForce(transform.forward * SHIP_SPEED, ForceMode.Impulse); } // Brake if (Input.GetKey(KeyCode.S)) { Brake(); } // Right incline if (Input.GetKey(KeyCode.D)) { } // Left incline if (Input.GetKey(KeyCode.A)) { } }
void Update() { holdingShootButton = Input.GetButton("Fire1"); buttonUp = Input.GetButtonUp("Fire1"); switch (gunState) { case GunState.CanShoot: if (Input.GetButtonDown("Fire1") && playerLogic.playerState == PlayerLogic.PlayerState.Aiming) { ShootMoon(); } break; case GunState.MoonIsMoving: if (buttonUp) { activeMoon.StopMoving(this); gunState = GunState.MoonCanBeCalledBack; } break; case GunState.MoonCanBeCalledBack: if (Input.GetKeyDown(KeyCode.C) && activeMoon) { activeMoon.CallBackMoon(); } break; } }
IEnumerator Reload(float wait) { inGameManager.isReloading = true; this.GetComponent <FaceoffPlayerHUD>().crossHairReloading(); reloadingModel = gunParent.GetChild(inGameManager.currentWeaponIndex).GetChild(0); // ANIMATION var animator = gunParent.GetChild(inGameManager.currentWeaponIndex).GetComponent <Animator>(); GunState gunState = gunParent.GetChild(inGameManager.currentWeaponIndex).GetComponent <GunState>(); if (animator != null) { animator.speed = 1.0f / wait; animator.Play("gun_reload", 0, 0); gunState.reloadSound(); } yield return(new WaitForSeconds(wait)); Gun gun = inGameManager.GetCurrentEquipment() as Gun; gunParent.GetChild(inGameManager.currentWeaponIndex).GetComponent <GunState>().ammoCount = gun.baseClipSize; pHud.AmmoChanged(gun.baseClipSize, gun.baseClipSize); inGameManager.isReloading = false; this.GetComponent <FaceoffPlayerHUD>().crossHairReloaded(); gunState.reloadStop(); }
void Start() { //Create the position for instantiating a bullet by taking half of the top border of the sprite to get the X value of the end of the gun sprite = GetComponent <SpriteRenderer>(); shootOffset = sprite.bounds.size.x / 2; shootPoint = new GameObject(); shootPoint.transform.parent = gameObject.transform; shootPoint.transform.position = new Vector3(transform.position.x + shootOffset + 0.2f, transform.position.y, transform.position.z); //Check if on the ground or equipped if (transform.parent == null) { gunState = GunState.UNEQUIPPED; } else { gunState = GunState.IDLE; } //Audio Source source = GetComponent <AudioSource>(); //Variable setup ammoInMag = magSize; reloadCountdown = reloadTime; rateCountdown = 0; ammoText = GameObject.Find("CurrentAmmoNum").GetComponent <Text>(); //Begin in the playing state gameState = GameState.PLAYING; }
/// <summary> /// Handles firing the gun for this jet /// </summary> private void FireGun() { switch (_myBehaviorState) { case TwinJetBehaviouralState.FIGHT: //See which barrel should be firing if (_oldGunState == GunState.LEFT) { _myGunState = GunState.RIGHT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.TwinJetBullet, _position + (GunRightBarrel * SpriteScale)); _oldGunState = GunState.RIGHT; } else { _myGunState = GunState.LEFT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.TwinJetBullet, _position + (GunLeftBarrel * SpriteScale)); _oldGunState = GunState.LEFT; } break; } }
// 실제 재장전 처리를 진행 private IEnumerator ReloadRoutine() { // 현재 상태를 재장전 중 상태로 전환 gunState = GunState.Reloading; // 재장전 소리 재생 gunAudioPlayer.PlayOneShot(reloadClip); // 재장전 소요 시간 만큼 처리를 쉬기 yield return(new WaitForSeconds(reloadTime)); int reloadCurAmmo = GI.CurAmmo; int reloadRemainAmmo = GI.RemainAmmo; // 탄창에 채울 탄약을 계산한다 int ammoToFill = magCapacity - reloadCurAmmo; // 탄창에 채워야할 탄약이 남은 탄약보다 많다면, // 채워야할 탄약 수를 남은 탄약 수에 맞춰 줄인다 if (reloadRemainAmmo < ammoToFill) { ammoToFill = reloadRemainAmmo; } // 탄창을 채운다 reloadCurAmmo += ammoToFill; // 남은 탄약에서, 탄창에 채운만큼 탄약을 뺸다 reloadRemainAmmo -= ammoToFill; GI.CurAmmo = reloadCurAmmo; GI.RemainAmmo = reloadRemainAmmo; // 총의 현재 상태를 발사 준비된 상태로 변경 gunState = GunState.Ready; }
public Gun() { bullets = max_bullets; state = GunState.Working; state |= GunState.Charged; state |= GunState.SaffetyOn; }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.E)) { if (currState == GunState.Rock) { currState = GunState.Quicksand; iss.SwitchImage("quicksand"); } else { currState = GunState.Rock; iss.SwitchImage("rock"); } } if (Input.GetMouseButtonDown(1)) { if (currState == GunState.Rock) { SwitchBlock(rock); } else { SwitchBlock(quicksand); } } if (Input.GetMouseButtonDown(0)) { SwitchBlock(background); } }
public void Initialize(PlayerShootHappenedEventHandler thing, PlayerGrenadeHappenedEventHandler thing2) { if (PlayerShootHappened == null) { PlayerShootHappened += thing; } if (PlayerGrenadeHappened == null) { PlayerGrenadeHappened += thing2; } MaxShootDelay = 250; CurrentShootDelay = 0; Score = 0; CurrentHP = 1; GrenadeAmmo = 3; MaxRumbleTime = 500; RumbleTime = 500; RumbleValues = new Vector2(0.5f, 0.5f); CurrentGunState = (GunState)CurrentGunID; }
void Update() { switch (whichGun) { case GunState.grappling: guns[0].SetActive(true); guns[1].SetActive(false); break; case GunState.shotgun: guns[0].SetActive(false); guns[1].SetActive(true); break; } if (Input.GetAxis("Mouse ScrollWheel") != 0f) { if (whichGun == GunState.grappling) { whichGun = GunState.shotgun; } else { whichGun = GunState.grappling; } } }
void Start() { state = GunState.idle; nextFire = Time.time; bulletBucket = GameObject.FindGameObjectWithTag("BulletBucket").transform; }
public void Add(GunState state) { lock (this) { States.Add(state); } }
public void ChangeOwnership(string id, string playerId) { GunState gun = GunRegistry[id]; Debug.Log($"Changing ownership of {id} from {gun.Owner} to {playerId}"); gun.Owner = playerId; }
/// <summary> /// Handles gun states /// </summary> /// <param name="original">True if called from Update()</param> protected void GunUpdate(bool original) { switch (state) { case GunState.Idle: // Do Nothing break; case GunState.Reloading: if (Time.time >= reloadStarted + stats.reloadDelay) { EndReload(); } break; case GunState.Recovering: if (burstIndex == -1) // Fired once { if (Time.time >= lastBurstStarted + stats.burstDelay && action1Released) { state = GunState.Idle; } } else if (burstIndex == 0) // Last round of burst { if (Time.time >= lastFired + stats.fireDelay && Time.time >= lastBurstStarted + stats.burstDelay) { state = GunState.Idle; burstIndex = -1; //Debug.LogError("Burst Over, " + Time.frameCount); } } else // Mid-burst { //Debug.Log("Mid-Burst, " + Time.frameCount+"\n" + Time.time + ", " + lastFired + ", " + stats.fireDelay); if (Time.time >= lastFired + stats.fireDelay) { if (CanShoot()) { float lastShot = lastFired; lastFired += stats.fireDelay; burstIndex--; Shoot(Time.time - (lastShot + stats.fireDelay)); } else { CancelBurst(); } } } break; case GunState.Switching: if (Time.time >= timeEquipped + stats.equipDelay) { FinishEquipping(); } break; } }
/// <summary> /// 清除变量 /// </summary> private void ClearVariate() { m_TimeOfStartFire = 0; m_TimeOfStopFire = 0; m_State = GunState.Stop; m_Targets.Clear(); m_OldTargets.Clear(); }
// Unity Methods void Awake() { fpsCamera = GetComponentInParent <Camera>(); currentState = GunState.Idle; bulletsInGun = gunCapacity; timeToShootSingleBullet = 1f / fireRate; shootingLayerMask = ~LayerMask.GetMask(layersToIgnore); }
private void ResetToVacuum() //resets gun back to vacuum { Debug.Log("Resetting back to Vacuum"); currentAmmoType = null; currentBullet = null; barrel.stateOfBarrel = BarrelCooldown.BarrelState.NONE; stateOfGun = GunState.VACUUM; //set gun state to vacuum }
private void CoolingDownUpdate() { _currentCooldownSpeed -= Time.deltaTime; if (_currentCooldownSpeed <= 0) { _gunState = GunState.ReadyToFire; } }
GunState gunState; //Используйте содержательные имена public Gun(string str = "Hello") // Не используйте перенные l, o так как их легко перепутать с 1 и 0 { bullets = MAX_BULLTETS; gunState = GunState.Working; gunState |= GunState.Charged; gunState |= GunState.SaffetyOn; label = str; }
private void makeShot() // правило одной опреации, функция должна делать толко одно действие { bullets--; precision -= 0.001; if (precision < 0.5) { gunState &= ~GunState.Working; } }
public string ManufactureGun(string type) { GunSettings info = GetGunInfo(type); GunState gun = new GunState(type, currentAmmo: info.magazineSize); GunRegistry.Add(gun.Id, gun); Debug.Log($"Manufactured new gun {type} with id {gun.Id}"); return(gun.Id); }
public void weaponSwap() { if (!reloading) { if (camstate == CamState.Main && fireTimer > 0) { if (gunState != GunState.Pistol && Input.GetKeyDown(KeyCode.Alpha1)) { lastGunState = gunState; gunState = GunState.Pistol; setWeapon(); } else if (gunState != GunState.SMG && Input.GetKeyDown(KeyCode.Alpha2)) { lastGunState = gunState; gunState = GunState.SMG; setWeapon(); } else if (gunState != GunState.Rifle && Input.GetKeyDown(KeyCode.Alpha3)) { lastGunState = gunState; gunState = GunState.Rifle; setWeapon(); } else if (gunState != GunState.Sniper && Input.GetKeyDown(KeyCode.Alpha4)) { lastGunState = gunState; gunState = GunState.Sniper; setWeapon(); } else if (gunState != GunState.Shotty && Input.GetKeyDown(KeyCode.Alpha5)) { lastGunState = gunState; gunState = GunState.Shotty; setWeapon(); } else if (gunState != GunState.Grenade && Input.GetButtonDown("Fire3")) { lastGunState = gunState; gunState = GunState.Grenade; setWeapon(); } else if (gunState == GunState.Grenade && Input.GetButtonUp("Fire3")) { doThrow(); gunState = lastGunState; setWeapon(); } } } }
void Update() { if (!photonView.IsMine) { return; } Gun gun = inGameManager.getCurrentEquipment() as Gun; if (gun == null) { return; } GunState gunState = gunParent.GetChild(inGameManager.currentWeaponIndex).GetComponent <GunState>(); // No Ammo if (gunState != null && !inGameManager.isReloading && gunState.ammoCount <= 0) { reloadCoroutine = StartCoroutine(Reload(gun.reloadTime)); } pHud.AmmoChanged(gunState.ammoCount, gunState.baseAmmo); if (!inGameManager.isReloading && gunState.ammoCount > 0) { // Semi-Auto if ((Input.GetMouseButtonDown((int)MouseButton.LeftMouse)) || (Input.GetKeyDown("joystick button 5")) && !gun.isAutomatic && Time.time >= nextFireTime) { nextFireTime = Time.time + 1 / (gun.baseRateOfFire / 60); photonView.RPC("Shoot", RpcTarget.All); } // Auto if (Input.GetMouseButton((int)MouseButton.LeftMouse) && gun.isAutomatic && Time.time >= nextFireTime) { nextFireTime = Time.time + 1 / (gun.baseRateOfFire / 60); photonView.RPC("Shoot", RpcTarget.All); } // Reload if ((Input.GetKeyDown(KeyCode.R) || (Input.GetKeyDown("joystick button 4"))) && gunState.ammoCount < gunState.baseAmmo) { reloadCoroutine = StartCoroutine(Reload(gun.reloadTime)); } } }
public void StartFire(Action <GameObject> notify) { if (gun_state == GunState.ready && GetAmmo() > 0) { this.notify = notify; this.gun_state = GunState.fire; CurrentFireDuration = TotalFireDuration; this.ammo--; } }
public Projectile(World world, Vector2 position, GunState state, Texture2D texture, Rectangle source) : base(world) { this.WPosition = position; this.State = state; this.Sprite = texture; this.Source = source; this.CVelocity = new Vector2(5f, 5f); Scale = ResScale = 0.2f; }
private void Start() { ammoRemain = GI.RemainAmmo; // 현재 탄창을 가득채우기 magAmmo = GI.CurAmmo; // 총의 현재 상태를 총을 쏠 준비가 된 상태로 변경 gunState = (magAmmo > 0) ? GunState.Ready : GunState.Empty; // 마지막으로 총을 쏜 시점을 초기화 lastFireTime = 0; }
public void dropGrenade() { if (gunState == GunState.Grenade) { gunState = lastGunState; Destroy(_grenade); _grenade = null; gSpawned = false; setWeapon(); } }
public override void StopFire() { m_FiredDuringThisPress = false; m_State = GunState.Stop; m_TimeOfStopFire = Time.time; m_BulletCountWhenStopFire = m_CurrentBulletCount; m_TimeOfStartFire = 0; m_TimeOfFiredLastBullet = 0; m_TimeOfDecreaseLastBullet = 0; }
void ShootMoon() { if (!activeMoon) { activeMoon = Instantiate(moonPrefab, shootPos.transform.position, transform.rotation); var moonRb = activeMoon.GetComponent <Rigidbody>(); moonRb.AddForce(transform.forward * 20f, ForceMode.Impulse); CameraScript.instance.CameraShakeZ(); gunState = GunState.MoonIsMoving; } }
public void CycleState() { int r = Random.Range(0, ModeSwitchSounds.Length); Player._AudioSource.PlayOneShot(ModeSwitchSounds[r]); if (CurrentGunState == GunState.Safety) { CurrentGunState = GunState.Single; } else if (CurrentGunState == GunState.Single) { CurrentGunState = GunState.Burst; } else if (CurrentGunState == GunState.Burst) { CurrentGunState = GunState.Auto; } else if (CurrentGunState == GunState.Auto) { CurrentGunState = GunState.Safety; } }
public override void PlayerControl(Input input) { if (state == GunState.inactive) { if (input.BtnClicked(InputButtons.RightTrigger_Mouse1)) { state = GunState.extending; Vector2 dir = input.GetRightStick().NormalizeSafe() * shootNodeSpeed + parent.body.velocity; shootNode.body.pos = parent.body.pos + dir * 5; shootNode.body.velocity = dir; shootNode.active = true; grav.active = false; spring.active = true; shootLink.active = true; } } else if (state == GunState.extending) { if (input.BtnReleased(InputButtons.RightTrigger_Mouse1)) { state = GunState.retracting; grav.active = true; spring.active = false; } } else if (state == GunState.retracting) { shootNode.body.velocity = VMath.Redirect(shootNode.body.velocity, parent.body.pos - shootNode.body.pos); float catchZone = 20f; //1f for bipedal action if ((parent.body.pos - shootNode.body.pos).Length() < catchZone) { state = GunState.inactive; shootNode.active = false; shootLink.active = false; } } if (input.BtnClicked(InputButtons.RightBumper_E)) { if (attachedNodesQueue.Count > 0) { Node n = attachedNodesQueue.Dequeue(); if (attachLink.targets.Contains(n)) { attachLink.targets.Remove(n); } if (attachLink.sources.Contains(n)) { attachLink.sources.Remove(n); } if (attachLink.formation.chainList.Contains(n)) { attachLink.formation.chainList.Remove(n); } if (attachedNodesQueue.Count == 0) { attachLink.active = false; } attachLink.formation.UpdateFormation(); } } if (input.BtnClicked(InputButtons.LeftBumper_Q)) { if (attachedNodesQueue.Count > 0) { if (attachedNodesQueue.Count != 0) attachedNodesQueue = new Queue<Node>(); if (attachLink.targets.Count != 0) attachLink.targets = new ObservableHashSet<Node>(); if (!attachLink.sources.Contains(parent)) { attachLink.formation.ClearChain(); if (attachLink.sources.Count != 0) attachLink.sources = new ObservableHashSet<Node>(); } attachLink.active = false; } } if (attachLink.active) { float amountPushed = 1f - input.newInputState.LeftTriggerAnalog; amountPushed = amountPushed * 100 + 50; if (attachLink.HasComp<Tether>()) { attachLink.Comp<Tether>().maxdist = (int)amountPushed; attachLink.Comp<Tether>().mindist = (int)amountPushed; } if (attachLink.HasComp<Spring>()) { attachLink.Comp<Spring>().restdist = (int)amountPushed; } } }
/// <summary> /// Called every update and performs according to the current state /// </summary> /// <param name="elapsedTime">Time elapsed since last update</param> private void onFrame(float elapsedTime) { switch (_myVisualState) { case TwinJetVisualState.HEALTHY: checkIfDamaged(); break; case TwinJetVisualState.DAMAGED: checkIfGunDestroyed(); break; case TwinJetVisualState.GUNDESTROYED: checkIfIsAlive(); break; case TwinJetVisualState.EXPLODING: Explode(); _myVisualState = TwinJetVisualState.DEAD; break; case TwinJetVisualState.DEAD: break; } switch (_myBehaviorState) { case TwinJetBehaviouralState.INTRO: checkIfIntroIsOver(); break; case TwinJetBehaviouralState.FIGHT: Fly(); if (_myFireState != TwinJetFireState.STAGE3) { if (checkIfGunIsReady()) { FireGun(); } else { _myGunState = GunState.REST; } } if (_myFireState != TwinJetFireState.STAGE1) { if (checkIfMissilesReady()) { FireMissiles(); } } _timerGunFireRate -= elapsedTime; _timerMissileFireRate -= elapsedTime; break; case TwinJetBehaviouralState.PAUSED: break; } if (!float.IsNaN(_velocity.X) && !float.IsNaN(_velocity.Y)) _position += _velocity * elapsedTime; }
/// <summary> /// Called when the overall state of this jet is changed /// </summary> private void onEntry() { //Mostly setting variables to appropriate values //or calling some helper functions switch (_myVisualState) { case TwinJetVisualState.HEALTHY: _myMaxSpeed = MaxHealthySpeed; _myGunFireRate = HealthyGunFireRate; _myMissileFireRate = HealthyMissileFireRate; _myFireState = TwinJetFireState.STAGE1; break; case TwinJetVisualState.DAMAGED: _myMaxSpeed = MaxDamagedSpeed; _myGunFireRate = DamagedGunFireRate; _myMissileFireRate = DamagedMissileFireRate; _myFireState = TwinJetFireState.STAGE2; break; case TwinJetVisualState.GUNDESTROYED: _myMaxSpeed = MaxGunLostSpeed; _myGunFireRate = GunLostGunFireRate; _myMissileFireRate = GunLostMissileFireRate; _myFireState = TwinJetFireState.STAGE3; _myGunState = GunState.DESTROYED; break; case TwinJetVisualState.EXPLODING: _myBehaviorState = TwinJetBehaviouralState.PAUSED; break; } switch (_myBehaviorState) { case TwinJetBehaviouralState.FIGHT: _myPattern.SetToNearestNode(CenterPosition); break; } }
/// <summary> /// Creates a shiny new jet /// </summary> /// <param name="id">the factory id on the underside of this jet</param> /// <param name="content">The content manager to use</param> /// <param name="newPosition">The position to spawn the jet</param> public TwinJet(uint id, ContentManager content, Vector2 newPosition) : base(id) { //Setting the health this.Health = FullHealth; this.Score = 75; //Setting alive to 'true' _isAlive = true; //Initializing the states _myVisualState = TwinJetVisualState.HEALTHY; _myBehaviorState = TwinJetBehaviouralState.INTRO; _myFireState = TwinJetFireState.STAGE1; _myGunState = GunState.REST; _oldGunState = GunState.LEFT; //Initializing rotation _myRotation = 0; //Setting the flight pattern to null _myPattern = null; //Setting position and velocity _position = newPosition; _velocity = Vector2.Zero; //Marking the intro as still occurring _isIntroOver = false; //Setup firerates _timerGunFireRate = 0; _timerMissileFireRate = 0; //Bring in the spritesheet _spriteSheet = content.Load<Texture2D>("Spritesheets/newshi.shp.000000"); //Setting up Sprite Bounds for the jet and gun _spriteBounds[(int)TwinJetVisualState.HEALTHY] = new Rectangle(98, 143, 93, 80); _spriteBounds[(int)TwinJetVisualState.DAMAGED] = new Rectangle(2, 143, 93, 53); _spriteBounds[(int)TwinJetVisualState.GUNDESTROYED] = new Rectangle(2, 143, 93, 53); _spriteBounds[(int)TwinJetVisualState.EXPLODING] = Rectangle.Empty; _spriteBounds[(int)TwinJetVisualState.DEAD] = Rectangle.Empty; _spriteGunBounds[(int)GunState.LEFT] = new Rectangle(62, 196, 21, 21); _spriteGunBounds[(int)GunState.REST] = new Rectangle(38, 196, 21, 20); _spriteGunBounds[(int)GunState.RIGHT] = new Rectangle(14, 196, 21, 21); _spriteGunBounds[(int)GunState.DESTROYED] = new Rectangle(38, 196, 21, 11); //Calls the on entry method to initialize some things onEntry(); }
/// <summary> /// This gets called be default, handles the behaviour and appearence of the /// Jet as it remains in its current state /// </summary> /// <param name="elapsedTime">Time since last update, mostly for managing timers</param> private void onFrame(float elapsedTime) { Vector2 playerPosition = new Vector2(ScrollingShooterGame.Game.Player.Bounds.X, ScrollingShooterGame.Game.Player.Bounds.Y); int playerWidth = ScrollingShooterGame.Game.Player.Bounds.Width; if (_myVisualState == JetMinionVisualState.HEALTHY || _myVisualState == JetMinionVisualState.DAMAGED) { switch (_myBehaviourState) { case JetMinionBehaviourState.IDLE: Idle(); checkIfOnScreen(); break; case JetMinionBehaviourState.ALERT: Alert(); checkIfInAlertRange(playerPosition); break; case JetMinionBehaviourState.SEEKSTRAFE: SeekStrafe(playerPosition); checkIfInStrafingRange(playerPosition); break; case JetMinionBehaviourState.STRAFE: Strafe(playerPosition); checkIfInFiringRange(playerPosition, playerWidth); break; case JetMinionBehaviourState.FIRE: if (checkIfGunReady()) { Fire(); } else { _myGunState = GunState.REST; } Strafe(playerPosition); checkIfInFiringRange(playerPosition, playerWidth); _timerFire -= elapsedTime; break; case JetMinionBehaviourState.RETREAT: Retreat(); checkIfIsAlive(); break; default: break; } } //We don't do anything specific based on the visual state except change some //sprites around, except for the exploding state, so there is no need //to include their empty cases here switch (_myVisualState) { case JetMinionVisualState.HEALTHY: checkIfDamaged(); checkIfLifeTimeOver(); _timerLife -= elapsedTime; break; case JetMinionVisualState.DAMAGED: checkIfLifeTimeOver(); checkIfIsAlive(); _timerLife -= elapsedTime; break; case JetMinionVisualState.EXPLODING: if (!checkIfFinishedExploding()) { Explode(); } break; default: break; } _position += _velocity * elapsedTime; }
/// <summary> /// Initializes the values of this Jet /// </summary> /// <param name="content"></param> /// <param name="position"></param> private void Initiailize(ContentManager content, Vector2 position) { //Setting Health _health = FullHealth; //Initializing States _myVisualState = JetMinionVisualState.HEALTHY; _myBehaviourState = JetMinionBehaviourState.IDLE; _myGunState = GunState.REST; _oldGunState = GunState.RIGHT; //Setting the initial position of the ship _position = position; //Setting up the initial direction _isMovingLeft = true; //Setting up the timers _timerLife = TotalLifeTime; _timerFire = HealthyFireRate; _timerExplosion = TotalExplosionTime; //Setting up the Explosion Animator _explosionAnimator = new ExplodeAnim(ExplosionType.SINGLE, 0.2f, new Rectangle((int)position.X, (int)position.Y, _spriteBounds[1].Width, _spriteBounds[1].Height)); _spriteSheet = content.Load<Texture2D>("Spritesheets/newshi.shp.000000"); _explosionSpriteSheet = content.Load<Texture2D>("Spritesheets/newsh6.shp.000000"); #region Initializing _spriteBounds _spriteBounds[(int)JetMinionVisualState.HEALTHY].X = 98; _spriteBounds[(int)JetMinionVisualState.HEALTHY].Y = 143; _spriteBounds[(int)JetMinionVisualState.HEALTHY].Width = 93; _spriteBounds[(int)JetMinionVisualState.HEALTHY].Height = 80; _spriteBounds[(int)JetMinionVisualState.DAMAGED].X = 2; _spriteBounds[(int)JetMinionVisualState.DAMAGED].Y = 143; _spriteBounds[(int)JetMinionVisualState.DAMAGED].Width = 93; _spriteBounds[(int)JetMinionVisualState.DAMAGED].Height = 53; //This makes returning bounds easier, no check required _spriteBounds[(int)JetMinionVisualState.EXPLODING] = Rectangle.Empty; _spriteBounds[(int)JetMinionVisualState.DEAD] = Rectangle.Empty; #endregion #region Initializing _spriteGun _spriteGun[(int)GunState.LEFT].X = 62; _spriteGun[(int)GunState.LEFT].Y = 196; _spriteGun[(int)GunState.LEFT].Width = 21; _spriteGun[(int)GunState.LEFT].Height = 21; _spriteGun[(int)GunState.REST].X = 38; _spriteGun[(int)GunState.REST].Y = 196; _spriteGun[(int)GunState.REST].Width = 21; _spriteGun[(int)GunState.REST].Height = 20; _spriteGun[(int)GunState.RIGHT].X = 14; _spriteGun[(int)GunState.RIGHT].Y = 196; _spriteGun[(int)GunState.RIGHT].Width = 21; _spriteGun[(int)GunState.RIGHT].Height = 21; #endregion }
/// <summary> /// Handles the Firing action when in the firing state /// </summary> private void Fire() { switch (_myBehaviourState) { case JetMinionBehaviourState.FIRE: if (_oldGunState == GunState.LEFT) { _myGunState = GunState.RIGHT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.JetMinionBullet, Position + (GunRightBarrel * SpriteScale)); _oldGunState = GunState.RIGHT; } else { _myGunState = GunState.LEFT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.JetMinionBullet, Position + (GunLeftBarrel * SpriteScale)); _oldGunState = GunState.LEFT; } break; } }
public virtual void SetState(GunState value) { SetProperty(ref _State, value, ref _StateEvent, _StateObservable); }
/// <summary> /// Handles firing the gun for this jet /// </summary> private void FireGun() { switch (_myBehaviorState) { case TwinJetBehaviouralState.FIGHT: //See which barrel should be firing if (_oldGunState == GunState.LEFT) { _myGunState = GunState.RIGHT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.TwinJetBullet, _position + (GunRightBarrel * SpriteScale)); _oldGunState = GunState.RIGHT; } else { _myGunState = GunState.LEFT; ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.TwinJetBullet, _position + (GunLeftBarrel * SpriteScale)); _oldGunState = GunState.LEFT; } break; } }
void Start() { currentGunState = new AgressiveGunState(); commands = new List<Command>(); foreach(Teammate t in teammates){ t.SetFireTeam(this); } }