말감둜그

ν¬λž˜ν”„ν†€ μ •κΈ€ WEEK12 DAY 91 - μŠ€νƒ 곡뢀 : μœ λ‹ˆν‹° 3D ν”Œλ ˆμ΄μ–΄ μ›€μ§μž„ & μ‘°μ΄μŠ€ν‹± μ‘°μž‘ λ³Έλ¬Έ

Krafton jungle

ν¬λž˜ν”„ν†€ μ •κΈ€ WEEK12 DAY 91 - μŠ€νƒ 곡뢀 : μœ λ‹ˆν‹° 3D ν”Œλ ˆμ΄μ–΄ μ›€μ§μž„ & μ‘°μ΄μŠ€ν‹± μ‘°μž‘

habbn 2024. 4. 6. 21:32
728x90
πŸ“†2024.04.06

1. μœ λ‹ˆν‹° 3d ν”Œλ ˆμ΄μ–΄ μ›€μ§μž„ & μ‘°μ΄μŠ€ν‹± μ‘°μž‘
2. λ°±μ€€ μ „μŸ-μ „νˆ¬

 

 

μ˜€λŠ˜μ€ μ‘°μ΄μŠ€ν‹±μœΌλ‘œ ν”Œλ ˆμ΄μ–΄ μ›€μ§μž„ μ‘°μž‘μ„ κ΅¬ν˜„ν•˜μ˜€λ‹€.

μ‘°μ΄μŠ€ν‹±μ„ μ‚¬μš©ν•΄μ„œ μ›€μ§μž„μ„ κ΅¬ν˜„ν•˜λŠ” 건 처음이라 ν•˜λ‚˜ν•˜λ‚˜ λ°°μ›Œκ°€λ©΄μ„œ ν–ˆλ‹€! 

 

μ‘°μ΄μŠ€ν‹± μ‘°μž‘μ„ ν•˜κΈ° μœ„ν•΄μ„œ μ‘°μ΄μŠ€ν‹± 에셋을 λ‹€μš΄λ°›μ•„μ•Ό ν•œλ‹€.

 

Joystick Pack | μž…μΆœλ ₯ 관리 | Unity Asset Store

Get the Joystick Pack package from Fenerax Studios and speed up your game development process. Find this & other μž…μΆœλ ₯ 관리 options on the Unity Asset Store.

assetstore.unity.com

 

 

PlayerController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public bool enableMobile = false;
    
    [SerializeField]
    private float smoothRotationTime;   //target κ°λ„λ‘œ νšŒμ „ν•˜λŠ”λ° κ±Έλ¦¬λŠ” μ‹œκ°„
    [SerializeField]
    private float smoothMoveTime;   //target μ†λ„λ‘œ λ°”λ€ŒλŠ”λ° κ±Έλ¦¬λŠ” μ‹œκ°„
    [SerializeField]
    private float moveSpeed;
    private float rotationVelocity;
    private float speedVelocity;
    private float currentSpeed;
    private float targetSpeed;

    Transform cameraTransform;
    public VariableJoystick joystick;

    void Awake()
    {
        cameraTransform = Camera.main.transform;
    }

    void Update()
    {
        Vector2 input = Vector2.zero;

        if (enableMobile)
        {
            input = new Vector2(joystick.input.x, joystick.input.y);
        }
        else
        {
            input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        }

        Vector2 inputDir = input.normalized;

        //μ›€μ§μž„μ„ λ©ˆμ·„μ„ λ•Œ λ‹€μ‹œ 처음 κ°λ„λ‘œ λŒμ•„κ°€λŠ” κ±Έ 막기 μœ„ν•¨
        if (inputDir != Vector2.zero)
        {
            float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg + cameraTransform.eulerAngles.y;
            transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, rotation, ref rotationVelocity, smoothRotationTime);
        }
        
        //μž…λ ₯ λ°©ν–₯에 λ”°λ₯Έ λͺ©ν‘œ 속도
        //inputDir.magnitudeλŠ” μž…λ ₯ λ²‘ν„°μ˜ 크기둜 μ‚¬μš©μžκ°€ μž…λ ₯ν•œ λ°©ν–₯의 크기에 ν•΄λ‹Ή
        targetSpeed = moveSpeed * inputDir.magnitude;
        
        //ν˜„μž¬ 속도λ₯Ό λͺ©ν‘œ μ†λ„λ‘œ λΆ€λ“œλŸ½κ²Œ μ‘°μ ˆν•œλ‹€.
        //SmoothDamp ν˜„μž¬ 속도λ₯Ό λͺ©ν‘œ μ†λ„λ‘œ μΌμ •ν•œ μ‹œκ°„(smoothMoveTime)λ™μ•ˆ λΆ€λ“œλŸ½κ²Œ λ³€ν™”
        //speedVelocityλŠ” μ†λ„μ˜ λ³€ν™”λŸ‰μ„ μΆ”μ ν•˜λŠ”λ° μ‚¬μš©λ˜λŠ” λ³€μˆ˜μ΄λ©°,
        //ref ν‚€μ›Œλ“œλ₯Ό 톡해 이 값을 ν•¨μˆ˜ λ‚΄μ—μ„œ 직접 λ³€κ²½ν•  수 μžˆλ‹€.
        currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedVelocity, smoothMoveTime);
        
        //ν˜„μž¬ μŠ€ν”Όλ“œμ—μ„œ νƒ€κ²Ÿ μŠ€ν”Όλ“œκΉŒμ§€ smoothMoveTime λ™μ•ˆ λ³€ν•œλ‹€.
        transform.Translate(transform.forward * currentSpeed * Time.deltaTime, Space.World);
        
    }
}

 

μ‘°μ΄μŠ€ν‹±μ„ μ΄μš©ν•΄μ„œ 이동을 ν•˜κ²Œλ” κ΅¬ν˜„μ„ ν•˜μ˜€κ³  ν…ŒμŠ€νŠΈλ₯Ό μœ„ν•΄μ„œ enableMobile boolν˜• λ³€μˆ˜λ₯Ό λ§Œλ“€μ–΄μ„œ ν‚€λ³΄λ“œ μž…λ ₯μœΌλ‘œλ„ 이동할 수 μžˆκ²Œλ” ν•˜μ˜€λ‹€. (ν„°μΉ˜νŒ¨λ“œμ™€ 이동이 λ™μ‹œμ— λ˜λŠ”μ§€ ν™•μΈν•˜κΈ° μœ„ν•΄ 디버깅 용으둜 λ§Œλ“  것이닀.)

 

if (inputDir != Vector2.zero)
{
    float rotation = Mathf.Atan2(inputDir.x, inputDir.y) * Mathf.Rad2Deg 
    					+ cameraTransform.eulerAngles.y;
    transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, 
    						rotation, ref rotationVelocity, smoothRotationTime);
}

 

이 뢀뢄은 μž…λ ₯이 μžˆλŠ” 경우 μž…λ ₯ λ°©ν–₯으둜 캐릭터λ₯Ό νšŒμ „μ‹œν‚€λŠ” 역할을 ν•˜κΈ° μœ„ν•΄ 각도λ₯Ό κ΅¬ν•΄μ£ΌλŠ” μ½”λ“œμ΄λ‹€.

 

1 . Mathf.Atan2(inputDir.x, inputDir.y)λŠ” μž…λ ₯ λ²‘ν„°μ˜ x와 μž…λ ₯ λ²‘ν„°μ˜ y λ₯Ό μ‚¬μš©ν•˜μ—¬ 각도λ₯Ό κ³„μ‚°ν•œλ‹€.

2. Mathf.Rad2Deg λ₯Ό μ‚¬μš©ν•΄μ„œ λΌλ””μ•ˆ 값을 κ°λ„λ‘œ λ³€ν™˜ν•œλ‹€.

-> Mathf.Atan2λŠ” λΌλ””μ•ˆμ„ returnν•˜κΈ°μ— λ‹€μ‹œ κ°λ„λ‘œ λ°”κΏ”μ£ΌλŠ” Mathf.Rad2Degλ₯Ό κ³±ν•΄μ€€λ‹€.

3. cameraTransform.eulerAngles.y λŠ” μΉ΄λ©”λΌμ˜ ν˜„μž¬ yμΆ• νšŒμ „ 값을 κ°€μ Έμ˜¨λ‹€.

4. μ΄λ ‡κ²Œ κ³„μ‚°λœ νšŒμ „κ°’μ„ μ‚¬μš©ν•˜μ—¬ Mathf.SmoothDampAngle ν•¨μˆ˜λ‘œ 캐릭터λ₯Ό λΆ€λ“œλŸ½κ²Œ νšŒμ „μ‹œν‚¨λ‹€.

-> Mathf.SmoothDampAngle ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄ ν”Œλ ˆμ΄μ–΄κ°€ λ”±λ”±ν•˜κ²Œ 움직이지 μ•Šκ³  λΆ€λ“œλŸ½κ²Œ μ›€μ§μ΄κ²Œ λœλ‹€.

-> Vector3.up은 y좕을 μ˜λ―Έν•œλ‹€. 

 

 

 


λ°±μ€€ : μ „μŸ - μ „νˆ¬

 

풀이 - bfs

import sys
from collections import deque
input = sys.stdin.readline

N, M = map(int,input().split())
peoples = [list(input().rstrip()) for _ in range(M)]

dx = [-1,1,0,0]
dy = [0,0,-1,1]

def bfs(a,b,color):
    q = deque()
    q.append((a,b))
    cnt = 1
    peoples[a][b]= "."
    while q:
        x, y  = q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            
            if(0 <= nx < M and 0 <= ny < N and peoples[nx][ny] == color):
                peoples[nx][ny] = "."
                q.append((nx,ny))
                cnt += 1
    return cnt    

w_result = 0
b_result = 0
for i in range(M):
    for j in range(N):
        if peoples[i][j] == "W":
            w_result += bfs(i,j,"W") **2
        elif peoples[i][j] == "B":
            b_result += bfs(i,j,"B") **2 
            
print(w_result, b_result)
728x90