diff options
author | marcinzelent <zelent.marcin@gmail.com> | 2019-04-28 03:40:19 +0200 |
---|---|---|
committer | marcinzelent <zelent.marcin@gmail.com> | 2019-04-28 03:40:19 +0200 |
commit | eebe04b0c81dc2660335a1e09157c7a18189ddc3 (patch) | |
tree | b0a6c56bf9ac688c731ffe1e84fe0f2e11205b0c /nGJ2019/Assets/Scripts | |
parent | 80cff62241a7e10e46d54ba62648076e93a734a1 (diff) | |
parent | d56bb08581cfebf985e5110aacac260447338da9 (diff) |
Merge branch 'master' of https://github.com/marcinzelent/ngj2019
Diffstat (limited to 'nGJ2019/Assets/Scripts')
-rw-r--r-- | nGJ2019/Assets/Scripts/DragonMovement.cs | 83 | ||||
-rw-r--r-- | nGJ2019/Assets/Scripts/SwarmSystem.cs | 30 |
2 files changed, 86 insertions, 27 deletions
diff --git a/nGJ2019/Assets/Scripts/DragonMovement.cs b/nGJ2019/Assets/Scripts/DragonMovement.cs index f3ae1d5..302a9e7 100644 --- a/nGJ2019/Assets/Scripts/DragonMovement.cs +++ b/nGJ2019/Assets/Scripts/DragonMovement.cs @@ -6,9 +6,14 @@ public class DragonMovement : MonoBehaviour { public List<Renderer> solids; + public GameObject hurtPrefab; + public float horizontalSpeed = 0.1f; public float verticalSpeed = 0.2f; + private Vector3 direcV = Vector3.zero; + private Vector3 deltaV = Vector3.zero; + public float horizontalBound = 6f; public float verticalBound = 4f; @@ -20,33 +25,30 @@ public class DragonMovement : MonoBehaviour private enum State {normal, swirl, slim, spread}; private State state = State.normal; + + private void applyMotion(Vector3 direc) + { + direcV = direcV + direc; + } private void moveUp() { - transform.Translate(Vector3.up * verticalSpeed); - if(transform.position.y > verticalBound) - transform.position = new Vector3(transform.position.x, verticalBound, transform.position.z); + applyMotion(Vector3.up * verticalSpeed); } private void moveDown() { - transform.Translate(Vector3.down * verticalSpeed); - if(transform.position.y < -verticalBound) - transform.position = new Vector3(transform.position.x, -verticalBound, transform.position.z); + applyMotion(Vector3.down * verticalSpeed); } private void moveLeft() { - transform.Translate(Vector3.left * horizontalSpeed); - if(transform.position.x < -horizontalBound) - transform.position = new Vector3(-horizontalBound, transform.position.y, transform.position.z); + applyMotion(Vector3.left * horizontalSpeed); } private void moveRight() { - transform.Translate(Vector3.right * horizontalSpeed); - if(transform.position.x > horizontalBound) - transform.position = new Vector3(horizontalBound, transform.position.y, transform.position.z); + applyMotion(Vector3.right * horizontalSpeed); } private void turnVisible(bool visible) @@ -169,9 +171,28 @@ public class DragonMovement : MonoBehaviour swarm.activate(false); } + void FixedUpdate() + { + transform.Translate(deltaV); + deltaV = 0.6f*deltaV + 0.4f*direcV; + direcV = Vector3.zero; + + if(transform.position.y > verticalBound) + transform.position = new Vector3(transform.position.x, verticalBound, transform.position.z); + + if(transform.position.y < -verticalBound) + transform.position = new Vector3(transform.position.x, -verticalBound, transform.position.z); + + if(transform.position.x < -horizontalBound) + transform.position = new Vector3(-horizontalBound, transform.position.y, transform.position.z); + + if(transform.position.x > horizontalBound) + transform.position = new Vector3(horizontalBound, transform.position.y, transform.position.z); + } + void Update() { - if(hurtCooldown < 0) + if(hurtCooldown > 0) hurtCooldown -= Time.deltaTime; // keyboard scheme @@ -232,12 +253,30 @@ public class DragonMovement : MonoBehaviour Gizmos.DrawWireCube(Vector3.zero, new Vector3(2*horizontalBound, 2*verticalBound, 0)); } + private IEnumerator makeGoAway(Transform t) + { + Vector3 delta = Random.onUnitSphere * Random.Range(0.03f, 0.1f); + Vector3 start = t.position; + while((start-t.position).magnitude < 3) + { + t.Translate(delta); + yield return new WaitForSeconds(0.01f); + } + Destroy(t.gameObject); + } + private void getHurt() { if(hurtCooldown <= 0) { healthBar.health--; hurtCooldown = 3; + + for(int i=0; i<30; i++) + { + Transform t = ((GameObject)Instantiate(hurtPrefab, transform.position + swarm.collapseCenter, Quaternion.identity)).transform; + StartCoroutine(makeGoAway(t)); + } } } @@ -246,7 +285,23 @@ public class DragonMovement : MonoBehaviour EnemyCollider enemy = other.gameObject.GetComponent<EnemyCollider>(); if(enemy != null) { - getHurt(); + switch(enemy.type) + { + case ObstacleType.caveWalls: + case ObstacleType.rockTop: + case ObstacleType.rockBottom: + case ObstacleType.rockJaws: + getHurt(); + break; + case ObstacleType.narrowPassage: + if(state != State.slim) + getHurt(); + break; + case ObstacleType.net: + if(state != State.spread) + getHurt(); + break; + } } } diff --git a/nGJ2019/Assets/Scripts/SwarmSystem.cs b/nGJ2019/Assets/Scripts/SwarmSystem.cs index 9658a92..798cf13 100644 --- a/nGJ2019/Assets/Scripts/SwarmSystem.cs +++ b/nGJ2019/Assets/Scripts/SwarmSystem.cs @@ -6,8 +6,12 @@ public class SwarmSystem : MonoBehaviour public GameObject swarmPrefab; public GameObject anchorPrefab; public int size = 1; + public Vector3 collapseCenter; + + public SkinnedMeshRenderer meshRender; public bool showGuides = false; + public bool showMesh = false; private List<Transform> units = new List<Transform>(); private List<Transform> anchors = new List<Transform>(); @@ -20,8 +24,6 @@ public class SwarmSystem : MonoBehaviour private List<int> boneCenterStarts = new List<int>(); private List<float> boneCenterDists = new List<float>(); - private SkinnedMeshRenderer meshRender; - private List<int> unitTris = new List<int>(); private List<List<int>> triGraph; @@ -334,8 +336,6 @@ public class SwarmSystem : MonoBehaviour void Start() { - meshRender = GetComponentInChildren<SkinnedMeshRenderer>(); - mapBones(); refreshMesh(); @@ -372,7 +372,9 @@ public class SwarmSystem : MonoBehaviour unit.position = anchors[u].position + Noise*noiseDirecs[u]; - Vector3 collapsedPos = Vector3.Project(unit.position - transform.position, Vector3.right) + transform.position; + Vector3 coll = transform.position + collapseCenter; + + Vector3 collapsedPos = Vector3.Project(unit.position - coll, Vector3.right)*0.3f + coll; unit.position = (1-Collapse)*unit.position + Collapse*collapsedPos; } @@ -382,8 +384,6 @@ public class SwarmSystem : MonoBehaviour { if(showGuides) { - meshRender = GetComponentInChildren<SkinnedMeshRenderer>(); - mapBones(); refreshMesh(); @@ -398,12 +398,13 @@ public class SwarmSystem : MonoBehaviour Mesh mesh = getCurrentMesh(); - for(int i=0; i<mesh.triangles.Length; i+=3) - { - //Gizmos.DrawSphere(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[i]]), 0.1f); - //Gizmos.DrawSphere(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[i+1]]), 0.1f); - //Gizmos.DrawSphere(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[i+2]]), 0.1f); - } + if(showMesh) + for(int i=0; i<mesh.triangles.Length; i+=3) + { + Gizmos.DrawSphere(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[i]]), 0.1f); + Gizmos.DrawSphere(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[i+1]]), 0.1f); + Gizmos.DrawSphere(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[i+2]]), 0.1f); + } int tri = 0; @@ -427,6 +428,9 @@ public class SwarmSystem : MonoBehaviour Gizmos.DrawLine(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[tri*3+1]]), meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[tri*3+2]])); Gizmos.DrawLine(meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[tri*3+2]]), meshRender.transform.TransformPoint(mesh.vertices[mesh.triangles[tri*3]])); + Gizmos.color = Color.green; + Gizmos.DrawLine(transform.position + collapseCenter - Vector3.right*5, transform.position + collapseCenter + Vector3.right*5); + } } }
\ No newline at end of file |