-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-world.js
More file actions
51 lines (49 loc) · 958 Bytes
/
generate-world.js
File metadata and controls
51 lines (49 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var _world = {
width: 10000,
height: 10000,
pieces: [],
ground: {
color: '#448844',
image: 'grass',
}
};
// Generate Random World.
for( var i = 0; i < 5000; i++ ) {
image = 'flower1';
width = 20;
height = 20;
if( i % 10 <= 4 ) {
image = 'flower1';
width = 17;
height = 16;
} else if ( i % 10 <= 7 ) {
image = 'flower2';
width = 28;
height = 25;
} else if ( i % 10 <= 8 ) {
image = 'tree1';
width = 115;
height = 157;
} else {
image = 'tree2';
width = 123;
height = 151;
}
_world.pieces.push({
image: image,
width: width,
height: height,
x: Math.round( Math.random() * _world.width ),
y: Math.round( Math.random() * _world.height ),
solid: false
});
console.log("Created... "+i);
}
var fs = require('fs');
fs.writeFile(__dirname+"/resources/world.json", JSON.stringify(_world), function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});