diff --git a/Assets/Prefabs/Network Prefabs/GamePlayer.prefab b/Assets/Prefabs/Network Prefabs/GamePlayer.prefab index f499650..d6440d5 100644 --- a/Assets/Prefabs/Network Prefabs/GamePlayer.prefab +++ b/Assets/Prefabs/Network Prefabs/GamePlayer.prefab @@ -118,13 +118,15 @@ MonoBehaviour: HookKey: 0 DashKey: 0 UltKey: 0 + topLeftDeath: {x: 0, y: 0, z: 0} + bottomRightDeath: {x: 0, y: 0, z: 0} speed: 10 airSpeed: 7 jumpForce: 8 smallJump: 4 gravity: -10 - wallJump: 4 - wallJumpPush: 10 + wallJump: 8 + wallJumpPush: 15 smallJumpPush: 5 pushSpeed: 0.2 hookRange: 15 @@ -138,6 +140,7 @@ MonoBehaviour: serializedVersion: 2 m_Bits: 1024 setuped: 0 + gameIsRunning: 1 velocity: 0 --- !u!114 &114186454880906932 MonoBehaviour: diff --git a/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab b/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab index 0255275..34498f7 100644 --- a/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab +++ b/Assets/Prefabs/Network Prefabs/LobbyPlayer.prefab @@ -26,6 +26,7 @@ GameObject: - component: {fileID: 23327928353891206} - component: {fileID: 54431066813788928} - component: {fileID: 136050800636592130} + - component: {fileID: 145676841850764652} m_Layer: 10 m_Name: LobbyPlayer m_TagString: Player @@ -119,18 +120,23 @@ MonoBehaviour: HookKey: 0 DashKey: 0 UltKey: 0 + topLeftDeath: {x: 0, y: 0, z: 0} + bottomRightDeath: {x: 0, y: 0, z: 0} speed: 10 airSpeed: 7 jumpForce: 8 smallJump: 4 gravity: -10 - wallJump: 4 - wallJumpPush: 10 + wallJump: 8 + wallJumpPush: 12 smallJumpPush: 5 pushSpeed: 0.2 - hookRange: 15 + hookRange: 10 hookObject: {fileID: 1574484083535614, guid: 798642a34216b3c4e84e665614a0979a, type: 2} playerHookSpeed: 2 + springForce: Infinity + damperForce: Infinity + ropeSwing: 5 dashSpeed: 15 smallProjectile: {fileID: 1556668439340832, guid: be1300b1777602f448d537a75a9093c3, type: 2} @@ -139,6 +145,7 @@ MonoBehaviour: serializedVersion: 2 m_Bits: 1024 setuped: 0 + gameIsRunning: 0 velocity: 0 --- !u!114 &114478164937343286 MonoBehaviour: @@ -190,10 +197,32 @@ CapsuleCollider: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 100100000} m_GameObject: {fileID: 1251834283741038} - m_Material: {fileID: 13400000, guid: 3f67cbc34e2adef4e808c3445e69a63d, type: 2} + m_Material: {fileID: 0} m_IsTrigger: 0 m_Enabled: 1 m_Radius: 0.5 m_Height: 2 m_Direction: 1 m_Center: {x: 0, y: 0, z: 0} +--- !u!145 &145676841850764652 +SpringJoint: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1251834283741038} + m_ConnectedBody: {fileID: 0} + m_Anchor: {x: 0, y: 0, z: 0} + m_AutoConfigureConnectedAnchor: 0 + m_ConnectedAnchor: {x: 0, y: 0, z: 0} + serializedVersion: 2 + m_Spring: 0 + m_Damper: 0 + m_MinDistance: 0 + m_MaxDistance: 0 + m_Tolerance: 0.025 + m_BreakForce: Infinity + m_BreakTorque: Infinity + m_EnableCollision: 0 + m_EnablePreprocessing: 1 + m_MassScale: 1 + m_ConnectedMassScale: 1 diff --git a/Assets/Prefabs/Plateform/SpawnPoint.prefab b/Assets/Prefabs/Plateform/SpawnPoint.prefab new file mode 100644 index 0000000..c475d13 --- /dev/null +++ b/Assets/Prefabs/Plateform/SpawnPoint.prefab @@ -0,0 +1,41 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &100100000 +Prefab: + m_ObjectHideFlags: 1 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: [] + m_RemovedComponents: [] + m_ParentPrefab: {fileID: 0} + m_RootGameObject: {fileID: 1661840454744596} + m_IsPrefabParent: 1 +--- !u!1 &1661840454744596 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + serializedVersion: 5 + m_Component: + - component: {fileID: 4121814324727574} + m_Layer: 0 + m_Name: SpawnPoint + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4121814324727574 +Transform: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1661840454744596} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Prefabs/Plateform/SpawnPoint.prefab.meta b/Assets/Prefabs/Plateform/SpawnPoint.prefab.meta new file mode 100644 index 0000000..c3d6c5e --- /dev/null +++ b/Assets/Prefabs/Plateform/SpawnPoint.prefab.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 19551d06920c9a045b4d0ab5f1547e89 +timeCreated: 1521044737 +licenseType: Free +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 100100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index e9f5d25..5ed246c 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -142,7 +142,25 @@ MonoBehaviour: m_EditorClassIdentifier: mapContainer: {fileID: 1420418010} tiles: - - color: {r: 0, g: 0.57254905, b: 0.27058825, a: 1} + - name: SpawnPoint + color: {r: 1, g: 1, b: 1, a: 1} + leftPrefab: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + middlePrefab: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + rightPrefab: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + underPrefeb: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + leftUnder: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + rightUnder: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + bothUnder: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, + type: 2} + bothTop: {fileID: 1661840454744596, guid: 19551d06920c9a045b4d0ab5f1547e89, type: 2} + - name: Grass + color: {r: 0, g: 0.57254905, b: 0.27058825, a: 1} leftPrefab: {fileID: 1418822140686544, guid: 995c1b88ff2258944a27e0144d0deca8, type: 2} middlePrefab: {fileID: 1418822140686544, guid: 995c1b88ff2258944a27e0144d0deca8, diff --git a/Assets/Scenes/Lobby.unity b/Assets/Scenes/Lobby.unity index 17c8b71..f17fa3f 100644 --- a/Assets/Scenes/Lobby.unity +++ b/Assets/Scenes/Lobby.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 diff --git a/Assets/Script/MapGenerator.cs b/Assets/Script/MapGenerator.cs index 5b9ec8d..e826649 100644 --- a/Assets/Script/MapGenerator.cs +++ b/Assets/Script/MapGenerator.cs @@ -34,6 +34,8 @@ public class MapGenerator : MonoBehaviour Vector3 bottomRight = new Vector3(map.width, 0, 0); cam.transform.position = new Vector3(map.width / 2, map.height / 2, -Vector3.Distance(topLeft, bottomRight) / 2.5f); + NetworkManager netManager = GameObject.Find("GameManager").GetComponent(); + StartCoroutine(netManager.SetDeathZone(topLeft, bottomRight)); } private void CreateTile(int x, int y) diff --git a/Assets/Script/MapTile.cs b/Assets/Script/MapTile.cs index 8d5c7ae..253cccd 100644 --- a/Assets/Script/MapTile.cs +++ b/Assets/Script/MapTile.cs @@ -3,6 +3,7 @@ [System.Serializable] public class MapTile { + public string name; public Color color; public GameObject leftPrefab; public GameObject middlePrefab; diff --git a/Assets/Script/NetworkManager.cs b/Assets/Script/NetworkManager.cs index b217a62..a53fe9c 100644 --- a/Assets/Script/NetworkManager.cs +++ b/Assets/Script/NetworkManager.cs @@ -386,7 +386,14 @@ public class NetworkManager : NetworkLobbyManager } pMovement.setuped = true; - pMovement.gameObject.transform.position = new Vector3(player * 2, 2, 0); + if (!gameIsRunning) + pMovement.transform.position = new Vector3(player * 2, 2, 0); + else + { + GameObject spawnPoint = GameObject.Find("SpawnPoint(Clone)"); + pMovement.transform.position = spawnPoint.transform.position; + Destroy(spawnPoint); + } pMovement.gameObject.GetComponent().velocity = new Vector3(0, 5, 0); } @@ -402,6 +409,17 @@ public class NetworkManager : NetworkLobbyManager return base.OnLobbyServerSceneLoadedForPlayer(lobbyPlayer, gamePlayer); } + public IEnumerator SetDeathZone(Vector3 topLeft, Vector3 bottomRight) + { + yield return new WaitForSeconds(0.5f); + foreach(GameObject foo in GameObject.FindGameObjectsWithTag("Player")) + { + PlayerMovement player = foo.GetComponent(); + player.topLeftDeath = topLeft; + player.bottomRightDeath = bottomRight; + } + } + private void PlayerDied(int player) { int playerCount = 0; diff --git a/Assets/Script/PlayerMovement.cs b/Assets/Script/PlayerMovement.cs index 10d1b78..d07c1db 100644 --- a/Assets/Script/PlayerMovement.cs +++ b/Assets/Script/PlayerMovement.cs @@ -12,6 +12,9 @@ public class PlayerMovement : MonoBehaviour public KeyCode DashKey = KeyCode.None; public KeyCode UltKey = KeyCode.None; + public Vector3 topLeftDeath; + public Vector3 bottomRightDeath; + [Space] [SerializeField] private int speed = 10; [SerializeField] private int airSpeed = 7; @@ -24,10 +27,16 @@ public class PlayerMovement : MonoBehaviour [SerializeField] private float pushSpeed = 0.2f; [Space] - [SerializeField] private float hookRange = 15; + [SerializeField] private float hookRange = 10; [SerializeField] private GameObject hookObject; [SerializeField] private float playerHookSpeed = 15; + [SerializeField] private float springForce = Mathf.Infinity; + [SerializeField] private float damperForce = Mathf.Infinity; + [SerializeField] private float ropeSwing = 1; private GameObject hook; + private bool wallHooked = false; + private Vector3 hookPosition; + private float hookLength; [Space] [SerializeField] private float dashSpeed = 15; @@ -44,6 +53,7 @@ public class PlayerMovement : MonoBehaviour [Space] public bool setuped = false; + [SerializeField] private bool gameIsRunning = false; [HideInInspector] public float velocity = 0; @@ -56,7 +66,6 @@ public class PlayerMovement : MonoBehaviour private MovingElement movingPlateform; private Rigidbody rb; - private void Start() { @@ -65,7 +74,7 @@ public class PlayerMovement : MonoBehaviour private bool IsGrounded() { - if (Mathf.Abs(RelativeVelocity().y) < 0.1f) + if (Mathf.Abs(RelativeVelocity().y) < 0.1f && !wallHooked) { if (groundedLastFrame) { @@ -182,8 +191,9 @@ public class PlayerMovement : MonoBehaviour private void FixedUpdate() { - if (JumpKey == KeyCode.None || Horizontal == null) - return; + //Check if player is outside the map bondaries + if (gameIsRunning && topLeftDeath.magnitude != 0 && (transform.position.x < topLeftDeath.x || transform.position.x > bottomRightDeath.x || transform.position.y > topLeftDeath.y || transform.position.y < bottomRightDeath.y)) + Die(); bool isGrounded = IsGrounded(); bool isSliding = IsSliding(); @@ -198,6 +208,7 @@ public class PlayerMovement : MonoBehaviour if (isGrounded || isPushing) canDash = true; + if (-1 < velocity && velocity < 1) velocity = 0; @@ -208,6 +219,7 @@ public class PlayerMovement : MonoBehaviour float horizontalVel = Input.GetAxis(Horizontal); + //Change air velocity after wall jump if (wallJumped) { if (-0.3 < horizontalVel && horizontalVel < 0.3) @@ -216,6 +228,14 @@ public class PlayerMovement : MonoBehaviour horizontalVel /= 2; } + //Handle hook display + if (wallHooked) + { + if(hook != null) + hook.GetComponent().SetPosition(0, rb.position); + } + + //Handle dash after user pressed the button if(dashTime > 0) { rb.velocity = dashVelocity; @@ -234,10 +254,23 @@ public class PlayerMovement : MonoBehaviour } } + //Make player move if(!isSliding || (isSliding && Mathf.Sign(wallDirection) != Mathf.Sign(Input.GetAxis(Horizontal)))) { if (dashTime <= 0) - rb.AddForce(new Vector3(horizontalVel * (isPushing ? pushSpeed : 1) * (airControl ? airSpeed : speed) - (rb.velocity.x - velocity), 0, 0), ForceMode.Impulse); + { + if (!wallHooked) + { + //Normal movement + rb.AddForce(new Vector3(horizontalVel * (isPushing ? pushSpeed : 1) * (airControl ? airSpeed : speed) - (rb.velocity.x - velocity), 0, 0), ForceMode.Impulse); + } + else + { + //Rope swing movement + if (rb.position.y < hookPosition.y - hookLength / 2) + rb.AddForce(new Vector3(Input.GetAxis(Horizontal) * ropeSwing, 0, 0)); + } + } } //Make user jump @@ -266,7 +299,7 @@ public class PlayerMovement : MonoBehaviour } //Apply more gravity - if (rb.velocity.y < 1 && !isSliding) + if (rb.velocity.y < 1 && !isSliding && !wallHooked) rb.AddForce(new Vector3(0, gravity, 0), ForceMode.Acceleration); //WallSlide @@ -285,31 +318,55 @@ public class PlayerMovement : MonoBehaviour } //Hook - if (Input.GetKeyUp(HookKey)) + if (wallHooked) { - Destroy(hook); - } - if (Input.GetKeyDown(HookKey)) - { - if (hook != null) + if (!Input.GetKey(HookKey)) + { Destroy(hook); - - Vector3 direction = NormaliseMovement(Input.GetAxis(Horizontal), Input.GetAxis(Vertical)); - - RaycastHit hit; - if (Physics.Raycast(rb.position, direction, out hit, hookRange)) - { - hook = Instantiate(hookObject, rb.position, Quaternion.identity); - hook.GetComponent().SetPositions(new Vector3[] { rb.position, hit.point }); - - if (hit.collider.tag == "Player") - { - hit.collider.GetComponent().Hooked(direction, rb.position); - } + SpringJoint spring = GetComponent(); + spring.connectedAnchor = new Vector3(0, 0, 0); + spring.spring = 0; + spring.damper = 0; + spring.maxDistance = 0; + wallHooked = false; + hookPosition = Vector3.zero; + hookLength = 0; } - else + } + else + { + if (Input.GetKeyDown(HookKey)) { - print("Mised"); + if (hook != null) + Destroy(hook); + + Vector3 direction = NormaliseMovement(Input.GetAxis(Horizontal), Input.GetAxis(Vertical)); + + RaycastHit hit; + if (Physics.Raycast(rb.position, direction, out hit, hookRange)) + { + wallHooked = true; + SpringJoint spring = GetComponent(); + spring.connectedAnchor = hit.point; + spring.spring = springForce; + spring.damper = damperForce; + spring.maxDistance = Vector3.Distance(rb.position, hit.point); + + hook = Instantiate(hookObject, rb.position, Quaternion.identity); + hook.GetComponent().SetPositions(new Vector3[] { rb.position, hit.point }); + + hookPosition = hit.point; + hookLength = Vector3.Distance(rb.position, hit.point); + + if (hit.collider.tag == "Player") + { + hit.collider.GetComponent().Hooked(direction, rb.position); + } + } + else + { + print("Mised"); + } } } @@ -360,6 +417,8 @@ public class PlayerMovement : MonoBehaviour private void Die() { + gameIsRunning = false; + if (gameObject.name == "GamePlayer (1)") GameObject.Find("GameManager").GetComponent().IsDead1 = true; if (gameObject.name == "GamePlayer (2)")