-
[게임엔진활용] 9강 플랫포머 게임 제작[DSU] 게임엔진활용 2026. 6. 8. 01:08728x90
플랫포머 게임 제작
- 충돌처리
- 이중점프
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121using UnityEngine;using UnityEngine.InputSystem;public class GameCollision : RenderView{struct ColObj{public Color c; // indexpublic Rect rt;// image, texture}ColObj[] co;float gravity = 720 * 4;// d / sfloat jump = 0;int jumpNum = 0;public override void load(){Rect[] rect = new Rect[6] {new Rect(200, 650, 120, 40),new Rect(500, 550, 120, 40),new Rect(800, 450, 120, 40),new Rect(1000, 350, 120, 40),new Rect(700, 150, 120, 40),new Rect(400, 200, 120, 40),};co = new ColObj[8];// 0 ~ 5 발판for (int i = 0; i < 6; i++){co[i] = new ColObj();co[i].c = Color.red;co[i].rt = rect[i];}// heroColObj c = new ColObj();c.c = Color.black;c.rt = new Rect(0, mc.devHeight - 60 - 500, 60, 60);co[6] = c;// itemc = new ColObj();c.c = Color.yellow;c.rt = new Rect(400, 200 - 60, 60, 60);co[7] = c;}public override void free(){}public override void draw(float dt){setRGBA(0, 0, 0, 0.5f);fillRect(0, 0, mc.devWidth, mc.devHeight);for (int i = 0; i < 8; i++){ColObj c = co[i];Rect rt = c.rt;setRGBA(c.c.r, c.c.g, c.c.b, c.c.a);fillRect(rt.x, rt.y, rt.width, rt.height);}setRGBA(1, 1, 1, 1);ref ColObj hero = ref co[6];if (Keyboard.current.spaceKey.wasPressedThisFrame){if (jumpNum < 2){jumpNum++;Debug.Log("jumpNum = " + jumpNum);jump = -700;}}if (Keyboard.current.aKey.isPressed){hero.rt.x -= 300 * dt;}else if (Keyboard.current.dKey.isPressed){hero.rt.x += 300 * dt;}jump += gravity * dt;if (jump > gravity)jump = gravity;hero.rt.y += jump * dt;float h = mc.devHeight - hero.rt.height;for (int i = 0; i < 6; i++){ref ColObj obj = ref co[i];if (containRect(hero.rt, obj.rt)){if (hero.rt.y > obj.rt.y - hero.rt.height - 1)h = obj.rt.y - hero.rt.height - 1;break;}}ref ColObj item = ref co[7];if (item.c != Color.clear &&containRect(hero.rt, item.rt)){item.c = Color.clear;Debug.Log("GameOver");}if (hero.rt.y > h){hero.rt.y = h;jumpNum = 0;}}public override void mouse(int state, float x, float y){}}cs 
'[DSU] 게임엔진활용' 카테고리의 다른 글
[게임엔진활용] 11강 피하기 게임 제작 (0) 2026.06.08 [게임엔진활용] 10강 파티클 시스템 (0) 2026.06.08 [게임엔진활용] 8강 사과 게임 제작 (0) 2026.06.08 [게임엔진활용] 7강 게임 시스템 구성 (0) 2026.06.08 [게임엔진활용] 6-2강 이미지 분할 및 애니메이션 (0) 2026.04.20

