-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathground.js
77 lines (70 loc) · 2.76 KB
/
ground.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
let groundStuff = [];
export async function initKelp(screen) {
const kelpTexture = await PIXI.Assets.load('./assets/kelp.png');
const kelpTexture2 = await PIXI.Assets.load('./assets/kelp2.png');
const kelpTexture3 = await PIXI.Assets.load('./assets/kelp3.png');
const kelpTexture4 = await PIXI.Assets.load('./assets/kelp4.png');
const kelpTexture5 = await PIXI.Assets.load('./assets/kelp5.png');
const coralTexture = await PIXI.Assets.load('./assets/corail1.png');
const coralTexture2 = await PIXI.Assets.load('./assets/corail2.png');
const treesTexture = await PIXI.Assets.load('./assets/trees.png');
const hutTexture = await PIXI.Assets.load('./assets/hut.png');
// const rockTexture = await PIXI.Assets.load('./assets/rock1.png');
// const rockTexture2 = await PIXI.Assets.load('./assets/rock2.png');
// for (let i = 0; i < heightmap.length; i++) {
// if (Math.random() < 0.9) {
// continue;
// }
// let randomTexture = Math.random() > 0.5 ? rockTexture : rockTexture2;
// const rock = new PIXI.Sprite(randomTexture);
// rock.width = 120;
// rock.height = 120;
// rock.x = i * 20 - 60;
// rock.y = -heightmap[i] * 20 - 120;
// rock.alpha = 0.9;
// screen.addChild(rock);
// }
for (let i = 0; i < heightmap.length; i++) {
let randomTexture;
if (0 <= heightmap[i]) {
randomTexture = Math.random() > 0.1 ? treesTexture : hutTexture;
} else if (-20 <= heightmap[i] && heightmap[i] <= -10) {
randomTexture = Math.random() > 0.5 ? coralTexture : coralTexture2;
} else {
switch (Math.floor(Math.random() * 5)) {
case 0:
randomTexture = kelpTexture;
break;
case 1:
randomTexture = kelpTexture2;
break;
case 2:
randomTexture = kelpTexture3;
break;
case 3:
randomTexture = kelpTexture4;
break;
case 4:
randomTexture = kelpTexture5;
break;
}
}
const stuff = new PIXI.Sprite(randomTexture);
stuff.width = 40;
stuff.height = 40;
stuff.x = i * 20 - 10;
stuff.y = -heightmap[i] * 20 - 30;
if (randomTexture === treesTexture) {
stuff.width = 80;
stuff.height = 80;
stuff.y -= 30;
stuff.x -= 20;
} else if (randomTexture === hutTexture) {
stuff.width = 50;
stuff.height = 50;
stuff.y -= 5;
stuff.x -= 5;
}
screen.addChild(stuff);
}
}