diff --git a/PalestineJam2021/Assets/Prefabs/Player.prefab b/PalestineJam2021/Assets/Prefabs/Player.prefab index 0a6ca6c..5b87a46 100644 --- a/PalestineJam2021/Assets/Prefabs/Player.prefab +++ b/PalestineJam2021/Assets/Prefabs/Player.prefab @@ -121,7 +121,7 @@ Rigidbody2D: m_Material: {fileID: 0} m_Interpolate: 0 m_SleepingMode: 1 - m_CollisionDetection: 0 + m_CollisionDetection: 1 m_Constraints: 4 --- !u!114 &-2119685637964449471 MonoBehaviour: @@ -137,6 +137,8 @@ MonoBehaviour: m_EditorClassIdentifier: walkMethod: 2 walkMagnitude: {x: 100, y: 100} + dashForce: 300 + maxShrink: 1 trapLayers: serializedVersion: 2 m_Bits: 8 diff --git a/PalestineJam2021/Assets/Scenes/Prototype.unity b/PalestineJam2021/Assets/Scenes/Prototype.unity index 7d4588c..58b2416 100644 --- a/PalestineJam2021/Assets/Scenes/Prototype.unity +++ b/PalestineJam2021/Assets/Scenes/Prototype.unity @@ -573,6 +573,10 @@ PrefabInstance: propertyPath: m_Name value: ScenarioManager objectReference: {fileID: 0} + - target: {fileID: 5344074379570608082, guid: 049c6b207f83b4b47a59ab3050133fea, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 5344074379570608083, guid: 049c6b207f83b4b47a59ab3050133fea, type: 3} propertyPath: shipsParent value: @@ -759,6 +763,10 @@ PrefabInstance: propertyPath: m_Name value: Player objectReference: {fileID: 0} + - target: {fileID: 7766016242766568218, guid: b680a125684eee4488dfdb8c367b9c0e, type: 3} + propertyPath: m_CollisionDetection + value: 1 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: b680a125684eee4488dfdb8c367b9c0e, type: 3} --- !u!1001 &7813215492338006163 diff --git a/PalestineJam2021/Assets/Scripts/PlayerControls.cs b/PalestineJam2021/Assets/Scripts/PlayerControls.cs index 300537a..de9bbf1 100644 --- a/PalestineJam2021/Assets/Scripts/PlayerControls.cs +++ b/PalestineJam2021/Assets/Scripts/PlayerControls.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -10,6 +11,15 @@ public class PlayerControls : MonoBehaviour [SerializeField] private Vector2 walkMagnitude = Vector2.one; private Vector2 walkDirection = Vector2.zero; + [Header("Dash")] + //[SerializeField] private float dashDuration = 0.3f; + [SerializeField] private float dashForce = 300f; + [SerializeField] private float maxShrink = 1f; + private bool shouldDash = false; + private bool dashing = false; + private Vector3 dashStartPosition; + private Vector3 dashTarget; + [Header("Trap")] [SerializeField] private LayerMask trapLayers; [SerializeField] private float slowFactor = 0.5f; @@ -28,16 +38,19 @@ public class PlayerControls : MonoBehaviour private Rigidbody2D rb2d; - // Start is called before the first frame update void Start() { rb2d = GetComponent(); } - // Update is called once per frame void Update() { walkDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); + if (!shouldDash) + { + shouldDash = Input.GetKeyDown(KeyCode.Mouse0); + } + dashTarget = Camera.main.ScreenToWorldPoint(Input.mousePosition); } void FixedUpdate() @@ -46,6 +59,14 @@ void FixedUpdate() { evictTimer = evictionDuration; shouldEvict = false; + shouldDash = false; + } + + if (shouldDash) + { + dashing = true; + shouldDash = false; + dashStartPosition = transform.position; } if (evictTimer > 0f) @@ -53,7 +74,15 @@ void FixedUpdate() rb2d.velocity = new Vector2(0, evictionVelocity); evictTimer -= Time.fixedDeltaTime; } - else + else if (dashing) + { + Vector2 direction = dashTarget - transform.position; + rb2d.AddForce(direction * dashForce, ForceMode2D.Impulse); + if (direction.magnitude <= 0.01f) + { + dashing = false; + } + } { Move(walkDirection, walkMagnitude); } @@ -112,6 +141,22 @@ IEnumerator Untrap() } } + void OnCollisionEnter2D(Collision2D collision) + { + if (dashing) + { + dashing = false; + + SoliderMap map = collision.gameObject.GetComponent(); + if (map != null) + { + float distance = (transform.position - dashStartPosition).magnitude; + map.Scale(-distance/10f * maxShrink); + } + } + + } + void OnTriggerEnter2D(Collider2D collider) { if (GetComponent().IsTouchingLayers(trapLayers)) diff --git a/PalestineJam2021/Assets/Scripts/ScenarioManager.cs b/PalestineJam2021/Assets/Scripts/ScenarioManager.cs index ee43829..cf3ef65 100644 --- a/PalestineJam2021/Assets/Scripts/ScenarioManager.cs +++ b/PalestineJam2021/Assets/Scripts/ScenarioManager.cs @@ -34,7 +34,6 @@ void Start() void Update() { - Debug.Log(Time.time); if (!zionistsAssembled && Time.time >= zionistAssemblyTime) { zionistsAssembled = true; @@ -78,7 +77,6 @@ void AssembleZionists() void SpawnTrap() { - Debug.Log("spawning"); trap = Instantiate(trapPrefab, Vector3.zero, Quaternion.identity); } @@ -111,6 +109,6 @@ void EvictPalestinians() void StartOccupation() { Destroy(trap); - FindObjectOfType().expanding = true; + FindObjectOfType().StartExpanding(); } } diff --git a/PalestineJam2021/Assets/Scripts/SoliderMap.cs b/PalestineJam2021/Assets/Scripts/SoliderMap.cs index cc9e04c..d265eeb 100644 --- a/PalestineJam2021/Assets/Scripts/SoliderMap.cs +++ b/PalestineJam2021/Assets/Scripts/SoliderMap.cs @@ -6,20 +6,46 @@ public class SoliderMap : MonoBehaviour { [SerializeField] private Vector3 expansionSpeed = Vector3.one; - protected internal bool expanding = false; + private bool expanding = false; + + void Start() + { + GetComponent().enabled = false; + } void FixedUpdate() { if (expanding) { - Vector3 scale = transform.localScale; - scale += expansionSpeed; + Scale(expansionSpeed); + } + } - scale.x = Mathf.Min(10f, scale.x); - scale.y = Mathf.Min(10f, scale.y); - scale.z = 1f; + protected internal void Scale(float toAdd) + { + Scale(Vector3.one * toAdd); + } - transform.localScale = scale; - } + protected internal void Scale(Vector3 toAdd) + { + Vector3 scale = transform.localScale; + scale += toAdd; + + scale.x = Mathf.Max(Mathf.Min(10f, scale.x), 0f); + scale.y = Mathf.Max(Mathf.Min(10f, scale.y), 0f); + scale.z = 1f; + + transform.localScale = scale; + } + + protected internal void StartExpanding() + { + GetComponent().enabled = true; + expanding = true; + } + + void OnCollisionEnter2D(Collision2D collision) + { + Debug.Log(collision.relativeVelocity); } }