BlueGit

timfa raytracer

Files

raytracer / src / main.js

main.js

main.js 1.6 KiB Download Raw
1console.log("Raytracer (frameworkv3 + paperdolls) starting");
2var game = new Game();
3
4window.onload = function ()
5{
6 game.preloadImagesThenStart(
7 [
8 { name: "stone", url: "images/stone.png" },
9 { name: "wood", url: "images/wood.png" },
10 { name: "shotgun", url: "images/shotgun.png" },
11 { name: "machinegun", url: "images/machinegun.png" },
12 { name: "pulserifle", url: "images/pulserifle.png" }
13 ],
14 function ()
15 {
16 Tiles.bindImages(game.images);
17 World.loadLevel(0);
18 Player.resetToSpawn();
19
20 var w = Math.max(320, window.innerWidth - 2);
21 var h = Math.max(240, window.innerHeight - 2);
22 var scene = new RaycastScene(w, h);
23 scene.npcLight = 1;
24 game.loadScene(scene);
25
26 NpcSystem.initEmpty();
27 NpcSystem.addNpc({ x: 48 + 64, y: 48, facingDeg: 180, clip: "walk", animating: true, label: "walker" });
28 NpcSystem.addNpc({ x: 48 + 128, y: 48 + 96, facingDeg: 90, clip: "walk", animating: false, time: 0.25, label: "guard" });
29 NpcSystem.addNpc({ x: 48 + 32, y: 48 + 160, facingDeg: 0, clip: "attack", animating: true, label: "attacker" });
30 NpcSystem.addNpc({ x: 200, y: 100, facingDeg: 270, clip: "walk", animating: true, label: "side" });
31
32 NpcSystem.load(
33 "paperdolls/male-body/",
34 "male-body-atlas.ppda",
35 "paperdolls/male-sword/",
36 "male-sword-atlas.ppda"
37 ).then(function ()
38 {
39 console.log("Paperdolls loaded (body + sword)");
40 }).catch(function (err)
41 {
42 console.error("Paperdoll load failed", err);
43 });
44
45 window.addEventListener("resize", function ()
46 {
47 scene.size.x = Math.max(320, window.innerWidth - 2);
48 scene.size.y = Math.max(240, window.innerHeight - 2);
49 });
50 }
51 );
52};