// Rotates the bat accordingly when swung, as well as returning the bat to // its initial position. public void Draw() { if (batState == BatState.Forwards) { eLine.RenderTransform = new RotateTransform(i -= incAngle, eLine.X1, eLine.Y1); } else if (batState == BatState.Backwards) { eLine.RenderTransform = new RotateTransform(i += incAngle, eLine.X1, eLine.Y1); } if (i <= maxAngle) { if (swung == true) { numMissed++; } batState = BatState.Backwards; } else if (i >= startAngle) { batState = BatState.Ready; collided = false; } }
private void OnTriggerExit2D(Collider2D other) { if (other.name == "Player") { m_BatState = BatState.Chase; } }
private void WokeBat() { int playersStillPlaying = 0; Player[] players = FindObjectsOfType <Player>(); for (int i = 0; i < players.Length; i++) { if (players[i].IsPetting()) { players[i].DisabledThisRound(); } else { playersStillPlaying += 1; } } ToggleSleepAndAwake(); batstate = BatState.WOKEN; if (playersStillPlaying > 0) { PlayAgain(); } else { isGameOver = true; } }
private void FlyToEndPoint() { if (!FlyByPath()) { return; } _state = BatState.Starting; }
private void WaitAttackEnd() { if (!_animator.GetCurrentAnimatorStateInfo(0).IsName(AttackAnimName)) { return; } _state = BatState.Returning; }
private void FlyToPlayer() { if (!FlyByPath()) { return; } _state = BatState.Returning; }
private void OnTriggerEnter2D(Collider2D other) { if (other.name == "Player") { m_BatState = BatState.Attack; //Debug.Log("attack state"); } }
private void Awake() { controller = GetComponent <BatController>(); state = GetComponent <BatState>(); body = GetComponent <Rigidbody>(); initialPosition = transform.position; timeToRespawnImage.enabled = false; }
void OnTriggerEnter(Component collision) { if (collision.gameObject.tag != MainCameraTag && _state != BatState.FlyingToPlayer) { return; } _animator.SetTrigger(AttackAnimTrigName); _state = BatState.Attacking; }
public void OnGettingHit() { if (state == BatState.DAMAGEABLE) { prefab.GetComponents <AudioSource>()[1].Play(); GameController.main.PlayerPlayHit(); state = BatState.ATTACKED; } }
// Update is called once per frame protected override void Update() { base.Update(); animation_counter++; animation_counter %= 2 * animation_inverval; GetComponent <SpriteRenderer> ().sprite = Sprites [animation_counter / animation_inverval]; if (bat_state == BatState.fast) { float u = (Time.time - timeStart) / duration; if (u >= 1) // if u >=1... { InitMovement(1); // ...then initialize movement to a new point u = 0; bat_state = BatState.slow; animation_inverval = 20; } // u = 1 - Mathf.Pow( 1-u, 2 ); // Apply Ease Out easing to u this.GetComponent <Transform> ().position = (1 - u) * points [0] + u * points [1]; // Simple linear interpolation } else if (bat_state == BatState.slow) { float u = (Time.time - timeStart) / duration; if (u >= 1) // if u >=1... { InitMovement(0); // ...then initialize movement to a new point u = 0; bat_state = BatState.stop; animation_inverval = 1000000000; } // u = 1 - Mathf.Pow( 1-u, 2 ); // Apply Ease Out easing to u this.GetComponent <Transform> ().position = (1 - u) * points [0] + u * points [1]; // Simple linear interpolation } else { float u = (Time.time - timeStart) / duration; if (u >= 1) // if u >=1... { InitMovement(2); // ...then initialize movement to a new point u = 0; bat_state = BatState.fast; animation_inverval = 10; } // u = 1 - Mathf.Pow( 1-u, 2 ); // Apply Ease Out easing to u this.GetComponent <Transform> ().position = (1 - u) * points [0] + u * points [1]; // Simple linear interpolation } }
private void PlayAgain() { secondsUntilSleeping = 3; ToggleTimer(true); startingTime = 0; batstate = BatState.WAITING; }
private void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.name == "Player") { other.gameObject.GetComponent <Player>().takeDamage(attackPower * DifficultyManager.getAttackMultiplier()); batAudio.clip = batDamageClip; batAudio.Play(); m_BatState = BatState.Chase; } }
private void StartNewFly() { _returned = false; var r = new Random(DateTime.Now.Millisecond); _endPosition = MakeNewRandomPoint(); _waitTime = r.Next(MinWaitSeconds, MaxWaitSeconds + 1); _elapsedNewTargetTime = TargetTime; _state = BatState.Waiting; }
private void SleepingBat(bool isSleeping) { animator.SetBool("isSleeping", isSleeping); batstate = BatState.SLEEPING; this.isSleeping = isSleeping; ToggleTimer(isSleeping); }
private void Wait() { _elapsedWaitTime += Time.deltaTime; _animator.SetTrigger(StayAnimTrigName); if (_elapsedWaitTime < _waitTime) { return; } _elapsedWaitTime = 0f; _state = BatState.FlyingToPlayer; }
public Bat(GameObject inPrefab, Vector2 inTransform, Vector2 inTarget, float inSpeed) { position = inTransform; target = inTarget; speed = inSpeed; state = BatState.FLYING; prefab = GameController.main.InstantAutoBat(inPrefab, inTransform); prefab.GetComponents <AudioSource>()[0].Play(); }
private void Start() { Rigidbody = GetComponent <Rigidbody>(); AnimationController = GetComponentInChildren <Animator>(); BatState = GetComponent <BatState>(); StartMass = Rigidbody.mass; if (Match.Instance) { InverseDirections = Match.Instance.inverseDirections[GetComponent <BatState>().ownerId]; } }
// Update is called once per frame protected override void Update () { base.Update (); animation_counter++; animation_counter %= 2*animation_inverval; GetComponent<SpriteRenderer> ().sprite = Sprites [animation_counter / animation_inverval]; if (bat_state == BatState.fast) { float u = (Time.time - timeStart) / duration; if (u >= 1) { // if u >=1... InitMovement (1); // ...then initialize movement to a new point u = 0; bat_state = BatState.slow; animation_inverval = 20; } // u = 1 - Mathf.Pow( 1-u, 2 ); // Apply Ease Out easing to u this.GetComponent<Transform> ().position = (1 - u) * points [0] + u * points [1]; // Simple linear interpolation } else if (bat_state == BatState.slow) { float u = (Time.time - timeStart) / duration; if (u >= 1) { // if u >=1... InitMovement (0); // ...then initialize movement to a new point u = 0; bat_state = BatState.stop; animation_inverval = 1000000000; } // u = 1 - Mathf.Pow( 1-u, 2 ); // Apply Ease Out easing to u this.GetComponent<Transform> ().position = (1 - u) * points [0] + u * points [1]; // Simple linear interpolation } else { float u = (Time.time - timeStart) / duration; if (u >= 1) { // if u >=1... InitMovement (2); // ...then initialize movement to a new point u = 0; bat_state = BatState.fast; animation_inverval = 10; } // u = 1 - Mathf.Pow( 1-u, 2 ); // Apply Ease Out easing to u this.GetComponent<Transform> ().position = (1 - u) * points [0] + u * points [1]; // Simple linear interpolation } }
public void UpdateBat() { float attackDistance = 3f; float deathDistance = 0.2f; if ((position - target).magnitude < attackDistance) { state = BatState.DAMAGEABLE; prefab.GetComponentInChildren <SpriteRenderer>().color = Color.red; } if ((position - target).magnitude < deathDistance) { GameController.main.PlayerPlayGettingHit(); GameController.main.doGameOver(); } }
// Start is called before the first frame update void Start() { animator = GetComponent <Animator>(); GetComponent <CircleCollider2D>().radius = attackRange; player = GameObject.FindGameObjectWithTag("Player"); rigBody = GetComponent <Rigidbody2D>(); speedHolder = speed; direction = rigBody.velocity; rotationRight = new Vector3(25, transform.eulerAngles.y, transform.eulerAngles.z); rotationLeft = new Vector3(-25, transform.eulerAngles.y, transform.eulerAngles.z); rotationNone = new Vector3(0, transform.eulerAngles.y, transform.eulerAngles.z); m_BatState = BatState.Wait; targetPosition = player.transform.position; playerLocation = targetPosition; swap = true; batAudio = GetComponent <AudioSource>(); }
private void TransitionTo(BatState newstate) { switch (newstate) { case BatState.Idle: animator.SetTrigger("Idle"); break; case BatState.Dead: OnDeadEnter(); break; case BatState.Chasing: animator.SetTrigger("Chasing"); break; } currentState = newstate; Debug.Log("Transition to: " + newstate); }
public void OnDead() { state = BatState.DEAD; prefab.GetComponent <DestroyOnDead>().dead = true; }
void SwitchState(BatState state, float durationDecrease) { State = state; StateDuration -= durationDecrease; }
void SwitchState(BatState state) { State = state; StateDuration = 0.0f; }
public void SetBatState(BatState newState) { batState = newState; }
public void AnimationChange(BatState state, BatDirection direction) { if (!animatable) { return; } batDirection = direction; string bodyAnimation = name + "_"; string headAnimation = ""; moveHead = true; switch (state) { case BatState.LUNGE: bodyAnimation = bodyAnimation + "Lunge"; headAnimation = "Attack"; if (direction == BatDirection.LEFT) { transform.localScale = new Vector3(-1, 1, 1); } else { transform.localScale = new Vector3(1, 1, 1); } switch (direction) { case BatDirection.FRONT: headAnimation = headAnimation + "_Front"; headAnchor = lungeFront; bodyAnimation = bodyAnimation + "_Front"; break; case BatDirection.BACK: headAnimation = headAnimation + "_Back"; headAnchor = lungeBack; bodyAnimation = bodyAnimation + "_Back"; break; case BatDirection.RIGHT: headAnimation = headAnimation + "_Side"; headAnchor = lungeSide; bodyAnimation = bodyAnimation + "_Side"; break; case BatDirection.LEFT: headAnimation = headAnimation + "_Side"; headAnchor = lungeSide; bodyAnimation = bodyAnimation + "_Side"; break; } break; case BatState.FLY: bodyAnimation = bodyAnimation + "Fly"; headAnimation = "Attack"; if (direction == BatDirection.LEFT) { transform.localScale = new Vector3(-1, 1, 1); } else { transform.localScale = new Vector3(1, 1, 1); } switch (direction) { case BatDirection.FRONT: headAnimation = headAnimation + "_Front"; headAnchor = flyFront; bodyAnimation = bodyAnimation + "_Front"; break; case BatDirection.BACK: headAnimation = headAnimation + "_Back"; headAnchor = flyBack; bodyAnimation = bodyAnimation + "_Back"; break; case BatDirection.RIGHT: headAnimation = headAnimation + "_Side"; headAnchor = flySide; bodyAnimation = bodyAnimation + "_Side"; break; case BatDirection.LEFT: headAnimation = headAnimation + "_Side"; headAnchor = flySide; bodyAnimation = bodyAnimation + "_Side"; break; } break; case BatState.SHOOT: bodyAnimation = bodyAnimation + "Idle"; headAnimation = "Attack"; if (direction == BatDirection.LEFT) { transform.localScale = new Vector3(-1, 1, 1); } else { transform.localScale = new Vector3(1, 1, 1); } switch (direction) { case BatDirection.FRONT: headAnimation = headAnimation + "_Front"; headAnchor = idleFront; bodyAnimation = bodyAnimation + "_Front"; break; case BatDirection.BACK: headAnimation = headAnimation + "_Back"; headAnchor = idleBack; bodyAnimation = bodyAnimation + "_Back"; break; case BatDirection.RIGHT: headAnimation = headAnimation + "_Side"; headAnchor = idleSide; bodyAnimation = bodyAnimation + "_Side"; break; case BatDirection.LEFT: headAnimation = headAnimation + "_Side"; headAnchor = idleSide; bodyAnimation = bodyAnimation + "_Side"; break; } break; case BatState.IDLE: bodyAnimation = bodyAnimation + "Idle"; headAnimation = "Idle"; if (direction == BatDirection.LEFT) { transform.localScale = new Vector3(-1, 1, 1); } else { transform.localScale = new Vector3(1, 1, 1); } switch (direction) { case BatDirection.FRONT: headAnimation = headAnimation + "_Front"; headAnchor = idleFront; bodyAnimation = bodyAnimation + "_Front"; break; case BatDirection.BACK: headAnimation = headAnimation + "_Back"; headAnchor = idleBack; bodyAnimation = bodyAnimation + "_Back"; break; case BatDirection.RIGHT: headAnimation = headAnimation + "_Side"; headAnchor = idleSide; bodyAnimation = bodyAnimation + "_Side"; break; case BatDirection.LEFT: headAnimation = headAnimation + "_Side"; headAnchor = idleSide; bodyAnimation = bodyAnimation + "_Side"; break; } break; case BatState.WALK: bodyAnimation = bodyAnimation + "Walk"; headAnimation = "Idle"; if (direction == BatDirection.LEFT) { transform.localScale = new Vector3(-1, 1, 1); } else { transform.localScale = new Vector3(1, 1, 1); } switch (direction) { case BatDirection.FRONT: headAnimation = headAnimation + "_Front"; headAnchor = idleFront; bodyAnimation = bodyAnimation + "_Front"; break; case BatDirection.BACK: headAnimation = headAnimation + "_Back"; headAnchor = idleBack; bodyAnimation = bodyAnimation + "_Back"; break; case BatDirection.RIGHT: headAnimation = headAnimation + "_Side"; headAnchor = idleSide; bodyAnimation = bodyAnimation + "_Side"; break; case BatDirection.LEFT: headAnimation = headAnimation + "_Side"; headAnchor = idleSide; bodyAnimation = bodyAnimation + "_Side"; break; } break; } bodyAnimator.Play(bodyAnimation); headAnimator.Play(headAnimation, 0); }
public void Initialize(MainWindow window) { ImageBrush imgBrush = new ImageBrush(new BitmapImage(new Uri(IMAGE_PATH + "lightsaber1" + ".png", UriKind.Relative))); // added 3 Media Player objects, they handle the sound for the bat class such as, // lightsaber loop, the turning of the lightsaber, and the lighsaber swing. lightsaberStart = new MediaPlayer(); lightsaberLoop = new MediaPlayer(); lightsaberSwing = new MediaPlayer(); // Setting the volume of each sound. lightsaberStart.Volume = .45; lightsaberLoop.Volume = .15; lightsaberSwing.Volume = .40; // Opening each mp3 file that goes with each media player. lightsaberStart.Open(new Uri(SOUND_PATH + "lightsaber_start.mp3", UriKind.Relative)); lightsaberLoop.Open(new Uri(SOUND_PATH + "lightsaber_loop.mp3", UriKind.Relative)); lightsaberSwing.Open(new Uri(SOUND_PATH + "lightsaber_swing.mp3", UriKind.Relative)); // have to create a event handler in order to loop the lightsaber_loop sound. lightsaberLoop.MediaEnded += LightsaberLoop_MediaEnded; // Plays the startup sound for the lightsaber. lightsaberStart.Play(); // You have to reset the position of the media sound after you play it. lightsaberStart.Position = new TimeSpan(); // Creates the bat to be drawn on display. eLine = window.myBat; eLine.Stroke = Brushes.Black; eLine.X1 = window.TheCanvas.Width / 1.40; eLine.X2 = window.TheCanvas.Width / 1.40; eLine.Y1 = window.TheCanvas.Height / 1.25; eLine.Y2 = eLine.Y1 - 225; eLine.StrokeThickness = 100; eLine.Stroke = imgBrush; eLine.RenderTransform = new RotateTransform(startAngle, eLine.X1, eLine.Y1); batState = BatState.Ready; i = startAngle; lightsaberLoop.Play(); swung = false; }
void Start() { transform.position = MakeNewRandomPoint(); _state = BatState.Starting; }
// enables the bat to be swung by the user. Allowing it to be in the initial angle, // then allowing it to be swung. public void SwingBat() { if (batState == BatState.Ready) { batState = BatState.Forwards; lightsaberSwing.Play(); lightsaberSwing.Position = new TimeSpan(); swung = true; } }
// Retarts bat to their initial positions, enables the ready phase, // restarts the number of misses the player has to 0. public void Reset(MainWindow window) { eLine.X1 = window.Width / 1.40; eLine.X2 = window.Width / 1.40; eLine.Y1 = window.Height / 1.25; eLine.Y2 = eLine.Y1 - 225; eLine.RenderTransform = new RotateTransform(startAngle, eLine.X1, eLine.Y1); batState = BatState.Ready; numMissed = 0; }
private void Start() { bat = GetComponent <BatState>(); }
private void FixedUpdate() { switch (m_BatState) { case BatState.Chase: // animator.Play("ghost-idle", 0);//we can set an animation if (Time.time > nextDirectionChange) { nextDirectionChange = Time.time + timeDelay; //set a target position if (swap) { targetPosition.x = player.transform.position.x + 0.1f + Random.value; swap = !swap; } else { targetPosition.x = player.transform.position.x - 0.1f - Random.value; swap = !swap; } targetPosition.y = player.transform.position.y + attackRange * 0.8f + Random.value; } break; case BatState.Attack: targetPosition.x = player.transform.position.x; targetPosition.y = player.transform.position.y; break; case BatState.Wait: if (Time.time > nextDirectionChange) { batAudio.clip = batFlyingClip; batAudio.Play(); nextDirectionChange = Time.time + 3f; //set a target position targetPosition.x = transform.position.x + Random.value; targetPosition.y = transform.position.y - Random.value; m_BatState = BatState.Chase; } break; }//end switch playerLocation = player.transform.position; direction = rigBody.velocity; if (targetPosition.x > transform.position.x + 0.1) { direction.x = 1 * speed; transform.eulerAngles = rotationRight; } else if (targetPosition.x < transform.position.x - 0.1) { direction.x = -1 * speed; transform.eulerAngles = rotationLeft; } else { direction.x = 0; transform.eulerAngles = rotationNone; } if (targetPosition.y > transform.position.y + 0.1) { direction.y = 1 * speed; } else if (targetPosition.y < transform.position.y - 0.1) { direction.y = -1 * speed; } else { direction.y = 0; } rigBody.velocity = direction; }