Finished
This commit is contained in:
parent
16507f4121
commit
436dd245aa
84 changed files with 79361 additions and 75 deletions
|
@ -25,6 +25,7 @@ public class BalanceCanvas : MonoBehaviour {
|
|||
[SerializeField] Slider maxYSpeed;
|
||||
[SerializeField] Slider maxBounces;
|
||||
[SerializeField] Slider maxBullets;
|
||||
[SerializeField] Slider throwForce;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake() {
|
||||
|
@ -45,6 +46,7 @@ public class BalanceCanvas : MonoBehaviour {
|
|||
SetupSlider(maxYSpeed, nameof(BulletStats.maxYSpeed));
|
||||
SetupSlider(maxBounces, nameof(BulletStats.maxBounces));
|
||||
SetupSlider(maxBullets, nameof(PlayerStats.maxBullets));
|
||||
SetupSlider(throwForce, nameof(EnemyStats.throwForce));
|
||||
}
|
||||
|
||||
void SliderChangedCallback(float arg0) => sliderChangedCallback?.Invoke();
|
||||
|
|
24
Assets/Scripts/EnemyStats.cs
Normal file
24
Assets/Scripts/EnemyStats.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class EnemyStats : MonoBehaviour{
|
||||
[HideInInspector] public float throwForce = 5f;
|
||||
protected Rigidbody2D Rb { get; private set; }
|
||||
protected Collider2D Collider { get; private set; }
|
||||
|
||||
protected virtual void Start() {
|
||||
Rb = GetComponent<Rigidbody2D>();
|
||||
Collider = GetComponent<Collider2D>();
|
||||
|
||||
BalanceCanvas.instance.sliderChangedCallback += RefreshStats;
|
||||
RefreshStats();
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
BalanceCanvas.instance.sliderChangedCallback -= RefreshStats;
|
||||
}
|
||||
|
||||
void RefreshStats() {
|
||||
throwForce = PlayerPrefs.GetFloat(nameof(throwForce), throwForce);
|
||||
}
|
||||
}
|
3
Assets/Scripts/EnemyStats.cs.meta
Normal file
3
Assets/Scripts/EnemyStats.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 52d8088a91444c8a84b0412967c4e0f0
|
||||
timeCreated: 1692732567
|
|
@ -21,6 +21,7 @@ namespace Level12 {
|
|||
if(!player) Destroy(other.gameObject);
|
||||
|
||||
_enemy.DoKill();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ namespace Level13 {
|
|||
if(!player) Destroy(other.gameObject);
|
||||
|
||||
_enemy.DoKill();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
8
Assets/Scripts/Level 14.meta
Normal file
8
Assets/Scripts/Level 14.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0e13a0f6182363a458a8e9909a35cc69
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Assets/Scripts/Level 14/Bullet14.cs
Normal file
50
Assets/Scripts/Level 14/Bullet14.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level14 {
|
||||
public class Bullet14 : 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) {
|
||||
++PlayerMovement14.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() {
|
||||
--PlayerMovement14.instance.Bullets;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 14/Bullet14.cs.meta
Normal file
11
Assets/Scripts/Level 14/Bullet14.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 096fc607326700d4880cfa7e0f0fe2eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Scripts/Level 14/Enemy14.cs
Normal file
54
Assets/Scripts/Level 14/Enemy14.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level14 {
|
||||
public class Enemy14 : EnemyStats {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] SpriteRenderer sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
static readonly int Lerp = Shader.PropertyToID("_Lerp");
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.transform.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
Rb.velocity = new Vector2(speed * _facingDirection, Rb.velocity.y);
|
||||
}
|
||||
|
||||
public void DoKill() {
|
||||
sprite.material.DOFloat(1f, Lerp, .1f).SetLoops(2, LoopType.Yoyo).SetUpdate(true);
|
||||
ScreenShake.Shake(5f, .2f);
|
||||
Collider.enabled = false;
|
||||
Rb.freezeRotation = false;
|
||||
Rb.AddForceAtPosition(Vector2.up * throwForce, transform.position + new Vector3(-.5f, .5f), ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
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 14/Enemy14.cs.meta
Normal file
11
Assets/Scripts/Level 14/Enemy14.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7db1aeb42b8347d449bd199310d9d4c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Level 14/EnemyWeakPoint14.cs
Normal file
27
Assets/Scripts/Level 14/EnemyWeakPoint14.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level14 {
|
||||
public class EnemyWeakPoint14 : MonoBehaviour {
|
||||
|
||||
Enemy14 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy14>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
|
||||
PlayerMovement14 player = other.GetComponent<PlayerMovement14>();
|
||||
|
||||
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
if(player) player.Animator.SetTrigger(PlayerMovement14.Jump1);
|
||||
if(player) player.BounceAnimator.SetTrigger(PlayerMovement14.Bounce);
|
||||
|
||||
if(!player) Destroy(other.gameObject);
|
||||
|
||||
_enemy.DoKill();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 14/EnemyWeakPoint14.cs.meta
Normal file
3
Assets/Scripts/Level 14/EnemyWeakPoint14.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 995ab0dca22928647a5c636edfd9879f
|
||||
timeCreated: 1691603524
|
130
Assets/Scripts/Level 14/PlayerMovement14.cs
Normal file
130
Assets/Scripts/Level 14/PlayerMovement14.cs
Normal file
|
@ -0,0 +1,130 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level14 {
|
||||
public class PlayerMovement14 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet14 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 PlayerMovement14 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;
|
||||
Bullet14 bullet14 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet14.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 14/PlayerMovement14.cs.meta
Normal file
11
Assets/Scripts/Level 14/PlayerMovement14.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d4d93ec5c235cb5488298abf70e96c8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 16.meta
Normal file
8
Assets/Scripts/Level 16.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6f69158ce97cc90429f6dc4b167d671d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Assets/Scripts/Level 16/Bullet16.cs
Normal file
50
Assets/Scripts/Level 16/Bullet16.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level16 {
|
||||
public class Bullet16 : 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) {
|
||||
++PlayerMovement16.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() {
|
||||
--PlayerMovement16.instance.Bullets;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 16/Bullet16.cs.meta
Normal file
11
Assets/Scripts/Level 16/Bullet16.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ffc4a1c4b7d23a14c97030c9cca9cc62
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Scripts/Level 16/Enemy16.cs
Normal file
54
Assets/Scripts/Level 16/Enemy16.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level16 {
|
||||
public class Enemy16 : EnemyStats {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] SpriteRenderer sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
static readonly int Lerp = Shader.PropertyToID("_Lerp");
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.transform.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
Rb.velocity = new Vector2(speed * _facingDirection, Rb.velocity.y);
|
||||
}
|
||||
|
||||
public void DoKill() {
|
||||
sprite.material.DOFloat(1f, Lerp, .1f).SetLoops(2, LoopType.Yoyo).SetUpdate(true);
|
||||
ScreenShake.Shake(5f, .2f);
|
||||
Collider.enabled = false;
|
||||
Rb.freezeRotation = false;
|
||||
Rb.AddForceAtPosition(Vector2.up * throwForce, transform.position + new Vector3(-.5f, .5f), ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
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 16/Enemy16.cs.meta
Normal file
11
Assets/Scripts/Level 16/Enemy16.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 100f0e08a6551254d8272504968916eb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Level 16/EnemyWeakPoint16.cs
Normal file
27
Assets/Scripts/Level 16/EnemyWeakPoint16.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level16 {
|
||||
public class EnemyWeakPoint16 : MonoBehaviour {
|
||||
|
||||
Enemy16 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy16>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
|
||||
PlayerMovement16 player = other.GetComponent<PlayerMovement16>();
|
||||
|
||||
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
if(player) player.Animator.SetTrigger(PlayerMovement16.Jump1);
|
||||
if(player) player.BounceAnimator.SetTrigger(PlayerMovement16.Bounce);
|
||||
|
||||
if(!player) Destroy(other.gameObject);
|
||||
|
||||
_enemy.DoKill();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 16/EnemyWeakPoint16.cs.meta
Normal file
3
Assets/Scripts/Level 16/EnemyWeakPoint16.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b997125f078d6f459771c53a5d20d66
|
||||
timeCreated: 1691603524
|
139
Assets/Scripts/Level 16/PlayerMovement16.cs
Normal file
139
Assets/Scripts/Level 16/PlayerMovement16.cs
Normal file
|
@ -0,0 +1,139 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level16 {
|
||||
public class PlayerMovement16 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet16 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;
|
||||
|
||||
[Header("Particles")]
|
||||
[SerializeField] ParticleSystem runningParticles;
|
||||
|
||||
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 PlayerMovement16 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;
|
||||
Bullet16 bullet16 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet16.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);
|
||||
|
||||
if(Mathf.Abs(_xVelocity) > 1f && grounded)
|
||||
runningParticles.Play();
|
||||
else
|
||||
runningParticles.Stop();
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 16/PlayerMovement16.cs.meta
Normal file
11
Assets/Scripts/Level 16/PlayerMovement16.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8da35824459924042b4cf7294a4ae276
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 17.meta
Normal file
8
Assets/Scripts/Level 17.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23f4ced8930551140b347d199f354377
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Assets/Scripts/Level 17/Bullet17.cs
Normal file
50
Assets/Scripts/Level 17/Bullet17.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level17 {
|
||||
public class Bullet17 : 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) {
|
||||
++PlayerMovement17.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() {
|
||||
--PlayerMovement17.instance.Bullets;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 17/Bullet17.cs.meta
Normal file
11
Assets/Scripts/Level 17/Bullet17.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e536bfdfb94eac844aba5fca3160aa10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
54
Assets/Scripts/Level 17/Enemy17.cs
Normal file
54
Assets/Scripts/Level 17/Enemy17.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level17 {
|
||||
public class Enemy17 : EnemyStats {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] SpriteRenderer sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
static readonly int Lerp = Shader.PropertyToID("_Lerp");
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.transform.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
Rb.velocity = new Vector2(speed * _facingDirection, Rb.velocity.y);
|
||||
}
|
||||
|
||||
public void DoKill() {
|
||||
sprite.material.DOFloat(1f, Lerp, .1f).SetLoops(2, LoopType.Yoyo).SetUpdate(true);
|
||||
ScreenShake.Shake(5f, .2f);
|
||||
Collider.enabled = false;
|
||||
Rb.freezeRotation = false;
|
||||
Rb.AddForceAtPosition(Vector2.up * throwForce, transform.position + new Vector3(-.5f, .5f), ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
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 17/Enemy17.cs.meta
Normal file
11
Assets/Scripts/Level 17/Enemy17.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cbfa4fa2e594e8746b323090657d457e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Level 17/EnemyWeakPoint17.cs
Normal file
27
Assets/Scripts/Level 17/EnemyWeakPoint17.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level17 {
|
||||
public class EnemyWeakPoint17 : MonoBehaviour {
|
||||
|
||||
Enemy17 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy17>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
|
||||
PlayerMovement17 player = other.GetComponent<PlayerMovement17>();
|
||||
|
||||
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
if(player) player.Animator.SetTrigger(PlayerMovement17.Jump1);
|
||||
if(player) player.BounceAnimator.SetTrigger(PlayerMovement17.Bounce);
|
||||
|
||||
if(!player) Destroy(other.gameObject);
|
||||
|
||||
_enemy.DoKill();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 17/EnemyWeakPoint17.cs.meta
Normal file
3
Assets/Scripts/Level 17/EnemyWeakPoint17.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 386320738617c644ebe66f92215e2969
|
||||
timeCreated: 1691603524
|
143
Assets/Scripts/Level 17/PlayerMovement17.cs
Normal file
143
Assets/Scripts/Level 17/PlayerMovement17.cs
Normal file
|
@ -0,0 +1,143 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level17 {
|
||||
public class PlayerMovement17 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet17 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;
|
||||
|
||||
[Header("Particles")]
|
||||
[SerializeField] ParticleSystem runningParticles;
|
||||
[SerializeField] ParticleSystem jumpParticles;
|
||||
|
||||
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 PlayerMovement17 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;
|
||||
Bullet17 bullet17 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet17.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);
|
||||
|
||||
Instantiate(jumpParticles, transform);
|
||||
|
||||
_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);
|
||||
|
||||
if(Mathf.Abs(_xVelocity) > 1f && grounded)
|
||||
runningParticles.Play();
|
||||
else
|
||||
runningParticles.Stop();
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 17/PlayerMovement17.cs.meta
Normal file
11
Assets/Scripts/Level 17/PlayerMovement17.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b4c6b56200d23064bb5a958a0785dd10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Level 18.meta
Normal file
8
Assets/Scripts/Level 18.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9ff703884836e3a49a57d1b581dfc166
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Assets/Scripts/Level 18/Bullet18.cs
Normal file
50
Assets/Scripts/Level 18/Bullet18.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level18 {
|
||||
public class Bullet18 : 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) {
|
||||
++PlayerMovement18.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() {
|
||||
--PlayerMovement18.instance.Bullets;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 18/Bullet18.cs.meta
Normal file
11
Assets/Scripts/Level 18/Bullet18.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: caea81241cc057c42855a9997bc0e991
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
59
Assets/Scripts/Level 18/Enemy18.cs
Normal file
59
Assets/Scripts/Level 18/Enemy18.cs
Normal file
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level18 {
|
||||
public class Enemy18 : EnemyStats {
|
||||
[SerializeField] float speed;
|
||||
|
||||
[SerializeField] LayerMask groundLayer;
|
||||
|
||||
[SerializeField] SpriteRenderer sprite;
|
||||
|
||||
[Header("Flipping Pivots")]
|
||||
[SerializeField] Transform flippingPivotLeft;
|
||||
[SerializeField] Transform flippingPivotRight;
|
||||
|
||||
[Header("Particles")]
|
||||
[SerializeField] ParticleSystem deathParticles;
|
||||
|
||||
int _facingDirection = 1;
|
||||
|
||||
static readonly int Lerp = Shader.PropertyToID("_Lerp");
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate() {
|
||||
if (_facingDirection > 0) {
|
||||
if (Physics2D.OverlapBox(flippingPivotRight.position, flippingPivotRight.localScale, 0, groundLayer)) {
|
||||
_facingDirection = -1;
|
||||
sprite.transform.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}else {
|
||||
if (Physics2D.OverlapBox(flippingPivotLeft.position, flippingPivotLeft.localScale, 0, groundLayer)) {
|
||||
_facingDirection = 1;
|
||||
sprite.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
Rb.velocity = new Vector2(speed * _facingDirection, Rb.velocity.y);
|
||||
}
|
||||
|
||||
public void DoKill() {
|
||||
Instantiate(deathParticles, transform.position, Quaternion.identity);
|
||||
|
||||
sprite.material.DOFloat(1f, Lerp, .1f).SetLoops(2, LoopType.Yoyo).SetUpdate(true);
|
||||
ScreenShake.Shake(5f, .2f);
|
||||
Collider.enabled = false;
|
||||
Rb.freezeRotation = false;
|
||||
Rb.AddForceAtPosition(Vector2.up * throwForce, transform.position + new Vector3(-.5f, .5f), ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
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 18/Enemy18.cs.meta
Normal file
11
Assets/Scripts/Level 18/Enemy18.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 854054e4bf3df674f9ade2564e916c69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/Scripts/Level 18/EnemyWeakPoint18.cs
Normal file
27
Assets/Scripts/Level 18/EnemyWeakPoint18.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Level18 {
|
||||
public class EnemyWeakPoint18 : MonoBehaviour {
|
||||
|
||||
Enemy18 _enemy;
|
||||
|
||||
void Awake() {
|
||||
_enemy = GetComponentInParent<Enemy18>();
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
|
||||
PlayerMovement18 player = other.GetComponent<PlayerMovement18>();
|
||||
|
||||
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
|
||||
if(player) player.Animator.SetTrigger(PlayerMovement18.Jump1);
|
||||
if(player) player.BounceAnimator.SetTrigger(PlayerMovement18.Bounce);
|
||||
|
||||
if(!player) Destroy(other.gameObject);
|
||||
|
||||
_enemy.DoKill();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Level 18/EnemyWeakPoint18.cs.meta
Normal file
3
Assets/Scripts/Level 18/EnemyWeakPoint18.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 64d2fda615c5f2a419468ab25896aecb
|
||||
timeCreated: 1691603524
|
143
Assets/Scripts/Level 18/PlayerMovement18.cs
Normal file
143
Assets/Scripts/Level 18/PlayerMovement18.cs
Normal file
|
@ -0,0 +1,143 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Level18 {
|
||||
public class PlayerMovement18 : PlayerStats {
|
||||
|
||||
[Header("Shooting")]
|
||||
[SerializeField] Bullet18 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;
|
||||
|
||||
[Header("Particles")]
|
||||
[SerializeField] ParticleSystem runningParticles;
|
||||
[SerializeField] ParticleSystem jumpParticles;
|
||||
|
||||
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 PlayerMovement18 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;
|
||||
Bullet18 bullet18 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
|
||||
bullet18.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);
|
||||
|
||||
Instantiate(jumpParticles, transform);
|
||||
|
||||
_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);
|
||||
|
||||
if(Mathf.Abs(_xVelocity) > 1f && grounded)
|
||||
runningParticles.Play();
|
||||
else
|
||||
runningParticles.Stop();
|
||||
}
|
||||
|
||||
void OnDrawGizmos() {
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, feetSize);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Level 18/PlayerMovement18.cs.meta
Normal file
11
Assets/Scripts/Level 18/PlayerMovement18.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2d04dc4df6815c945871c6c50fc9b729
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue