I want a breakout turorial =[

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

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

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

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:

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 :slight_smile:

pom :cowboy:

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

Click Here!

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

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.