<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Character : MonoBehaviour
{
<<<<<<< HEAD
    // 나도 모른다!!
=======
    // 머꼬!!
>>>>>>> f37fabdef3ccee5d05679ad2bc927fb826e2e94e
    public int _hp;                // 체력
    public int _damage;            // 공격력
    public int _defence;           // 방어력
    public int _evasion;           // 회피율
    public int _accuracy;          // 적중률
    
    // 회피 여부
    public virtual bool AttackSuccess(int accuracy, int evasion)
    {
        if ((accuracy - evasion) < 100)
        {
            int attackNumber = Random.Range(0, 100);
            if (attackNumber >= (accuracy - evasion))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return true;
        }
    }

    // 데미지 계산
    public virtual int OnDamage(bool attackSuccess, int damage, int defence)
    {
        if (attackSuccess)
        {
            // 계산한 데미지값이 0보다 클경우
            if ((damage - defence) > 0)
            {
                return damage - defence;
            }
            // 작거나 같을 경우
            else
            {
                return 1;
            }
        }
        // 회피일 때 
        else
        {
            return 0;
        }
    }

    public virtual void Die()
    {
        if (_hp <= 0)
        {
            Destroy(this.gameObject);
        }
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Goblin : Character
{

    // Start is called before the first frame update
    void Start()
    {
        _hp = 30;
        _damage = 5;
        _defence = 1;
        _accuracy = 100;
        _evasion = 0;
    }

    // Update is called once per frame
    void Update()
    {
        Die();
    }

    public override bool AttackSuccess(int accuracy, int evasion)
    {
        return base.AttackSuccess(accuracy, evasion);
    }

    public override int OnDamage(bool attackSuccess, int damage, int defence)
    {
        return base.OnDamage(attackSuccess, damage, defence);
    }

    public override void Die()
    {
        base.Die();
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemManager : MonoBehaviour
{
    public List<GameObject> _Item;
    public PlayerController playerController;

    // 무기 활성화
    public void WeaponOpen(int itemNumber)
    {
        WeaponClose();
        _Item[itemNumber].gameObject.SetActive(true);
        Debug.Log(_Item[itemNumber]);
        playerController._weapon = _Item[itemNumber];
    }
    
    public void WeaponClose()
    {
        for (int x = 0; x < _Item.Count; x++)
        {
            _Item[x].gameObject.SetActive(false);
        }
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    internal GameObject _weapon;
    private Rigidbody2D _playerRigidbody;
    private Animator _playerAnimator;

    private float _moveSpeed = 300f;
    private float _jumpForce = 500f;
    private float _xInput;
    private float Timer = 0f;

    private int _jumpCount;

    private bool _death;
    private bool _jumpping;
    private bool _weaponUp;
    private bool _dashing;

    // Start is called before the first frame update
    void Start()
    {
        _playerRigidbody = GetComponent<Rigidbody2D>();
        _playerAnimator = GetComponent<Animator>();

        _jumpCount = 0;
        _death = false;
        _jumpping = false;
        _weaponUp = true;
        _dashing = false;
    }

    // Update is called once per frame
    void Update()
    {
        Move();
        Jump();
        PlayerAnimation();
        Attack();
        if (!_jumpping)
        {
            Dash();
            Timer += Time.deltaTime;
            if (Timer > 5f)
            {
                _dashing = false;
                Timer = 0f;
            }
        }
    }

    // 이동
    public void Move()
    {

        _xInput = Input.GetAxis("Horizontal");
        float _playerSpeed = _xInput * _moveSpeed * Time.deltaTime;

        Vector2 NewVector = new Vector2(_playerSpeed, _playerRigidbody.velocity.y);
        _playerRigidbody.velocity = NewVector;

        if (_xInput < 0) // 왼쪽
        {
            transform.rotation = Quaternion.Euler(0, 180, 0);
        }
        else if (_xInput > 0) // 오른쪽
        {
            transform.rotation = Quaternion.Euler(0, 0, 0);
        }
        else
        {
            _playerSpeed = 0;
        }
    }

    // 점프
    public void Jump()
    {
        if (Input.GetKeyDown(KeyCode.Space) && _jumpCount < 2)
        {
            _jumpCount++;

            _playerRigidbody.velocity = Vector2.zero;
            _playerRigidbody.AddForce(Vector2.up * _jumpForce);
        }
    }
    public void PlayerAnimation()
    {
        if (_xInput != 0 && _jumpping == false)
        {
            _playerAnimator.SetBool("SetMove", true);
            _playerAnimator.SetBool("SetJump", false);
            _playerAnimator.SetBool("SetIdle", false);
        }
        else if (_xInput == 0 && _jumpping == false)
        {
            _playerAnimator.SetBool("SetMove", false);
            _playerAnimator.SetBool("SetJump", false);
            _playerAnimator.SetBool("SetIdle", true);
        }
        else if (_jumpping || (_xInput == 0 && _jumpping))
        {
            _playerAnimator.SetBool("SetMove", false);
            _playerAnimator.SetBool("SetJump", true);
            _playerAnimator.SetBool("SetIdle", false);
        }
    }

    public void Dash()
    {
        if (Input.GetKeyDown(KeyCode.X) && !_dashing )
        {
            _moveSpeed = 900f;
            _dashing = true;
            Invoke("DashOff", 1f);
        }
    }

    public void DashOff()
    {
        _moveSpeed = 300f;
    }

    public void Attack()
    {
        if (Input.GetKeyDown(KeyCode.Z))
        {
            if (_weaponUp)
            {
                _weapon.GetComponent<SpriteRenderer>().flipY = true;
                _weaponUp = false;
            }
            else
            {
                _weapon.GetComponent<SpriteRenderer>().flipY = false;
                _weaponUp = true;
            }
        }
    }

    public void Defense()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {

        }
    }

    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "Floor")
        {
            _jumpCount = 0;
            _jumpping = false;
        }
    }

    private void OnCollisionExit2D(Collision2D other)
    {
        if (other.gameObject.tag == "Floor")
        {
            _jumpping = true;
        }
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : Character
{
    bool canAttack = true;
    

    // Start is called before the first frame update
    void Start()
    {
        _hp = 80;
        _damage = 10;
        _defence = 1;
        _evasion = 0;  
        _accuracy = 100;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        
    }

    public override bool AttackSuccess(int accuracy, int evasion)
    {
        return base.AttackSuccess(accuracy, evasion);
    }

    public override int OnDamage(bool attackSuccess, int damage, int defence)
    {
        return base.OnDamage(attackSuccess, damage, defence);
    }

    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.tag == "Monster")
        {
            if (Input.GetKeyDown(KeyCode.Z) && canAttack)
            {
                Collider2D[] hitColliders = Physics2D.OverlapCircleAll(other.gameObject.transform.position, 0);
                int i = 0;
                while (i < hitColliders.Length)
                {
                    Character monster = hitColliders[i].gameObject.GetComponent<Character>();
                    int damage = OnDamage(AttackSuccess(_accuracy, monster._evasion), _damage, monster._defence);
                    monster._hp -= damage;
                    i++;
                }
                canAttack = false;
            }
            if (Input.GetKeyUp(KeyCode.Z))
            {
                canAttack = true;
            }

        }
    }
}
<file_sep>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    int[] _itemKind = new int[8]; // 0 = 장검, 1 = 양손도끼, 2 = 창, 3 = 해머, 4 = 양손방패, 5 = 한손검, 6 = 한손도끼, 7 = 한손방패

    internal ItemManager IM;

    void Start()
    {
        for (int weaponNumber = 0 ; weaponNumber < _itemKind.Length ; weaponNumber++)
        {
            _itemKind[weaponNumber] = weaponNumber;
        }
        IM = gameObject.GetComponent<ItemManager>();
        IM.WeaponClose();
    }

    void Update()
    {
        
    }
    public void LongSword()
    {
        IM.WeaponOpen(_itemKind[0]);
        Debug.Log("LongSword");
    }
    public void LongAxe()
    {
        IM.WeaponOpen(_itemKind[1]);
        Debug.Log("LongAxe");
    }
    public void Spear()
    {
        IM.WeaponOpen(_itemKind[2]);
        Debug.Log("Spear");
    }
    public void Hammer()
    {
        IM.WeaponOpen(_itemKind[3]);
        Debug.Log("Hammer");
    }
    public void BigShilder()
    {
        IM.WeaponOpen(_itemKind[4]);
        Debug.Log("BigShilder");
    }
    public void ShortSword()
    {
        IM.WeaponOpen(_itemKind[5]);
        Debug.Log("ShortSword");
    }
    public void ShortAxe()
    {
        IM.WeaponOpen(_itemKind[6]);
        Debug.Log("ShortAxe");
    }
    public void SmallShilder()
    {
        IM.WeaponOpen(_itemKind[7]);
        Debug.Log("SmallShilder");
    }

}
