private void Start() { GetBalaIndex(); GetRigidBody().drag = GetPlayerDeceleration(); life = 1; score = 0; SetCanShoot(true); damageable = true; matchController = FindObjectOfType <MatchController>(); //matchController.AddPlayer(this); spawnPoint = matchController.GetSpawnPoint(this); teamId = 5; movementSM = new StateMachine(); groundedState = new GroundedState(this, movementSM); shootingState = new ShootingState(this, movementSM); shieldState = new ShieldState(this, movementSM); deadState = new DeadState(this, movementSM); stunState = new StunState(this, movementSM); feederState = new FeederState(this, movementSM); movementSM.Initialize(shootingState); }
// Use this for initialization void Start() { state = ShootingState.Free; currentBullet = null; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; line = GetComponent <LineRenderer>(); line.startWidth = 0.1f; line.endWidth = 0.1f; bulletList = new List <Bullet>(); Bullet aggresiveBullet = new Bullet(BulletType.Aggresive); aggresiveBullet.OnPickupBullet += new EventHandler(OnPickupBullet); aggresiveBullet.OnShoot += new EventHandler(OnShoot); bulletList.Add(aggresiveBullet); Bullet seeThroughBullet = new Bullet(BulletType.WallVisibility); seeThroughBullet.OnPickupBullet += new EventHandler(OnPickupBullet); seeThroughBullet.OnShoot += new EventHandler(OnShoot); bulletList.Add(seeThroughBullet); Bullet transmitterBullet = new Bullet(BulletType.WallTransmitter); transmitterBullet.OnPickupBullet += new EventHandler(OnPickupBullet); transmitterBullet.OnShoot += new EventHandler(OnShoot); bulletList.Add(transmitterBullet); }
// Unity functions private void Awake() { NormalState = new NormalState(this); BigState = new BigState(this); ShootingState = new ShootingState(this); InvincibleState = new InvincibleState(this); }
public void StartNewCooldown(float duration, ShootingState sender) { Task.Factory.StartNew(async() => { await Task.Delay((int)(duration * 1000)); sender.IsOffCooldown = true; }); }
void BeginShoot() { ShootState = ShootingState.aiming; InitialDistance = Random.insideUnitSphere * InitialRadius; EffectiveShootPoint = Target.position + Vector3.ProjectOnPlane(InitialDistance, Target.position - transform.position); PinpointProgress = TimeToPinpoint; }
void DoShoot() { Debug.Log("Fire"); ShootState = ShootingState.recover; CreateProjectile(); Invoke("CompleteRecover", 0.5f); }
/// <summary> /// Sets the state of the Player /// </summary> /// <param name="state">Which state to set</param> /// <exception cref="ArgumentOutOfRangeException"></exception> public void SetState(PlayerStates state) { PlayerBaseState playerState; switch (state) { case PlayerStates.Shoot: playerState = new ShootingState(this); break; case PlayerStates.Walking: playerState = new WalkingState(this); break; case PlayerStates.Talking: playerState = new TalkingState(this); break; case PlayerStates.Win: playerState = new WinState(this); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } _currentState?.ExitState(); _currentState = playerState; _currentState.EnterState(); }
private void Shoot() { Ray cameraRay = new Ray(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2)), Camera.main.transform.forward * 50.0f); // Camera.main.ScreenToWorldPoint, Camera.main.transform.forward if (Physics.Raycast(cameraRay, out shootHit)) { if (currentBullet.type != BulletType.VFX) { if (shootHit.collider.tag == "Enemy") { shootHit.collider.GetComponent <EnemyExtendedAI>().Inject(currentBullet.type); } if (shootHit.collider.tag == "Wall") { if (currentBullet.type == BulletType.WallTransmitter) { Instantiate(Resources.Load("WallTransmitter"), shootHit.point, Quaternion.identity); } if (currentBullet.type == BulletType.WallVisibility) { Instantiate(Resources.Load("WallSight"), shootHit.point, Quaternion.identity); } } } else { vfxButtet = (GameObject)Instantiate(Resources.Load("ParticleVFX"), Hand.transform.position, Quaternion.identity); vfxBulletState = true; } } //DrawLine(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2)), Camera.main.transform.forward * 50.0f); //Debug.DrawRay(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2)), Camera.main.transform.forward * 50.0f, Color.red, 22.2f); currentBullet.Shoot(); state = ShootingState.Free; }
public IActionState GetState(string state) { IActionState actionState = null; if (_states.ContainsKey(state)) { actionState = _states[state]; } else { switch (state) { case "Moving": actionState = new MovingState(); break; case "Idle": actionState = new IdleState(); break; case "Shooting": actionState = new ShootingState(); break; } _states.Add(state, actionState); } return(actionState); }
public TowerShooting(Tower tower, Bullet.Factory factory) { _tower = tower; _bulletFactory = factory; TowerShootingState = ShootingState.NoTarget; _shootCD = _tower.TowerParameters.AttackDelay; }
private void Start() { state = new StateMachine(); grounding = new GroundedState(gameObject, state); shooting = new ShootingState(gameObject, state); state.Initialize(grounding); }
/// <summary> /// Declaration of references will be used for the states logic goes here /// Eg. /// public ISteer steeringScript; /// public GameObject pathRoute; /// public Queue<GameObject> enemyQueue = new Queue<GameObject>(); /// /// </summary> private void Start() { /// <summary> /// Instantiation of states Instances goes here. /// Eg. /// chaseEnemy = new ChaseState() /// { /// chasingRange = this.chasingRange, /// shootingRange = this.shootingRange, /// alertRange = this.alertRange, /// movementController = this /// }; /// </summary> ////Instantiate the first state assemblyDissassemblyState = new AssemblyDissassemblyState() { gameplayFSMManager = this }; assemblyDisAssemblyTutorialState = new AssemblyDisAssemblyTutorialState() { gameplayFSMManager = this }; shootingState = new ShootingState() { gameplayFSMManager = this }; testingState = new TestingState() { gameplayFSMManager = this }; tutorialState = new TutorialState() { gameplayFSMManager = this }; pauseState = new PauseState() { gameplayFSMManager = this }; stateTransition = new StateTransition() { gameplayFSMManager = this }; //push the first state for the player PushState(tutorialState); if (hintTxt) { hintTxt.enabled = false; } }
private void FixedUpdate() { if (Input.GetMouseButtonDown(0) && currentBullet != null && currentBullet.count > 0) { state = ShootingState.isShooting; } if (state == ShootingState.isShooting) { Shoot(); } }
// override methods public override void Update() { if (this.state == ShootingState.Warming && Program.CurrentTime - this.CreateTime > 3000) { this.state = ShootingState.Explosing; } if (this.state == ShootingState.Explosing && Program.CurrentTime - this.CreateTime > 4000) { this.state = ShootingState.Closing; } base.Update(); }
public void StopCharge() { ClearSegments(); Destroy(_impactObj); _impactObj = null; if (_charged != 0 && _currentState != ShootingState.Idle) { _animator.SetTrigger(Idle); _currentState = ShootingState.Idle; } _charged = 0; }
public void StartCharge() { _charged = Math.Min(1, _charged + Time.deltaTime); if (_charged >= _chargeTime && _currentState != ShootingState.Shooting) { _animator.SetTrigger(Shooting); _currentState = ShootingState.Shooting; } else if (_charged < _chargeTime && _currentState != ShootingState.Charging) { _animator.SetTrigger(Charging); _currentState = ShootingState.Charging; } }
public bool checkIfTargetIsInRange() { if (target != null && Vector3.Distance(transform.position, target.transform.position) < AttackRange) { Debug.Log("ENEMY IS IN RANGE"); currShootingState = ShootingState.StartShooting; return(true); } else { Debug.Log("ENEMY IS NOT RANGE"); } currShootingState = ShootingState.StopShooting; return(false); }
void Update() { if (fire_triggered) { start_fire(); } switch (state) { case ShootingState.fire: state = ShootingState.resetting; break; case ShootingState.burst: var time_since_last_shot = Time.time - last_shot_time; if (time_since_last_shot > time_between_burst_shots) { if (burst_shots_count < shots_per_burst) { shoot(); } else { burst_shots_count = 0; state = ShootingState.resetting; } } break; case ShootingState.resetting: if (default_firing_animation) { transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); // TEMPORARY effect } var time_since_last_firing = Time.time - last_firing_time; if (time_since_last_firing > time_between_firing) { reset_to_ready(); } break; default: break; } }
private IEnumerator ChangingStateDelay() { yield return(new WaitForSeconds(2.5f)); currstate = State.shootingstate; int rand = Random.Range(0, 2); if (rand == 0) { ShootingSt = ShootingState.Bullets; } else { ShootingSt = ShootingState.Ray; } StopAllCoroutines(); }
// override methods public override void Update() { if (this.state == ShootingState.Warming && Program.CurrentTime - this.CreateTime > 2000) { this.state = ShootingState.Shooting; } else if (this.state == ShootingState.Shooting && Program.CurrentTime - this.CreateTime > 4000) { this.state = ShootingState.Closing; } else if (this.state == ShootingState.Closed) { this.CanRemove = true; } base.Update(); }
void Start() { var idle = new IdleState <Feed>(); shooting = new ShootingState <Feed>(this.transform, target, this); var cooldown = new CooldownState <Feed>(); idle.AddTransition(Feed.EnemigoEntraEnLOS, shooting); shooting.AddTransition(Feed.EnemigoSaleDeLOS, idle); shooting.AddTransition(Feed.ArmaRecalentada, cooldown); cooldown.AddTransition(Feed.ArmaEnfriada, shooting); cooldown.AddTransition(Feed.EnemigoSaleDeLOS, idle); stateMachine = new FSM <Feed>(idle); shootState = true; }
// Called when we begin the firing state. private void start_firing_state() { if (default_firing_animation) { transform.localScale = new Vector3(2.0f, 2.0f, 2.0f); // TEMPORARY effect } last_firing_time = Time.time; select_bullet_prefab(); switch (firing_mode) { case GunFiringMode.one_shot: state = ShootingState.fire; break; case GunFiringMode.burst: state = ShootingState.burst; break; } }
public void ManageShooting() { switch (TowerShootingState) { case ShootingState.NoTarget: if (_tower.GetTarget() != null) { TowerShootingState = ShootingState.TargetLocked; } else { return; } break; case ShootingState.TargetLocked: if (_shootCD <= 0) { Shoot(); } else { _shootCD -= Time.deltaTime; } break; case ShootingState.TargetKilled: //when we change state to this? //Whait for cd to finish if (_shootCD > 0) { _shootCD -= Time.deltaTime; } else { _shootCD = 0; TowerShootingState = ShootingState.NoTarget; } break; } }
private void OnEnable() { CutsceneObj = GameObject.Find("GameManager").GetComponent <BossRoomBehavior>().BeforeBossUI; player = GameObject.Find("Player"); BossBar = GameObject.Find("GameManager").GetComponent <BossRoomBehavior>().BossBar; BossNameText = GameObject.Find("GameManager").GetComponent <BossRoomBehavior>().BossName; BossBar.SetActive(true); BossNameText.SetActive(true); src = GetComponent <AudioSource>(); BossNameText.GetComponent <Text>().text = name; BossBar.GetComponent <Slider>().maxValue = MaxHealth; BossBar.GetComponent <Slider>().value = MaxHealth; //InitializeSpinState(); currstate = State.shootingstate; ShootingSt = ShootingState.Bullets; StartCoroutine(custcene()); currstate = State.CutSceneState; /* foreach(GameObject lr in LaserRenderers) * { * lr.GetComponent<LineRenderer>().SetPosition(0, lr.transform.position); * }*/ }
protected virtual IEnumerator ShootState() { while (true) { yield return(new WaitWhile(() => bulletRemaining <= 0)); yield return(new WaitUntil(() => shootingState == ShootingState.Shoot)); if (reloadingState == ReloadingState.Reloading) { reloadingState = ReloadingState.StopReloading; // Detiene la recarga de balas shootingState = ShootingState.Idle; continue; //yield return new WaitUntil(() => reloadingState == ReloadingState.Ready); } Shoot(); yield return(new WaitForSeconds(data.bulletShotTime)); shootingState = ShootingState.Idle; } }
private void Start() { rigidBody.drag = playerDeceleration; life = maxLife; score = 0; canShoot = true; canShield = true; damageable = true; stunSlider.maxValue = stunTime; lifeText.text = "Vida: " + life; scoreText.GetComponent <TMPro.TextMeshProUGUI>().text = score + " pts"; hudManager = GetComponent <HUDmanager>(); GetBalaIndex(); if (PhotonNetwork.IsConnected && PV.IsMine) { canvas.SetActive(true); mainCamera.enabled = true; playerInput.enabled = true; mobileCharacter.enabled = true; audioListener.enabled = true; sAlas.Play(); } if (PhotonNetwork.IsConnected && PhotonNetwork.IsMasterClient) { matchController = FindObjectOfType <MatchController>(); matchController.AddPlayer(this); teamId = FindObjectOfType <RoomManager>().FindTeamIdByPlayer(PV.Owner); if (teamId == -1) { teamId = 0; Debug.Log("No se ha encontrado el teamId, se le ha añadido al equipo 0"); } PV.RPC("GetSpawnpoint_RPC", RpcTarget.All, teamId); } else if (!PhotonNetwork.IsConnected) { canvas.SetActive(true); mainCamera.enabled = true; playerInput.enabled = true; mobileCharacter.enabled = true; RoomManagerOffline RMO = FindObjectOfType <RoomManagerOffline>(); if (RMO.gamemodeIndex == 3) { teamId = 0; } else { teamId = RMO.jugadoresInfo[GetComponentInChildren <PlayerInput>().playerIndex + 1][1]; } if (playerInput.playerIndex == 0) { audioListener.enabled = true; } matchController = FindObjectOfType <MatchController>(); matchController.AddPlayer(this); spawnPoint = matchController.GetSpawnPoint(this); GetComponent <Transform>().position = spawnPoint.transform.position; hudManager.setBackground(); } movementSM = new StateMachine(); groundedState = new GroundedState(this, movementSM); shootingState = new ShootingState(this, movementSM); shieldState = new ShieldState(this, movementSM); deadState = new DeadState(this, movementSM); stunState = new StunState(this, movementSM); feederState = new FeederState(this, movementSM); movementSM.Initialize(groundedState); }
public override void Render(Graphics g) { if (this.state == ShootingState.Warming) { g.DrawLine(Pens.Red, Point1.X, Point1.Y, Point2.X, Point2.Y); g.FillEllipse(Brushes.DarkRed, Point1.X - 10, Point1.Y - 10, 20, 20); return; } if (this.state == ShootingState.Shooting) { g.DrawLine(Pens.Red, Point1.X, Point1.Y, Point2.X, Point2.Y); float th = this.thickness; float len = (Point2 - Point1).Norm(); int n = (int)(len / th) + 1; float step = 1.0f / n; float t = 0; int end = this.shootingEndStep; for (int i = 0; i < end; i++) { Vector p = Point1 + (Point2 - Point1) * t; t += step; float left = (p.X - Bitmap.Width / 2); float top = (p.Y - Bitmap.Height / 2); g.DrawImage(Bitmap, left, top); } this.laserStartPoint = Point1; this.laserEndPoint = Point1 + (Point2 - Point1) * t; if (shootingEndStep < n) { shootingEndStep += 4; } } if (this.state == ShootingState.Closing) { float th = this.thickness; float len = (Point2 - Point1).Norm(); int n = (int)(len / th) + 1; float step = 1.0f / n; int end = n; for (int i = shootingStartStep; i < end; i++) { Vector p = Point1 + (Point2 - Point1) * (i * step); float left = (p.X - Bitmap.Width / 2); float top = (p.Y - Bitmap.Height / 2); g.DrawImage(Bitmap, left, top); } this.laserStartPoint = Point1 + (Point2 - Point1) * (shootingStartStep * step); this.laserEndPoint = Point2; if (shootingStartStep < n) { shootingStartStep += 4; } else { this.state = ShootingState.Closed; } } }
void Update() { // if (Input.GetKey(KeyCode.DownArrow)) // { // _angle += 5; // } // // if (Input.GetKey(KeyCode.UpArrow)) // { // _angle -= 5; // } if (Input.GetMouseButtonDown(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)) { if (Input.touchCount > 0) { _mouseStartPosition = Input.GetTouch(0).position; } else { _mouseStartPosition = Input.mousePosition; } _startClickTime = Time.time; Vector3 ray = Camera.main.ScreenToWorldPoint(_mouseStartPosition); RaycastHit2D hit = Physics2D.Raycast(ray, Vector2.zero); if (hit.collider != null) { if (hit.transform.gameObject.CompareTag("Player")) { _shootingState = ShootingState.IsShooting; } else { _shootingState = ShootingState.IsTargeting; } } else { _shootingState = ShootingState.IsTargeting; } } if (Input.GetMouseButton(0) || Input.touchCount > 0) { Vector2 mousePosition; if (Input.touchCount > 0) { mousePosition = Input.GetTouch(0).position; } else { mousePosition = Input.mousePosition; } if (_shootingState == ShootingState.IsShooting) { float distance = Vector2.Distance(_mouseStartPosition, mousePosition); float currentTime = Time.time - _startClickTime; _force = currentTime * ShootingSpeed; if (_force > 10) { _force = 10; } Arrow.SetActive(true); ShootPoint.localScale = Vector3.one * Mathf.Lerp(0.2f, 1f, _force / 10f); if (distance > 200) { _shootingState = ShootingState.IsCanceled; ShootPoint.localScale = Vector3.one * .2f; Arrow.SetActive(false); } } else if (_shootingState == ShootingState.IsTargeting) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(mousePosition); Vector3 nonZeroZ = mousePos - CannonBarrel.position; Vector3 direction = new Vector3(nonZeroZ.x, nonZeroZ.y, 0); CannonBarrel.up = direction; } } if ((Input.GetMouseButtonUp(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)) && _shootingState == ShootingState.IsShooting) { // shoot GameObject cannonBall = Instantiate(CannonBall, ShootPoint.position, Quaternion.identity); Rigidbody2D rigidBody = cannonBall.GetComponent <Rigidbody2D>(); rigidBody.AddForce(ShootPoint.up * CannonForce * _force, ForceMode2D.Impulse); _force = 0; ShootPoint.localScale = Vector3.one * .2f; Arrow.SetActive(false); } else if ((Input.GetMouseButtonUp(0) || (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)) && _shootingState == ShootingState.IsCanceled) { ShootPoint.localScale = Vector3.one * .2f; Arrow.SetActive(false); } }
void CompleteRecover() { ShootState = ShootingState.idle; Debug.Log("Ready to shoot again"); }
void Awake() { currState = AttackState.Stop; currShootingState = ShootingState.StopShooting; }