Hollow Knight/Assets/Prefabs/Enemy.prefab @@ -72,7 +72,7 @@ SpriteRenderer: m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: -533003135 m_SortingLayer: 8 m_SortingLayer: 7 m_SortingOrder: 0 m_Sprite: {fileID: 21300000, guid: 165152424fdd34c2890576da528bc5a3, type: 2} m_Color: {r: 1, g: 1, b: 1, a: 1} @@ -164,12 +164,13 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: health: 3 walkSpeed: 2 behaveIntervalLeast: 1 behaveIntervalMost: 3 edgeSafeDistance: 0.5 detectDistance: 6 hurtRecoil: {x: -2, y: 2} recoilTime: 0.5 damageToPlayer: 1 hurtRecoil: {x: -2, y: 0} hurtRecoilTime: 0.2 deathForce: {x: -2, y: 2} destroyDelay: 3 walkSpeed: 2 edgeSafeDistance: 0.5 behaveIntervalLeast: 1 behaveIntervalMost: 3 4 Hollow Knight/Assets/Prefabs/Enemy2.prefab @@ -166,8 +166,8 @@ MonoBehaviour: health: 2 detectDistance: 12 damageToPlayer: 1 hurtRecoil: {x: -2, y: 2} recoilTime: 0.5 hurtRecoil: {x: -2, y: 0} hurtRecoilTime: 0.2 deathForce: {x: -2, y: 2} destroyDelay: 3 shootInterval: 3 8 Hollow Knight/Assets/Prefabs/Player.prefab @@ -415,22 +415,22 @@ MonoBehaviour: health: 5 moveSpeed: 5 jumpSpeed: 7 jumpChance: 2 jumpLeft: 0 climbJumpForce: {x: 8, y: 10} fallSpeed: 5 sprintSpeed: 10 sprintTime: 0.15 sprintInterval: 0.4 attackInterval: 0.3 invulnerableColor: {r: 1, g: 1, b: 1, a: 0.69803923} hurtVelocity: {x: 3, y: 3} hurtRecoil: {x: -2, y: 2} hurtTime: 0.5 hurtRecoverTime: 1 deathForce: {x: 4, y: 4} deathRecoil: {x: -3, y: 2} deathDelay: 1.5 attackUpRecoil: {x: 0, y: -1} attackForwardRecoil: {x: -1, y: 0} attackDownRecoil: {x: 0, y: 4} hurtRecoil: {x: -2, y: 2} attackUpEffect: {fileID: 1646975930611572} attackForwardEffect: {fileID: 1410729049005502} attackDownEffect: {fileID: 1941861638662376} 6 Hollow Knight/Assets/Prefabs/Projectile.prefab @@ -14,7 +14,7 @@ GameObject: - component: {fileID: 1145997144} - component: {fileID: 4246052302286641822} - component: {fileID: 1751933315563110821} m_Layer: 10 m_Layer: 20 m_Name: Projectile m_TagString: Enemy m_Icon: {fileID: 0} @@ -71,8 +71,8 @@ SpriteRenderer: m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: -115107807 m_SortingLayer: 0 m_SortingLayerID: -329351783 m_SortingLayer: 9 m_SortingOrder: 0 m_Sprite: {fileID: 21300004, guid: 25daabec7472d41b2825a2fd911ff8b4, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} 8 Hollow Knight/Assets/Scenes/Level1.unity @@ -166,7 +166,7 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: -0.21664953} m_SpriteTilingProperty: border: {x: 0.58, y: 0.049999997, z: 0, w: 0.96999997} pivot: {x: 0.5, y: 0.5} @@ -177,7 +177,7 @@ BoxCollider2D: adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 m_Size: {x: 1.08, y: 10} m_Size: {x: 1.08, y: 9.566701} m_EdgeRadius: 0 --- !u!212 &3939263 SpriteRenderer: @@ -4117,7 +4117,7 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: -0.17870045} m_Offset: {x: -0.07220173, y: 1.1091597} m_SpriteTilingProperty: border: {x: 0.88, y: 0.93, z: 1.11, w: 0.71999997} pivot: {x: 0.5, y: 0.5} @@ -4128,7 +4128,7 @@ BoxCollider2D: adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 m_Size: {x: 24.5, y: 3.0443296} m_Size: {x: 24.644403, y: 0.46860933} m_EdgeRadius: 0 --- !u!212 &1316187718 SpriteRenderer: 20 Hollow Knight/Assets/Scenes/Level2.unity @@ -1322,11 +1322,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4195380477820900, guid: 3f189b4e844dd4c15bacde99d721494d, type: 3} propertyPath: m_LocalPosition.x value: 17.16 value: -0.81 objectReference: {fileID: 0} - target: {fileID: 4195380477820900, guid: 3f189b4e844dd4c15bacde99d721494d, type: 3} propertyPath: m_LocalPosition.y value: 12.05 value: 4.26 objectReference: {fileID: 0} - target: {fileID: 4195380477820900, guid: 3f189b4e844dd4c15bacde99d721494d, type: 3} propertyPath: m_LocalPosition.z @@ -4120,12 +4120,12 @@ PrefabInstance: - target: {fileID: 3300419883422892897, guid: 7785e96e5cf5f4d06b7ee6b8cefb9158, type: 3} propertyPath: m_LocalPosition.x value: 82.51 value: 82.04 objectReference: {fileID: 0} - target: {fileID: 3300419883422892897, guid: 7785e96e5cf5f4d06b7ee6b8cefb9158, type: 3} propertyPath: m_LocalPosition.y value: 10.8 value: 11.07 objectReference: {fileID: 0} - target: {fileID: 3300419883422892897, guid: 7785e96e5cf5f4d06b7ee6b8cefb9158, type: 3} @@ -5578,7 +5578,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2039137590} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 46.42, y: 4.04, z: -10} m_LocalPosition: {x: 46.383, y: 4.25, z: -10} m_LocalScale: {x: 1.2000009, y: 1.4000009, z: 1} m_Children: [] m_Father: {fileID: 406749421} @@ -5609,18 +5609,18 @@ BoxCollider2D: m_IsTrigger: 0 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} m_Offset: {x: 0.04564905, y: 0} m_SpriteTilingProperty: border: {x: 0, y: 0, z: 0, w: 0} pivot: {x: 0.5, y: 0.5} oldSize: {x: 1.23, y: 1.37} newSize: {x: 21, y: 1.36} newSize: {x: 17.694143, y: 1.36} adaptiveTilingThreshold: 0.5 drawMode: 2 adaptiveTiling: 0 m_AutoTiling: 0 serializedVersion: 2 m_Size: {x: 21, y: 1} m_Size: {x: 17.43932, y: 1} m_EdgeRadius: 0 --- !u!212 &2039137595 SpriteRenderer: @@ -5666,7 +5666,7 @@ SpriteRenderer: m_FlipX: 0 m_FlipY: 0 m_DrawMode: 2 m_Size: {x: 21, y: 1.36} m_Size: {x: 17.694143, y: 1.36} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 @@ -6152,7 +6152,7 @@ PrefabInstance: - target: {fileID: 3720960542313605643, guid: aa1799629b988461caedcaae1c13d103, type: 3} propertyPath: m_LocalPosition.x value: 10.24 value: 12.87 objectReference: {fileID: 0} - target: {fileID: 3720960542313605643, guid: aa1799629b988461caedcaae1c13d103, type: 3} 2 Hollow Knight/Assets/Scripts/Enemy/EnemyController.cs @@ -10,7 +10,7 @@ public abstract class EnemyController : MonoBehaviour public int damageToPlayer; public Vector2 hurtRecoil; public float recoilTime; public float hurtRecoilTime; public Vector2 deathForce; public float destroyDelay; 107 Hollow Knight/Assets/Scripts/Enemy/GunnerController.cs @@ -9,6 +9,7 @@ public class GunnerController : EnemyController public GameObject projectilePrefab; private bool _isShooting; private bool _isShootable; private Transform _playerTransform; private Transform _transform; @@ -25,6 +26,10 @@ void Start() _animator = gameObject.GetComponent(); _spriteRenderer = gameObject.GetComponent(); _isShootable = true; _isShooting = false; // default to idle mode _currentState = new Idle(); } @@ -37,6 +42,7 @@ void Update() // flip sprite int direction = _playerEnemyDistance > 0 ? 1 : _playerEnemyDistance < 0 ? -1 : 0; // flip sprite if (direction != 0 && health > 0) { Vector3 newScale = _transform.localScale; @@ -59,27 +65,8 @@ void Update() _isShooting = !_isShooting; } _currentState.Execute(this); } private void shootPlayer() { _animator.SetTrigger("attack"); Vector2 direction = _playerTransform.position - _transform.position; StartCoroutine(shootPlayerCoroutine(direction)); } private IEnumerator shootPlayerCoroutine(Vector2 direction) { yield return new WaitForSeconds(0.2f); Vector3 position = _transform.position; Quaternion rotation = _transform.rotation; GameObject projectileObj = Instantiate(projectilePrefab, position, rotation); Projectile projectile = projectileObj.GetComponent(); projectile.direction = direction; projectile.trigger(); if (health > 0) _currentState.Execute(this); } public override float behaveInterval() @@ -104,19 +91,33 @@ public override void hurt(int damage) StartCoroutine(hurtCoroutine()); } private IEnumerator hurtCoroutine() { yield return new WaitForSeconds(hurtRecoilTime); Vector2 newVelocity; newVelocity.x = 0; newVelocity.y = 0; _rigidbody.velocity = newVelocity; } protected override void die() { _animator.SetTrigger("isDead"); _rigidbody.bodyType = RigidbodyType2D.Dynamic; // stop movement Vector2 newVelocity; newVelocity.x = 0; newVelocity.y = 0; _rigidbody.velocity = newVelocity; // change layer to prevent collision gameObject.layer = LayerMask.NameToLayer("Decoration"); // death recoil Vector2 newForce; newForce.x = _transform.localScale.x * deathForce.x; newForce.y = deathForce.y; @@ -125,16 +126,6 @@ protected override void die() StartCoroutine(fadeCoroutine()); } private IEnumerator hurtCoroutine() { yield return new WaitForSeconds(recoilTime); Vector2 newVelocity; newVelocity.x = 0; newVelocity.y = 0; _rigidbody.velocity = newVelocity; } private IEnumerator fadeCoroutine() { @@ -151,10 +142,42 @@ private IEnumerator fadeCoroutine() } } if (health > 0) Destroy(gameObject); Destroy(gameObject); } private void shootPlayer() { if (_isShootable) { _animator.SetTrigger("attack"); _isShootable = false; Vector2 direction = _playerTransform.position - _transform.position; StartCoroutine(shootPlayerCoroutine(direction, shootInterval)); } } private IEnumerator shootPlayerCoroutine(Vector2 direction, float shootInterval) { yield return new WaitForSeconds(0.2f); // set diretion of shooting Vector3 position = _transform.position; Quaternion rotation = _transform.rotation; GameObject projectileObj = Instantiate(projectilePrefab, position, rotation); Projectile projectile = projectileObj.GetComponent(); projectile.direction = direction; // shoot the player with projectile projectile.trigger(); yield return new WaitForSeconds(shootInterval); if (!_isShootable) _isShootable = true; } /* ######################################################### */ public class Idle : State { public override bool checkValid(EnemyController enemyController) @@ -165,13 +188,12 @@ public override bool checkValid(EnemyController enemyController) public override void Execute(EnemyController enemyController) { // don't do anything while being idle } } public class Shooting : State { private bool _isShootable = true; public override bool checkValid(EnemyController enemyController) { @@ -183,20 +205,7 @@ public override void Execute(EnemyController enemyController) { GunnerController gunnerController = (GunnerController)enemyController; if (_isShootable) { gunnerController.shootPlayer(); gunnerController.StartCoroutine(executeCoroutine(gunnerController.behaveInterval())); } } private IEnumerator executeCoroutine(float delay) { _isShootable = false; yield return new WaitForSeconds(delay); if (!_isShootable) _isShootable = true; gunnerController.shootPlayer(); } } } 36 Hollow Knight/Assets/Scripts/Enemy/PatrolController.cs @@ -82,10 +82,17 @@ public override float behaveInterval() return UnityEngine.Random.Range(behaveIntervalLeast, behaveIntervalMost); } public int reachEdge() { return _reachEdge; } public override void hurt(int damage) { health = Math.Max(health - damage, 0); _isMovable = false; if (health == 0) { die(); @@ -100,9 +107,10 @@ public override void hurt(int damage) StartCoroutine(hurtCoroutine()); } public int reachEdge() private IEnumerator hurtCoroutine() { return _reachEdge; yield return new WaitForSeconds(hurtRecoilTime); _isMovable = true; } private bool checkGrounded(Vector2 offset) @@ -151,8 +159,6 @@ protected override void die() { _animator.SetTrigger("isDead"); _isMovable = false; Vector2 newVelocity; newVelocity.x = 0; newVelocity.y = 0; @@ -165,18 +171,9 @@ protected override void die() newForce.y = deathForce.y; _rigidbody.AddForce(newForce, ForceMode2D.Impulse); _isMovable = false; StartCoroutine(fadeCoroutine()); } private IEnumerator hurtCoroutine() { _isMovable = false; yield return new WaitForSeconds(recoilTime); _isMovable = true; } private IEnumerator fadeCoroutine() { @@ -196,6 +193,8 @@ private IEnumerator fadeCoroutine() Destroy(gameObject); } /* ######################################################### */ public abstract class PatrolState { public abstract bool checkValid(PatrolController enemyController); @@ -204,9 +203,15 @@ public abstract class PatrolState public class Patrol : State { private PatrolState _currentState = new Idle(); private PatrolState _currentState; private int _currentStateCase = 0; private bool _isFinished = true; private bool _isFinished; // ready for next state public Patrol() { _currentState = new Idle(); _isFinished = true; } public override bool checkValid(EnemyController enemyController) { @@ -219,6 +224,7 @@ public override void Execute(EnemyController enemyController) PatrolController patrolController = (PatrolController)enemyController; if (!_currentState.checkValid(patrolController) || _isFinished) { // randomly change current state int randomStateCase; do { 1 Hollow Knight/Assets/Scripts/GlobalController.cs @@ -4,6 +4,7 @@ public class GlobalController : MonoBehaviour { // Singleton public static GlobalController Instance { get; private set; } public GameObject player; 2 Hollow Knight/Assets/Scripts/Obstacle/Obstacle.cs @@ -6,6 +6,6 @@ public class Obstacle : MonoBehaviour { public void destroy() { GameObject.Destroy(gameObject); Destroy(gameObject); } } 208 Hollow Knight/Assets/Scripts/Player/PlayerController.cs Large diffs are not rendered by default. 3 Hollow Knight/Assets/Scripts/Trap/DragPlayer.cs @@ -9,6 +9,7 @@ public class DragPlayer : MonoBehaviour // Start is called before the first frame update void Start() { // the dragging speed is from script MovingTrap _movingTrap = gameObject.GetComponent(); } @@ -17,8 +18,8 @@ private void OnCollisionStay2D(Collision2D collision) if (collision.collider.gameObject != GlobalController.Instance.player) return; // drag the player on it Transform playerTransform = GlobalController.Instance.player.GetComponent(); Vector3 playerNewPosition = playerTransform.position; playerNewPosition.x += _movingTrap.movingSpeed * Time.deltaTime; playerTransform.position = playerNewPosition; 8 Hollow Knight/Assets/Scripts/Trap/Projectile.cs @@ -9,12 +9,6 @@ public class Projectile : Trap public float movingSpeed; public float destroyTime; // Start is called before the first frame update void Start() { } private void OnCollisionEnter2D(Collision2D collision) { string layerName = LayerMask.LayerToName(collision.collider.gameObject.layer); @@ -37,6 +31,6 @@ public override void trigger() private IEnumerator destroyCoroutine(float delay) { yield return new WaitForSeconds(delay); GameObject.Destroy(this); Destroy(this); } } 7 Hollow Knight/ProjectSettings/GraphicsSettings.asset @@ -3,7 +3,7 @@ --- !u!30 &1 GraphicsSettings: m_ObjectHideFlags: 0 serializedVersion: 12 serializedVersion: 13 m_Deferred: m_Mode: 1 m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} @@ -31,6 +31,9 @@ GraphicsSettings: m_AlwaysIncludedShaders: - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0} m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} @@ -55,3 +58,5 @@ GraphicsSettings: m_AlbedoSwatchInfos: [] m_LightsUseLinearIntensity: 0 m_LightsUseColorTemperature: 0 m_LogWhenShaderIsCompiled: 0 m_AllowEnlightenSupportForUpgradedProject: 1 2 Hollow Knight/ProjectSettings/Physics2DSettings.asset @@ -53,4 +53,4 @@ Physics2DSettings: m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432} m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745} m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804} m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff3ffeffff19feffff39f7fffffff7fffffff7ffff1df4ffff58f7ffff98f7ffffdcf7ffffdff7fffffff7ffff03f0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffefffffffffffffffffffff3ffeffff19eeffff39e7ffffffe7ffffffe7ffff1de4ffff58e7ffff98e7ffffdce7ffffdfe7ffffffe7ffff03e0ffdf01e0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 5 Hollow Knight/ProjectSettings/TagManager.asset @@ -35,7 +35,7 @@ TagManager: - AirWall - HUD - Trigger - - Projectile - - - @@ -75,6 +75,9 @@ TagManager: - name: Player uniqueID: 616613477 locked: 0 - name: Projectile uniqueID: 3965615513 locked: 0 - name: HUD uniqueID: 2293902781 locked: 0