Enemies half done

This commit is contained in:
Gerard Gascón 2023-08-22 20:12:53 +02:00
parent eaa8cdd462
commit 16507f4121
93 changed files with 31744 additions and 119 deletions

View file

@ -8,9 +8,11 @@ public abstract class BulletStats : MonoBehaviour{
[HideInInspector] public int maxBounces = 3;
protected Rigidbody2D Rb { get; private set; }
protected SpriteRenderer Sprite { get; private set; }
protected virtual void Start() {
Rb = GetComponent<Rigidbody2D>();
Sprite = GetComponent<SpriteRenderer>();
BalanceCanvas.instance.sliderChangedCallback += RefreshStats;
RefreshStats();

View file

@ -7,7 +7,7 @@ namespace Level1 {
}
void OnCollisionEnter2D(Collision2D other) {
Destroy(gameObject);
if(!other.gameObject.CompareTag("Enemy")) Destroy(gameObject);
}
}
}

View file

@ -10,11 +10,13 @@ namespace Level1 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement1 player = other.GetComponent<PlayerMovement1>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement1.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement1.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -25,10 +25,13 @@ namespace Level10 {
void OnCollisionEnter2D(Collision2D other) {
--_currentBounces;
if (_currentBounces != 0 && !other.gameObject.CompareTag("Enemy")) return;
if (_currentBounces != 0 || other.gameObject.CompareTag("Enemy")) return;
--PlayerMovement10.instance.Bullets;
Destroy(gameObject);
}
void OnDestroy() {
--PlayerMovement10.instance.Bullets;
}
}
}

View file

@ -10,11 +10,13 @@ namespace Level10 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement10 player = other.GetComponent<PlayerMovement10>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement10.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement10.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 03325dc33f2ee9249bf5a8f6946a1a00
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1cb0eec774ddaf14eae33d2d5723c5ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f2a986d8b795d9c4882683d3f7966da7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c4e0c84e4ee95fc409bda5fe1266d247
timeCreated: 1691603524

View 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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d8ff7ba51b9e50645b8f09beac3178cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a65e763cd4441cb4c8aace2113a59df1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,50 @@
using System;
using DG.Tweening;
using UnityEngine;
namespace Level12 {
public class Bullet12 : 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) {
++PlayerMovement12.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() {
--PlayerMovement12.instance.Bullets;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6a4580a70f5f2934db7cad7cf95c3de2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,57 @@
using System;
using DG.Tweening;
using UnityEngine;
namespace Level12 {
public class Enemy12 : MonoBehaviour {
[SerializeField] float speed;
[SerializeField] LayerMask groundLayer;
[SerializeField] SpriteRenderer sprite;
[Header("Flipping Pivots")]
[SerializeField] Transform flippingPivotLeft;
[SerializeField] Transform flippingPivotRight;
int _facingDirection = 1;
Rigidbody2D _rb;
static readonly int Lerp = Shader.PropertyToID("_Lerp");
// 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.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() {
Tween tween = sprite.material.DOFloat(1f, Lerp, .1f).SetLoops(1, LoopType.Yoyo);
tween.onComplete += () => Destroy(gameObject);
}
void OnDrawGizmos() {
if(!flippingPivotLeft || !flippingPivotRight) return;
Gizmos.color = Color.red;
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 50176a3b63d43f646ac00fd79ec96859
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,26 @@
using DG.Tweening;
using UnityEngine;
namespace Level12 {
public class EnemyWeakPoint12 : MonoBehaviour {
Enemy12 _enemy;
void Awake() {
_enemy = GetComponentInParent<Enemy12>();
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement12 player = other.GetComponent<PlayerMovement12>();
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement12.Jump1);
if(player) player.BounceAnimator.SetTrigger(PlayerMovement12.Bounce);
if(!player) Destroy(other.gameObject);
_enemy.DoKill();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 62e3f2343b67c864d9a1c51737c13c8e
timeCreated: 1691603524

View file

@ -0,0 +1,130 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace Level12 {
public class PlayerMovement12 : PlayerStats {
[Header("Shooting")]
[SerializeField] Bullet12 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 PlayerMovement12 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;
Bullet12 bullet12 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
bullet12.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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1d16d85dfae88064aadec70c2343def5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: df1106a61771136428f35c12550f969c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,50 @@
using System;
using DG.Tweening;
using UnityEngine;
namespace Level13 {
public class Bullet13 : 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) {
++PlayerMovement13.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() {
--PlayerMovement13.instance.Bullets;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 018ae2407c801eb4faedba313f1a5133
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,60 @@
using System;
using DG.Tweening;
using UnityEngine;
namespace Level13 {
public class Enemy13 : MonoBehaviour {
[SerializeField] float speed;
[SerializeField] LayerMask groundLayer;
[SerializeField] SpriteRenderer sprite;
[Header("Flipping Pivots")]
[SerializeField] Transform flippingPivotLeft;
[SerializeField] Transform flippingPivotRight;
int _facingDirection = 1;
Rigidbody2D _rb;
static readonly int Lerp = Shader.PropertyToID("_Lerp");
// 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.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() {
Tween tween = sprite.material.DOFloat(1f, Lerp, .1f).SetLoops(1, LoopType.Yoyo).SetUpdate(true);
ScreenShake.Shake(5f, .2f);
tween.onComplete += () => {
Destroy(gameObject);
};
}
void OnDrawGizmos() {
if(!flippingPivotLeft || !flippingPivotRight) return;
Gizmos.color = Color.red;
Gizmos.DrawWireCube(flippingPivotLeft.position, flippingPivotLeft.localScale);
Gizmos.DrawWireCube(flippingPivotRight.position, flippingPivotRight.localScale);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 184d6d22b4f6c604ca0eb24ab5a44d6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,26 @@
using DG.Tweening;
using UnityEngine;
namespace Level13 {
public class EnemyWeakPoint13 : MonoBehaviour {
Enemy13 _enemy;
void Awake() {
_enemy = GetComponentInParent<Enemy13>();
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement13 player = other.GetComponent<PlayerMovement13>();
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement13.Jump1);
if(player) player.BounceAnimator.SetTrigger(PlayerMovement13.Bounce);
if(!player) Destroy(other.gameObject);
_enemy.DoKill();
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ea1698e32522d98479fd2ba4c65cd156
timeCreated: 1691603524

View file

@ -0,0 +1,130 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace Level13 {
public class PlayerMovement13 : PlayerStats {
[Header("Shooting")]
[SerializeField] Bullet13 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 PlayerMovement13 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;
Bullet13 bullet13 = Instantiate(bullet, shootingPos.position, Quaternion.identity);
bullet13.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);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: acdcfe13adffdd948b9640654baedeb8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -7,7 +7,7 @@ namespace Level2 {
}
void OnCollisionEnter2D(Collision2D other) {
Destroy(gameObject);
if(!other.gameObject.CompareTag("Enemy")) Destroy(gameObject);
}
}
}

View file

@ -11,11 +11,13 @@ namespace Level2 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement2 player = other.GetComponent<PlayerMovement2>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement2.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement2.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -7,7 +7,7 @@ namespace Level3 {
}
void OnCollisionEnter2D(Collision2D other) {
Destroy(gameObject);
if(!other.gameObject.CompareTag("Enemy")) Destroy(gameObject);
}
}
}

View file

@ -10,11 +10,13 @@ namespace Level3 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement3 player = other.GetComponent<PlayerMovement3>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement3.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement3.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -7,7 +7,7 @@ namespace Level4 {
}
void OnCollisionEnter2D(Collision2D other) {
Destroy(gameObject);
if(!other.gameObject.CompareTag("Enemy")) Destroy(gameObject);
}
}
}

View file

@ -10,11 +10,13 @@ namespace Level4 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement4 player = other.GetComponent<PlayerMovement4>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement4.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement4.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -7,7 +7,7 @@ namespace Level5 {
}
void OnCollisionEnter2D(Collision2D other) {
Destroy(gameObject);
if(!other.gameObject.CompareTag("Enemy")) Destroy(gameObject);
}
}
}

View file

@ -10,11 +10,13 @@ namespace Level5 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement5 player = other.GetComponent<PlayerMovement5>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement5.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement5.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -12,11 +12,5 @@ namespace Level8 {
public void AddForce(int direction) {
GetComponent<Rigidbody2D>().velocity = Vector2.right * direction * bulletSpeed;
}
void OnCollisionEnter2D(Collision2D other) {
if (other.gameObject.CompareTag("Enemy")) {
Destroy(gameObject);
}
}
}
}

View file

@ -10,11 +10,13 @@ namespace Level8 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement8 player = other.GetComponent<PlayerMovement8>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement8.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement8.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -24,7 +24,7 @@ namespace Level9 {
void OnCollisionEnter2D(Collision2D other) {
--_currentBounces;
if (_currentBounces != 0 && !other.gameObject.CompareTag("Enemy")) return;
if (_currentBounces != 0 || other.gameObject.CompareTag("Enemy")) return;
Destroy(gameObject);
}

View file

@ -10,11 +10,13 @@ namespace Level9 {
}
void OnTriggerEnter2D(Collider2D other) {
if (!other.CompareTag("Player")) return;
if (!other.CompareTag("Player") && !other.CompareTag("Bullet")) return;
PlayerMovement9 player = other.GetComponent<PlayerMovement9>();
player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
player.Animator.SetTrigger(PlayerMovement9.Jump1);
if(player) player.Rb.velocity = new Vector2(player.Rb.velocity.x, player.deathForce);
if(player) player.Animator.SetTrigger(PlayerMovement9.Jump1);
if(!player) Destroy(other.gameObject);
Destroy(_enemy.gameObject);
}
}

View file

@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using Cinemachine;
using UnityEngine;
public static class ScreenShake {
static CinemachineVirtualCamera vCam;
static ScreenShakeUpdate shakeUpdate;
class ScreenShakeUpdate : MonoBehaviour {
[HideInInspector] public float shakeTimer;
[HideInInspector] public float shakeTimerTotal;
[HideInInspector] public float startingIntensity;
void Update() {
if (shakeTimer > 0) {
shakeTimer -= Time.deltaTime;
CinemachineBasicMultiChannelPerlin multiChannelPerlin =
vCam.GetCinemachineComponent<CinemachineBasicMultiChannelPerlin>();
multiChannelPerlin.m_AmplitudeGain =
Mathf.Lerp(startingIntensity, 0f, 1 - (shakeTimer / shakeTimerTotal));
}
}
}
/// <summary>Shake the camera
/// <para>It needs a cinemachine camera with a noise profile in it.</para>
/// </summary>
public static void Shake(float intensity, float time) {
if (vCam == null) {
vCam = Camera.main.GetComponent<CinemachineBrain>().ActiveVirtualCamera.VirtualCameraGameObject
.GetComponent<CinemachineVirtualCamera>();
}
if (shakeUpdate == null) {
shakeUpdate = new GameObject("ShakeUpdate").AddComponent<ScreenShakeUpdate>();
}
shakeUpdate.startingIntensity = intensity;
shakeUpdate.shakeTimer = shakeUpdate.shakeTimerTotal = time;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6fdeff5e06ed01a45b4095700b4390ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: