From 724e6dc39e9d629000ca650acca09d869c5a11c3 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Sat, 19 Oct 2013 11:46:30 -0700 Subject: [PATCH] Reworked sprite math to be simple. --- .../virtual/src/raycast/javascript/intcast.js | 359 +++++++++--------- 1 file changed, 188 insertions(+), 171 deletions(-) diff --git a/Platform/Apple/virtual/src/raycast/javascript/intcast.js b/Platform/Apple/virtual/src/raycast/javascript/intcast.js index 797707e9..0a678ad7 100644 --- a/Platform/Apple/virtual/src/raycast/javascript/intcast.js +++ b/Platform/Apple/virtual/src/raycast/javascript/intcast.js @@ -21,29 +21,29 @@ var map = [ ]; var itemTypes = [ - { img : "sprites/tablechairs.png", block : true }, // 0 - { img : "sprites/armor.png", block : true }, // 1 - { img : "sprites/plantgreen.png", block : true }, // 2 - { img : "sprites/lamp.png", block : false } // 3 + { img : "sprites/tablechairs.png", block : true }, // 0 + { img : "sprites/armor.png", block : true }, // 1 + { img : "sprites/plantgreen.png", block : true }, // 2 + { img : "sprites/lamp.png", block : false } // 3 ]; var mapItems = [ - // lamps in center area - {type:3, x:9, y:7}, - {type:3, x:15, y:7}, + // lamps in center area + {type:3, x:9, y:7}, + {type:3, x:15, y:7}, - // lamps in bottom corridor - {type:3, x:5, y:12}, - {type:3, x:11, y:12}, - {type:3, x:11, y:12}, + // lamps in bottom corridor + {type:3, x:5, y:12}, + {type:3, x:11, y:12}, + {type:3, x:11, y:12}, - // tables in long bottom room - {type:0, x:10, y:10}, - {type:0, x:11, y:10}, - // lamps in long bottom room - {type:3, x:8, y:10}, - {type:3, x:11, y:10} + // tables in long bottom room + {type:0, x:10, y:10}, + {type:0, x:11, y:10}, + // lamps in long bottom room + {type:3, x:8, y:10}, + {type:3, x:11, y:10} ]; // Player attributes [ref BigBlue2_10] @@ -85,10 +85,10 @@ var twoPI = Math.PI * 2; var numTextures = 4; var wallTextures = [ - "walls/walls_1.png", - "walls/walls_2.png", - "walls/walls_3.png", - "walls/walls_4.png" + "walls/walls_1.png", + "walls/walls_2.png", + "walls/walls_3.png", + "walls/walls_4.png" ]; var userAgent = navigator.userAgent.toLowerCase(); @@ -132,29 +132,29 @@ var visibleSprites = []; var oldVisibleSprites = []; function initSprites() { - spriteMap = []; - for (var y=0;y cycleDelay) { - cycleDelay = Math.max(1, cycleDelay - (timeDelta - cycleDelay)) - } + if (timeDelta > cycleDelay) { + cycleDelay = Math.max(1, cycleDelay - (timeDelta - cycleDelay)) + } - setTimeout(gameCycle, cycleDelay); + setTimeout(gameCycle, cycleDelay); - lastGameCycleTime = now; + lastGameCycleTime = now; } @@ -188,24 +188,24 @@ var lastRenderCycleTime = 0; function renderCycle() { - updateMiniMap(); + updateMiniMap(); - castRays(); + castRays(); - // time since last rendering - var now = new Date().getTime(); - var timeDelta = now - lastRenderCycleTime; - var cycleDelay = 1000 / 30; - if (timeDelta > cycleDelay) { - cycleDelay = Math.max(1, cycleDelay - (timeDelta - cycleDelay)) - } - lastRenderCycleTime = now; - setTimeout(renderCycle, cycleDelay); + // time since last rendering + var now = new Date().getTime(); + var timeDelta = now - lastRenderCycleTime; + var cycleDelay = 1000 / 30; + if (timeDelta > cycleDelay) { + cycleDelay = Math.max(1, cycleDelay - (timeDelta - cycleDelay)) + } + lastRenderCycleTime = now; + setTimeout(renderCycle, cycleDelay); - fps = 1000 / timeDelta; - if (showOverlay) { - updateOverlay(); - } + fps = 1000 / timeDelta; + if (showOverlay) { + updateOverlay(); + } } // Set up data tables prior to rendering [ref BigBlue2_20] @@ -351,77 +351,97 @@ function printTbl(arr) { } function clearSprites() { - // clear the visible sprites array but keep a copy in oldVisibleSprites for later. - // also mark all the sprites as not visible so they can be added to visibleSprites again during raycasting. - oldVisibleSprites = []; - for (var i=0;i" + overlayText; - overlayText = ""; + overlay.innerHTML = "FPS: " + fps.toFixed(1) + "
" + overlayText; + overlayText = ""; } @@ -430,33 +450,33 @@ function initScreen() { var screen = $("screen"); for (var i=0;i