-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
149 lines (120 loc) · 3.13 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JCast Engine Demo</title>
<script type="text/javascript" src="lib/jcast.min.js"></script>
</head>
<body>
<canvas width="410" height="210"></canvas>
<script type="text/javascript">
// Get canvas reference:
var canvas = document.querySelector('canvas');
// Instantiate and center the camera:
var camera = new jcast.Camera({
farClipPlane: 10
});
camera.transform.position.x
= camera.transform.position.y = 5;
// Define your coloured materials to be used:
var bgMaterial = new jcast.Material({
color: new jcast.Color({
r: 162,
g: 218,
b: 235
})
});
var floorMaterial = new jcast.Material({
color: new jcast.Color({
r: 150,
g: 150,
b: 150
})
});
var blockMaterial = new jcast.Material({
color: new jcast.Color({
r: 195,
g: 195,
b: 195
})
});
var pillarMaterial = new jcast.Material({
color: new jcast.Color({
r: 200,
g: 200,
b: 200
})
});
var glassMaterial = new jcast.Material({
color: new jcast.Color({
r: 200,
g: 0,
b: 200,
a: 0.5
})
});
// Define your blocks/walls:
var block = new jcast.Block({
walls: [
new jcast.Wall({
material: blockMaterial
})
]
});
var pillarBlock = new jcast.Block({
walls: [
new jcast.Wall({
material: pillarMaterial
}),
new jcast.Wall({
material: pillarMaterial
})
]
});
var glassBlock = new jcast.Block({
walls: [
new jcast.Wall({
material: glassMaterial
})
]
});
// Create your map:
var map = new jcast.Map({
width: 10,
height: 10,
depth: 1,
name: 'Test Map',
camera,
bg: bgMaterial,
floor: floorMaterial
});
// Populate your map with your blocks:
// Add the glass block:
map.setBlock(8, 5, glassBlock);
// We loop through each border of the map, if the current position is even then we add the normal block, otherwise we add a pillar:
for (var x = 0; x < map.width; x++) {
map.setBlock(x, 0, (x % 2) == 0 ? block : pillarBlock);
map.setBlock(x, map.height - 1, (x % 2) == 0 ? block : pillarBlock);
}
for (var y = 0; y < map.height; y++) {
map.setBlock(0, y, (y % 2) == 0 ? block : pillarBlock);
map.setBlock(map.width - 1, y, (y % 2) == 0 ? block : pillarBlock);
}
// Init and start your game:
var game = jcast.init({ canvas, map });
game.start();
// Rotate the camera by intervals:
var vrs = 0.01;
setInterval(() => {
var z = camera.transform.rotation.z;
if (z >= 1.0 || z <= -1.0) {
vrs *= -1;
}
// Rotate horizontally and vertically:
camera.rotate(0, jcast.Time.deltaTime, vrs);
}, 1000 / 60);
</script>
</body>
</html>