-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenerateMap.js
30 lines (29 loc) · 960 Bytes
/
GenerateMap.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
function GenerateMap(){
var arr = new Array(SizeX);
for(var i=0;i<SizeX;i++) {
arr[i]=new Array(SizeY);
for(var j=0;j<SizeY;j++)
arr[i][j]=1;
}
Coin.Top = Math.floor(Math.random()*(SizeX/4));
Coin.Left = Math.floor(Math.random()*(SizeY/4));
Ninja.Top = Math.floor(Math.random()*(SizeX/4)+(3*SizeX/4));
Ninja.Left = Math.floor(Math.random()*(SizeY/4)+(3*SizeY/4));
var obstacle=0;
while(obstacle!=Obstacles){
var random_obstacle = {
Top: Math.floor(Math.random()*SizeX),
Left: Math.floor(Math.random()*SizeY)
};
if(arr[random_obstacle.Top][random_obstacle.Left]!=0&&!AreEqual(random_obstacle,Ninja)&&!AreEqual(random_obstacle,Coin)){
arr[random_obstacle.Top][random_obstacle.Left]=0;
obstacle++;
}
}
Map = arr;
//var test = AStar(1);
return arr;
if(!test)
return GenerateMap();
return arr;
}