모 바 일 임 작 한국 IT 전문학교 박재성 게 제. 7 장 Flying Owl 모 바 일 임 작 게 제.

Slides:



Advertisements
Similar presentations
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Advertisements

Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Basic Unity Scripting/Programming & Components
INNER WORKINGS OF UNITY 3D. WHAT WE ARE GOING TO COVER Intro to Unity Physics & Game Objects Cameras & Lighting Textures & Materials Quaternions and Rotation.
UFCFSU-30-13D Technologies for the Web Creating and Using GUI Components.
Crossword Puzzle Solver Michael Keefe. Solver structure.
Guide to Programming with Python
 2D (not 3D) display or interface elements  GUI = Graphical User Interface  HUD = Heads Up Display  ex. player’s health, lives remaining, number of.
AI & 2D Development COSC 315 Fall 2014 Bridget M. Blodgett.
UART Test UNIT 14 로봇 SW 교육원 조용수. 학습 목표 UART Init UART Send UART Receive UART -> Debugging Console Up/Down Game 제작 2.
Yingcai Xiao EDP Scripting Yingcai Xiao. Why do we need EDP? What is EDP? How to implement EDP? How can we take advantages of EDP in game design and implement?
With C# or “JavaScript” Telerik School Academy Unity 2D Game Development.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 13 Wenbing Zhao
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
SE 350 – Programming Games Lecture 7: Programming with Unity Lecturer: Gazihan Alankuş Please look at the last slide for assignments (marked with TODO)
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
전광판 만들기 UNIT 04 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Layout XML 이란 ? 기본 XML 속성 Text View 2.
CSC 343/642 Interactive 3D Game Development George J. Grevera, Ph.D. George J. Grevera, Ph.D.
망고 100 보드로 놀아보자 -18 Android 메뉴 생성 및 아이콘 생성 (SPDIF,WM8960)
EEC-492/592 Kinect Application Development Lecture 14 Wenbing Zhao
Web Games Programming Unity Scripting Fundamentals.
UFCFS D Technologies for the Web Unity 3D: Review of Topics and Related Concepts.
Learning Unity. Getting Unity
Method, Event, Layout API. $.mobile.changePage //transition to the "confirm" page with a "pop" transition without tracking it in history $.mobile.changePage(
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
SE 320 – Introduction to Game Development Lecture 7: Programming Lecturer: Gazihan Alankuş Please look at the last two slides for assignments (marked with.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
UFCEK-20-3Web Games Programming Unity 3D: Review of Topics Publishing for the Web.
Fundamentals of Level Editor Design and Implementation.
Unity GUI Creating and Using GUI Components. Agenda GUI Components GUI Layout Using Styles and Skins for Design ‘Look and Feel’ Scripting GUI Communication.
More loops while and do-while. Recall the for loop in general for (initialization; boolean_expression; update) { }
영상 획득 영상 저장 카메라 파라메터 커스텀 이미지
Lesson 4.GUI.  GuiTexture  GuiText  3DText Lection 4.GUI.
CLASSES CHAPTER Topics  Understanding Classes –The Anatomy of a Class  Class Inheritance –Superclasses and Subclasses –Virtual and Override 2.
GameDevClub CODE CHEAT SHEET NOTE: ALL OF THE CODE IS CASE-SENSITIVE AND THE SYNTAX IS STRICT SO A LOT OF YOUR ERRORS WILL PROBABLY COME FROM TYPOS If.
Network 두더지 잡기 게임 2 조 신흥섭 권석진 김관수 최현식 김주호.
Visual C 실전 예제 Drawing Tool.
실전 이미지 처리 프로그래밍 Lecture #10. 강의 목차 ▶ 실제 게임을 구현하는 데 필요한 화면 구성을 알아본다. ▶ Canvas 클래스와 Graphics 클래스를 이용해 가장 기본적인 게임 화면을 하나씩 직접 구현해 본다. 2Mobile Programming.
Terrain. Basic Terrain Rendering  산이나 계곡등의 지형을 나타내는 방식  텍스쳐를 추가하면 해변이나 풀덮인 언덕, 눈덮힌 산 등을 표현할 수도 있다.  전체 지형을 다 그리는 것은 낭비이며 보이는 부분만 그리고 (View Frustum.
3D Game Programming Homework Assignment # 4 Combat System The scene data (in the HW04 folder) : battle_field.cwn The terrain data (in the HW04 folder)
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Yingcai Xiao Event-driven Programming in Game Development Yingcai Xiao.
Expressive Intelligence Studio // Center for Games and Playable Media // Unity Pro John Murray Expressive.
Behavior trees & The C# programming language for Java programmers
Advanced 3D Game Project
First Person Shooter Project
EEC-693/793 Applied Computer Vision with Depth Cameras
Lecture 2 Richard Gesick
More (C#) Scripting Day 2, Lesson 1.
EEC-693/793 Applied Computer Vision with Depth Cameras
Event-driven Programming
null, true, and false are also reserved.
Updating an Animated Scene
Collision Detection.
Oculus Rift DK2 + Leap Motion Unity Tutorial
C# Basics These slides are designed for Game Design Class
Lecture 3 Richard Gesick
EEC-693/793 Applied Computer Vision with Depth Cameras
Building a Game with Unity3D
Week 6: Time and triggers!
Myo + Oculus Rift Tutorial
EEC-693/793 Applied Computer Vision with Depth Cameras
Fundaments of Game Design
Welcome back to Software Development!
Deeper into the Depths: Casting, Scope, Gizmos, Layers, Self-Destruct.
public class Dillo {     public int length;     public boolean isDead;         
Unity Game Development
Unity Game Development
Collisions with Static Objects
Presentation transcript:

모 바 일 임 작 한국 IT 전문학교 박재성 게 제

7 장 Flying Owl 모 바 일 임 작 게 제

7.1 게임의 개요 - 올빼미가 나뭇가지를 밟고 점프해서 위로 높이 날아가는 2D 게임 -PC/ 웹용 게임에서는 키보드로 올빼미가 이동. 모바일에서는 좌우로 기울여서 ( 가속센서 ) 이 동

7.3 게임의 리소스

7.4 게임의 흐름도

7.5 카메라와 Light 설정 -2D 형태로 제작. 카메라의 원근이 필요없다.Projection 속성을 Orthographic 으로 지정. -Directional Light 추가 7.6 Object 만들기 -1) 배경하늘 만들기 plane 을 설치하고, 이름은 sky 로 변경. sky 비트맵 설정 -2) 올빼미 만들기 plane 을 설치하고, 이름은 owl 로 변경. 비트맵을 owl1 으로 매핑

7.6 Object 만들기 -3) 나뭇가지 만들기 plane 을 설치하고, 이름은 Branch 로 변경. branch 비트맵 설정 -4) 선물 만들기 plane 을 설치하고, 이름은 Gift 로 변경. 비트맵을 gift1 으로 매핑 -5) 참새 만들기 Plane 을 설치하고, 이름은 Bird 로 변경. 비트맵을 bird_107X92X6 으로 매핑 -6) 점수 오브젝트 만들기 하이어아키에서 Create > GUI Text 선택해서 GUI Text 추가. 이름을 txtScore 로 설정.

7.7 Object 에 Collider 추가 -Owl, Bird 는 Sphere Collider 추가 -Branch, Gift 는 Box Collider 추가 -Owl 에는 Rigidbody 도 추가. Is Trigger 는 ON, Use Gravity 는 해제

7.8 Object 에 Tag 달기 -Gift 에는 태그를 지정하지 않는다. 코드로 동적 지정. -Branch, Bird 는 태그 지정

7.9 프리팹 만들기 -Prefab 폴더를 만들고 Branch, Gift, Bird, txtScore 를 프리팹으로 만든다. - 하이어아키의 Gift, Bird, txtScore 는 삭제 게임 화면 디자인

-Spawn Point 만들기 빈 오브젝트를 만들어서 spPoint 로 작명한 후 Position 을 (0, 12, 03) 으로 설정 -Main Camera 의 하위 개체 설정 배경화면과 spPoint 를 Main Camera 의 하위 개체로 설정. 카메라와 같이 이동하도록 함.

7.11 게임 화면 스크롤 using UnityEngine; using System.Collections; public class CsSky : MonoBehaviour { float speed = 0.03f; void Update () { // 오프셋이용. float ofsX = speed * Time.time; transform.renderer.material.mainTextureOffset = new Vector2(ofsX, 0); } } // end of class

7.11 게임 화면 스크롤 -Spawn Point 만들기 빈 오브젝트를 만들어서 spPoint 로 작명한 후 Position 을 (0, 12, 03) 으로 설정 -Main Camera 의 하위 개체 설정 배경화면과 spPoint 를 Main Camera 의 하위 개체로 설정. 카메라와 같이 이동하도록 함.

7.12 화면을 벗어난 나뭇가지 제거 using UnityEngine; using System.Collections; public class CsBranch : MonoBehaviour { void Update () { // 월드 좌표를 스크린 좌표로 변환 Vector3 view = Camera.main.WorldToScreenPoint(transform.position); if (view.y < -50) { // 화면 아래로 내려가면 제거 Destroy(gameObject); } } // end of class

7.13 Gift 스크립트 작성 void DisplayScore () { // Gift 의 Tag 를 점수로 변환 int n = int.Parse(transform.tag.Substring(4, 1)) * 500; // 점수 표시용 GUIText 만들기 Transform obj = Instantiate(txtScore) as Transform; obj.guiText.text = " +" + n + " "; // World 좌표를 Viewport 좌표로 변환 var pos = Camera.main.WorldToViewportPoint(transform.position); obj.position = pos; // Gift 제거 Destroy(gameObject); }

7.14 참새의 이동 public class CsBird : MonoBehaviour { public Transform txtScore;// 프리팹 int frmCnt = 6; // 전체 프레임 수 int frmPerSec;// 1 초에 표시할 프레임 수 float frmDelay;// 프레임 표시 간격 int frmNum = 0; // 현재 표시할 프레임 번호 int speed;// 이동 속도 bool isDrop = false;// 추락중인가 ? void Start () { speed = Random.Range(3, 7); frmPerSec = Random.Range(10, 18); frmDelay = 1.0f / frmPerSec; }

7.14 참새의 이동 void Update () { float amtMove = speed * Time.smoothDeltaTime; if (!isDrop) { AnimateBird(); transform.Translate(Vector3.right * amtMove); } else {// 아래로 이동 transform.Translate(Vector3.down * amtMove, Space.World); } // 화면을 벗어난 오브젝트 제거 Vector3 view = Camera.main.WorldToScreenPoint(transform.position); if (view.y Screen.width + 50) { Destroy(gameObject); }

7.14 참새의 이동 void DropBird () { isDrop = true; // 참새 회전 transform.eulerAngles = new Vector3(0, 0, 180); // 감점 표시 Transform obj = Instantiate(txtScore) as Transform; obj.guiText.text = " "; // World 좌표를 Viewport 좌표로 변환 var pos = Camera.main.WorldToViewportPoint(transform.position); obj.position = pos; } - txtScore 변수에 txtScore 프리팹 연결

7.15 득점 및 감점 표시 void Start () { StartCoroutine("DisplayScore"); } void Update () { Vector3 pos = transform.position; pos.y += 0.001f; transform.position = pos; } IEnumerator DisplayScore() { yield return new WaitForSeconds(0.5f); for (float a = 1; a >= 0; a -= 0.05f) { transform.guiText.material.color = new Vector4(1, 1, 1, a); yield return new WaitForFixedUpdate(); } Destroy(gameObject); }

7.16 올빼미의 이동 public class CsOwl : MonoBehaviour { public GUISkin skin;// GUI Skin public Transform branch;// 프리팹 public Transform gift; public Transform bird; public AudioClip sndJump;// 효과음 및 배경음악 public AudioClip sndGift; public AudioClip sndBird; public AudioClip sndStage; public AudioClip sndOver;

7.16 올빼미의 이동 Transform spPoint;// Spawn Point Transform newBranch;// 새로만들 나뭇가지 int speedSide = 10;// 좌우 이동 속도 int speedJump = 16;// 점프 속도 int gravity = 25;// 추락 속도 Vector3 moveDir = Vector3.zero;// 올빼미의 이동 방향 int giftCnt = 0;// 획득한 선물 수 float score = 0;// 득점 float maxY = 0;// 올빼미의 최대 높이 bool isDead = false;

7.17 게임 초기화 void Start () { // 모바일 단말기 설정 Screen.orientation = ScreenOrientation.LandscapeRight; Screen.sleepTimeout = SleepTimeout.NeverSleep; spPoint = GameObject.Find("spPoint").transform; // 나뭇가지 만들기 newBranch = Instantiate(branch, spPoint.position, spPoint.rotation) as Transform; Screen.showCursor = false;// 커서 감추기 } void Update () { if (isDead) return; JumpOwl();// 올빼미 점프 MoveOwl();// 올빼미 이동 MoveCamera();// 카메라 이동 MakeGift();// 선물과 새 만들기 }

7.18 게임 루프 void Update () { if (isDead) return; JumpOwl();// 올빼미 점프 MoveOwl();// 올빼미 이동 MoveCamera();// 카메라 이동 MakeGift();// 선물과 새 만들기 }

7.19 올빼미의 점프 void JumpOwl () { RaycastHit hit; // 올빼미 아래에 나뭇가지가 있는지 조사 if (Physics.Raycast(transform.position, Vector3.down, out hit, 0.9f)) { if (hit.transform.tag == "BRANCH") { moveDir.y = speedJump; AudioSource.PlayClipAtPoint(sndJump, transform.position); }

7.20 올빼미의 좌우 이동 void MoveOwl () { // 올빼미 위치를 Screen 좌표로 변환 Vector3 view = Camera.main.WorldToScreenPoint(transform.position); if (view.y < -50) {// 화면 아래를 벗어나면 isDead = true;// 게임 오버 return; } moveDir.x = 0;// 올빼미의 좌우 이동 방향

7.20 올빼미의 좌우 이동 // Mobile 처리 if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { // 중력 가속도 센서 읽기 float x = Input.acceleration.x; // 왼쪽으로 기울였나 ? if (x 35) { moveDir.x = 2 * x * speedSide; } // 오른쪽으로 기울였나 ? if (x > 0.2f && view.x < Screen.width - 35) { moveDir.x = 2 * x * speedSide; } } else {// Keyboard 읽기 float key = Input.GetAxis("Horizontal"); if ((key 35) || (key > 0 && view.x < Screen.width - 35)) { moveDir.x = key * speedSide; }

7.20 올빼미의 좌우 이동 // 매 프레임마다 점프 속도 감소 moveDir.y -= gravity * Time.deltaTime; transform.Translate(moveDir * Time.smoothDeltaTime); // 올빼미의 날개 int n = 2;// 날개 펴기 if (moveDir.y < 0) n = 1;// 날개 접기 transform.renderer.material.mainTexture = Resources.Load("owl" + n) as Texture2D; }

7.20 올빼미의 좌우 이동

7.21 카메라의 이동 void MoveCamera () { // 올빼미의 최대 높이 구하기 if (transform.position.y > maxY) { maxY = transform.position.y; // 카메라 위치 이동 Camera.main.transform.position = new Vector3(0, maxY - 2.5f, -10); score = maxY * 1000; } // 가장 최근의 나뭇가지와 spPoint 와의 거리 구하기 if (spPoint.position.y - newBranch.position.y >= 4) { float x = Random.Range(-10f, 10f) * 0.5f; Vector3 pos = new Vector3(x, spPoint.position.y, 0.3f); newBranch = Instantiate(branch, pos, Quaternion.identity) as Transform; // 나뭇가지의 회전방향 설정 int mx = (Random.Range(0, 2) == 0) ? -1 : 1; int my = (Random.Range(0, 2) == 0) ? -1 : 1; newBranch.renderer.material.mainTextureScale = new Vector2(mx, my); }

7.22 Bird 와 Gift 만들기 void MakeGift () { if (Random.Range(1, 1000) < 980) return; Vector3 pos = Vector3.zero; // 오브젝트 표시 위치 pos.y = maxY + Random.Range(4, 5.5f); if (Random.Range(0, 100) < 50) { pos.x = -12f; Instantiate(bird, pos, Quaternion.identity); // 참새 만들기 } else { // 선물 만들기 pos.x = Random.Range(-5f, 5f); Transform obj = Instantiate(gift, pos, Quaternion.identity) as Transform; int n = Random.Range(1, 4); obj.tag = "GIFT" + n; obj.gameObject.renderer.material.mainTexture = Resources.Load("gift" + n) as Texture2D; }

7.23 Gift 의 개수 제한 if (Random.Range(0, 100) < 50) { // 참새 만들기 pos.x = -12f; Instantiate(bird, pos, Quaternion.identity); } else { // 화면의 선물 수를 5 개 이내로 제한 int n1 = GameObject.FindGameObjectsWithTag("GIFT1").Length; int n2 = GameObject.FindGameObjectsWithTag("GIFT2").Length; int n3 = GameObject.FindGameObjectsWithTag("GIFT3").Length; if (n1 + n2 + n3 >= 5) return; … }

7.24 충돌의 판정 void OnTriggerEnter (Collider coll) { switch (coll.transform.tag.Substring(0, 4)) { case "GIFT" : AudioSource.PlayClipAtPoint(sndGift, transform.position); // 득점 처리 int n = int.Parse(coll.transform.tag.Substring(4)); score += n * 500; giftCnt++; // 선물 제거 coll.transform.SendMessage("DisplayScore", SendMessageOptions.DontRequireReceiver); break; case "BIRD" : if (coll.transform.eulerAngles.z != 0) return; AudioSource.PlayClipAtPoint(sndBird, transform.position); score -= 1000; // 참새 추락 처리 coll.transform.SendMessage("DropBird", SendMessageOptions.DontRequireReceiver); break; }

7.25 득점 및 게임 오버 표시 void OnTriggerEnter (Collider coll) { switch (coll.transform.tag.Substring(0, 4)) { case "GIFT" : AudioSource.PlayClipAtPoint(sndGift, transform.position); // 득점 처리 int n = int.Parse(coll.transform.tag.Substring(4)); score += n * 500; giftCnt++; // 선물 제거 coll.transform.SendMessage("DisplayScore", SendMessageOptions.DontRequireReceiver); break; case "BIRD" : if (coll.transform.eulerAngles.z != 0) return; AudioSource.PlayClipAtPoint(sndBird, transform.position); score -= 1000; // 참새 추락 처리 coll.transform.SendMessage("DropBird", SendMessageOptions.DontRequireReceiver); break; }

7.25 득점 및 게임 오버 표시 void OnGUI() { GUI.skin = skin; string tScore = " Score : ## "; string tHeight = " Height : ## "; string tGift = " Gift : ## "; tScore = tScore.Replace("##", "" + (int)score); tHeight = tHeight.Replace("##", "" + (int)maxY); tGift = tGift.Replace("##", "" + giftCnt); int w = Screen.width / 2; int h = Screen.height / 2; GUI.Label(new Rect(20, 30, 200, 80), tScore); GUI.Label(new Rect(w - 50, 30, 150, 80), tHeight); GUI.Label(new Rect(w * 1.5f, 30, 120, 80), tGift); if (!isDead) return;

7.25 득점 및 게임 오버 표시 Screen.showCursor = true;// 커서 보이기 // 배경 음악 바꾸기 if (audio.clip != sndOver) { audio.clip = sndOver; audio.loop = false; audio.Play(); } if (GUI.Button(new Rect(w - 70, h - 50, 140, 60), "Play Game")) { Application.LoadLevel("MainGame"); } if (GUI.Button(new Rect(w - 70, h + 50, 140, 60), "Quit Game")) { Application.Quit(); }

7.26 모바일 기기의 중력가속도 센서