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

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

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