forked from Overv/WebCraft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
singleplayer.html
74 lines (59 loc) · 1.96 KB
/
singleplayer.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
<!DOCTYPE HTML>
<html>
<head>
<title>WebCraft</title>
<!-- Character encoding -->
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<!-- Stylesheet -->
<link href="style/main.css" rel="stylesheet" type="text/css">
<!-- Modules -->
<script src="js/glMatrix-1.2.min.js" type="text/javascript"></script>
<script src="js/blocks.js" type="text/javascript"></script>
<script src="js/helpers.js" type="text/javascript"></script>
<script src="js/world.js" type="text/javascript"></script>
<script src="js/render.js" type="text/javascript"></script>
<script src="js/physics.js" type="text/javascript"></script>
<script src="js/player.js" type="text/javascript"></script>
</head>
<body oncontextmenu="return false">
<!-- Render surface -->
<canvas id="renderSurface"></canvas>
<!-- Material selection -->
<table id="materialSelector">
<tr></tr>
</table>
<!-- Initialisation code -->
<script type="text/javascript">
// Create a new flat world
var world = new World( 16, 16, 16 );
world.createFlatWorld( 6 );
// Set up renderer
var render = new Renderer( "renderSurface" );
render.setWorld( world, 8 );
render.setPerspective( 60, 0.01, 200 );
// Create physics simulator
var physics = new Physics();
physics.setWorld( world );
// Create new local player
var player = new Player();
player.setWorld( world );
player.setInputCanvas( "renderSurface" );
player.setMaterialSelector( "materialSelector" );
// Render loop
setInterval( function()
{
var time = new Date().getTime() / 1000.0;
// Simulate physics
physics.simulate();
// Update local player
player.update();
// Build a chunk
render.buildChunks( 1 );
// Draw world
render.setCamera( player.getEyePos().toArray(), player.angles );
render.draw();
while ( new Date().getTime() / 1000 - time < 0.016 );
}, 1 );
</script>
</body>
</html>