-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapHelper.functions.coffee
80 lines (64 loc) · 2.02 KB
/
mapHelper.functions.coffee
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
srand = require "srand"
###
Returns a 48x200 px area
###
exports.getMapTile = (seed, pos) ->
LENGTH = 200
WIDTH = 48
offsetY = pos * LENGTH
objects =
obstacles: [],
speedup: [],
slowdown: []
srand.seed seed*1000 + pos;
randMax = (max) ->
return Math.floor(srand.random() * max)
randMinMax = (min,max) ->
return Math.floor(srand.random() * (max - min)) + min
yStart = 5 + offsetY
lengthNextBlock = randMinMax(10,20)
while (yStart + lengthNextBlock) < ((pos + 1) * LENGTH)
typeRand = randMax 100
if typeRand in [0..35]
# block on the left side
objects.obstacles.push {
x1: 0,
y1: yStart,
x2: randMinMax(10,20),
y2: yStart + lengthNextBlock
}
if typeRand in [36..70]
# block on the right side
objects.obstacles.push {
x1: WIDTH - randMinMax(10,20),
y1: yStart,
x2: WIDTH,
y2: yStart + lengthNextBlock
}
if typeRand in [71..85]
lengthNextBlock = 5
# block in the left side
objects.obstacles.push {
x1: 0,
y1: yStart,
x2: randMinMax(5,20),
y2: yStart + lengthNextBlock
}
# block on the right side
objects.obstacles.push {
x1: WIDTH - randMinMax(5,20),
y1: yStart,
x2: WIDTH,
y2: yStart + lengthNextBlock
}
if typeRand in [86..100]
# block in the left side
objects.obstacles.push {
x1: randMinMax(10,20),
y1: yStart,
x2: randMinMax(WIDTH - 20,WIDTH - 10),
y2: yStart + lengthNextBlock
}
yStart = yStart + 20 + randMax 25
lengthNextBlock = randMinMax(10, 20)
return objects