Commit 3486b29f authored by 18손재민's avatar 18손재민

Merge branch 'master' into tetris

parents 088c7ec6 0688c38f
......@@ -253,20 +253,34 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f289cad4933d4bf42ae5c82c57bd88e4, type: 3}
m_Name:
m_EditorClassIdentifier:
maxSpeed: 400
speed: 600
speedAir: 5
jumpSpeed: 400
ropeSpeed: 200
doubleJumpSpeed: 400
maxSpeed: 5
maxDashSpeed: 10
accerlation: 600
jumpSpeed: 10
ropeSpeed: 3
doubleJumpSpeed: 10
dashAccerlation: 1000
isDashing: 0
platformArray: []
horizontal: 0
horizontalRaw: 0
dashStart: 0
groundLayer:
serializedVersion: 2
m_Bits: 256
ropeLayer:
serializedVersion: 2
m_Bits: 512
platformLayer:
serializedVersion: 2
m_Bits: 2048
outerwallLayer:
serializedVersion: 2
m_Bits: 4096
ropeDistance: 0.3
rayDistance: 1
ropeUp: 0.6
ropeDown: 0.7
--- !u!212 &489222436
SpriteRenderer:
m_ObjectHideFlags: 0
......@@ -364,6 +378,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
LCUI: {fileID: 0}
ttx: 0
tty: 0
--- !u!1001 &695959412
Prefab:
m_ObjectHideFlags: 0
......
......@@ -99,42 +99,52 @@ public class CameraController : MonoBehaviour {
{
float posx = player.transform.position.x;
float posy = player.transform.position.y;
if (RoomCol(1) != -1)
{
posy = RoomCol(1) - camY;
}
if (RoomCol(2) != -1)
{
posy = RoomCol(2) + camY;
}
if (RoomCol(3) != -1)
{
posx = RoomCol(3) + camX;
}
if (RoomCol(4) != -1)
{
posx = RoomCol(4) - camX;
}
if (RoomCol(3) != -1 && RoomCol(4) != -1)
{
float middle = Player.tx * 24f + 12f;
if (middle - RoomCol(3) > 20f)
{
posx = RoomCol(3) + camX;
}
else if (RoomCol(4) - middle > 20f)
{
posx = RoomCol(4) - camX;
}
else
Room curRoom = MapManager.mapGrid[Player.tx, Player.ty];
if (!curRoom.GetComponentInChildren<RoomInGame>().isRoomClear)
{
posx = player.transform.position.x;
if (RoomCol(1) != -1)
{
posy = RoomCol(1) - camY;
}
if (RoomCol(2) != -1)
{
posy = RoomCol(2) + camY;
}
if (RoomCol(3) != -1)
{
posx = RoomCol(3) + camX;
}
if (RoomCol(4) != -1)
{
posx = RoomCol(4) - camX;
}
if (RoomCol(3) != -1 && RoomCol(4) != -1)
{
float middle = Player.tx * 24f + 12f;
if (middle - RoomCol(3) > 20f)
{
posx = RoomCol(3) + camX;
}
else if (RoomCol(4) - middle > 20f)
{
posx = RoomCol(4) - camX;
}
else
{
posx = player.transform.position.x;
}
//방의 중심과 비교하여 어느게 더 가까운가
}
}
//방의 중심과 비교하여 어느게 더 가까운가
}
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, 0), 2f * Time.deltaTime);
transform.position = new Vector3(transform.position.x, transform.position.y, -1); //카메라를 원래 z축으로 이동
transform.position = Vector3.Lerp(transform.position, new Vector3(posx, posy, 0), 2f * Time.deltaTime);
transform.position = new Vector3(transform.position.x, transform.position.y, -1); //카메라를 원래 z축으로 이동
}
// Camera.main.transform.position = new Vector3(posx, posy, -10);
......
......@@ -6,6 +6,7 @@ public class Player : MonoBehaviour {
public LifeCrystalUI LCUI;
public static int tx, ty;
public int ttx;
public int tty;
// Use this for initialization
void Start () {
......@@ -15,6 +16,8 @@ public class Player : MonoBehaviour {
// Update is called once per frame
void Update () {
tx = (int)(transform.position.x / 24f);
ty = (int)(transform.position.y / 24f);
ttx = tx;
tty = ty;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class PlayerController : MonoBehaviour
{
......@@ -10,36 +11,50 @@ public class PlayerController : MonoBehaviour
[SerializeField]
private float maxSpeed;
[SerializeField]
private float speed;
private float maxDashSpeed;
[SerializeField]
private float speedAir;
private float accerlation;
[SerializeField]
private float jumpSpeed;
[SerializeField]
private float ropeSpeed;
[SerializeField]
private float doubleJumpSpeed;
[SerializeField]
private float dashAccerlation;
[SerializeField]
private bool isDashing = false;
public TilemapCollider2D[] platformArray;
// 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
[SerializeField]
private float horizontal = 0;
[SerializeField]
private float horizontalRaw = 0;
private float verticalRaw = 0;
private bool jump = false;
[SerializeField]
private int dashStart = 0;
// Variables for IsGrounded()
[SerializeField]
private LayerMask groundLayer;
[SerializeField]
private LayerMask ropeLayer;
[SerializeField]
private LayerMask platformLayer;
[SerializeField]
private LayerMask outerwallLayer;
[SerializeField]
private float ropeDistance = 0.3f;
[SerializeField]
private float rayDistance;
[SerializeField]
private float ropeUp, ropeDown;
// Use this for initialization
void Start()
{
......@@ -52,6 +67,7 @@ public class PlayerController : MonoBehaviour
horizontal = Input.GetAxis("Horizontal");
horizontalRaw = Input.GetAxisRaw("Horizontal");
verticalRaw = Input.GetAxisRaw("Vertical");
if (Input.GetButtonDown("Jump"))
{
jump = true;
......@@ -63,6 +79,13 @@ public class PlayerController : MonoBehaviour
isGrounded = IsGrounded();
if (isGrounded)
isJumpable = true;
if(isGrounded)
{
if (horizontalRaw == 1f) transform.localScale = new Vector3(1f, transform.localScale.y, transform.localScale.z);
else if (horizontalRaw == -1f) transform.localScale = new Vector3(-1f, transform.localScale.y, transform.localScale.z);
}
if (IsInRope())
{
......@@ -72,11 +95,13 @@ public class PlayerController : MonoBehaviour
{
isInRope = false;
rb.gravityScale = 2f;
}
rb.velocity = new Vector2(0f, verticalRaw * Time.smoothDeltaTime * ropeSpeed);
StartCoroutine(RopeDelay());
}
rb.velocity = new Vector2(0f, verticalRaw * ropeSpeed);
}
else if (jump)
else if (verticalRaw != 0 && ropeEnabled && horizontalRaw == 0)
{
isInRope = true;
rb.gravityScale = 0f;
......@@ -96,41 +121,109 @@ public class PlayerController : MonoBehaviour
{
if (isGrounded)
{
vertical = jumpSpeed * Time.smoothDeltaTime;
vertical = jumpSpeed;
}
else if (isJumpable)
{
vertical = doubleJumpSpeed * Time.smoothDeltaTime;
vertical = doubleJumpSpeed;
isJumpable = false;
}
}
if(verticalRaw == -1 && !isDownPlatform)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, platformLayer);
if (hit.collider != null && rb.velocity.y == 0)
{
Room curRoom = MapManager.mapGrid[Player.tx, Player.ty];
platformArray = curRoom.GetComponentsInChildren<TilemapCollider2D>();
isDownPlatform = true;
StartCoroutine(DownPlatform());
}
}
//rb.velocity = new Vector2(horizontal * speed * Time.smoothDeltaTime, vertical);
// rb.velocity = new Vector2(rb.velocity.x, vertical);
rb.AddForce(horizontalRaw * speed * Time.smoothDeltaTime * Vector2.right);
if(horizontalRaw != 0)
{
if(horizontal != 1 && horizontal != -1 && dashStart == 0)
{
//짧게 눌렀을 때
dashStart = 1;
}
}
if(horizontalRaw == 0 && horizontal != 0 && dashStart == 1)
{
//방금 뗐을때
dashStart = 2;
//이제 빠르게 켜면 됨
}
if(dashStart == 2 && horizontalRaw != 0)
{
isDashing = true;
}
if(horizontalRaw == 0 && horizontal == 0)
{
dashStart = 0;
isDashing = false;
}
if(isDashing)
rb.AddForce(horizontalRaw * dashAccerlation * Time.smoothDeltaTime * Vector2.right);
else
rb.AddForce(horizontalRaw * accerlation * Time.smoothDeltaTime * Vector2.right);
if (((horizontalRaw == 0) || (rb.velocity.x > 0 && horizontalRaw < 0)
|| (rb.velocity.x < 0 && horizontalRaw > 0)) && (isGrounded))
{
rb.AddForce(rb.velocity.x * (-10f) * Vector2.right);
rb.AddForce(rb.velocity.x * (-10f) * Vector2.right * Time.smoothDeltaTime);
}
rb.velocity = new Vector2(Mathf.Clamp(rb.velocity.x, -maxSpeed * Time.smoothDeltaTime, maxSpeed * Time.smoothDeltaTime), vertical);
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);
}
jump = false;
}
bool IsGrounded() // Is player grounded?
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, groundLayer);
RaycastHit2D hit1 = Physics2D.Raycast(transform.position, Vector2.down, rayDistance, groundLayer);
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 hit.collider != null;
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, Vector2.right, ropeDistance, ropeLayer);
RaycastHit2D hit2 = Physics2D.Raycast(transform.position, Vector2.left, ropeDistance, ropeLayer);
Debug.DrawRay(transform.position, ropeDistance * Vector2.right, Color.red);
Debug.DrawRay(transform.position, ropeDistance * Vector2.left, Color.red);
return hit1.collider != null || hit2.collider != null;
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);
Debug.DrawRay(transform.position + ropeUp * Vector3.up, ropeDistance * Vector2.left, Color.red);
Debug.DrawRay(transform.position - ropeDown * Vector3.up, ropeDistance * Vector2.right, Color.red);
Debug.DrawRay(transform.position - ropeDown * Vector3.up, ropeDistance * Vector2.left, Color.red);
return hit1.collider != null || hit2.collider != null || hit3.collider != null || hit4.collider != null;
}
public IEnumerator DownPlatform()
{
foreach (TilemapCollider2D element in platformArray)
{
if (element.name == "platform")
{
element.enabled = false;
yield return new WaitForSeconds(0.3f);
element.enabled = true;
isDownPlatform = false;
}
}
}
public IEnumerator RopeDelay()
{
ropeEnabled = false;
isJumpable = true;
yield return new WaitForSeconds(0.5f);
ropeEnabled = true;
}
}
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Room class
/// </summary>
......
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