커뮤니티로 돌아가기

대화

렛듀님의 글에서 이어진 답글 0개

렛
렛듀@kds01215

[미완] 미완성 슈팅게임 만들기 강좌입니다~ ㉮ 슈팅게임의 첫 단계! 인스턴트 네임~ 슈팅게임을 만들어 봅시다. 저번 강좌의 똥피하기, 그런건 아무래도 상관 없습니다 이번은 특집! 회사용 슈팅게임을 만들어봅시다~ 95년때 유행했던 게임이죠. 일단 배경을 그립니다. 그린 후 캐릭터와 장애물, ufo, 미사일 두개, 장애물이 부서질때 나오는 또다른 장애물을 만듭니다. 캐릭터는 ship로 인스턴트 네임을 주시구요 장애물은 asteroid 부서질때 나오는 또다른 장애물은 meteor ufo의 미사일은 enemyFire ufo는 enemy 캐릭터의 미사일은 missile 이렇게 인스턴트 네임을 줍니다. ㉡ 본격적으로 슈팅게임을 만들어보자! 모든 배경은 다 무비클립으로 등록하시구요 무비클립의 캐릭터에 이 액션을 줍니다. onClipEvent (load) { // -------------------------------------------------------- // set up sounds // ------------------ // 사운드 설정 laser = new Sound(); shield = new Sound(); big_ass = new Sound(); little_ass = new Sound(); diamond_collected = new Sound(); laser.attachsound("laser"); diamond_collected.attachsound("diamond_collected"); shield.attachsound("shield"); little_ass.attachsound("little_ass"); big_ass.attachsound("big_ass"); // ------------------ // -------------------------------------------------------- // initialize variables // ------------------ // 본격적의 움직임 설정 movie_height = 400; movie_width = 550; xmov = 0; ymov = 0; accel = .2; angle_accel = 4; angle = 0; speed = 0; missile_speed = 15; max_missiles = 10; _root.max_missiles = max_missiles; nose = 10; i = 0; go_space = "yes"; function hit() { gotoAndPlay(2); } } onClipEvent (enterFrame) { // 다음 레벨 if (Key.isDown(Key.UP)) { speed = Number(speed)+accel; flame_left.gotoAndPlay(2); flame_right.gotoAndPlay(2); } if (Key.isDown(Key.DOWN)) { speed = Number(speed)-accel; } if (Key.isDown(Key.RIGHT)) { angle = Number(angle)+angle_accel; setProperty("", _rotation, angle); flame_left.gotoAndPlay(2); } if (Key.isDown(Key.LEFT)) { angle = Number(angle)-angle_accel; setProperty("", _rotation, angle); flame_right.gotoAndPlay(2); } if (Key.isDown(Key.SPACE) && go_space == "yes") { laser.start(); duplicateMovieClip("_root.missile", "missile"+i, i); _root["missile"+i].xmov = missile_speed*math.cos((math.pi/180)*angle); _root["missile"+i].ymov = missile_speed*math.sin((math.pi/180)*angle); setProperty(_root["missile"+i], _x, this._x+nose*math.cos((math.pi/180)*angle)); setProperty(_root["missile"+i], _y, this._y+nose*math.sin((math.pi/180)*angle)); setProperty(_root["missile"+i], _rotation, angle); i = ++i; if (i>max_missiles) { i = 0; } go_space = "no"; } else if (Key.isDown(Key.SPACE) != true) { go_space = "yes"; } // no need for this to be calculated ever frame. just didnt get to it. xmov = speed*math.cos((math.pi/180)*angle); ymov = speed*math.sin((math.pi/180)*angle); setProperty("", _x, this._x+xmov); setProperty("", _y, this._y+ymov); // make the ship appear on the other side of the screen if it leaves. if (this._y movie_height+10) { // setProperty ("", _x, movie_width-this._x); setProperty("", _y, 0); } else if (this._x movie_width+10) { setProperty("", _x, 0); // setProperty ("", _y, movie_height-this._y); } } 그리고 첫번째 장애물에 이 액션을 부여합니다. onClipEvent (load) { // 함수 생성 function explode () { _root.ship.big_ass.start(); _root.duplicator.x = this._x; _root.duplicator.y = this._y; _root.duplicator.Meteors(); removeMovieClip (_root["missile"+i]); removeMovieClip (""); } } onClipEvent (enterFrame) { // 본격적인 움직임 설정 if (_name!="asteroid") { setProperty ("", _x, xmov+this._x); setProperty ("", _y, ymov+this._y); setProperty ("", _rotation, this._rotation+rot); if (_root.ship.hitTest(this)) { _root.energy._xscale -= 10; _root.ship.hit(); _root.ship.shield.start(); explode(); } i = -1; while (++i 550 + this._width || this._y 400 + this._width) { removeMovieClip (""); } } } 그리고 장애물의 파편에 이 액션을 부여합니다. // 떨어질때의 움직임 설정 onClipEvent (load) { rot = Random(4)-Random(4); this.gotoAndStop(random(2)+1); } // 본격적인 히트테스트 설정 onClipEvent (enterFrame) { if (_name!="meteor") { setProperty ("", _x, xmov+this._x); setProperty ("", _y, ymov+this._y); setProperty ("", _rotation, this._rotation+rot); if (_root.ship.hitTest(this)) { if (_currentframe==1) { _root.ship.hit(); _root.ship.little_ass.start(); _root.ship.shield.start(); _root.energy._xscale -= 5; } else { _root.ship.diamond_collected.start(); _root.energy._xscale += 5; _root.score++; } // 무비클립 설정 removeMovieClip (""); } i = -1; while (++i 570 or this._y 420) { removeMovieClip (""); } } 그리고 ufo의 미사일에 이 액션을 부여합니다. // 움직임 설정 onClipEvent (enterFrame) { if (this._name != "enemyFire") { this._x += xmov; this._y += ymov; if (this._x 570 or this._y 420) { removeMovieClip(""); } if (this.hitTest(_root.ship)) { _root.ship.play(); _root.energy._xscale -= 10; _root.ship.shield.start(); removeMovieClip(this); } } } 그리고 ufo에게 이 액션을 부여합니다. // 기본 설정 onClipEvent (load) { dup = 1; friction = .98; function randomTime() { subTime = (_root.duplicator.max)/(_root.duplicator.difficulty-2); // trace (_root.asteroid.max); // trace (_root.asteroid.difficulty); amountTime = _root.duplicator.max+1; time = 0; // trace (subTime); // trace (next); // trace (amountTime); } function nextTime() { next += subTime; } randomTime(); next = subTime; livingTime = random(100)+50; livingStart = 0; fire = 0; missile_speed = 8; nose = 10; function findAngle() { adx = this._x-_root.ship._x; ady = this._y-_root.ship._y; check = Math.atan(ady/adx)*(180/Math.PI); if (this._x>_root.ship._x && this._y _root.ship._y) { angle = check; } else { angle = check-180; } } } // 시간 설정 onClipEvent (enterFrame) { time++; // trace (time); if (this._name == "enemy") { if (time>=next) { // trace (time); // trace (next); // trace (subTime); dup++; next += subTime; duplicateMovieClip(this, "e"+dup, dup+5000); _root["e"+dup].gravx = random(20); _root["e"+dup].gravy = random(20); _root["e"+dup].target = "ship"; _root["e"+(dup-1)].target = "farAway"; _root["e"+dup].newOne = 0; _root["e"+(dup-1)].newOne = 1; side = random(4)+1; if (side == 0) { _root["e"+dup]._x = random(550); _root["e"+dup]._y = -this._width/2; } else if (side == 1) { _root["e"+dup]._x = random(550); _root["e"+dup]._y = 400+this._width/2; } else if (side == 2) { _root["e"+dup]._x = -this._width/2; _root["e"+dup]._y = random(400); } else { _root["e"+dup]._x = 550+this._width/2; _root["e"+dup]._y = random(400); } if (time>amountTime) { randomTime(); next = 0; // trace ("yes"); // 본격적인 움직임 설정 } } } else { livingStart++; // trace (livingStart); // trace (livingStart); trace("ship"); if (livingStart>livingTime || newOne == 1) { target = "farAway"; } else { target = "ship"; } movex = this._x; movey = this._y; ex = _root[target]._x; ey = _root[target]._y; gravx += (ex-movex)/300; gravy += (ey-movey)/300; if (movex>ex) { dirx = 1; } else { dirx = 0; } if (dirx == 1) { if (movexex) { gravx *= -1; } } if (movey>ey) { diry = 1; } else { diry = 0; } if (diry == 1) { if (moveyey) { gravy *= -1; } } this._x += gravx; this._y += gravy; gravx *= friction; gravy *= friction; if (this._x 텍스트를 만들고 무비클립으로 지정합니다. 텍스트의 내용은 asteroid duplicator 그리고 인스턴트 네임을 duplicator라고 줍니다. 그다음 그 무비클립에 이 액션을 부여합니다. // 기본 설정 onClipEvent (load) { i = 0; ii = 0; delay = 0; difficulty = 4; delta = 100; function nextLevel () { val = new Array(); for (diff = 0; diff max) { delay = 0; _root.statusGame.play (); num += 2; difficulty += 2; delta -= 20; nextLevel (); } function Meteors () { ms = Random(3)+1; duplicateMovieClip ("_root.meteor", "meteor"+ii, Number(500)+ii); setProperty (_root["meteor"+ii], _x, x); setProperty (_root["meteor"+ii], _y, y); _root["meteor"+ii].xmov = ms; _root["meteor"+ii].ymov = ms; ii = ++ii; duplicateMovieClip ("_root.meteor", "meteor"+ii, Number(500)+ii); setProperty (_root["meteor"+ii], _x, x); setProperty (_root["meteor"+ii], _y, y); _root["meteor"+ii].xmov = -ms; _root["meteor"+ii].ymov = -ms; ii = ++ii; duplicateMovieClip ("_root.meteor", "meteor"+ii, Number(500)+ii); setProperty (_root["meteor"+ii], _x, x); setProperty (_root["meteor"+ii], _y, y); _root["meteor"+ii].xmov = -ms; _root["meteor"+ii].ymov = ms; ii = ++ii; duplicateMovieClip ("_root.meteor", "meteor"+ii, Number(500)+ii); setProperty (_root["meteor"+ii], _x, x); setProperty (_root["meteor"+ii], _y, y); _root["meteor"+ii].xmov = ms; _root["meteor"+ii].ymov = -ms; ii = ++ii; } } 그리고 캐릭터의 미사일에 이 액션을 넣습니다. // 미사일 설정 onClipEvent (enterFrame) { if (_name!="missile") { setProperty ("", _x, xmov+this._x); setProperty ("", _y, ymov+this._y); // 스크린 설정 if (this._x 570 or this._y 420) { removeMovieClip (""); } } } 그리고 체력 게이지 무비클립을 만든뒤 인스턴트 네임을 energy라고 줍니다. 그리고 액션을 줍니다. // 게이지 설정 onClipEvent (enterFrame) { if (this._xscale = 100) { this._xscale = 100; } } 그리고 체력 게이지 무비클립을 만든뒤 인스턴트 네임을 energy라고 줍니다. 그리고 액션을 줍니다. // 게이지 설정 onClipEvent (enterFrame) { if (this._xscale = 100) { this._xscale = 100; } } 그리고 동적 텍스트 두개를 만든 후 변수를 각각 score, ak라고 준 후 원하는 곳에 배치합니다.