Permalink
Browse files

Change glitchMode type to be more intuitive.

  • Loading branch information...
kevadsett committed Sep 10, 2016
1 parent 4312c20 commit 394359bb29d83ecb0574cb784d56ff3895272382
@@ -2,16 +2,15 @@ function LevelTileController(position, width, height, type, index) {
this.model = new LevelTileModel(position, width, height, type, index);
this.view = new LevelTileView(this.model);
GameEvents.on("glitchModeChanged", this.onGlitchModeChanged, this);
this.onGlitchModeChanged();
this.onGlitchModeChanged(window.glitchMode);
}
LevelTileController.prototype = {
getPosition: function() {
return this.model.position.copy();
},
onGlitchModeChanged: function() {
var shouldGlitch = (this.model.type.name === "floor" && window.glitchMode) || (this.model.type.name === "antifloor" && !window.glitchMode);
this.model.isGlitching = shouldGlitch;
onGlitchModeChanged: function(glitchMode) {
this.model.isGlitching = this.model.type.name === glitchMode;
},
destroy: function() {
this.view.destroy();
@@ -57,17 +57,17 @@ PlayerController.prototype = {
},
adjustXVelocity: function() {
if (this.keysdown.right && !this.keysdown.left) {
if (window.glitchMode) {
GameEvents.emit("glitchModeChanged", false);
if (window.glitchMode === "floor") {
GameEvents.emit("glitchModeChanged", "antifloor");
}
if (this.model.velocity.x < 0) {
this.model.velocity.x = 0;
}
this.model.velocity.x += (ACCELERATION * this.lastFrameTime);
this.model.velocity.x = Math.min(this.model.velocity.x, MAX_SPEED)
} else if (this.keysdown.left && !this.keysdown.right) {
if (!window.glitchMode) {
GameEvents.emit("glitchModeChanged", true);
if (window.glitchMode === "antifloor") {
GameEvents.emit("glitchModeChanged", "floor");
}
if (this.model.velocity.x > 0) {
this.model.velocity.x = 0;
@@ -117,12 +117,12 @@ PlayerController.prototype = {
var type = collisionData.collidee.getType();
switch (type) {
case "floor":
if (!window.glitchMode) {
if (window.glitchMode === "antifloor") {
this.handleBlockerCollision(collisionData.collidee);
}
break;
case "antifloor":
if (window.glitchMode) {
if (window.glitchMode === "floor") {
this.handleBlockerCollision(collisionData.collidee);
}
break;
View
@@ -39,12 +39,12 @@ window.NewGame = function() {
loadLevel(levelIndex);
});
GameEvents.on("glitchModeChanged", function(mode) {
window.glitchMode = mode;
GameEvents.on("glitchModeChanged", function(glitchMode) {
window.glitchMode = glitchMode;
});
function loadLevel(nextIndex) {
window.glitchMode = false;
window.glitchMode = "antifloor";
levelContainer.destroyLevelData();
levelCollisionController.destroyCollisionData();
@@ -7,7 +7,7 @@ LevelContainerView.prototype = {
draw: function(layer) {
if (layer !== "background") return;
var gradient;
if (window.glitchMode) {
if (window.glitchMode === "antifloor") {
gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
gradient.addColorStop(0, "rgb(241, 196, 15)");
gradient.addColorStop(0.25, "rgb(241, 196, 15)");

0 comments on commit 394359b

Please sign in to comment.