Enemies half done
This commit is contained in:
		
							parent
							
								
									eaa8cdd462
								
							
						
					
					
						commit
						16507f4121
					
				
					 93 changed files with 31744 additions and 119 deletions
				
			
		
							
								
								
									
										50
									
								
								Assets/Scripts/Level 11/Bullet11.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								Assets/Scripts/Level 11/Bullet11.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
using System;
 | 
			
		||||
using DG.Tweening;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace Level11 {
 | 
			
		||||
    public class Bullet11 : BulletStats {
 | 
			
		||||
        int _currentBounces;
 | 
			
		||||
 | 
			
		||||
        [SerializeField] Sprite red, yellow;
 | 
			
		||||
 | 
			
		||||
        protected override void Start() {
 | 
			
		||||
            base.Start();
 | 
			
		||||
 | 
			
		||||
            _currentBounces = maxBounces;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void FixedUpdate() {
 | 
			
		||||
            if (Rb.velocity.y <= maxYSpeed) return;
 | 
			
		||||
            Vector2 velocity = Rb.velocity;
 | 
			
		||||
            velocity.y = maxYSpeed;
 | 
			
		||||
            Rb.velocity = velocity;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void AddForce(int direction) {
 | 
			
		||||
            ++PlayerMovement11.instance.Bullets;
 | 
			
		||||
            GetComponent<Rigidbody2D>().velocity = Vector2.right * direction * bulletSpeed;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void OnCollisionEnter2D(Collision2D other) {
 | 
			
		||||
            transform.DOPunchScale(transform.localScale * 1.5f, .1f);
 | 
			
		||||
 | 
			
		||||
            DOTween.Sequence()
 | 
			
		||||
                .AppendCallback(() => {
 | 
			
		||||
                    Sprite.sprite = yellow;
 | 
			
		||||
                }).AppendInterval(.1f)
 | 
			
		||||
                .AppendCallback(() => {
 | 
			
		||||
                    Sprite.sprite = red;
 | 
			
		||||
                });
 | 
			
		||||
            
 | 
			
		||||
            --_currentBounces;
 | 
			
		||||
            if (_currentBounces != 0 || other.gameObject.CompareTag("Enemy")) return;
 | 
			
		||||
            
 | 
			
		||||
            Destroy(gameObject);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        void OnDestroy() {
 | 
			
		||||
            --PlayerMovement11.instance.Bullets;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								Assets/Scripts/Level 11/Bullet11.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Level 11/Bullet11.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
fileFormatVersion: 2
 | 
			
		||||
guid: 1cb0eec774ddaf14eae33d2d5723c5ec
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
							
								
								
									
										48
									
								
								Assets/Scripts/Level 11/Enemy11.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								Assets/Scripts/Level 11/Enemy11.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,48 @@
 | 
			
		|||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace Level11 {
 | 
			
		||||
    public class Enemy11 : MonoBehaviour {
 | 
			
		||||
        [SerializeField] float speed;
 | 
			
		||||
 | 
			
		||||
        [SerializeField] LayerMask groundLayer;
 | 
			
		||||
 | 
			
		||||
        [SerializeField] Transform sprite;
 | 
			
		||||
 | 
			
		||||
        [Header("Flipping Pivots")] 
 | 
			
		||||
        [SerializeField] Transform flippingPivotLeft;
 | 
			
		||||
        [SerializeField] Transform flippingPivotRight;
 | 
			
		||||
 | 
			
		||||
        int _facingDirection = 1;
 | 
			
		||||
        Rigidbody2D _rb;
 | 
			
		||||
    
 | 
			
		||||
        // Start is called before the first frame update
 | 
			
		||||
        void Awake() {
 | 
			
		||||
            _rb = GetComponent<Rigidbody2D>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Update is called once per frame
 | 
			
		||||
        void FixedUpdate() {
 | 
			
		||||
            if (_facingDirection > 0) {
 | 
			
		||||
                if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
 | 
			
		||||
                    _facingDirection = -1;
 | 
			
		||||
                    sprite.localScale = new Vector3(-1, 1, 1);
 | 
			
		||||
                }
 | 
			
		||||
            }else {
 | 
			
		||||
                if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
 | 
			
		||||
                    _facingDirection = 1;
 | 
			
		||||
                    sprite.localScale = Vector3.one;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            _rb.velocity = new Vector2(speed * _facingDirection, _rb.velocity.y);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void OnDrawGizmos() {
 | 
			
		||||
            if(!flippingPivotLeft || !flippingPivotRight) return;
 | 
			
		||||
 | 
			
		||||
            Gizmos.color = Color.red;
 | 
			
		||||
        
 | 
			
		||||
            Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
 | 
			
		||||
            Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								Assets/Scripts/Level 11/Enemy11.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Level 11/Enemy11.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
fileFormatVersion: 2
 | 
			
		||||
guid: f2a986d8b795d9c4882683d3f7966da7
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
							
								
								
									
										26
									
								
								Assets/Scripts/Level 11/EnemyWeakPoint11.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Assets/Scripts/Level 11/EnemyWeakPoint11.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,26 @@
 | 
			
		|||
using DG.Tweening;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace Level11 {
 | 
			
		||||
	public class EnemyWeakPoint11 : MonoBehaviour {
 | 
			
		||||
 | 
			
		||||
		Enemy11 _enemy;
 | 
			
		||||
	
 | 
			
		||||
		void Awake() {
 | 
			
		||||
			_enemy = GetComponentInParent<Enemy11>();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		void OnTriggerEnter2D(Collider2D other) {
 | 
			
		||||
			if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
 | 
			
		||||
			PlayerMovement11 player = other.GetComponent<PlayerMovement11>();
 | 
			
		||||
 | 
			
		||||
			if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
 | 
			
		||||
			if(player) player.Animator.SetTrigger(PlayerMovement11.Jump1);
 | 
			
		||||
			if(player) player.BounceAnimator.SetTrigger(PlayerMovement11.Bounce);
 | 
			
		||||
			
 | 
			
		||||
			if(!player) Destroy(other.gameObject);
 | 
			
		||||
 | 
			
		||||
			Destroy(_enemy.gameObject);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										3
									
								
								Assets/Scripts/Level 11/EnemyWeakPoint11.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								Assets/Scripts/Level 11/EnemyWeakPoint11.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,3 @@
 | 
			
		|||
fileFormatVersion: 2
 | 
			
		||||
guid: c4e0c84e4ee95fc409bda5fe1266d247
 | 
			
		||||
timeCreated: 1691603524
 | 
			
		||||
							
								
								
									
										130
									
								
								Assets/Scripts/Level 11/PlayerMovement11.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								Assets/Scripts/Level 11/PlayerMovement11.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,130 @@
 | 
			
		|||
using UnityEngine;
 | 
			
		||||
using UnityEngine.InputSystem;
 | 
			
		||||
 | 
			
		||||
namespace Level11 {
 | 
			
		||||
    public class PlayerMovement11 : PlayerStats {
 | 
			
		||||
    
 | 
			
		||||
        [Header("Shooting")]
 | 
			
		||||
        [SerializeField] Bullet11 bullet;
 | 
			
		||||
        [SerializeField] Transform shootingPos;
 | 
			
		||||
    
 | 
			
		||||
        [Header("Physics")] 
 | 
			
		||||
        [SerializeField] LayerMask groundMask;
 | 
			
		||||
        [SerializeField] Vector2 feetSize;
 | 
			
		||||
    
 | 
			
		||||
        float _horizontalInput;
 | 
			
		||||
        float _xVelocity, _accelerationVelocity;
 | 
			
		||||
        float _currentCoyoteTime, _currentBufferTime;
 | 
			
		||||
        bool _grounded;
 | 
			
		||||
 | 
			
		||||
        float _facingDirectionVelocity;
 | 
			
		||||
        
 | 
			
		||||
        public int Bullets { set; get; }
 | 
			
		||||
 | 
			
		||||
        int _facingDirection = 1;
 | 
			
		||||
 | 
			
		||||
        PlayerInput _playerInput;
 | 
			
		||||
 | 
			
		||||
        [Header("Animations")] 
 | 
			
		||||
        [SerializeField] Animator animator;
 | 
			
		||||
        [SerializeField] Animator bounceAnimator;
 | 
			
		||||
        public Animator Animator => animator;
 | 
			
		||||
        public Animator BounceAnimator => bounceAnimator;
 | 
			
		||||
 | 
			
		||||
        public static readonly int Jump1 = Animator.StringToHash("Jump");
 | 
			
		||||
        static readonly int XVelocity = Animator.StringToHash("xVelocity");
 | 
			
		||||
        static readonly int YVelocity = Animator.StringToHash("yVelocity");
 | 
			
		||||
        static readonly int Grounded = Animator.StringToHash("Grounded");
 | 
			
		||||
        public static readonly int Bounce = Animator.StringToHash("Bounce");
 | 
			
		||||
        
 | 
			
		||||
        public static PlayerMovement11 instance;
 | 
			
		||||
 | 
			
		||||
        void Awake() {
 | 
			
		||||
            instance = this;
 | 
			
		||||
            
 | 
			
		||||
            _playerInput = new PlayerInput();
 | 
			
		||||
        
 | 
			
		||||
            _playerInput.Gameplay.Horizontal.started += HorizontalHandler;
 | 
			
		||||
            _playerInput.Gameplay.Horizontal.performed += HorizontalHandler;
 | 
			
		||||
            _playerInput.Gameplay.Horizontal.canceled += HorizontalHandler;
 | 
			
		||||
 | 
			
		||||
            _playerInput.Gameplay.Jump.started += Jump;
 | 
			
		||||
            _playerInput.Gameplay.Jump.canceled += Jump;
 | 
			
		||||
        
 | 
			
		||||
            _playerInput.Gameplay.Fire.performed += Fire;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void Jump(InputAction.CallbackContext obj) {
 | 
			
		||||
            if (obj.started) {
 | 
			
		||||
                _currentBufferTime = bufferTime;
 | 
			
		||||
            }else if (obj.canceled) {
 | 
			
		||||
                if (Rb.velocity.y < 0f) return;
 | 
			
		||||
                Rb.velocity = new Vector2(Rb.velocity.x, Rb.velocity.y * jumpCancellationMultiplier);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void Fire(InputAction.CallbackContext obj) {
 | 
			
		||||
            if (Bullets >= maxBullets) return;
 | 
			
		||||
            Bullet11 bullet11 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
 | 
			
		||||
            bullet11.AddForce(_facingDirection);
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
        void HorizontalHandler(InputAction.CallbackContext obj) {
 | 
			
		||||
            _horizontalInput = obj.ReadValue<float>();
 | 
			
		||||
            _facingDirection = _horizontalInput > 0 ? 1 : _horizontalInput < 0 ? -1 : _facingDirection;
 | 
			
		||||
        }
 | 
			
		||||
    
 | 
			
		||||
        void OnEnable() {
 | 
			
		||||
            _playerInput.Enable();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void OnDisable() {
 | 
			
		||||
            _playerInput.Disable();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Update is called once per frame
 | 
			
		||||
        void Update() {
 | 
			
		||||
            float xScale = Mathf.SmoothDamp(transform.localScale.x, _facingDirection, ref _facingDirectionVelocity,
 | 
			
		||||
                .1f);
 | 
			
		||||
            transform.localScale = new Vector3(xScale, 1, 1);
 | 
			
		||||
            
 | 
			
		||||
            animator.SetFloat(XVelocity, Mathf.Abs(_xVelocity));
 | 
			
		||||
            bounceAnimator.SetFloat(XVelocity, Mathf.Abs(_xVelocity));
 | 
			
		||||
            animator.SetFloat(YVelocity, Rb.velocity.y);
 | 
			
		||||
            animator.SetBool(Grounded, _grounded);
 | 
			
		||||
            bounceAnimator.SetBool(Grounded, _grounded);
 | 
			
		||||
 | 
			
		||||
            if (_currentBufferTime > 0f && _currentCoyoteTime > 0f) {
 | 
			
		||||
                Rb.velocity = new Vector2(Rb.velocity.x, jumpForce);
 | 
			
		||||
                animator.SetTrigger(Jump1);
 | 
			
		||||
                bounceAnimator.SetTrigger(Bounce);
 | 
			
		||||
 | 
			
		||||
                _currentBufferTime = _currentCoyoteTime = 0f;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            _currentCoyoteTime -= Time.deltaTime;
 | 
			
		||||
            _currentBufferTime -= Time.deltaTime;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void FixedUpdate() {
 | 
			
		||||
            bool grounded = Physics2D.OverlapBox(transform.position, feetSize, 0, groundMask);
 | 
			
		||||
            if (!_grounded && grounded) {
 | 
			
		||||
                bounceAnimator.SetTrigger(Bounce);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            _grounded = grounded;
 | 
			
		||||
            if (_grounded && Rb.velocity.y < .1f)
 | 
			
		||||
                _currentCoyoteTime = coyoteTime;
 | 
			
		||||
 | 
			
		||||
            _xVelocity = Rb.velocity.x;
 | 
			
		||||
            _xVelocity = Mathf.SmoothDamp(_xVelocity, _horizontalInput * speed, ref _accelerationVelocity,
 | 
			
		||||
                acceleration);;
 | 
			
		||||
            Rb.velocity = new Vector2(_xVelocity, Rb.velocity.y);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void OnDrawGizmos() {
 | 
			
		||||
            Gizmos.color = Color.red;
 | 
			
		||||
            Gizmos.DrawWireCube(transform.position, feetSize);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								Assets/Scripts/Level 11/PlayerMovement11.cs.meta
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/Level 11/PlayerMovement11.cs.meta
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
fileFormatVersion: 2
 | 
			
		||||
guid: d8ff7ba51b9e50645b8f09beac3178cc
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue