Beispiel #1
0
        /// <summary>
        /// Creates the damage area.
        /// </summary>
        protected virtual void CreateDamageArea()
        {
            _damageArea      = new GameObject();
            _damageArea.name = this.name + "DamageArea";
            _damageArea.transform.position = this.transform.position;
            _damageArea.transform.rotation = this.transform.rotation;
            _damageArea.transform.SetParent(this.transform);

            if (DamageAreaShape == MeleeDamageAreaShapes.Rectangle)
            {
                _boxCollider2D        = _damageArea.AddComponent <BoxCollider2D>();
                _boxCollider2D.offset = AreaOffset;
                _boxCollider2D.size   = AreaSize;
                _damageAreaCollider   = _boxCollider2D;
            }
            if (DamageAreaShape == MeleeDamageAreaShapes.Circle)
            {
                _circleCollider2D = _damageArea.AddComponent <CircleCollider2D>();
                _circleCollider2D.transform.position = this.transform.position + this.transform.rotation * AreaOffset;
                _circleCollider2D.radius             = AreaSize.x / 2;
                _damageAreaCollider = _circleCollider2D;
            }
            _damageAreaCollider.isTrigger = true;

            Rigidbody2D rigidBody = _damageArea.AddComponent <Rigidbody2D> ();

            rigidBody.isKinematic = true;

            _damageOnTouch = _damageArea.AddComponent <DamageOnTouch>();
            _damageOnTouch.TargetLayerMask            = TargetLayerMask;
            _damageOnTouch.DamageCaused               = DamageCaused;
            _damageOnTouch.DamageCausedKnockbackType  = Knockback;
            _damageOnTouch.DamageCausedKnockbackForce = KnockbackForce;
            _damageOnTouch.InvincibilityDuration      = InvincibilityDuration;
        }
Beispiel #2
0
 /// <summary>
 /// On awake, we store the initial speed of the object
 /// </summary>
 protected virtual void Awake()
 {
     _facingRightInitially = ProjectileIsFacingRight;
     _initialSpeed         = Speed;
     _collider             = GetComponent <BoxCollider2D>();
     _spriteRenderer       = GetComponent <SpriteRenderer>();
     _damageOnTouch        = GetComponent <DamageOnTouch>();
     _initialInvulnerabilityDurationWFS = new WaitForSeconds(InitialInvulnerabilityDuration);
     if (_spriteRenderer != null)
     {
         _initialFlipX = _spriteRenderer.flipX;
     }
     _initialLocalScale = transform.localScale;
 }
        /// <summary>
        /// Gets and stores input manager, camera and components
        /// </summary>
        public virtual void Initialization()
        {
            // we initialize our state machines
            MovementState  = new MMStateMachine <CharacterStates.MovementStates>(this.gameObject, SendStateChangeEvents);
            ConditionState =
                new MMStateMachine <CharacterStates.CharacterConditions>(this.gameObject, SendStateChangeEvents);

            if (InitialFacingDirection == FacingDirections.Left)
            {
                IsFacingRight = false;
            }
            else
            {
                IsFacingRight = true;
            }

            // instantiate camera target
            if (CameraTarget == null)
            {
                CameraTarget = new GameObject();
            }

            CameraTarget.transform.SetParent(this.transform);
            CameraTarget.transform.localPosition = Vector3.zero;
            CameraTarget.name            = "CameraTarget";
            _cameraTargetInitialPosition = CameraTarget.transform.localPosition;

            // we get the current input manager
            SetInputManager();
            GetMainCamera();
            // we store our components for further use
            CharacterState  = new CharacterStates();
            _spriteRenderer = this.gameObject.GetComponent <SpriteRenderer>();
            _controller     = this.gameObject.GetComponent <CorgiController>();
            CacheAbilitiesAtInit();
            if (CharacterBrain == null)
            {
                CharacterBrain = this.gameObject.GetComponent <AIBrain>();
            }

            _health        = this.gameObject.GetComponent <Health>();
            _damageOnTouch = this.gameObject.GetComponent <DamageOnTouch>();
            CanFlip        = true;
            AssignAnimator();

            _originalGravity = _controller.Parameters.Gravity;

            ForceSpawnDirection();
        }
Beispiel #4
0
        /// <summary>
        /// Sets the projectile's owner.
        /// </summary>
        /// <param name="newOwner">New owner.</param>
        public virtual void SetOwner(GameObject newOwner)
        {
            _owner = newOwner;
            DamageOnTouch damageOnTouch = this.gameObject.GetComponentNoAlloc <DamageOnTouch>();

            if (damageOnTouch != null)
            {
                damageOnTouch.Owner = newOwner;
                damageOnTouch.Owner = newOwner;
                if (!DamageOwner)
                {
                    damageOnTouch.IgnoreGameObject(newOwner);
                }
            }
        }
        /// <summary>
        /// Creates the damage area.
        /// </summary>
        protected virtual void CreateDamageArea()
        {
            GameObject damageArea = new GameObject();

            damageArea.name = this.name + "DamageArea";
            damageArea.transform.position = this.transform.position;
            damageArea.transform.rotation = this.transform.rotation;
            damageArea.transform.SetParent(this.transform);

            if (DamageAreaShape == MeleeDamageAreaShapes.Rectangle)
            {
                BoxCollider2D boxcollider2d = damageArea.AddComponent <BoxCollider2D>();
                boxcollider2d.offset = AreaOffset;
                boxcollider2d.size   = AreaSize;
                _damageArea          = boxcollider2d;
            }
            if (DamageAreaShape == MeleeDamageAreaShapes.Circle)
            {
                CircleCollider2D circlecollider2d = damageArea.AddComponent <CircleCollider2D>();
                circlecollider2d.transform.position = this.transform.position + this.transform.rotation * AreaOffset;
                circlecollider2d.radius             = AreaSize.x / 2;
                _damageArea = circlecollider2d;
            }
            _damageArea.isTrigger = true;

            Rigidbody2D rigidBody = damageArea.AddComponent <Rigidbody2D>();

            rigidBody.isKinematic = true;

            DamageOnTouch damageOnTouch = damageArea.AddComponent <DamageOnTouch>();

            damageOnTouch.TargetLayerMask            = TargetLayerMask;
            damageOnTouch.DamageCaused               = DamageCaused;
            damageOnTouch.DamageCausedKnockbackType  = Knockback;
            damageOnTouch.DamageCausedKnockbackForce = KnockbackForce;
            damageOnTouch.InvincibilityDuration      = InvincibilityDuration;

            _plasmaBladeKnockBacker = damageArea.AddComponent <PlasmaBladeKnockBacker>();
            _plasmaBladeKnockBacker.CorgiController      = _controller;
            _plasmaBladeKnockBacker.PlayerKnockbackForce = PlayerKnockbackForce;
            _plasmaBladeKnockBacker.characterPlayer      = Owner;
            _plasmaBladeKnockBacker.ClashEffect          = MeleeClashEffect;
            _plasmaBladeKnockBacker.BladeClashEffect     = MeleeBladeClashEffect;
        }
Beispiel #6
0
        /// <summary>
        /// Gets and stores input manager, camera and components
        /// </summary>
        protected virtual void Initialization()
        {
            // we initialize our state machines
            MovementState  = new MMStateMachine <CharacterStates.MovementStates>(gameObject, SendStateChangeEvents);
            ConditionState = new MMStateMachine <CharacterStates.CharacterConditions>(gameObject, SendStateChangeEvents);

            if (InitialFacingDirection == FacingDirections.Left)
            {
                IsFacingRight = false;
            }
            else
            {
                IsFacingRight = true;
            }

            // we get the current input manager
            SetInputManager();
            // we get the main camera
            if (Camera.main == null)
            {
                return;
            }
            SceneCamera = Camera.main.GetComponent <CameraController>();
            // we store our components for further use
            CharacterState      = new CharacterStates();
            _spriteRenderer     = GetComponent <SpriteRenderer>();
            _controller         = GetComponent <CorgiController>();
            _characterAbilities = GetComponents <CharacterAbility>();
            _aiBrain            = GetComponent <AIBrain>();
            _health             = GetComponent <Health> ();
            _damageOnTouch      = GetComponent <DamageOnTouch>();
            CanFlip             = true;
            AssignAnimator();

            _originalGravity = _controller.Parameters.Gravity;

            ForceSpawnDirection();
        }
 // Use this for initialization
 void Start()
 {
     _damageOnTouch = GetComponent <DamageOnTouch>();
     SuperBlasterBonus();
 }
Beispiel #8
0
        /// <summary>
        /// Adds all the possible components to a character
        /// </summary>
        protected virtual void GenerateCharacter(Character.CharacterTypes type)
        {
            Character character = (Character)target;

            Debug.LogFormat(character.name + " : Character Autobuild Start");

            if (type == Character.CharacterTypes.Player)
            {
                character.CharacterType = Character.CharacterTypes.Player;
                // sets the layer
                character.gameObject.layer = LayerMask.NameToLayer("Player");
                // sets the tag
                character.gameObject.tag = "Player";
                // sets the player ID
                character.PlayerID = "Player1";
            }

            if (type == Character.CharacterTypes.AI)
            {
                character.CharacterType = Character.CharacterTypes.AI;
                // sets the layer
                character.gameObject.layer = LayerMask.NameToLayer("Enemies");
            }

            // Adds the rigidbody2D
            Rigidbody2D rigidbody2D = (character.GetComponent <Rigidbody2D>() == null) ? character.gameObject.AddComponent <Rigidbody2D>() : character.GetComponent <Rigidbody2D>();

            rigidbody2D.useAutoMass            = false;
            rigidbody2D.mass                   = 1;
            rigidbody2D.drag                   = 0;
            rigidbody2D.angularDrag            = 0.05f;
            rigidbody2D.gravityScale           = 1;
            rigidbody2D.interpolation          = RigidbodyInterpolation2D.None;
            rigidbody2D.sleepMode              = RigidbodySleepMode2D.StartAwake;
            rigidbody2D.collisionDetectionMode = CollisionDetectionMode2D.Discrete;
            rigidbody2D.isKinematic            = true;

            // Adds the boxcollider 2D
            BoxCollider2D boxcollider2D = (character.GetComponent <BoxCollider2D>() == null) ? character.gameObject.AddComponent <BoxCollider2D>() : character.GetComponent <BoxCollider2D>();

            boxcollider2D.isTrigger = true;

            // Adds the Corgi Controller
            CorgiController corgiController = (character.GetComponent <CorgiController>() == null) ? character.gameObject.AddComponent <CorgiController>() : character.GetComponent <CorgiController>();

            corgiController.PlatformMask                = LayerMask.GetMask("Platforms");
            corgiController.MovingPlatformMask          = LayerMask.GetMask("MovingPlatforms");
            corgiController.OneWayPlatformMask          = LayerMask.GetMask("OneWayPlatforms");
            corgiController.MovingOneWayPlatformMask    = LayerMask.GetMask("MovingOneWayPlatforms");
            corgiController.MidHeightOneWayPlatformMask = LayerMask.GetMask("MidHeightOneWayPlatforms");

            if (character.GetComponent <Health>() == null)
            {
                character.gameObject.AddComponent <Health>();
            }

            if (character.GetComponent <CharacterLevelBounds>() == null)
            {
                character.gameObject.AddComponent <CharacterLevelBounds>();
            }
            if (character.GetComponent <CharacterHorizontalMovement>() == null)
            {
                character.gameObject.AddComponent <CharacterHorizontalMovement>();
            }
            if (character.GetComponent <CharacterCrouch>() == null)
            {
                character.gameObject.AddComponent <CharacterCrouch>();
            }
            if (character.GetComponent <CharacterDash>() == null)
            {
                character.gameObject.AddComponent <CharacterDash>();
            }
            if (character.GetComponent <CharacterDive>() == null)
            {
                character.gameObject.AddComponent <CharacterDive>();
            }
            if (character.GetComponent <CharacterDangling>() == null)
            {
                character.gameObject.AddComponent <CharacterDangling>();
            }
            if (character.GetComponent <CharacterJump>() == null)
            {
                character.gameObject.AddComponent <CharacterJump>();
            }
            if (character.GetComponent <CharacterRun>() == null)
            {
                character.gameObject.AddComponent <CharacterRun>();
            }
            if (character.GetComponent <CharacterJetpack>() == null)
            {
                character.gameObject.AddComponent <CharacterJetpack>();
            }
            if (character.GetComponent <CharacterLookUp>() == null)
            {
                character.gameObject.AddComponent <CharacterLookUp>();
            }
            if (character.GetComponent <CharacterGrip>() == null)
            {
                character.gameObject.AddComponent <CharacterGrip>();
            }
            if (character.GetComponent <CharacterWallClinging>() == null)
            {
                character.gameObject.AddComponent <CharacterWallClinging>();
            }
            if (character.GetComponent <CharacterWalljump>() == null)
            {
                character.gameObject.AddComponent <CharacterWalljump>();
            }
            if (character.GetComponent <CharacterLadder>() == null)
            {
                character.gameObject.AddComponent <CharacterLadder>();
            }
            if (character.GetComponent <CharacterPause>() == null)
            {
                character.gameObject.AddComponent <CharacterPause>();
            }
            if (character.GetComponent <CharacterButtonActivation>() == null)
            {
                character.gameObject.AddComponent <CharacterButtonActivation>();
            }
            if (character.GetComponent <CharacterHandleWeapon>() == null)
            {
                character.gameObject.AddComponent <CharacterHandleWeapon>();
            }

            if (type == Character.CharacterTypes.AI)
            {
                // Adds Damage on touch
                DamageOnTouch damageOnTouch = (character.GetComponent <DamageOnTouch>() == null) ? character.gameObject.AddComponent <DamageOnTouch>() : character.GetComponent <DamageOnTouch>();
                damageOnTouch.TargetLayerMask = LayerMask.GetMask("Player");

                if (character.GetComponent <AIWalk>() == null)
                {
                    character.gameObject.AddComponent <AIWalk>();
                }
            }

            Debug.LogFormat(character.name + " : Character Autobuild Complete");
        }