BlueGit

timfa raytracer

Files

raytracer / archive / legacy-js / before-shot.html

before-shot.html

before-shot.html 1.7 KiB Download Raw
1<html><head><style>html,body{margin:0;overflow:hidden;background:#000}</style></head>
2<body>
3<script>
4// Patch before scripts load: fixed size
5Object.defineProperty(window, 'innerWidth', {get:()=>960});
6Object.defineProperty(window, 'innerHeight', {get:()=>540});
7</script>
8<script src="js/GameWindow.js"></script>
9<script src="js/Canvas.js"></script>
10<script src="js/Vector.js"></script>
11<script src="js/image.js"></script>
12<script src="js/Levels.js"></script>
13<script src="js/Tiles.js"></script>
14<script src="js/GameInput.js"></script>
15<script src="js/World.js"></script>
16<script src="js/Player.js"></script>
17<script>
18window.onload = function(){
19 GameWindow.init(0,0,960,540);
20 GameWindow.fullscreen = false;
21 GameInput.g_init();
22 World.loadLevel(0);
23 Player.rotation = 0;
24 Player.pitch = 0;
25 Player.horizontalResolution = 200;
26 // wait for images
27 function ready(){
28 var ok = true;
29 [Tiles.Stone.Image, Tiles.Wood.Image, Player.shotgunImg].forEach(function(im){
30 if(!im || !im.g_image || !im.g_image.complete || im.g_image.naturalWidth===0) ok=false;
31 });
32 if(!ok){ setTimeout(ready, 50); return; }
33 GameWindow.redraw(); // one frame then stop rAF by replacing
34 var frames=0;
35 var orig=GameWindow.redraw;
36 GameWindow.redraw=function(){
37 frames++;
38 GameWindow.width=960; GameWindow.height=540;
39 GameWindow.canvas.width=960; GameWindow.canvas.height=540;
40 GameWindow.canvasContext.fillStyle='rgb(0,0,0)';
41 GameWindow.canvasContext.fillRect(0,0,960,540);
42 Player.draw3D();
43 if(frames<3) requestAnimationFrame(GameWindow.redraw);
44 else document.title='READY';
45 };
46 GameWindow.redraw();
47 }
48 ready();
49};
50</script>
51</body></html>