활동 내용

1. 활동 내역

1) 유니티

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

public class PlayerController : MonoBehaviour {
    private Rigidbody playerRigidbody;
    public float speed = 8f;

    void Start() {
        playerRigidbody = GetComponent<Rigidbody>();
    }

    void Update() {
        float xInput = Input.GetAxis("Horizontal");
        float zInput = Input.GetAxis("Vertical");

        float xSpeed = xInput * speed;
        float zSpeed = zInput * speed;

        Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed);
        playerRigidbody.velocity = newVelocity;
    }
    
     public void Die() {
        gameObject.SetActive(false);
    }
}

플레이어 캐릭터의 이동을 만들었다. 물리값을 가지게 하는 리지드바기 컴포넌트를 적용했다. 입력 값을 기반으로 캐릭터를 움직이도록 수평 수직 입력을 받고 그에 맞는 속도를 계산하여 움직이게 했다. 게임 오브젝트가 동작을 정지하게하는 die 메서드를 제작했다.

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

public class Bullet : MonoBehaviour {
    public float speed = 8f;
    private Rigidbody bulletRigidbody;

    void Start() {
        bulletRigidbody = GetComponent<Rigidbody>();
        bulletRigidbody.velocity = transform.forward * speed;
        Destroy(gameObject, 3f);
    }
}

총알 오브젝트가 생성되면 앞으로 이동하고, 3초 후에 자동으로 파괴되도록 하는 코드를 작성했다.

Untitled

구현한 화면이다 플레이어는 게임 매니저에서 wasd입력을 받고 플레이어를 움직인다. 탄막은 씬 시작시 앞으로 지정된 방향으로 날아간다.

2) 알고리즘 문제해결(분할 정복)

해결한 문제) 1074번 Z

#include <stdio.h>
#include <math.h>

int sabunmun_z(int n, int row, int col);

void z(int n, int r, int c ,long long int start) 
{
    if (n == 0)
    {
        printf("%lld",start);
        return;
    }
    
    long long int a = start; 
    long long int half = pow(2, n - 1);
    a += half * half *  sabunmun_z(n, r, c);
    if (r > half) r -= half;
    if (c > half) c -= half;
    z(n-1, r, c ,a);
}

int sabunmun_z(int n, int row, int col)
{
    int k = pow(2, n - 1);
    if (k < row)
    {
        if (k < col)
            return 3;
        else
            return 2;
    }
    else
    {
        if (k < col)
            return 1;
        else
            return 0;
    }
}

int main(void)
{
    int n, r, c;
    scanf("%d %d %d", &n, &r, &c);
    r++;
    c++;
    z(n, r, c, 0);
}

3) 추후 계획