|
_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; } |