One-line text ray-caster, where all you can see is just a line of text. Control with cursors.
for(_=');FleE.aD+aXe+WinV&&(U=0,(a=at=Math.*PI,,e,n,o=b[h]]&&p(styE:0)|00>=sV(=0;28>for(),=f(td.onkeycos(;var =,tD,h,b))=>(0<=t?-1:r[I[r]..]Uy=o=(o+h<b.Ength&&PI*t+l)%lM[t,l=2r=parseInt("axgulq06kf",36).toStrVg(2).split(""s=.4i=n=e=2,y=oM=[],p=>{c=o)*a,a*o+c)Ut+=cX)UWi=t,n=e},f)=>|t|a||5<||t||15*tX]xh=0<t?~~(W1)-e:ceil(e-1)-e,a=h*a/t,0==t?{b:9}:{x:o?nX:Wh,y:o?Wh:nX,b:h*hX*a}k,h5*.y-(o?h)+.x-(n?ta.c=t||5t],aD=Wsqrt.bau=>>M[t.keyCode%37];AA;A++)b.VnerHTML+="<p =display:VlVe-block>"+"JS1K"[A%4]+"</p>" I=d.querySeEctorAll("p"Fdown=u(1up=u(0setInterval(function(t){.004,M[0-213*tM[3-3*taa;a++){s*/28-.5) h=y+t=i,c=n,r=[],bhFh=he={x:e,y:c,c:0,a:0};do{if(r.push(e0<e.c)break d=x(b,h.x.yFc=x(h,b.y.x,1e=d.b<c.b?k(d,1,0:k(c,0,1}whiE(5>=eDFb=r,r,h=-1;++.c;F(5/((b)D*t)b=1-max(bD/5,0opacity=b,transform="scaEY("+t+")")}})';G=/[-U-XD-F]/.exec(_);)with(_.split(G))_=join(shift());eval('var '+_)
Zm9yKF89Jyk7RmxlRS5hRCthWGUrV2luViYmKFU9MCwfKGEePWEddD0cTWF0aC4bKhtQSSwaLGUZGSxuLG8YPWJbaF0XXSYmcCgWc3R5RRU6MCl8MBQwPhM9G3NWKBI9MDsyOD4RZm9yKBApLA8PEz1mKHQOZC5vbmtleQwbY29zKAs7dmFyIAk9Hix0CBlELGgsYikHGCk9PigGMDw9dD8tMTpyWwVJW3JdLhUuBF1VeT1vPShvKwNoPGIuRW5ndGgmJgIbUEkqdCtsKSVsD01bAXQYLGw9M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based on a canvas raycaster build by Laerin
// https://codepen.io/xgundam05/pen/vcBbL
var CIRCLE = Math.PI * 2;
const wall_text = 'JS1K';
let RayMap_walls = parseInt("axgulq06kf", 36).toString(2).split(''),
RayMap_width = 5,
RayMap_height = 10,
RayCamera_fov = Math.PI * 0.4,
RayCamera_range = 14,
RayCamera_lightRange = 5,
p_x, p_y,
RayCamera_p_x = p_x = 3,
RayCamera_p_y = p_y = 4,
dir,
RayCamera_dir = dir = 0,
RaycastRenderer_height = 9,
RaycastRenderer_resolution = 28,
// 37 - l, 39 - r, 38 - f, 40 - b
Controls_states = [],
lastTime = 0,
str = '',
rot = (angle) => {
dir = (dir + angle + CIRCLE) % (CIRCLE);
RayCamera_dir = dir;
},
walk = (distance) => {
var dx = Math.cos(dir) * distance;
var dy = Math.sin(dir) * distance;
if (RayMap_Get(p_x + dx, p_y) <= 0) p_x += dx;
if (RayMap_Get(p_x, p_y + dy) <= 0) p_y += dy;
RayCamera_p_x = p_x;
RayCamera_p_y = p_y;
},
update = (seconds) => {
if (Controls_states[0]) rot(-Math.PI * seconds);
if (Controls_states[2]) rot(Math.PI * seconds);
if (Controls_states[1]) walk(3 * seconds);
if (Controls_states[3]) walk(-3 * seconds);
};
function RayMap_Get(x, y) {
x = x | 0;
y = y | 0;
if (x < 0 || x >= RayMap_width || y < 0 || y >= RayMap_height) return -1;
return RayMap_walls[y * RayMap_width + x];
};
function RayMap_Raycast(x, y, angle, range) {
var cells = [];
var sin = Math.sin(angle);
var cos = Math.cos(angle);
var stepX, stepY, nextStep;
nextStep = { x, y, cell: 0, distance: 0 };
do {
cells.push(nextStep);
if (nextStep.cell > 0)
break;
stepX = RayMap___step(sin, cos, nextStep.x, nextStep.y);
stepY = RayMap___step(cos, sin, nextStep.y, nextStep.x, true);
nextStep = stepX.length2 < stepY.length2
? RayMap___inspect(stepX, 1, 0, nextStep.distance, cos, sin)
: RayMap___inspect(stepY, 0, 1, nextStep.distance, cos, sin);
} while (nextStep.distance <= range);
return cells;
};
function RayMap___step(rise, run, x, y, inverted) {
var dx = run > 0 ? ~~(x + 1) - x : Math.ceil(x - 1) - x;
var dy = dx * rise / run;
return (run === 0) ? { length2: 9 } : {
x: inverted ? y + dy : x + dx,
y: inverted ? x + dx : y + dy,
length2: dx * dx + dy * dy
};
};
function RayMap___inspect(step, shiftX, shiftY, distance, cos, sin) {
var dx = cos < 0 ? shiftX : 0;
var dy = sin < 0 ? shiftY : 0;
var index = (((step.y - dy) | 0) * RayMap_width) + ((step.x - dx) | 0);
step.cell = (index < 0 || index >= 440) ? -1 : RayMap_walls[index];
step.distance = distance + Math.sqrt(step.length2);
return step;
};
function RayCamera_Rotate(angle) {
RayCamera_dir = (RayCamera_dir + angle + CIRCLE) % (CIRCLE);
}
function RaycastRenderer___project(height, angle, distance) {
var z = distance * Math.cos(angle);
var wallHeight = RaycastRenderer_height * height / z;
return wallHeight;
};
function RaycastRenderer___drawColumn(column, ray, angle) {
var hit = -1;
while (++hit < ray.length && ray[hit].cell <= 0);
if (hit < ray.length) {
var step = ray[hit];
var wall = RaycastRenderer___project(1, angle, step.distance);
const alpha = 1 - Math.max((step.distance) / RayCamera_lightRange, 0);
els[column].style.opacity = alpha;
els[column].style.transform = 'scaleY(' + wall + ')';
}
};
function RaycastRenderer___drawColumns() {
for (var col = 0; col < RaycastRenderer_resolution; col++) {
var angle = RayCamera_fov * (col / RaycastRenderer_resolution - 0.5);
var ray = RayMap_Raycast(RayCamera_p_x, RayCamera_p_y, RayCamera_dir + angle, RayCamera_range);
RaycastRenderer___drawColumn(col, ray, angle);
}
};
function Controls_onKey(val, e) {
return (e) => {
Controls_states[e.keyCode%37] = val;
}
};
for (let i = 0; i < RaycastRenderer_resolution; i++) {
str += '<p style="display:inline-block;margin-top:99px">' + wall_text[i % wall_text.length] + '</p>';
}
b.innerHTML = str;
let els = d.querySelectorAll('p');
d.onkeydown = Controls_onKey(1);
d.onkeyup = Controls_onKey(0);
function UpdateRender() {
var seconds = 0.004;
update(seconds);
RaycastRenderer___drawColumns();
}
setInterval(UpdateRender);