# I want a breakout turorial =\[

**URL:** <https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307>\
**Category:** programming\
**Created:** [January 16, 2004, 10:45pm UTC](https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307 "2004-01-16T22:45:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elion](https://avatars.discourse-cdn.com/v4/letter/e/4491bb/32.png) [@elion](https://forum.kirupa.com/u/elion)\
**Post date:** [January 16, 2004, 10:45pm UTC](https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307/1 "2004-01-16T22:45:29Z")

</div>

I haven’t seen any of the sort on Kirupa, anyone know of any good ones? :whistle:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 4, 2004, 10:48pm UTC](https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307/2 "2004-02-04T22:48:24Z")

</div>

Thanks to marz AGAIN for help… i needed one of the concepts used in this game, and i applied it on my friends game!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 8, 2004, 7:42pm UTC](https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307/3 "2004-02-08T19:42:34Z")

</div>

Here’s a version I was working on some time ago. It’s still a big bugged, but it works (click to get it started):

[http://membres.lycos.fr/museebranly/Arkanoid2.swf](http://membres.lycos.fr/museebranly/Arkanoid2.swf)

I’ve attached the file, it’s quite simple, really: there’s just a block and the paddle. The code is written in an .as file and included:

```auto
Game = {};
Game.left = 0;
Game.right = 300;
Game.up = 0;
Game.down = 300;

function endGame () {
	trace ("End of Game");
	delete ball.onEnterFrame;
	pad.stopDrag();
	popup ("Next Level!");
}
function checkEndGame() {
	var num = 0;
	for (var i in brick_board) {
		if (brick_board* instanceof MovieClip) num++;
	}
	trace ("rest: "+num);
	if (num == 0) {
		endGame ();
	}
}
function initBricks (myMap) {
	// size of the bricks
	this.createEmptyMovieClip ("brick_board",0);
	var h = 10;
	var w = 40;
	var c = 0;
	for (var i in myMap) {
		for (var j in myMap*) {
			if (myMap*[j] != 0) {
				var cl = brick_board.attachMovie ("brick", "b"+c, c);
				cl._x = j * w;
				cl._y = i * h;
				cl.life = myMap*[j];
				c++;
			}
		}
	}
}
map1 = [
		 [0,0,0,0,0,0,0],
		 [0,0,1,1,1,1,0],
		 [0,0,1,1,1,1,0],
		 [0,0,1,1,1,1,0],
		 [0,0,1,1,1,1,0],
		 [0,0,1,1,1,1,0],
		 [0,0,1,1,1,1,0]
		];
MovieClip.prototype.checkForBrick = function () {
	for (var cl in brick_board) {
		var clip = brick_board[cl];
		if (clip.hitTest(this.x, this.y, true)) {
			var u = clip._y;
			var d = clip._y + 10//clip._height;
			var l = clip._x;
			var r = clip._x + clip._width;
			var bounce = 0;
			clip.life--;
			trace (clip.life);
			if ( clip.life == 0) clip.removeMovieClip();
			if (this._x <= l && this.x >= l) {
				this.x = l;
				this.vx *= -1;
				bounce = 1;
			}
			else if (this._x >= r && this.x <= r) {
				this.x = r;
				this.vx *= -1;
				bounce = 1;
			}
			if (this._y <= u && this.y >= u) {
				this.y = u;
				this.vy *= -1;
				bounce = 1;
			}
			else if (this._y >= d && this.y <= d) {
				this.y = d;
				this.vy *= -1;
				bounce = 1;
			}
			if (!bounce) {
				trace ("Houston, we have a problem!");
				trace (this.x + ":" + this._x + ":" + l + ":" + r);
				trace (this.y + ":" + this._y + ":" + d + ":" + u);
			}
			checkEndGame();
		}
	}
}
MovieClip.prototype.checkForWalls = function () {
	if (this.x < Game.left) {
		this.x = Game.left;
		this.vx *= -1;
	}
	else if (this.x > Game.right) {
		this.x = Game.right;
		this.vx *= -1;
	}
	if (this.y < Game.up) {
		this.y = Game.up;
		this.vy *= -1;
	}
	else if (this.y > Game.down) {
		var l = pad._x - pad._width/2;
		var r = pad._x + pad._width/2;
		if (this.x > l && this.x < r) {
			this.y = Game.down;
			this.vy *= -1;
			var dx = this.x - (l+r)/2;
			var ang = Math.atan2(this.vy, this.vx);
			var sp = Math.sqrt (this.vx*this.vx + this.vy*this.vy);
			ang += dx / 100 ;
			this.vx = sp * Math.cos (ang);
			this.vy = sp * Math.sin (ang);
		}
		else {
			trace ("you lose!!");
		}
	}
}
function move () {
//	this.x = this._x;
//	this.y = this._y;
	this.x += this.vx;
	this.y += this.vy;
	this.checkForWalls();
	this.checkForBrick();
	this._x = this.x;
	this._y = this.y;
}
function init (map) {
	initBricks (map);
	var ang = -random (180);
	var sp = 10;
	ball.vx = sp * Math.cos (ang * Math.PI/180);
	ball.vy = sp * Math.sin (ang * Math.PI/180);
	ball.x = ball._x = pad._x = (Game.right + Game.left)/2;
	ball.y = ball._y = pad._y = Game.down;
	ball.onEnterFrame = move;
	pad.StartDrag (true, pad._width/2, Game.down, Game.right - pad._width/2, Game.down);
}

this.onMouseDown = function () {
	init(map1);
	delete this.onMouseDown;
}

```

Hopefully you’ll understand what I’m doing in there 🙂

pom :cowboy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 8, 2004, 7:47pm UTC](https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307/4 "2004-02-08T19:47:58Z")

</div>

> \*Originally posted by joso \*  
> \*\*here’s one i knocked up, needs tidying up tho…check it out :-

[Click Here!](http://www.atreyuonline.com/flash/breakout.html)

:hr: \*\*  
Nice job! But does the ball ever hit the side of a block or did you just rule out the possibility? Just curious 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 8, 2004, 11:08pm UTC](https://forum.kirupa.com/t/i-want-a-breakout-turorial/40307/5 "2004-02-08T23:08:14Z")

</div>

Actually… The first game I ever created was a breakout sort of game…

_goes to find it really quickly_…

Gah… Can’t find it… Ohh well… I’ll throw mine up here shortly… I’m actually creating special blocks and such.
