Skip to content

Commit

Permalink
phase 1 dash attack
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarWKH committed Jun 23, 2021
1 parent abd0d7a commit 963d1e7
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 15 deletions.
4 changes: 3 additions & 1 deletion PalestineJam2021/Assets/Prefabs/Player.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -137,6 +137,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
walkMethod: 2
walkMagnitude: {x: 100, y: 100}
dashForce: 300
maxShrink: 1
trapLayers:
serializedVersion: 2
m_Bits: 8
Expand Down
8 changes: 8 additions & 0 deletions PalestineJam2021/Assets/Scenes/Prototype.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
51 changes: 48 additions & 3 deletions PalestineJam2021/Assets/Scripts/PlayerControls.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -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;
Expand All @@ -28,16 +38,19 @@ public class PlayerControls : MonoBehaviour

private Rigidbody2D rb2d;

// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}

// 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()
Expand All @@ -46,14 +59,30 @@ void FixedUpdate()
{
evictTimer = evictionDuration;
shouldEvict = false;
shouldDash = false;
}

if (shouldDash)
{
dashing = true;
shouldDash = false;
dashStartPosition = transform.position;
}

if (evictTimer > 0f)
{
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);
}
Expand Down Expand Up @@ -112,6 +141,22 @@ IEnumerator Untrap()
}
}

void OnCollisionEnter2D(Collision2D collision)
{
if (dashing)
{
dashing = false;

SoliderMap map = collision.gameObject.GetComponent<SoliderMap>();
if (map != null)
{
float distance = (transform.position - dashStartPosition).magnitude;
map.Scale(-distance/10f * maxShrink);
}
}

}

void OnTriggerEnter2D(Collider2D collider)
{
if (GetComponent<CircleCollider2D>().IsTouchingLayers(trapLayers))
Expand Down
4 changes: 1 addition & 3 deletions PalestineJam2021/Assets/Scripts/ScenarioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void Start()

void Update()
{
Debug.Log(Time.time);
if (!zionistsAssembled && Time.time >= zionistAssemblyTime)
{
zionistsAssembled = true;
Expand Down Expand Up @@ -78,7 +77,6 @@ void AssembleZionists()

void SpawnTrap()
{
Debug.Log("spawning");
trap = Instantiate(trapPrefab, Vector3.zero, Quaternion.identity);
}

Expand Down Expand Up @@ -111,6 +109,6 @@ void EvictPalestinians()
void StartOccupation()
{
Destroy(trap);
FindObjectOfType<SoliderMap>().expanding = true;
FindObjectOfType<SoliderMap>().StartExpanding();
}
}
42 changes: 34 additions & 8 deletions PalestineJam2021/Assets/Scripts/SoliderMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Collider2D>().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<Collider2D>().enabled = true;
expanding = true;
}

void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log(collision.relativeVelocity);
}
}

0 comments on commit 963d1e7

Please sign in to comment.