Permalink
Browse files

Take into account glitch mode when generating collisions, and regener…

…ate when it changes.
  • Loading branch information...
kevadsett committed Sep 10, 2016
1 parent 7f46163 commit 0056f6a336206aa5801290e3f84aecedab99cf98
Showing with 34 additions and 25 deletions.
  1. +33 −24 src/js/controllers/LevelCollisionController.js
  2. +1 −1 src/js/game.js
@@ -9,30 +9,24 @@ LevelCollisionController.prototype = {
throw new Error("No data provided");
}
this.destroyCollisionData();
var row, col, r, c;
var prevCell, currentCell;
var width = TILE_SIZE;
var height = TILE_SIZE;
var lineCollider;
for (r = 0; r < data.length; r++) {
prevCell = undefined;
for (c = 0; c < data[r].length; c++) {
currentCell = data[r][c];
currentCell = this.switchCellType(data[r][c]);
if (prevCell != undefined) {
if (prevCell != currentCell) {
if (currentCell !== 0) {
this.collisions.push(new LineColliderController(
new Vector2(width * c, height * r),
new Vector2(width * c, height * (r+1)),
currentCell
));
this.createLineCollider(r, c, r+1, c, currentCell);
}
if (prevCell !== 0) {
this.collisions.push(new LineColliderController(
new Vector2(width * c, height * (r+1)),
new Vector2(width * c, height * r),
prevCell
));
this.createLineCollider(r+1, c, r, c, prevCell);
}
}
@@ -43,29 +37,44 @@ LevelCollisionController.prototype = {
for (c = 0; c < data[0].length; c++) {
for (r = 0; r < data.length; r++) {
currentCell = data[r][c];
currentCell = this.switchCellType(data[r][c]);
if (prevCell != undefined) {
if (prevCell != currentCell) {
if (currentCell !== 0) {
this.collisions.push(new LineColliderController(
new Vector2(width * (c+1), height * r),
new Vector2(width * c, height * r),
currentCell
));
this.createLineCollider(r, c+1, r, c, currentCell);
}
if (prevCell !== 0) {
this.collisions.push(new LineColliderController(
new Vector2(width * c, height * r),
new Vector2(width * (c+1), width * r),
prevCell
));
this.createLineCollider(r, c, r, c+1, prevCell);
}
}
}
prevCell = currentCell;
}
}
},
switchCellType: function(cell) {
if (window.glitchMode === "floor") {
if (cell === 3) {
return 0;
} else if (cell === 4) {
return 5;
}
} else {
if (cell === 4) {
return 0;
} else if (cell === 3) {
return 5;
}
}
return cell;
},
createLineCollider: function(rowA, columnA, rowB, columnB, type) {
this.collisions.push(new LineColliderController(
new Vector2(TILE_SIZE * columnA, TILE_SIZE * rowA),
new Vector2(TILE_SIZE * columnB, TILE_SIZE * rowB),
type
));
},
destroyCollisionData: function() {
for (var i = 0; i < this.collisions.length; i++) {
this.collisions[i].destroy();
View
@@ -41,12 +41,12 @@ window.NewGame = function() {
GameEvents.on("glitchModeChanged", function(glitchMode) {
window.glitchMode = glitchMode;
levelCollisionController.generateCollisionsFromLevelData(LevelData[levelIndex]);
});
function loadLevel(nextIndex) {
window.glitchMode = "antifloor";
levelContainer.destroyLevelData();
levelCollisionController.destroyCollisionData();
var nextLevel = LevelData[nextIndex];
var maxDimension = getMaxDimension(nextLevel);

0 comments on commit 0056f6a

Please sign in to comment.