Skip to content

Commit

Permalink
Reset over days
Browse files Browse the repository at this point in the history
  • Loading branch information
mrspeaker committed Apr 27, 2014
1 parent 5d0b790 commit db48092
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 71 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<script src="scripts/entities/BeachBum.js"></script>
<script src="scripts/entities/SurfPatrol.js"></script>
<script src="scripts/entities/Player.js"></script>
<script src="scripts/screens/PopupDialog.js"></script>
<script src="scripts/screens/TitleScreen.js"></script>
<script src="scripts/screens/MainScreen.js"></script>
<script src="scripts/Game.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions lib/Ω/screens/Screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
return body;
},

removeAll: function () {
if (this._bodies) {
this._bodies = null;
}
},

get: function (tag) {

return this._bodies[tag] || [];
Expand Down
Binary file modified res/images/tiles.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/images/tiles.pxm
Binary file not shown.
4 changes: 4 additions & 0 deletions scripts/entities/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

},

reset: function () {
this.state.set("BORN");
},

tick: function () {

this.state.tick();
Expand Down
4 changes: 4 additions & 0 deletions scripts/entities/SurfPatrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

},

reset: function () {
this.state.set("BORN");
},

tick: function () {

this.state.tick();
Expand Down
77 changes: 46 additions & 31 deletions scripts/levels/Beach.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,49 @@
hoverCell: null,
walkableSandCells: null,

init: function (width, length, env) {var this$0 = this;
init: function (width, length, env) {

this.walkableSandCells = this.sheet.cellW * 2;

var map = this.generateMap(width, length);
this.env = env;
this.cellW = width;
this.cellL = length;

this.reset();

},

reset: function () {var this$0 = this;

if (this.sunbathers) {
this.sunbathers.forEach(function(sb) {
sb.remove = true;
});
}

var map = this.generateMap(this.cellW, this.cellL);
this.map = map.map;
this.treasure = map.treasure;

this.w = this.map.w;
this.h = this.map.h;

this.pos = {
x: Ω.env.w / 2,
y: 0
};

var bb = (function(){function GET_ITER$0(v){if(v){if(Array.isArray(v))return 0;if(typeof v==='object'&&typeof v['@@iterator']==='function')return v['@@iterator']();}throw new Error(v+' is not iterable')};var $D$0;var $D$1;var $D$2;var $D$3;var $result$0 = [], x;$D$3 = ([1,2,3,4,5,6,7,8,9]);$D$0 = GET_ITER$0($D$3);$D$2 = $D$0 === 0;$D$1 = ($D$2 ? $D$3.length : void 0);for(; $D$2 ? ($D$0 < $D$1) : !($D$1 = $D$0["next"]())["done"]; ){x = ($D$2 ? $D$3[$D$0++] : $D$1["value"]);{$result$0.push(this.add(new window.BeachBum(
Ω.math.snap(Ω.utils.rand(this.w), 32),
Ω.math.snap(Ω.utils.rand(this.h - 96), 32) + 32,
Ω.utils.rand(2)
), "extras", 2))}};;return $result$0}).call(this);
x: Ω.env.w / 2,
y: 0
};

bb.forEach(function(b) {
var cell = this$0.map.getBlockCell([b.x, b.y]);
this$0.map.cells[cell[1]][cell[0]] = this$0.walkableSandCells + this$0.sheet.cellW + 1;
this$0.map.cells[cell[1] + 1][cell[0]] = this$0.walkableSandCells + this$0.sheet.cellW + 1;
});
this.sunbathers = (function(){function GET_ITER$0(v){if(v){if(Array.isArray(v))return 0;if(typeof v==='object'&&typeof v['@@iterator']==='function')return v['@@iterator']();}throw new Error(v+' is not iterable')};var $D$0;var $D$1;var $D$2;var $D$3;var $result$0 = [], x;$D$3 = ([1,2,3,4,5,6,7,8,9]);$D$0 = GET_ITER$0($D$3);$D$2 = $D$0 === 0;$D$1 = ($D$2 ? $D$3.length : void 0);for(; $D$2 ? ($D$0 < $D$1) : !($D$1 = $D$0["next"]())["done"]; ){x = ($D$2 ? $D$3[$D$0++] : $D$1["value"]);{$result$0.push(this.add(new window.BeachBum(
Ω.math.snap(Ω.utils.rand(this.w), 32),
Ω.math.snap(Ω.utils.rand(this.h - 96), 32) + 32,
Ω.utils.rand(2)
), "extras", 2))}};;return $result$0}).call(this);

this.env = env;
this.sunbathers.forEach(function(b) {
var cell = this$0.map.getBlockCell([b.x, b.y]);
this$0.map.cells[cell[1]][cell[0]] = this$0.walkableSandCells + this$0.sheet.cellW + 1;
this$0.map.cells[cell[1] + 1][cell[0]] = this$0.walkableSandCells + this$0.sheet.cellW + 1;
});

},

Expand All @@ -46,23 +60,24 @@
},

search: function (player, removeIfFound) {
var blockPixPos = [player.x, player.y + 24];
var blockCellPos = this.map.getBlockCell(blockPixPos);
var blockType = this.map.getBlock(blockPixPos);
// Dodgy hack: if on first line == not searched
if (!removeIfFound && blockType < this.sheet.cellW) {
this.map.setBlock(blockPixPos, blockType + this.sheet.cellW);
}
var blockPixPos = [player.x, player.y + 24];
var blockCellPos = this.map.getBlockCell(blockPixPos);
var blockType = this.map.getBlock(blockPixPos);
// Dodgy hack: if on first line == not searched

if (!removeIfFound && blockType < this.sheet.cellW) {
this.map.setBlock(blockPixPos, blockType + this.sheet.cellW);
}

// Any treasure?
var treasure = 0;
if (blockCellPos[1] > -1) {
treasure = this.treasure[blockCellPos[1]][blockCellPos[0]]
if (treasure && removeIfFound) {
this.treasure[blockCellPos[1]][blockCellPos[0]] = 0;
}
}
return treasure;
treasure = this.treasure[blockCellPos[1]][blockCellPos[0]]
if (treasure && removeIfFound) {
this.treasure[blockCellPos[1]][blockCellPos[0]] = 0;
}
}
return treasure;
},

dig: function (player, stage) {
Expand All @@ -87,7 +102,7 @@
this.hoverCell = targetPixels;

this.pos.x = player.x - (Ω.env.w / 2) + 24;
this.pos.y = player.y - (Ω.env.h / 2);
this.pos.y = player.y - (Ω.env.h / 2);

this.pos.x = Math.min(Math.max(0, this.pos.x), this.map.w - this.env.w);
this.pos.y = Math.min(Math.max(-80, this.pos.y), this.map.h - this.env.h);
Expand Down
31 changes: 26 additions & 5 deletions scripts/screens/MainScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

init: function () {

this.reset();

},

reset: function () {

this.removeAll();

var env = {
x:0,
y:0,
Expand All @@ -35,26 +43,39 @@
tick: function () {

this.state.tick();
console.log(this.state.get());

switch (this.state.get()) {
case "BORN":
this.state.set("DAYBREAK");
break;
case "DAYBREAK":
this.curTime = 0;
this.state.set("DAY");
if (this.state.first()) {
this.tick_DAY();
}
if (this.state.count === 30) {
this.curTime = 0;
window.game.setDialog(new window.PopupDialog("day break!"));
this.state.set("DAY");
}
break;
case "DAY":
this.curTime++;
if (this.curTime / 30 > 8) {
if (this.curTime / 100 > 8) {
// Day over.
this.state.set("SUNSET");
} else {
this.tick_DAY();
}
break;
case "SUNSET":
this.state.set("DAYBREAK");
if (this.state.first()) {
window.game.setDialog(new window.PopupDialog("Day is done."));

}
if (this.state.count > 10) {
this.state.set("DAYBREAK");
this.reset();
}
break;
case "GAMEOVER":
window.game.reset();
Expand Down
44 changes: 44 additions & 0 deletions scripts/screens/PopupDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(function (Ω) {

"use strict";

var PopupDialog = Ω.Dialog.extend({

init: function (msg, key, cb) {

this._super(key, cb);

this.msg = msg;

},

tick: function (delta) {

this.time += delta;

if (this.time > 1.5 || (this.killKey && Ω.input.pressed(this.killKey))) {
Ω.input.release(this.killKey);
this.done();
}

},

render: function (gfx) {

var c = gfx.ctx;

c.fillStyle = "hsl(0, 60%, 60%)";
c.strokeStyle = "#fff";
c.fillRect(gfx.w * 0.15, gfx.h * 0.25, gfx.w * 0.7, gfx.h * 0.5);
c.strokeRect(gfx.w * 0.15, gfx.h * 0.25, gfx.w * 0.7, gfx.h * 0.5);

c.fillStyle = "#fff";
c.fillText(this.msg, gfx.w * 0.3, gfx.h * 0.5);

}

});

window.PopupDialog = PopupDialog;

}(window.Ω));
4 changes: 4 additions & 0 deletions src/entities/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

},

reset: function () {
this.state.set("BORN");
},

tick: function () {

this.state.tick();
Expand Down
4 changes: 4 additions & 0 deletions src/entities/SurfPatrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

},

reset: function () {
this.state.set("BORN");
},

tick: function () {

this.state.tick();
Expand Down
75 changes: 45 additions & 30 deletions src/levels/Beach.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,45 @@

this.walkableSandCells = this.sheet.cellW * 2;

var map = this.generateMap(width, length);
this.env = env;
this.cellW = width;
this.cellL = length;

this.reset();

},

reset: function () {

if (this.sunbathers) {
this.sunbathers.forEach((sb) => {
sb.remove = true;
});
}

var map = this.generateMap(this.cellW, this.cellL);
this.map = map.map;
this.treasure = map.treasure;

this.w = this.map.w;
this.h = this.map.h;

this.pos = {
x: Ω.env.w / 2,
y: 0
};

var bb = [this.add(new window.BeachBum(
Ω.math.snap(Ω.utils.rand(this.w), 32),
Ω.math.snap(Ω.utils.rand(this.h - 96), 32) + 32,
Ω.utils.rand(2)
), "extras", 2) for (x of [1,2,3,4,5,6,7,8,9])];
x: Ω.env.w / 2,
y: 0
};

bb.forEach((b) => {
var cell = this.map.getBlockCell([b.x, b.y]);
this.map.cells[cell[1]][cell[0]] = this.walkableSandCells + this.sheet.cellW + 1;
this.map.cells[cell[1] + 1][cell[0]] = this.walkableSandCells + this.sheet.cellW + 1;
});
this.sunbathers = [this.add(new window.BeachBum(
Ω.math.snap(Ω.utils.rand(this.w), 32),
Ω.math.snap(Ω.utils.rand(this.h - 96), 32) + 32,
Ω.utils.rand(2)
), "extras", 2) for (x of [1,2,3,4,5,6,7,8,9])];

this.env = env;
this.sunbathers.forEach((b) => {
var cell = this.map.getBlockCell([b.x, b.y]);
this.map.cells[cell[1]][cell[0]] = this.walkableSandCells + this.sheet.cellW + 1;
this.map.cells[cell[1] + 1][cell[0]] = this.walkableSandCells + this.sheet.cellW + 1;
});

},

Expand All @@ -46,23 +60,24 @@
},

search: function (player, removeIfFound) {
var blockPixPos = [player.x, player.y + 24];
var blockCellPos = this.map.getBlockCell(blockPixPos);
var blockType = this.map.getBlock(blockPixPos);
// Dodgy hack: if on first line == not searched
if (!removeIfFound && blockType < this.sheet.cellW) {
this.map.setBlock(blockPixPos, blockType + this.sheet.cellW);
}
var blockPixPos = [player.x, player.y + 24];
var blockCellPos = this.map.getBlockCell(blockPixPos);
var blockType = this.map.getBlock(blockPixPos);
// Dodgy hack: if on first line == not searched

if (!removeIfFound && blockType < this.sheet.cellW) {
this.map.setBlock(blockPixPos, blockType + this.sheet.cellW);
}

// Any treasure?
let treasure = 0;
if (blockCellPos[1] > -1) {
treasure = this.treasure[blockCellPos[1]][blockCellPos[0]]
if (treasure && removeIfFound) {
this.treasure[blockCellPos[1]][blockCellPos[0]] = 0;
}
}
return treasure;
treasure = this.treasure[blockCellPos[1]][blockCellPos[0]]
if (treasure && removeIfFound) {
this.treasure[blockCellPos[1]][blockCellPos[0]] = 0;
}
}
return treasure;
},

dig: function (player, stage) {
Expand All @@ -87,7 +102,7 @@
this.hoverCell = targetPixels;

this.pos.x = player.x - (Ω.env.w / 2) + 24;
this.pos.y = player.y - (Ω.env.h / 2);
this.pos.y = player.y - (Ω.env.h / 2);

this.pos.x = Math.min(Math.max(0, this.pos.x), this.map.w - this.env.w);
this.pos.y = Math.min(Math.max(-80, this.pos.y), this.map.h - this.env.h);
Expand Down

0 comments on commit db48092

Please sign in to comment.