Commit 4031879c authored by 18손재민's avatar 18손재민

플랫폼에서 붕쯔붕쯔하는거 고침

parent f09feb42
...@@ -39,7 +39,7 @@ Transform: ...@@ -39,7 +39,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1623439448163086} m_GameObject: {fileID: 1623439448163086}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 1.8, z: 0} m_LocalPosition: {x: 24.9, y: 18, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
...@@ -147,7 +147,7 @@ MonoBehaviour: ...@@ -147,7 +147,7 @@ MonoBehaviour:
ropeDistance: 0.3 ropeDistance: 0.3
rayDistance: 1 rayDistance: 1
ropeUp: 0.6 ropeUp: 0.6
ropeDown: 0.7 ropeDown: 0.8
--- !u!114 &114906702720267008 --- !u!114 &114906702720267008
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
......
...@@ -7,7 +7,6 @@ public class PlayerController : MonoBehaviour ...@@ -7,7 +7,6 @@ public class PlayerController : MonoBehaviour
{ {
private Rigidbody2D rb; // RigidBody2D of this game object private Rigidbody2D rb; // RigidBody2D of this game object
private Animator anim; private Animator anim;
[SerializeField] [SerializeField]
private float rbGravityScale; private float rbGravityScale;
// Speeds of player // Speeds of player
...@@ -31,6 +30,7 @@ public class PlayerController : MonoBehaviour ...@@ -31,6 +30,7 @@ public class PlayerController : MonoBehaviour
// Bool values for jump & doublejump // Bool values for jump & doublejump
private bool isGrounded = true; private bool isGrounded = true;
private bool isJumpable = true; // Can player jump or doublejump? private bool isJumpable = true; // Can player jump or doublejump?
private bool isInRope = false;
private bool isDownPlatform = false; private bool isDownPlatform = false;
private bool ropeEnabled = true; private bool ropeEnabled = true;
// Inputs // Inputs
...@@ -57,34 +57,35 @@ public class PlayerController : MonoBehaviour ...@@ -57,34 +57,35 @@ public class PlayerController : MonoBehaviour
private float rayDistance; private float rayDistance;
[SerializeField] [SerializeField]
private float ropeUp, ropeDown; private float ropeUp, ropeDown;
enum PlayerState { Idle, Walk, Run, GoingUp, GoingDown, Rope}
PlayerState playerState,previousState;
enum PlayerState { Idle, Walk, Run, GoingUp, GoingDown, Rope }
PlayerState playerState, previousState;
// Use this for initialization
void Start() void Start()
{ {
rb = gameObject.GetComponent<Rigidbody2D>(); rb = gameObject.GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
playerState = PlayerState.Idle;
previousState = PlayerState.Idle;
} }
// Update is called once per frame
void Update() void Update()
{ {
horizontal = Input.GetAxis("Horizontal"); horizontal = Input.GetAxis("Horizontal");
horizontalRaw = Input.GetAxisRaw("Horizontal"); horizontalRaw = Input.GetAxisRaw("Horizontal");
verticalRaw = Input.GetAxisRaw("Vertical"); verticalRaw = Input.GetAxisRaw("Vertical");
if (Input.GetButtonDown("Jump")) if (Input.GetButtonDown("Jump"))
{ {
jump = true; jump = true;
} }
} }
private void FixedUpdate() private void FixedUpdate()
{ {
isGrounded = IsGrounded(); isGrounded = IsGrounded();
if (GameManager.gameState == GameState.Ingame && MapManager.isDoorClosing != true) if (GameManager.gameState == GameState.Ingame)
{ {
if (isGrounded) if (isGrounded)
...@@ -109,10 +110,11 @@ public class PlayerController : MonoBehaviour ...@@ -109,10 +110,11 @@ public class PlayerController : MonoBehaviour
} }
if (IsInRope()) if (IsInRope())
{ {
if (playerState == PlayerState.Rope) if (isInRope)
{ {
if (horizontalRaw != 0f && verticalRaw == 0f) if (horizontalRaw != 0f && verticalRaw == 0f)
{ {
isInRope = false;
playerState = PlayerState.Idle; playerState = PlayerState.Idle;
rb.gravityScale = rbGravityScale; rb.gravityScale = rbGravityScale;
StartCoroutine(RopeDelay()); StartCoroutine(RopeDelay());
...@@ -123,20 +125,21 @@ public class PlayerController : MonoBehaviour ...@@ -123,20 +125,21 @@ public class PlayerController : MonoBehaviour
} }
else if (verticalRaw != 0 && ropeEnabled && horizontalRaw == 0) else if (verticalRaw != 0 && ropeEnabled && horizontalRaw == 0)
{ {
isInRope = true;
playerState = PlayerState.Rope; playerState = PlayerState.Rope;
rb.gravityScale = 0f; rb.gravityScale = 0f;
transform.position = new Vector2(Mathf.Round(transform.position.x - 0.5f) + 0.5f, transform.position.y); transform.position = new Vector2(Mathf.Round(transform.position.x - 0.5f) + 0.5f, transform.position.y);
rb.velocity = new Vector2(0f, 0f); rb.velocity = new Vector2(0f, 0f);
} }
anim.SetFloat("ropeUpDown", verticalRaw);
} }
else else
{ {
isInRope = false;
playerState = PlayerState.Idle; playerState = PlayerState.Idle;
rb.gravityScale = rbGravityScale; rb.gravityScale = rbGravityScale;
} }
if (playerState != PlayerState.Rope) if (!isInRope)
{ {
float vertical = rb.velocity.y; float vertical = rb.velocity.y;
if (jump) if (jump)
...@@ -151,6 +154,7 @@ public class PlayerController : MonoBehaviour ...@@ -151,6 +154,7 @@ public class PlayerController : MonoBehaviour
isJumpable = false; isJumpable = false;
} }
} }
if (!isGrounded) if (!isGrounded)
{ {
if (vertical > 0) playerState = PlayerState.GoingUp; if (vertical > 0) playerState = PlayerState.GoingUp;
...@@ -188,6 +192,7 @@ public class PlayerController : MonoBehaviour ...@@ -188,6 +192,7 @@ public class PlayerController : MonoBehaviour
else else
rb.AddForce(horizontalRaw * accerlation * Time.smoothDeltaTime * Vector2.right); rb.AddForce(horizontalRaw * accerlation * Time.smoothDeltaTime * Vector2.right);
if (isGrounded) if (isGrounded)
{ {
if (horizontalRaw == 0) playerState = PlayerState.Idle; if (horizontalRaw == 0) playerState = PlayerState.Idle;
...@@ -197,17 +202,19 @@ public class PlayerController : MonoBehaviour ...@@ -197,17 +202,19 @@ public class PlayerController : MonoBehaviour
else playerState = PlayerState.Walk; else playerState = PlayerState.Walk;
} }
} }
if (((horizontalRaw == 0) || (rb.velocity.x > 0 && horizontalRaw < 0) if (((horizontalRaw == 0) || (rb.velocity.x > 0 && horizontalRaw < 0)
|| (rb.velocity.x < 0 && horizontalRaw > 0)) && (isGrounded)) || (rb.velocity.x < 0 && horizontalRaw > 0)) && (isGrounded))
{ {
// rb.AddForce(rb.velocity.x * (-100f) * Vector2.right * Time.smoothDeltaTime); // rb.AddForce(rb.velocity.x * (-100f) * Vector2.right * Time.smoothDeltaTime);
rb.velocity = new Vector2(rb.velocity.x / (1.5f), rb.velocity.y); rb.velocity = new Vector2(rb.velocity.x / (1.5f), rb.velocity.y);
} }
if (isDashing) rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxDashSpeed, maxDashSpeed), vertical); if (isDashing) rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxDashSpeed, maxDashSpeed), vertical);
else else
rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxSpeed, maxSpeed), vertical); rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxSpeed, maxSpeed), vertical);
} }
if(previousState != playerState) if (previousState != playerState)
switch (playerState) switch (playerState)
{ {
case PlayerState.Idle: anim.SetTrigger("idle"); break; case PlayerState.Idle: anim.SetTrigger("idle"); break;
...@@ -218,6 +225,7 @@ public class PlayerController : MonoBehaviour ...@@ -218,6 +225,7 @@ public class PlayerController : MonoBehaviour
case PlayerState.Rope: anim.SetTrigger("rope"); break; case PlayerState.Rope: anim.SetTrigger("rope"); break;
} }
previousState = playerState; previousState = playerState;
} }
jump = false; jump = false;
} }
...@@ -227,12 +235,12 @@ public class PlayerController : MonoBehaviour ...@@ -227,12 +235,12 @@ public class PlayerController : MonoBehaviour
RaycastHit2D hit2 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, platformLayer); RaycastHit2D hit2 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, platformLayer);
RaycastHit2D hit3 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, outerwallLayer); RaycastHit2D hit3 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, outerwallLayer);
Debug.DrawRay(transform.position, rayDistance * Vector2.down, Color.white); Debug.DrawRay(transform.position, rayDistance * Vector2.down, Color.white);
return (hit1.collider != null || hit2.collider != null || hit3.collider != null) && rb.velocity.y == 0 ;//플랫폼 점프 버그 방지 return (hit1.collider != null || hit2.collider != null || hit3.collider != null) && rb.velocity.y == 0;//플랫폼 점프 버그 방지
} }
bool IsInRope() // Is player in rope? bool IsInRope() // Is player in rope?
{ {
RaycastHit2D hit1 = Physics2D.Raycast(transform.position + ropeUp*Vector3.up, Vector2.right, ropeDistance, ropeLayer); RaycastHit2D hit1 = Physics2D.Raycast(transform.position + ropeUp * Vector3.up, Vector2.right, ropeDistance, ropeLayer);
RaycastHit2D hit2 = Physics2D.Raycast(transform.position + ropeUp*Vector3.up, Vector2.left, ropeDistance, ropeLayer); RaycastHit2D hit2 = Physics2D.Raycast(transform.position + ropeUp * Vector3.up, Vector2.left, ropeDistance, ropeLayer);
RaycastHit2D hit3 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.right, ropeDistance, ropeLayer); RaycastHit2D hit3 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.right, ropeDistance, ropeLayer);
RaycastHit2D hit4 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.left, ropeDistance, ropeLayer); RaycastHit2D hit4 = Physics2D.Raycast(transform.position - ropeDown * Vector3.up, Vector2.left, ropeDistance, ropeLayer);
Debug.DrawRay(transform.position + ropeUp * Vector3.up, ropeDistance * Vector2.right, Color.red); Debug.DrawRay(transform.position + ropeUp * Vector3.up, ropeDistance * Vector2.right, Color.red);
...@@ -247,10 +255,10 @@ public class PlayerController : MonoBehaviour ...@@ -247,10 +255,10 @@ public class PlayerController : MonoBehaviour
{ {
if (element.name == "platform") if (element.name == "platform")
{ {
element.enabled = false; Physics2D.IgnoreCollision(element, transform.GetComponent<Collider2D>(), true);
yield return new WaitForSeconds(0.3f); yield return new WaitForSeconds(0.3f);
while(playerState == PlayerState.Rope) yield return new WaitForSeconds(0.1f); while (isInRope) yield return new WaitForSeconds(0.1f);
element.enabled = true; Physics2D.IgnoreCollision(element, transform.GetComponent<Collider2D>(), false);
isDownPlatform = false; isDownPlatform = false;
} }
} }
...@@ -263,5 +271,5 @@ public class PlayerController : MonoBehaviour ...@@ -263,5 +271,5 @@ public class PlayerController : MonoBehaviour
ropeEnabled = true; ropeEnabled = true;
} }
} }
...@@ -29,6 +29,9 @@ public enum ItemType ...@@ -29,6 +29,9 @@ public enum ItemType
MasterpieceAdd MasterpieceAdd
} }
public enum PlayerState { Idle, Walk, Run, GoingUp, GoingDown, Rope }
/// <summary> /// <summary>
/// Enum for game's state. /// Enum for game's state.
/// </summary> /// </summary>
......
...@@ -30,5 +30,9 @@ public class GameManager : MonoBehaviour { ...@@ -30,5 +30,9 @@ public class GameManager : MonoBehaviour {
gameState = GameState.Ingame; gameState = GameState.Ingame;
StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>().ChangeScene()); StartCoroutine(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>().ChangeScene());
} }
if(gameState == GameState.GameOver)
{
Time.timeScale = 0;
}
} }
} }
...@@ -253,8 +253,6 @@ public class MapManager : MonoBehaviour { ...@@ -253,8 +253,6 @@ public class MapManager : MonoBehaviour {
Press rightPress = Instantiate(press, new Vector3(10 * tetrisMapSize, y * tetrisMapSize, 2), Quaternion.identity); Press rightPress = Instantiate(press, new Vector3(10 * tetrisMapSize, y * tetrisMapSize, 2), Quaternion.identity);
leftPress.initialCollapseTime = Time.time; leftPress.initialCollapseTime = Time.time;
rightPress.initialCollapseTime = Time.time; rightPress.initialCollapseTime = Time.time;
leftPress.isLeft = true;
rightPress.isLeft = false;
leftPress.row = y; leftPress.row = y;
leftPress.bottomRow = y; leftPress.bottomRow = y;
leftPress.createdOrder = order; leftPress.createdOrder = order;
...@@ -282,8 +280,41 @@ public class MapManager : MonoBehaviour { ...@@ -282,8 +280,41 @@ public class MapManager : MonoBehaviour {
int doorCloseCounter = 0; int doorCloseCounter = 0;
int roomDestroyCounter = 0; int roomDestroyCounter = 0;
int row = leftPress.row; int row = leftPress.row;
float collapseRate = 0; float collapseSpeed = 0;
while (Time.time - initialCollapseTime < collapseTime) collapseSpeed = (float)1 / collapseTime;
leftPress.transform.localScale = new Vector3(0, 1, 1);
rightPress.transform.localScale = new Vector3(0, 1, 1);
while (leftPress.transform.localScale.x < 20)
{
yield return new WaitForSeconds(0.05f);
if (currentRoom.mapCoord.y == row)
collapseSpeed = (float)1 / (10 * collapseTime);
else
collapseSpeed = (float)1 / collapseTime;
leftPress.transform.localScale += new Vector3(collapseSpeed, 0, 0);
rightPress.transform.localScale += new Vector3(-collapseSpeed, 0, 0);
if (collapseSpeed - doorCloseCounter * 0.2f > (float)1 / 12)
{
mapGrid[doorCloseCounter, row].CloseDoor("Up", false);
mapGrid[doorCloseCounter, row].CloseDoor("Down", false);
mapGrid[width - doorCloseCounter - 1, row].CloseDoor("Up", false);
mapGrid[width - doorCloseCounter - 1, row].CloseDoor("Down", false);
mapGrid[doorCloseCounter, row].isRoomDestroyed = true;
mapGrid[width - doorCloseCounter - 1, row].isRoomDestroyed = true;
doorCloseCounter++;
}
if (collapseSpeed - roomDestroyCounter * 0.2f > 0.2f)
{
if (mapGrid[roomDestroyCounter, row] == currentRoom || mapGrid[width - roomDestroyCounter - 1, row] == currentRoom)
{
GameManager.gameState = GameState.GameOver;
}
//Destroy(mapGrid[roomDestroyCounter, row].gameObject);
//Destroy(mapGrid[width - roomDestroyCounter - 1, row].gameObject);
roomDestroyCounter++;
}
}
/*while (Time.time - initialCollapseTime < collapseTime)
{ {
yield return new WaitForSeconds(0.01f); yield return new WaitForSeconds(0.01f);
collapseRate = (Time.time - initialCollapseTime) / collapseTime; collapseRate = (Time.time - initialCollapseTime) / collapseTime;
...@@ -299,9 +330,9 @@ public class MapManager : MonoBehaviour { ...@@ -299,9 +330,9 @@ public class MapManager : MonoBehaviour {
mapGrid[width - doorCloseCounter - 1, row].isRoomDestroyed = true; mapGrid[width - doorCloseCounter - 1, row].isRoomDestroyed = true;
doorCloseCounter++; doorCloseCounter++;
} }
if(collapseRate - roomDestroyCounter * 0.2f > 0.2f) if (collapseRate - roomDestroyCounter * 0.2f > 0.2f)
{ {
if(mapGrid[roomDestroyCounter, row] == currentRoom || mapGrid[width - roomDestroyCounter - 1, row] == currentRoom) if (mapGrid[roomDestroyCounter, row] == currentRoom || mapGrid[width - roomDestroyCounter - 1, row] == currentRoom)
{ {
GameManager.gameState = GameState.GameOver; GameManager.gameState = GameState.GameOver;
} }
...@@ -309,8 +340,8 @@ public class MapManager : MonoBehaviour { ...@@ -309,8 +340,8 @@ public class MapManager : MonoBehaviour {
//Destroy(mapGrid[width - roomDestroyCounter - 1, row].gameObject); //Destroy(mapGrid[width - roomDestroyCounter - 1, row].gameObject);
roomDestroyCounter++; roomDestroyCounter++;
} }
} }*/
for(int i = row + 1; i < realHeight; i++) for (int i = row + 1; i < realHeight; i++)
{ {
if(isRowDeleting[i]) if(isRowDeleting[i])
{ {
......
...@@ -27,10 +27,7 @@ public class Press : MonoBehaviour ...@@ -27,10 +27,7 @@ public class Press : MonoBehaviour
/// Number of presses created simultaneously with this press. /// Number of presses created simultaneously with this press.
/// </summary> /// </summary>
public int simultaneouslyCreatedPressNumber; public int simultaneouslyCreatedPressNumber;
/// <summary>
/// Check if this press is on left side or not.
/// </summary>
public bool isLeft;
private void OnTriggerEnter2D(Collider2D collision) private void OnTriggerEnter2D(Collider2D collision)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment