-
Notifications
You must be signed in to change notification settings - Fork 5
/
level-generation.js
63 lines (51 loc) · 1.36 KB
/
level-generation.js
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
52
53
54
55
56
57
58
59
60
61
62
63
drawLevel = function(context,seed,frame) {
var canvas = $("#bird-canvas");
var level = getLevel(1000,seed);
var block_width = 30;
var block_space_multiplier = 10;
var block_space = block_width * block_space_multiplier;
var block_period = block_space + block_width;
var pos_x = 150;
var frame_shift = (frame * 1);
level.forEach(function(level) {
var pos_x = pos_x + block_period;
context.fillStyle = "#ff6600";
context.fillRect(
(level.x * block_period) - frame_shift,
0,
block_width,
level.y1
);
context.fillRect(
(level.x * block_period) - frame_shift,
level.y2,
block_width,
$(window).height() - level.y2
);
})
}
getLevel = function(height,block_seed) {
var blocks = [];
for (i = 2; i < 1000; i++) {
block_seed = md5(block_seed)
var hex = "0x";
blocks.push(block_pos(height,parseInt(hex.concat(block_seed.substr(1,2))),i));
}
return blocks;
}
var block_pos = function(height,seed,difficulty) {
var difficulty_factor = 4;
var apature = 400;
var pos = ((seed/255)*(height*0.6))+(height*0.2);
var modifier = (apature - (difficulty * difficulty_factor));
if(modifier < 100) {
var modifier = 100;
}
return {
'x':i,
// 'y1':Math.random() * 10,
// 'y2':Math.random() * 250
'y1': pos - (modifier/2),
'y2': pos + (modifier/2),
};
}