UNPKG

node-wad

Version:
52 lines (39 loc) 1.64 kB
// Generated by CoffeeScript 1.12.6 var MapEdit, WAD, buildSlantProgression, buildSlantSquare, cosineSlant, fs, m, maxX, minX, rangeY, ref, w; fs = require("fs"); ref = require('..'), WAD = ref.WAD, MapEdit = ref.MapEdit; w = new WAD(true); m = new MapEdit('MAP02'); minX = -1024; maxX = 1024; rangeY = 1024 + 512; buildSlantSquare = function(x, y, width, height, startSlant, endSlant, bInvert, sectorData, lineData) { var pos; if (bInvert) { pos = [[x, y - startSlant], [x + width, y - endSlant], [x + width, y + height + endSlant], [x, y + height + startSlant]]; } else { pos = [[x, y + startSlant], [x + width, y + endSlant], [x + width, y - height - endSlant], [x, y - height - startSlant]]; } return m.buildSector(pos, sectorData, lineData); }; cosineSlant = function(segmentWidth, index, maxIndex) { var input, output; input = (index / maxIndex - 0.5) * Math.PI; output = Math.cos(input) * segmentWidth; return output; }; buildSlantProgression = function(x, y, width, height, slantFunc, resolution, sectorData, lineData) { var index, newSlant, pos, prevSlant; prevSlant = slantFunc(resolution, 0, width / resolution); index = 0; while (index < resolution) { pos = width / resolution * index; newSlant = slantFunc(width / resolution, index + 1, resolution); buildSlantSquare(x + pos, y, width / resolution, height, prevSlant, newSlant, true, sectorData, lineData); prevSlant = newSlant; index++; } return m; }; buildSlantProgression(0, -rangeY / 2, -minX + maxX, rangeY, cosineSlant, 32).addThing(96, 0, 1, 0).toLumps(w); fs.writeFileSync("testSlant.wad", w.write());