아주 심플한 벽돌깨기를 만들 수 있는 기본 뼈대가 되는 플래시 게임 소스코드는 첨부파일을 받으면 되고 실행화면은 아래 플래시에서 미리 볼 수 있다. 핵심이 되는 소스 코드는 제일 하단에 볼 수 있고 스스로 플래시 툴을 가지고 개성에 맞게 수정하고 실험하다보면 멋진 벽돌깨기 게임을 만들 수 있지 않을까? 플래시 및 액션스크립트 입문자를 위해 필요하다면 공개 프로젝트(?) 형태로 함께 벽돌깨기 게임을 만들어 볼 수도 있다. 다른 게임 소스가 필요하다면 아래 링크로 찾아가 검색해보고 맘에 드는 소스를 받아서 공부해볼 수 있다.
http://www.hompydesign.com/club/flash_movie.php?menu0=Games

웹프로그래머의 홈페이지정보 블로그 http://hompy.info


[주요 액션스크립트 소스코드]

_root.score = 0;

sndHit1 = new Sound();
sndHit1.attachSound("snd_hit2");

sndHit2 = new Sound();
sndHit2.attachSound("snd_hit1");

Mouse.show();
//start positions
x=300;
y=200;
stickX = 0;

//boundaries
boundaries = new Object();
boundaries.minX = 22;
boundaries.maxX = 527;
boundaries.minY = 22;
boundaries.maxY = 385.9;

//directions
direction = new Object();
direction.offsX = 0;
direction.offsY = 3;
direction.stick = 0;

//bricks
bricks = new Object();
bricks.x = 19;
bricks.y = 6;
bricks.cornerArea = 0.4;
bricks.stickEdge = 0.2;

init();

//functions

//count next position of X and Y of the object
function returnXY(x,y)
{
 var collision = false;
 //stick collision
 if (_root.ball.hitTest(_root.stick) && direction.offsY >= 0) {

  collision = true;
  direction.offsY *= -1;
  offset = _root.stick._width/2*(1-bricks.stickEdge);
  leftEdge = _root._xmouse - offset;
  rightEdge = _root._xmouse + offset;  
  if (_root.ball._x <= leftEdge && direction.offsX >= 0) {
   direction.offsX = -3;
  } else if (_root.ball._x < _root._xmouse && direction.offsX <= 0) {
   direction.offsX = -2;
  } else if (_root.ball._x >= rightEdge && direction.offsX <= 0) {
   direction.offsX = 3;
  } else if (_root.ball._x > _root._xmouse && direction.offsX >= 0) {
   direction.offsX = 2;
  }
 }
 //screen collision
 if (x >= boundaries.maxX || x<= boundaries.minX)
 {  
  direction.offsX *= -1;
 }
 if (y <= boundaries.minY)
 {
  direction.offsY *= -1;
 }
 //down fall
 if (y >= boundaries.maxY) {
  gotoAndPlay(2);
 }
 
 //brick collision
 hitten = getCollision();
 if (hitten != false) {
  collision = true;  
 
  if (eval(hitten)._totalframes == eval(hitten)._currentframe) {
   removeMovieClip(hitten);
   _root.score += 10;
   if (_root.score == bricks.x*bricks.y) {
    gotoAndPlay(1);
   }
  } else {
   _root.score += 5;
   eval(hitten).nextFrame();
  }
  //if (_root.ball._x > eval(hitten)._x - eval(hitten)._width/2 && _root.ball._x < eval(hitten)._x + eval(hitten)._width/2) {
   direction.offsY *= -1;
  //}
  offset = eval(hitten)._width*(1-bricks.cornerArea);
  leftEdge = eval(hitten)._x - offset;
  rightEdge = eval(hitten)._x + offset;

  if (_root.ball._x <= leftEdge && direction.offsX > 0) {
   direction.offsX *= -1;
  } else if (_root.ball._x >= rightEdge && direction.offsX < 0) {
   direction.offsX *= -1;
  } 
 }
 x+= direction.offsX;
 y+= direction.offsY;

 returnObj = new Object();
 returnObj.x = x;
 returnObj.y = y;
 
 if (collision)
 {
  var snd = Math.round(Math.random());
  if (snd)
   sndHit1.start();
  else
   sndHit2.start();
 }
 
 return returnObj;
}

//makes bricks
function init() {
 _root.brick1._visible = false;
 
 for (j=0; j<bricks.y; j++) {
  amount = bricks.x;
  i=0;
  while (amount>0) {
   duplicateMovieClip (_root.brick1, "mc_"+i+"_"+j, i+j*bricks.x);
   setProperty ("mc_"+i+"_"+j, _x, _root.brick1._x - i*_root.brick1._width);
   setProperty ("mc_"+i+"_"+j, _y, _root.brick1._y + j*_root.brick1._height);
   i++;
   amount--;
  }
 }
}

//detects collisions
function getCollision() {
 for (i=0; i<bricks.y; i++) {
  for (j=0; j<bricks.x; j++) {
   if (_root.ball.hitTest(eval("mc_"+j+"_"+i))) {
    return "mc_"+j+"_"+i;
   }
  }
 }
 return false;
}

이올린에 북마크하기(0) 이올린에 추천하기(0)

트랙백 주소 :: http://www.hompydesign.com/tt/trackback/134

댓글을 달아 주세요

  1. 비밀방문자 2008/10/23 12:17  댓글주소  수정/삭제  댓글쓰기

    관리자만 볼 수 있는 댓글입니다.