Skip to content

Commit

Permalink
Loading and saving levels, bug fixing, removing batches
Browse files Browse the repository at this point in the history
  • Loading branch information
Casmo committed Aug 22, 2015
1 parent 5ecead6 commit 1c55ef1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
4 changes: 0 additions & 4 deletions src/BreakOut.Brick.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,5 @@ BreakOut.Brick.prototype.remove = function () {
}

BreakOut.Element.prototype.remove.call(this);
BreakOut.totalBricks--;
if (BreakOut.totalBricks <= 0) {
BreakOut.loadLevel();
}

};
6 changes: 6 additions & 0 deletions src/BreakOut.Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ BreakOut.Element.prototype = {
},

remove: function () {
if (this.name == 'brick') {
BreakOut.totalBricks--;
if (BreakOut.totalBricks <= 0) {
BreakOut.loadLevel();
}
}
if (this.object != null) {
stage.removeChild(this.object);
}
Expand Down
58 changes: 22 additions & 36 deletions src/BreakOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ var BreakOut = {
'level002.json',
'level003.json'
],
/**
* List with batch operations to execute
*/
batches: [],
update: function(time) {
if (this.players.length <= 0 && this.settings.debug == false) {
return false;
Expand All @@ -62,21 +58,6 @@ var BreakOut = {
for (var i = 0; i < this.objects.length; i++) {
this.objects[i].update(time);
}
var batches = [];
var spliceIndexes = [];
for (var i = 0; i < this.batches.length; i++) {
switch (this.batches[i].type) {
case 'damage':
this.batches[i].object.damage(this.batches[i].ball, this.batches[i].value);
continue;
break;
default:
console.log(this.batches[i].type);
continue;
}
batches.push(this.batches[i]);
}
this.batches = batches;
},
totalBricks: 0, // if zero on destroy next level.
scores: [],
Expand Down Expand Up @@ -121,12 +102,7 @@ var BreakOut = {
}
if (this.objects[i].object.position.x >= minX && this.objects[i].object.position.x <= maxX &&
this.objects[i].object.position.y >= minY && this.objects[i].object.position.y <= maxY) {
this.batches.push({
type: 'damage',
object: this.objects[i],
value: Infinity,
ball: ball
});
this.objects[i].damage(ball, Infinity);
}
}

Expand Down Expand Up @@ -201,13 +177,15 @@ var BreakOut = {
tmpPlayer.init();
tmpPlayer.add();
tmpPlayer.object.position.x = BreakOut.settings.width / 2;
tmpPlayer.object.position.y = 150;
tmpPlayer.team = 'B';
var ball = new BreakOut.Ball({radius: 8});
ball.init();
ball.object.position.x = 8;
ball.object.position.y = this.settings.height / 2;
ball.add();
tmpPlayer.object.position.y = BreakOut.settings.height - 150;
tmpPlayer.team = 'A';
for (var i = 0; i < 2; i++) {
var ball = new BreakOut.Ball({radius: 8});
ball.init();
ball.object.position.x = Math.random() * 64;
ball.object.position.y = Math.random() * this.settings.height / 2;
ball.add();
}
}

for (var i = 0; i < 5; i++) {
Expand Down Expand Up @@ -262,9 +240,17 @@ var BreakOut = {
if (this.settings.debug == false) {
COUCHFRIENDS.connect();
}

if (window.localStorage) {
var level = window.localStorage.getItem('currentLevel');
if (level != '' && level >= 0) {
this.currentLevel = level;
}
}
},
loadLevel: function () {

BreakOut.totalBricks = 0;
for (var i = 0; i < this.players.length; i++) {
var player = this.players[i];

Expand All @@ -279,11 +265,10 @@ var BreakOut = {
x: Math.random() * 56 - 28,
y: yPosBall
};
player.element.ball = player.element.ball;
//player.element.ball = player.element.ball;
player.element.attachedBalls = [];
player.element.attachedBalls.push(player.element.ball);
}

var file = this.levels[this.currentLevel];
ajax(BreakOut.settings.assetDir + file, function (jsonData) {
jsonData = JSON.parse(jsonData);
Expand Down Expand Up @@ -369,12 +354,13 @@ var BreakOut = {
}
});

BreakOut.init();

this.currentLevel++;
if (this.currentLevel > this.levels.length) {
this.currentLevel = 0;
}
if (window.localStorage) {
var level = window.localStorage.setItem('currentLevel', this.currentLevel);
}
},
addPlayer: function (id) {
var countA = 0;
Expand Down
Binary file modified src/assets/effect-fire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/effect-freeze.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/effect-sticky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 22 additions & 10 deletions src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,31 @@ function init() {
document.getElementById('game').innerHTML = '';
document.getElementById('game').appendChild(renderer.view);

if (BreakOut.settings.debug == true) {
var levels = [];
levels.push('leveldebug.json');
for (var i = 0; i < BreakOut.levels.length; i++) {
levels.push(BreakOut.levels[i]);
}
BreakOut.levels = levels;
}

// Levels are build for 1280x520 (720 - (2 * 100)) resolutions. Let's make sure the level is
// rendered in the center
BreakOut.init();
BreakOut.loadLevel();

window.addEventListener('mousemove', function (e) {
if (typeof tmpPlayer == 'undefined') {
return;
}
tmpPlayer.object.position.x = e.clientX;
mousePos.x = e.clientX;
mousePos.y = e.clientY;
});
if (BreakOut.settings.debug == true) {
window.addEventListener('mousemove', function (e) {
if (typeof tmpPlayer == 'undefined') {
return;
}
tmpPlayer.object.position.x = e.clientX;
mousePos.x = e.clientX;
mousePos.y = e.clientY;
});
window.addEventListener('click', function (e) {
tmpPlayer.shoot();
});
}
requestAnimationFrame(update);
}

Expand Down

0 comments on commit 1c55ef1

Please sign in to comment.