-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo4.html
80 lines (74 loc) · 2.68 KB
/
demo4.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src = "../build/anvil.js"></script>
<link rel = 'stylesheet' href = './styles.css'/>
<title>Example Game</title>
</head>
<body>
<canvas id = "can"></canvas>
<script>
const { Scene, SceneManager, GameObject, Polygon, Input, Light, Sprite } = ANVIL;
const player = new Polygon({
points: [[0,0],[0,50],[50,50],[50,0]],
backgroundColor: "red"
});
//new Light(position, diffuse, strength?, color?): Light
const flashLight = new Light([0,0], 100, 0.8, [255,255,255]);
flashLight.pin(player)
const myScene = new Scene({
lighting: true,
physics: true,
lightOptions: {
ambient: 0.001
},
physicsOptions: {scale: 0}
});
myScene.addObject(player);
myScene.addLight(flashLight);
myScene.bindCamera(player);
const moveLeft = new Input("a", 10);
moveLeft.on = () => {
player.move([-5,0]);
}
moveLeft.activate();
const moveRight = new Input("d", 10);
moveRight.on = () => {
player.move([5,0]);
}
moveRight.activate();
const moveUp = new Input("w", 10);
moveUp.on = () => {
player.move([0,-5]);
}
moveUp.activate();
const moveDown = new Input("s", 10);
moveDown.on = () => {
player.move([0,5]);
}
moveDown.activate();
for(var i = 0; i < 100; i++){
const box = new Polygon({
points: [[0,0],[0,50],[50,50],[50,0]],
backgroundColor: "blue",
blocks: [player]
});
box.move([Math.random() * 1000, Math.random() * 1000]);
myScene.addObject(box);
}
const end = new Polygon({
points: [[0,0],[0,50],[50,50],[50,0]],
backgroundColor: "green"
})
myScene.addObject(end);
myScene.enableCollisionsBetween(player,end,()=>{
alert("you win");
window.location.reload();
});
end.move([Math.random() * 1000, Math.random() * 1000]);
const sceneManager = new SceneManager({initialScene: myScene, canvas: document.getElementById("can")});
</script>
</body>
</html>