Skip to content

Commit 0470bcb

Browse files
author
Jorg Thuijls
committed
first
0 parents  commit 0470bcb

21 files changed

+2514
-0
lines changed

.gitignore

Whitespace-only changes.

LICENSE

Whitespace-only changes.

README.md

Whitespace-only changes.

img/tiles2.png

45.5 KB
Loading

img/tiles2.xcf

92 KB
Binary file not shown.

index.html

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!--
2+
To change this license header, choose License Headers in Project Properties.
3+
To change this template file, choose Tools | Templates
4+
and open the template in the editor.
5+
-->
6+
<!DOCTYPE html>
7+
<html>
8+
<head>
9+
<title>TODO supply a title</title>
10+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
11+
<meta name="viewport" content="width=device-width">
12+
<style>
13+
body,html{
14+
padding: 0;
15+
margin:0;
16+
sbackground-color: #3C292C;
17+
}
18+
</style>
19+
</head>
20+
<body>
21+
22+
<canvas id="game"></canvas>
23+
<script type="text/javascript">
24+
var require = {
25+
waitSeconds: 15,
26+
urlArgs: "bust=" + new Date().getTime()
27+
};
28+
</script>
29+
<script data-main="js/main" src="js/libs/require.min.js"></script>
30+
<script>
31+
var btn = document.createElement("button");
32+
var t = document.createTextNode("pause");
33+
btn.appendChild(t);
34+
btn.style.position = 'fixed';
35+
btn.style.top = '30px';
36+
btn.style.left = '15px';
37+
btn.onclick = function() {
38+
window.game.engine.toggle();
39+
}
40+
document.body.appendChild(btn);
41+
42+
var opt = ['normal', 'normalgrid', 'grid', 'flatgrid', 'experiment'];
43+
var style = document.createElement("select");
44+
style.style.position = 'fixed';
45+
style.style.top = '30px';
46+
style.style.left = '80px';
47+
for (var i = 0; i < opt.length; i++) {
48+
var o = document.createElement('option');
49+
o.value = opt[i];
50+
o.innerHTML = opt[i];
51+
style.appendChild(o);
52+
}
53+
style.onchange = function(val) {
54+
window.game.settings.get(this.value);
55+
}
56+
document.body.appendChild(style);
57+
58+
var range = document.createElement('input');
59+
range.type = 'range';
60+
range.min = 0;
61+
range.max = 100;
62+
range.value = 40;
63+
range.style.position = 'fixed';
64+
range.style.top = '60px';
65+
range.style.left = '15px';
66+
67+
range.onchange = function() {
68+
window.game.grid.setLevel(this.value);
69+
}
70+
document.body.appendChild(range);
71+
</script>
72+
</body>
73+
</html>

js/engine.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
define([], function() {
2+
3+
window.requestAnimFrame = (function() {
4+
return window.requestAnimationFrame ||
5+
window.webkitRequestAnimationFrame ||
6+
window.mozRequestAnimationFrame ||
7+
window.oRequestAnimationFrame ||
8+
window.msRequestAnimationFrame ||
9+
function(/* function */ callback, /* DOMElement */ element) {
10+
window.setTimeout(callback, 1000 / 60);
11+
};
12+
})();
13+
14+
window.cancelAnimFrame = (function() {
15+
window.cancelAnimFrame ||
16+
function(id) {
17+
clearTimeout(id);
18+
};
19+
})();
20+
21+
var lastRun = new Date().getTime();
22+
23+
var engine = {
24+
animate: false,
25+
resources: null,
26+
screen: null,
27+
grid: [],
28+
init: function(grid) {
29+
var timer = setInterval(function() {
30+
if (engine.resources.loaded) {
31+
engine.grid = grid;
32+
engine.loop()
33+
clearInterval(timer);
34+
} else {
35+
console.log('waiting for resource');
36+
}
37+
}, 50);
38+
},
39+
loop: function(frame) {
40+
if (engine.animate) {
41+
var delta = (new Date().getTime() - lastRun) / 1000;
42+
lastRun = new Date().getTime();
43+
fps = Math.floor(1 / delta);
44+
45+
requestAnimFrame(engine.loop);
46+
engine.draw();
47+
engine.update();
48+
49+
engine.screen.write(fps, 50, 50)
50+
} else {
51+
requestAnimFrame(engine.loop);
52+
engine.draw();
53+
//engine.update(0);
54+
}
55+
56+
},
57+
draw: function() {
58+
engine.screen.clear();
59+
engine.screen.grid(engine.resources, engine.grid.grid);
60+
},
61+
update: function() {
62+
engine.grid.recalc();
63+
},
64+
scale: function(x, y) {
65+
engine.screen.scale(x, y);
66+
},
67+
start: function() {
68+
engine.animate = true;
69+
},
70+
stop: function() {
71+
engine.animate = false;
72+
},
73+
toggle: function() {
74+
engine.animate = !engine.animate;
75+
}
76+
}
77+
78+
return engine;
79+
});

js/functions.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
define([], function() {
2+
var ret = {position: {}, client: {}, document: {}};
3+
4+
var d = document;
5+
var e = d.documentElement;
6+
var g = d.getElementsByTagName('body')[0];
7+
ret.client.width = window.innerWidth || e.clientWidth || g.clientWidth;
8+
ret.client.height = window.innerHeight || e.clientHeight || g.clientHeight;
9+
10+
ret.position.x = (window.pageXOffset || e.scrollLeft) - (e.clientLeft || 0);
11+
ret.position.y = (window.pageYOffset || e.scrollTop) - (e.clientTop || 0);
12+
13+
ret.document.height = Math.max(
14+
d.body.scrollHeight, d.documentElement.scrollHeight,
15+
d.body.offsetHeight, d.documentElement.offsetHeight,
16+
d.body.clientHeight, d.documentElement.clientHeight
17+
);
18+
19+
ret.document.width = Math.max(
20+
d.body.scrollWidth, d.documentElement.scrollWidth,
21+
d.body.offsetWidth, d.documentElement.offsetWidth,
22+
d.body.clientWidth, d.documentElement.clientWidth
23+
);
24+
25+
return ret;
26+
});

js/grid.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
define(['libs/simplex.perlin', 'settings'], function(simplex, settings) {
2+
3+
var loop = 0;
4+
5+
var grid = function() {
6+
this.noise = {};
7+
this.grid = [];
8+
this.lvl = this.setLevel(40);
9+
this.noise.normal = function(noise) {
10+
return noise;
11+
}
12+
13+
this.noise.bw = function(noise) {
14+
return noise > 0.5 ? 0 : 1;
15+
}
16+
17+
this.noise.bwbw = function(noise) {
18+
return ((noise * 8) % 2) < 1 ? 0 : 1
19+
}
20+
this.noise.repeat = function(noise) {
21+
return (noise * 1024 % 256) / 256
22+
}
23+
this.noise.lines = function(noise) {
24+
return Math.abs(noise - .5) * 2.5
25+
}
26+
this.noise.mud = function(noise) {
27+
//requires Y in there
28+
return Math.floor(Math.pow(noise * 4, 1.1))
29+
}
30+
31+
32+
33+
this.function = this.noise[settings.option.perlin.function];
34+
};
35+
36+
grid.prototype.addNoiseFunction = function(opt) {
37+
this.noise[opt.name] = opt.function;
38+
}
39+
40+
grid.prototype.useNoiseFunction = function(name) {
41+
this.function = this.noise[name];
42+
}
43+
44+
45+
grid.prototype.createGrid = function() {
46+
this.function = this.noise[settings.option.perlin.function];
47+
var p = simplex;
48+
49+
var maxX = settings.option.grid.x
50+
var maxY = settings.option.grid.y;
51+
52+
var zz = Math.random() * 100;
53+
var x, y, xx, yy;
54+
55+
p.setRng(Math); //math has a random number generator called 'random()'
56+
p.noiseDetail(settings.option.grid.octavtes, settings.option.grid.persistence);
57+
58+
for (var y = 0; y < maxY; y++) {
59+
this.grid[y] = new Array(maxX);
60+
for (var x = 0; x < maxX; x++) {
61+
xx = 0 + x * this.level;
62+
yy = 0 + y * this.level;
63+
64+
this.grid[y][x] = this.function(p.noise(xx, yy, zz));
65+
}
66+
67+
}
68+
return this.grid;
69+
}
70+
71+
grid.prototype.setLevel = function(lvl) {
72+
this.level = 0.01 + (0.09 * (lvl/100));
73+
}
74+
75+
grid.prototype.getLevel = function() {
76+
return Math.floor((this.level - 0.01) / 0.09) * 100
77+
}
78+
79+
grid.prototype.recalc = function(frame) {
80+
var p = simplex;
81+
loop++
82+
83+
for (var y = 0; y < this.grid.length; y++) {
84+
for (var x = 0; x < this.grid[0].length; x++) {
85+
var fDff = loop == 0 ? 1.5 : 1;
86+
xx = 0 + x * this.level * fDff;
87+
yy = 0 + y * this.level * fDff;
88+
89+
//console.log(xx + ' ' + yy);
90+
this.grid[y][x] = this.function(p.noise(xx, yy, loop * 0.005));
91+
}
92+
}
93+
}
94+
95+
return new grid();
96+
97+
});

js/grid3d.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
define(['libs/perlin.simplex', 'libs/simplex.perlin', 'settings'], function(simplex, perlin, settings) {
2+
3+
var loop = 0;
4+
5+
var grid = function() {
6+
this.noise = {};
7+
this.grid = [];
8+
this.noise.normal = function(noise) {
9+
return noise;
10+
}
11+
12+
this.noise.bw = function(noise) {
13+
return noise > 0.5 ? 0 : 1;
14+
}
15+
16+
this.noise.bwbw = function(noise) {
17+
return ((noise * 8) % 2) < 1 ? 0 : 1
18+
}
19+
this.noise.repeat = function(noise) {
20+
return (noise * 1024 % 256) / 256
21+
}
22+
this.noise.lines = function(noise) {
23+
return Math.abs(noise - .5) * 2.5
24+
}
25+
this.noise.mud = function(noise) {
26+
//requires Y in there
27+
return Math.floor(Math.pow(noise * 4, 1.1))
28+
}
29+
30+
31+
32+
this.
33+
function = this.noise[settings.option.perlin.function];
34+
};
35+
36+
grid.prototype.addNoiseFunction = function(opt) {
37+
this.noise[opt.name] = opt.
38+
function;
39+
}
40+
41+
grid.prototype.useNoiseFunction = function(name) {
42+
this.
43+
function = this.noise[name];
44+
}
45+
46+
47+
grid.prototype.createGrid = function() {
48+
//this.function = this.noise[settings.option.perlin.function];
49+
50+
var maxZ = 80;
51+
52+
var maxX = 80;//settings.option.grid.x
53+
var maxY = 80;//settings.option.grid.y;
54+
var fScl = .0422;
55+
var zz = Math.random() * 100;
56+
var x, y, xx, yy;
57+
perlin.setRng(Math); //math has a random number generator called 'random()'
58+
perlin.noiseDetail(settings.option.grid.octavtes, settings.option.grid.persistence);
59+
for (var z = 0; z < maxZ; z++) {
60+
this.grid[z] = new Array(maxZ)
61+
for (var y = 0; y < maxY; y++) {
62+
this.grid[z][y] = new Array(maxY);
63+
for (var x = 0; x < maxX; x++) {
64+
xx = 0 + x * fScl;
65+
yy = 0 + y * fScl;
66+
zz = 0 + z * fScl;
67+
68+
if (perlin.noise(xx, yy, zz) * maxZ < z) {
69+
this.grid[z][y][x] = 2;
70+
} else {
71+
//simplex.noise(xx, yy, Math)
72+
this.grid[z][y][x] = simplex.noise3d(xx, yy, zz*0.3);//simplex.noise3d(xx, yy, zz);
73+
}
74+
75+
76+
}
77+
}
78+
}
79+
return this.grid;
80+
}
81+
82+
grid.prototype.recalc = function(frame) {
83+
var p = simplex;
84+
var fScl = .0422;
85+
loop++
86+
87+
for (var y = 0; y < this.grid.length; y++) {
88+
for (var x = 0; x < this.grid[0].length; x++) {
89+
var fDff = loop == 0 ? 1.5 : 1;
90+
xx = 0 + x * fScl * fDff;
91+
yy = 0 + y * fScl * fDff;
92+
93+
//console.log(xx + ' ' + yy);
94+
this.grid[y][x] = this.
95+
function(p.noise(xx, yy, loop * 0.005));
96+
}
97+
}
98+
}
99+
100+
return new grid();
101+
102+
});

0 commit comments

Comments
 (0)