コード例 #1
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
    private void ShowNextTrainingMessage()
    {
        TrainingHandler handler =
            MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler");

        handler.ShowNext();
    }
コード例 #2
0
 protected override void OnMouseDown()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     if (!TrainingHandler.IsTrainingFinished())
     {
         if (!MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler").IsPassengerClickAllowed())
         {
             return;
         }
     }
     if (
         MonobehaviorHandler.GetMonobeharior()
         .GetObject <BonusTimer>("bonusTimer")
         .IsAnyBonusActive())
     {
         bool    isDoubleClick = Character.TimeSincePreviousClickMade < MovableCharacterSM.MaxClickDuration;
         Vector2 targetPos     = MonobehaviorHandler.GetMonobeharior()
                                 .GetObject <Floor>("Floor").GetCurrentMousePosition();
         List <MovableCharacterSM> affectedCharacters = MonobehaviorHandler.GetMonobeharior()
                                                        .GetObject <BonusTimer>("bonusTimer").HandleClick(targetPos, isDoubleClick);
         if (!affectedCharacters.Contains(Character))
         {
             base.OnMouseDown();
         }
     }
     else
     {
         base.OnMouseDown();
     }
 }
コード例 #3
0
ファイル: ConductorDragState.cs プロジェクト: Syjgin/zerotram
    public override void OnUpdate()
    {
        if (_conductor.GetDragTarget() == null || !Input.GetMouseButton(0))
        {
            _conductor.StopDrag(false);
            return;
        }
        Vector3 targetPos = new Vector3();

        if (!MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetCurrentMousePosition(ref targetPos))
        {
            return;
        }
        Vector2 dragOffset = _conductor.GetDragOffset();

        if (dragOffset.sqrMagnitude > 0.1f)
        {
            MovableCharacter.Animator.Play("walk");
            Vector3 newPosition = Vector3.MoveTowards(MovableCharacter.transform.position, _conductor.GetDragTarget().transform.position,
                                                      _conductor.MovingToDragTargetVelocity * Time.deltaTime);
            newPosition.z = -1;
            MovableCharacter.transform.position = newPosition;
        }
        else
        {
            MovableCharacter.Animator.Play("drag");
            Vector3 newPos = (Vector2)targetPos + _conductor.GetDragOffset();
            MovableCharacter.CalculateOrientation(newPos);
            MovableCharacter.transform.position = newPos;
        }
    }
コード例 #4
0
    public bool FindRunAwayTarget(PassengerSM ps)
    {
        _passengers.RemoveAll(item => item == null);
        foreach (var passenger in _passengers)
        {
            if (passenger != ps)
            {
                float dist = ((Vector2)passenger.transform.position - (Vector2)ps.transform.position).sqrMagnitude;
                if (dist < ps.AttackMaxDistance)
                {
                    if (ps.TryRunAwayFromMovable(passenger))
                    {
                        return(true);
                    }
                }
            }
        }
        ConductorSM hero          = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
        float       conductorDist = ((Vector2)hero.transform.position - (Vector2)ps.transform.position).sqrMagnitude;

        if (conductorDist < ps.AttackMaxDistance)
        {
            if (ps.TryRunAwayFromMovable(hero))
            {
                return(true);
            }
        }
        return(false);
    }
コード例 #5
0
 public void KillStickPassenger()
 {
     foreach (var passengerSm in _passengers)
     {
         if (passengerSm.IsStick())
         {
             if (!TrainingHandler.IsTrainingFinished())
             {
                 if (passengerSm.IsStickModifiedForTraining())
                 {
                     TrainingHandler handler =
                         MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler");
                     handler.SetIsGnomeSurvived(false);
                     handler.ShowNext();
                 }
             }
             else
             {
                 RegisterDeath(passengerSm);
             }
             if (passengerSm != null)
             {
                 MonoBehaviour.Destroy(passengerSm.gameObject);
             }
             return;
         }
     }
 }
コード例 #6
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
    protected override void Update()
    {
        base.Update();
        ConductorSM hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();

        if (hero == null)
        {
            return;
        }
        CalculateIndicator();
        if (!hero.IsDragging())
        {
            StopDrag(false);
        }
        if (AttackTarget != null)
        {
            if (AttackTarget.CanNotInteract())
            {
                AttackTarget = null;
            }
        }
        _attackingDenyPeriod -= Time.deltaTime;
        if (_attackingDenyPeriod <= 0)
        {
            IsAttackingAllowed = true;
        }
        if (AttackTarget != null)
        {
            float dist = AttackTargetDistance();
            if (dist > AttackMaxDistance)
            {
                AttackTarget = null;
            }
        }
    }
コード例 #7
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
    public void CalculateMagnet()
    {
        if (_isMagnetActivated)
        {
            if (_hasTicket && _isVisibleToHero)
            {
                _isMagnetActivated = false;
                _isMagnetTurnedOn  = false;
            }
        }
        ConductorSM hero         = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
        Vector2     heroPosition = hero.transform.position;
        float       heroDist     = ((Vector2)transform.position - heroPosition).sqrMagnitude;

        if (heroDist < _magnetDistance || _isMagnetActivated)
        {
            _isMagnetActivated = true;
            if (heroDist < 0.1f)
            {
                return;
            }
            if (!GetTarget().Equals(heroPosition))
            {
                SetTarget(hero.transform.position);
            }
        }
    }
コード例 #8
0
    public override void OnUpdate()
    {
        MovableCharacter.Animator.Play("walk");
        if (_passenger.IsMagnetTurnedOn())
        {
            _passenger.CalculateMagnet();
        }
        float sqrRemainingDistance = MovableCharacter.GetTargetDistance();

        if (sqrRemainingDistance <= 0.1)
        {
            if (MovableCharacter.IsGoingAway)
            {
                if (GameController.GetInstance().IsDoorsOpen() && MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").IsPassengerNearDoors(_passenger))
                {
                    CalculateStickOnExit();
                    if (!_passenger.IsStick())
                    {
                        GameObject.Destroy(_passenger.gameObject);
                        return;
                    }
                }
            }
            else
            {
                if (!_passenger.IsStick())
                {
                    _passenger.MakeIdle();
                }
            }
            return;
        }
        CalculatePosition();
    }
コード例 #9
0
 void FixedUpdate()
 {
     if (_isPaused)
     {
         _currentStickSoundRemainingTime -= Time.fixedDeltaTime;
         if (_currentStickSoundRemainingTime <= 0)
         {
             _currentStickSoundRemainingTime = StickSoundDelay;
             _player.PlayAudioById("tramdoorstuck");
         }
         if (_currentStickPassenger == null)
         {
             _currentStickPassenger = GameController.GetInstance().GetStickPassenger();
             if (_currentStickPassenger != null)
             {
                 _currentStickDoor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetPassengerDoor(_currentStickPassenger)
                                     .GetComponent <DoorsAnimationController>();
             }
         }
         if (_currentStickDoor != null)
         {
             _currentStickDoor.Glitch();
         }
         return;
     }
     if (_isDoorsOpen)
     {
         _currentStopDuration += Time.fixedDeltaTime;
         if (_currentStopDuration > _stopDuration)
         {
             _isDoorsOpen         = false;
             _currentStopDuration = 0;
             UpdateDoors();
         }
     }
     else
     {
         if (!_isMovementTimeLocked)
         {
             _currentMoveDuration += Time.fixedDeltaTime;
         }
         if (_currentMoveDuration > _currentStationTotalMoveDuration)
         {
             _isDoorsOpen         = true;
             _currentMoveDuration = 0;
             GameController.GetInstance().CheckBeforeDoorsOpen();
             UpdateDoors();
             GameController.GetInstance().IncrementStationNumberForPassengers();
             if (_countToFinish > 0)
             {
                 _countToFinish--;
                 if (_countToFinish == 0)
                 {
                     MonobehaviorHandler.GetMonobeharior()
                     .GetObject <TrainingHandler>("TrainingHandler").ShowNext();
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: ConductorSM.cs プロジェクト: Syjgin/zerotram
 public override void HandleDoubleClick()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").DoubleClick();
 }
コード例 #11
0
    public void RegisterDeath(MovableCharacterSM obj)
    {
        if (obj is ConductorSM)
        {
            GameOver(true);
        }
        else
        {
            if (obj is PassengerSM)
            {
                var ps = obj as PassengerSM;
                if (ps.HasTicket())
                {
                    if (!ps.WasStickWhenFlyAway)
                    {
                        _killedPassengers++;
                    }
                    if (!ps.IsVisibleToHero())
                    {
                        if (_totalHares > 0)
                        {
                            _totalHares--;
                        }
                    }
                }
                else
                {
                    if (!_flyingAwayByKinds.ContainsKey(ps.GetClassName()))
                    {
                        _flyingAwayByKinds.Add(ps.GetClassName(), 1);
                    }
                    else
                    {
                        int currentValue = _flyingAwayByKinds [ps.GetClassName()];
                        _flyingAwayByKinds [ps.GetClassName()] = currentValue + 1;
                    }
                    if (_totalHares > 0)
                    {
                        _totalHares--;
                    }
                }

                _passengers.Remove(ps);
            }
            UpdateStats();
            if (_maxKilledPassengers < 0)
            {
                GameOver(false);
            }
            else
            {
                if (_passengers.Count == 0)
                {
                    MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").StopNow();
                }
            }
        }
    }
コード例 #12
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
    public void MoveToRandomPosition()
    {
        Vector2 target = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetRandomPosition();

        if (target != default(Vector2))
        {
            SetTarget(target);
        }
    }
コード例 #13
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
 public void IncrementStationCount()
 {
     _currentTramStopCount++;
     if (_currentTramStopCount > _tramStopCount && !IsGoingAway)
     {
         DoorsAnimationController door1 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door1");
         DoorsAnimationController door2 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door2");
         DoorsAnimationController door3 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door3");
         DoorsAnimationController door4 =
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsAnimationController>("door4");
         List <DoorsAnimationController> selected = new List <DoorsAnimationController>();
         if (door1.IsOpened())
         {
             selected.Add(door1);
         }
         if (door2.IsOpened())
         {
             selected.Add(door2);
         }
         if (door3.IsOpened())
         {
             selected.Add(door3);
         }
         if (door4.IsOpened())
         {
             selected.Add(door4);
         }
         if (selected.Count == 0)
         {
             return;
         }
         int randomPercent = Randomizer.GetRandomPercent();
         int step          = 100 / selected.Count;
         int currentStep   = 0;
         int i             = 0;
         for (i = 0; i < selected.Count - 1; i++)
         {
             if (currentStep > randomPercent)
             {
                 break;
             }
             currentStep += step;
         }
         BoxCollider2D collider = selected[i].GetComponent <BoxCollider2D>();
         Vector2       target   = new Vector2(selected[i].gameObject.transform.position.x, selected[i].gameObject.transform.position.y) + collider.offset;
         Velocity *= 2;
         if (_isGoAwayVelocityIncreased)
         {
             Velocity *= 2;
         }
         IsGoingAway = true;
         base.SetTarget(target);
     }
 }
コード例 #14
0
 public override void Deactivate()
 {
     base.Deactivate();
     GameController.GetInstance().BonusEffectToPassengers(this, false);
     if (IsConductorAffected)
     {
         ConductorSM conductor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
         RemoveEffectFromConductor(conductor);
     }
 }
コード例 #15
0
 public void GameOver(bool isConductorDied)
 {
     MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero().StopDrag(false);
     _isGameFinished = true;
     Time.timeScale  = 0;
     UpdateListeners(isConductorDied);
     foreach (var gameStateNotificationListener in _listeners)
     {
         gameStateNotificationListener.GameOver();
     }
 }
コード例 #16
0
 private void CalculateStickOnExit()
 {
     if (_passenger.GetActiveState().Equals((int)MovableCharacterSM.MovableCharacterStates.Stick))
     {
         return;
     }
     _passenger.CalculateStick();
     if (_passenger.IsStick())
     {
         MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(true);
     }
 }
コード例 #17
0
ファイル: MovableCharacterSM.cs プロジェクト: Syjgin/zerotram
    protected override void Update()
    {
        base.Update();
        float newScale = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").CalculateLocalScaleForMovable(this);

        if (Math.Abs(newScale - _currentScale) > 0.01f)
        {
            _currentScale = newScale;
            bool inversed = (CharacterBody.transform.localScale.x < 0);
            CharacterBody.transform.localScale = new Vector3(inversed ? -newScale : newScale, newScale, 1);
        }
    }
コード例 #18
0
 protected override void OnStart()
 {
     _timeSinceStateChanged = 0;
     if (_hero == null)
     {
         _hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
     }
     if (_floor == null)
     {
         _floor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor");
     }
 }
コード例 #19
0
 public override void Activate()
 {
     base.Activate();
     if (IsPassengersAffected)
     {
         GameController.GetInstance().BonusEffectToPassengers(this, true);
     }
     if (IsConductorAffected)
     {
         ConductorSM conductor = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();
         AddEffectToConductor(conductor);
     }
 }
コード例 #20
0
    public override void OnUpdate()
    {
        RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

        if (Input.GetMouseButtonDown(0))
        {
            Vector2 transform2d = MovableCharacter.transform.position;
            float   distance    = (transform2d - hit.centroid).sqrMagnitude;
            if (distance < 1 && MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero().IsInAttackRadius(MovableCharacter.transform.position))
            {
                _passenger.HandleClick();
            }
        }
    }
コード例 #21
0
 protected override void AddEffectAfterCheck(PassengerSM passenger)
 {
     MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(false);
     passenger.ActiveBonuses.Add(GetBonusType());
     if (_data == null)
     {
         _data            = new FreezeData();
         _data.Distance   = Dist;
         _data.StartPoint = Position;
         _floor           = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor");
         _floor.SnowDrop(_data, true);
     }
     passenger.ActivateFreezeBonus(_data);
 }
コード例 #22
0
ファイル: MovableCharacterSM.cs プロジェクト: Syjgin/zerotram
 public void CalculateOrientation(Vector2 target)
 {
     if (_currentScale == 0)
     {
         _currentScale = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").CalculateLocalScaleForMovable(this);
     }
     if (target.x > transform.position.x)
     {
         CharacterBody.transform.localScale = new Vector3(-_currentScale, _currentScale, 1);
     }
     else
     {
         CharacterBody.transform.localScale = new Vector3(_currentScale, _currentScale, 1);
     }
 }
コード例 #23
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
    public void AddVortexEffect(Vector2 point, float dist)
    {
        float   randomAngleInDegrees = Randomizer.GetInRange(0, 360);
        float   radians   = randomAngleInDegrees * Mathf.Deg2Rad;
        float   finalDist = Mathf.Min(dist * 0.5f, Randomizer.GetNormalizedRandom() * dist);
        float   xOffset   = finalDist * Mathf.Cos(radians);
        float   yOffset   = finalDist * Mathf.Sin(radians);
        Vector3 oldPos    = transform.position;
        Vector3 newPos    = new Vector3(oldPos.x + xOffset, oldPos.y + yOffset, oldPos.z);

        MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").NormalizePosition(ref newPos, true);
        StopStick();
        MakeIdle();
        transform.position = newPos;
    }
コード例 #24
0
ファイル: PassengerSM.cs プロジェクト: Syjgin/zerotram
    public override void HandleDoubleClick()
    {
        ConductorSM hero = MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").GetHero();

        if (hero.CanKick(this))
        {
            if (_isFlyAwayDenied)
            {
                return;
            }
            hero.Kick(this);
            return;
        }
        hero.StartDrag(this);
    }
コード例 #25
0
 void OnMouseDown()
 {
     if (Time.timeScale == 0)
     {
         return;
     }
     if (!TrainingHandler.IsTrainingFinished())
     {
         if (_currentPeriod < WaitTimeForTraining)
         {
             return;
         }
     }
     MonobehaviorHandler.GetMonobeharior()
     .GetObject <BonusTimer>("bonusTimer").ActivateDrop(this);
 }
コード例 #26
0
    private void CalculateTarget()
    {
        if (_passenger.GetPursuer() == null)
        {
            _passenger.MakeIdle();
            return;
        }
        float   dot             = Vector2.Dot(_passenger.GetPursuer().transform.position, _passenger.transform.position);
        float   angle           = Mathf.Acos(dot);
        Vector2 incrementVector = new Vector2(_passenger.AttackMaxDistance, 0);
        Vector2 rotated         = Quaternion.Euler(0, 0, angle) * incrementVector;
        Vector3 final           = (Vector2)_passenger.transform.position + rotated;

        MonobehaviorHandler.GetMonobeharior().GetObject <Floor>("Floor").NormalizePosition(ref final, true);
        _passenger.SetEscapeTarget(final);
        _targetCalculated = true;
    }
コード例 #27
0
 void Update()
 {
     if (_isGlitch)
     {
         if (_currentStickPeriod > 0)
         {
             _currentStickPeriod -= Time.deltaTime;
         }
         else
         {
             _currentStickPeriod = 0;
             GameController.GetInstance().KillStickPassenger();
             MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(false);
             _isGlitch = false;
         }
     }
 }
コード例 #28
0
ファイル: StickNote.cs プロジェクト: Syjgin/zerotram
 void FixedUpdate()
 {
     if (_currentStickPeriod > 0)
     {
         _currentStickPeriod -= Time.fixedDeltaTime;
     }
     else
     {
         _currentStickPeriod = 0;
     }
     UpdateText();
     if (_currentStickPeriod == 0)
     {
         GameController.GetInstance().KillStickPassenger();
         MonobehaviorHandler.GetMonobeharior().GetObject <DoorsTimer>("DoorsTimer").SetPaused(false);
     }
 }
コード例 #29
0
    public static void ReplacePassenger(PassengerSM passenger)
    {
        Vector3 passengerPosition = passenger.transform.position;
        bool    hasTicket         = passenger.HasTicket();
        bool    isVisibleToHero   = passenger.IsVisibleToHero();
        string  passengerType     = passenger.GetClassName();

        passenger.enabled = false;
        if (_spawner == null)
        {
            _spawner = MonobehaviorHandler.GetMonobeharior().GetObject <Spawner>("Spawner");
        }
        PassengerSM newPassenger = _spawner.SpawnAlternativePassenger(passengerPosition, passengerType);

        newPassenger.SetTicketAndVisibility(hasTicket, isVisibleToHero);
        GameController.GetInstance().ReplacePassenger(newPassenger, passenger);
    }
コード例 #30
0
    public override void OnUpdate()
    {
        MovableCharacter.Animator.Play("attacked");
        Vector3 newPosition = Vector3.MoveTowards(MovableCharacter.transform.position, _flyTarget, 50 * Time.deltaTime);

        MovableCharacter.transform.position = newPosition;
        float sqrRemainingDistance = ((Vector2)newPosition - (Vector2)_flyTarget).sqrMagnitude;

        if (sqrRemainingDistance <= 1)
        {
            if (_passenger.IsFlyAwayListenerActivated())
            {
                MonobehaviorHandler.GetMonobeharior().GetObject <TrainingHandler>("TrainingHandler").ShowNext();
            }
            MonoBehaviour.Destroy(MovableCharacter.gameObject);
        }
    }