public NpcController(GameView inGameView, ActorFacing inFacing) : base(inGameView)
        {
            // --------------------------------------------------------------------------------
            // Initializing
            // --------------------------------------------------------------------------------
            _animator = inGameView.GetComponent <GameAnimator>() ??
                        throw new Exception($"GameView [{inGameView.name}] must attached GameAnimator component.");

            _collider = inGameView.GetComponent <HitBox>() ??
                        throw new Exception($"GameView [{inGameView.name}] must attached GameCollider component.");

            _view = inGameView as EnemyView ?? throw new Exception($"NpcController can only attached to EnemyView");

            _lastAction    = ActorActions.None;
            _currentAction = ActorActions.None;
            _facing        = inFacing;
            _directionX    = GetIntDirection();
            _view.SetDirectionX(_directionX);

            // --------------------------------------------------------------------------------
            // Add Ray Sensor to detect player
            // --------------------------------------------------------------------------------
            var rayLength = (_view.GetSize().x / 2) + _view.Profile.sightDistance;

            _sightRay                 = gameView.AddComponent(new RaySensor(gameView, GetDirection(), rayLength, true));
            _sightRay.onHitEvent     += inO => { hasEnemy = true; };
            _sightRay.onHitLostEvent += () => { hasEnemy = false; };
            _sightRay.SetOffset(new Vector2(0, (_view.GetSize().y - 7)));  //set the origin ray as middle center

            SystemFacade.NPC.AddComponent(this);
        }
    private SpriteRenderer createNewWeap(float x, GameCollider shotPrefab)
    {
        var shot = Instantiate(shotPrefab);

        shot.transform.parent        = transform;
        shot.transform.localPosition = new Vector2(x, 0);
        shot.GetComponent <BoxCollider2D>().enabled = false;
        return(setSemiTransparrent(shot.GetComponent <SpriteRenderer>()));
    }
Beispiel #3
0
        public List <GameCollider> shoot()
        {
            GameCollider shotPrefab = weaponry.ShotPrefabsByDamage.EqualOrNextGreater(weaponry.DamageMultiplier);
            var          latest     = MonoBehaviour.Instantiate(shotPrefab);
            var          collider   = latest.GetComponent <GameCollider>();

            latest.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 1000f);

            return(new List <GameCollider> {
                collider
            });
        }
Beispiel #4
0
    public virtual void TakeHitFrom(GameCollider other)
    {
        CreateHitEffect(other.transform);
        if (Health <= 0)
        {
            return;
        }

        Health -= other.Damage;
        if (Health <= 0)
        {
            Kill();
        }
    }
Beispiel #5
0
    public override void TakeHitFrom(GameCollider dmgDealer)
    {
        var interactor = dmgDealer.GetComponent <UCharacterInteractor>();

        if (interactor != null)
        {
            interactor.InteractWith(this);
        }
        else
        {
            base.TakeHitFrom(dmgDealer);
            healthBar.UpdateHealth(Health);

            spawnShield();
        }
    }
        protected virtual void OnEnable()
        {
            gameCollider = (GameCollider)target;

            // get serialized objects so we can use attached property drawers (e.g. tooltips, ...)
            _collidingTagProperty         = serializedObject.FindProperty("_collidingTag");
            _intervalProperty             = serializedObject.FindProperty("_interval");
            _disableAfterUseProperty      = serializedObject.FindProperty("_disableAfterUse");
            _onlyWhenLevelRunningProperty = serializedObject.FindProperty("_onlyWhenLevelRunning");
            _enterProperty         = serializedObject.FindProperty("_enter");
            _processWithinProperty = serializedObject.FindProperty("_processWithin");
            _runIntervalProperty   = serializedObject.FindProperty("_runInterval");
            _withinProperty        = serializedObject.FindProperty("_within");
            _exitProperty          = serializedObject.FindProperty("_exit");

            // setup actions types
            _gameActionClassDetails = GameActionEditorHelper.FindTypesClassDetails();
        }
Beispiel #7
0
        public ControlView(GameView inGameView, PlayerProfile inProfile) : base(inGameView)
        {
            // --------------------------------------------------------------------------------
            // Initializing
            // --------------------------------------------------------------------------------
            _collider = inGameView.GetComponent <HitBox>() ??
                        throw new NullReferenceException($"Missing Component HitBox");

            _animator = inGameView.GetComponent <GameAnimator>() ??
                        throw new NullReferenceException($"Missing Component GameAnimator");

            _view = inGameView as PlayerView ?? throw new Exception($"ControlView must be attached on PlayerView");

            _facing        = ActorFacing.Right;
            _directionX    = 1;
            profile        = inProfile;
            _lastAction    = ActorActions.None;
            _currentAction = ActorActions.None;
            _isQuickMove   = false;
            _jumpRequest   = false;

            // --------------------------------------------------------------------------------
            // Add Ray Sensor to detect is level collider
            // --------------------------------------------------------------------------------
            var rayChild  = _view.CreateChild("CollisionRay");
            var rayLength = (_view.GetSize().x / 2) + profile.colliderBlockDistance;

            _levelColliderSensor                 = rayChild.AddComponent(new RaySensor(rayChild, GetDirection(), rayLength, true));
            _levelColliderSensor.onHitEvent     += inO => { _isBlocked = true; };
            _levelColliderSensor.onHitLostEvent += () => { _isBlocked = false; };
            _levelColliderSensor.SetOffset(new Vector2(0, (_view.GetSize().y / 2))); //set the origin ray as middle center
            // --------------------------------------------------------------------------------
            // Add Ray Sensor to detect is grounded
            // --------------------------------------------------------------------------------
            var rayGround = gameView.AddComponent(new RaySensor(gameView, Vector2.down, 5f, true));

            rayGround.onHitEvent     += inO => { _playerInTheAir = false; };
            rayGround.onHitLostEvent += () => { _playerInTheAir = true; };
        }
Beispiel #8
0
 protected static void RetaliateAgainst(GameCollider other)
 {
     other.CollideWithOtherCharacter();
 }