반응형

이 게임은 첫 팀 프로젝트 게임일 수 있겠다. 제작기간은 1달 남짓이며, 기획과 프로그래머, 그래픽의 역할이 분리되어 소스를 받아 작업한 최초의 결과물이다. 본인은 메인 프로그래머를 맡았으며, 게임의 전반적인 구현을 하였다.

 

캐릭터 움직임, UI작용, 퍼즐, 타일 설치를 하였다.

BGM은 아무거나 하자는 팀원 회의로 프로그램을 맡은 필자가 우주배경에 맞는 스타2 브금을 채택하였다.

 

규칙 및 제한 걸음 횟수 UI

퍼즐은 화면 상단 가운데에 있는 이동 횟수만큼 타일을 건널 수 있다. 마지막 걸음 시에 다른 회색발판을 밟게 되면 다음 스테이지로 넘어가게 된다.

 

기타 우주 배경을 자아내기 위해 카메라 무빙을 살짝 주어 떠있는 연출효과를 넣었으며, 캐릭터 역시 부드럽게 회전할 수 있도록 Slerp 효과를 주었다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
using UnityEngine;
using System.Collections;
 
public enum CHAR_TYPE { NONE = 0, LEFT = 1, RIGHT, BACK, FORWARD, WIN}
 
public class Character : BaseObject {
 
    //캐릭터는 게임의 승리를 다룰 수 있습니다.
    [SerializeField]    GameManager gameManager;
 
    private RaycastHit hit;
    private Ray ray;
    private CHAR_TYPE char_type;
 
    //지정 좌표로 이동하는 변수
    private Vector3 move_pos;
    Animator animator;
 
    private float win_delay;
 
    //사운드
    [SerializeField]
    private AudioClip[] audioclip;
    private AudioSource audio_src;
 
    //이동횟수
    private int character_move_count;
 
 
 
    private float sound_delay;
 
 
    /*****************************/
 
    // Use this for initialization
    public void Init(Vector3 _Init_pos) {
        char_type = CHAR_TYPE.NONE;
 
        animator = gameObject.GetComponent<Animator>();
        audio_src = gameObject.AddComponent<AudioSource>();
 
        Set_Speed(1.5f);
 
        Set_Pos(_Init_pos + new Vector3(.0f, .05f, .0f));
        //위치 초기화
        move_pos = Get_Pos();
 
        win_delay = .0f;
        sound_delay = 0.0f;
        character_move_count = 0;
    }
 
    // Update is called once per frame
    public void Updated() {
        Update_BoxCheck();
        Update_Action(move_pos);
        Update_Sound();
    }
 
    void Update_BoxCheck()
    {
        // 선택된 오브젝트에 대한 처리
        if (Input.GetMouseButtonDown(0))
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                Box box = hit.transform.GetComponent<Box>() as Box;
                //두 개의 카드를 뒤집게만 한다.
 
                //집은 곳에 박스가 없으면
                if (box == nullreturn;
                //집은 곳이 NONE박스면
                if (box.Get_Box() == BOX_TYPE.NONE) return;
 
                //조건이 완성되지 않은 채 도착지점은 갈 수 없습니다.
                if (box.Get_Box() == BOX_TYPE.FINISH && gameManager.Check_Condition() == WIN_CONDITION.NO) return;
                //지금 이동 중인 경우
                else if (char_type != CHAR_TYPE.NONE) return;
 
                //집은 곳이 캐릭터가 위치한 경우
                if (this.Get_Pos().x - box.Get_Pos().x == .0f && this.Get_Pos().z - box.Get_Pos().z == .0f) return;
                //집은 곳이 이동 영역 안인 경우 이동
                //위 조건은 ㅡ 자, 아래 조건은 ㅣ 자
                else if ((Mathf.Abs(this.Get_Pos().x - box.Get_Pos().x) <= 1.0f && Mathf.Abs(this.Get_Pos().z - box.Get_Pos().z) == .0f) ||
                        (Mathf.Abs(this.Get_Pos().x - box.Get_Pos().x) == .0f && Mathf.Abs(this.Get_Pos().z - box.Get_Pos().z) <= 1.0f))
                {
                    if (box.Get_Pos().x - Get_Pos().x == 0)
                    {
                        if (box.Get_Pos().z > Get_Pos().z) char_type = CHAR_TYPE.FORWARD;
                        else char_type = CHAR_TYPE.BACK;
                    }
                    else if (box.Get_Pos().z - Get_Pos().z == 0)
                    {
                        if (box.Get_Pos().x > Get_Pos().x) char_type = CHAR_TYPE.RIGHT;
                        else char_type = CHAR_TYPE.LEFT;
                    }
                    //좌표를 보정합니다.
                    move_pos = box.Get_Pos();
 
                    //이동 횟수를 증가시킵니다.
                    character_move_count++;
                }
                //이외의 경우 - 이동 영역 밖을 누른 경우는 아무 일도 하지 않습니다.
                else return;
            }
        }
 
 
        //승리를 조건을 만족한 경우 도착 지점을 가게 되면 승리합니다.
        else if (Physics.Raycast(Get_Pos() + Vector3.up, Vector3.down, out hit, Mathf.Infinity) && char_type == CHAR_TYPE.NONE)
        {
            Box box = hit.transform.GetComponent<Box>() as Box;
            if (box.Get_Box() == BOX_TYPE.FINISH && gameManager.Check_Condition() == WIN_CONDITION.YES)
            {
                char_type = CHAR_TYPE.WIN;
            }
        }
    }
 
    //이동 함수
    void Update_Action(Vector3 _box_pos)
    {
        switch (char_type)
        {
            case CHAR_TYPE.NONE:
 
                //애니메이션 효과
                animator.SetInteger("ASTROMAN"0);
 
                Set_Pos(new Vector3(_box_pos.x, .05f, _box_pos.z));
                Char_Slerp(Vector3.back);
                break;
 
            //왼쪽으로 이동
            case CHAR_TYPE.LEFT:
                animator.SetInteger("ASTROMAN"1);
 
                if (_box_pos.x - Get_Pos().x < 0)
                {
                    Add_Pos(Vector3.left * Get_Speed() * Time.deltaTime);
                    Char_Slerp(Vector3.left);
                }
                else
                {
                    Arriving_Box();
                    char_type = CHAR_TYPE.NONE;
                }
                break;
 
            //오른쪽으로 이동
            case CHAR_TYPE.RIGHT:
                animator.SetInteger("ASTROMAN"1);
 
                if (_box_pos.x - Get_Pos().x > 0)
                {
                    Add_Pos(Vector3.right * Get_Speed() * Time.deltaTime);
                    Char_Slerp(Vector3.right);
                }
                else
                {
                    Arriving_Box();
                    char_type = CHAR_TYPE.NONE;
                }
                break;
 
            //앞쪽으로 이동
            case CHAR_TYPE.FORWARD:
                animator.SetInteger("ASTROMAN"1);
                if (_box_pos.z - Get_Pos().z > 0)
                {
                    Add_Pos(Vector3.forward * Get_Speed() * Time.deltaTime);
                    Char_Slerp(Vector3.forward);
                }
                else
                {
                    Arriving_Box();
                    char_type = CHAR_TYPE.NONE;
                }
                break;
 
            //뒤쪽으로 이동
            case CHAR_TYPE.BACK:
                animator.SetInteger("ASTROMAN"1);
                if (_box_pos.z - Get_Pos().z < 0)
                {
                    Add_Pos(Vector3.back * Get_Speed() * Time.deltaTime);
                    Char_Slerp(Vector3.back);
                }
                else
                {
                    Arriving_Box();
                    char_type = CHAR_TYPE.NONE;
                }
                break;
 
            //승리 조건
            case CHAR_TYPE.WIN:
                animator.SetInteger("ASTROMAN"0);
                Char_Slerp(Vector3.back);
 
                win_delay += Time.deltaTime;
 
                if(win_delay> 1.0f)
                    animator.SetInteger("ASTROMAN"2);
 
                if (win_delay > 3.0f)
                {
                    gameManager.Win();
                }
                break;
        }
    }
 
    //방향틀기 함수
    void Char_Slerp(Vector3 dir)
    {
        Vector3 forward = Vector3.Slerp(transform.forward, dir,
            360.0f * Time.deltaTime / Vector3.Angle(transform.forward, dir));
 
        transform.LookAt(transform.position + forward);
    }
 
    //박스 바꾸기 함수
    void Arriving_Box()
    {
        if (Physics.Raycast(Get_Pos() + Vector3.up, Vector3.down, out hit, Mathf.Infinity))
        {
            Box box = hit.transform.GetComponent<Box>() as Box;
            box.Change_Box();
        }
    }
 
    //사운드 함수
    void Update_Sound()
    {
        switch (char_type)
        {
            case CHAR_TYPE.BACK:
            case CHAR_TYPE.FORWARD:
            case CHAR_TYPE.LEFT:
            case CHAR_TYPE.RIGHT:
                sound_delay += Time.deltaTime;
 
                if (sound_delay > .3f)
                {
                    audio_src.Stop();
                    audio_src.clip = audioclip[0];
                    audio_src.Play();
                    sound_delay = .0f;
                }
                break;
 
            case CHAR_TYPE.WIN:
                sound_delay += Time.deltaTime;
 
                if (sound_delay > 1.5f)
                {
                    audio_src.clip = audioclip[1];
                    audio_src.Play();
                    sound_delay = 0.0f;
                }
                break;
        }
    }
 
    //이동횟수 반환 함수
    public int Get_Move_Count()
    {
        return character_move_count;
    }
}
 
cs

217 방향 틀기

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using UnityEngine;
using System.Collections;
 
public class CameraManager : MonoBehaviour {
 
    private Animator animator;
    private float camera_delay;
 
    // Use this for initialization
    public void Init () {
        animator = gameObject.GetComponent<Animator>();
        camera_delay = .0f;
    }
    
    // Update is called once per frame
    public void Updated () {
        camera_delay += Time.deltaTime;
 
        if (camera_delay < 1.0f) return;
        else animator.SetBool("Move"true);
    }
}
 
cs
SetBool 활용

미리 지정해둔 카메라 애니메이션을 활용하였고 카메라 워킹 애니메이션을 결정하는 변수는 해당 게임에서 딱 켜고 끄는 행위에 국한되는 점, 차후 개발이 진행되지 않는 점을 고려하여 Bool변수가 가장 적합하다 판단하였다.

 

 

반응형
Posted by Kestone Black Box
,