Topic: Been too long since I've done much JS hacking... Pages that link to <a href="https://ozoneasylum.com/backlink?for=28932" title="Pages that link to Topic: Been too long since I&amp;#039;ve done much JS hacking..." rel="nofollow" >Topic: Been too long since I&#039;ve done much JS hacking...\

 
Author Thread
Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

IP logged posted posted 02-14-2007 01:48 Edit Quote

Here's a little first-person dungeon thingy in 635 bytes... use the arrow keys to move and turn... and note that you CAN walk through walls, so be careful ;p

http://www.rpi.edu/~laporj2/random/code/dungeon.html

I was shooting for 512 bytes, but I am just not sure it's possible. In any case, the most interesting idea here is that the scene is made up of a bunch of 8x8 tiles which get composited together.

I'm also certain that there's a better way to store the map to save space and be easier to render...

[edit] oh yes, I should probably note that I've only tested it in Firefox, and I'd be pretty amazed if it worked in anything else...

---
Website

(Edited by Iron Wallaby on 02-14-2007 02:21)

reisio
Paranoid (IV) Inmate

From: Florida
Insane since: Mar 2005

IP logged posted posted 02-14-2007 03:28 Edit Quote

That's slick.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

IP logged posted posted 02-14-2007 04:53 Edit Quote

To atone for my lack of 256b sins, here's a quickie that DOES fit into my desired size constraint...

http://www.rpi.edu/~laporj2/random/code/jumpingjack.html

---
Website

rukuartic
Bipolar (III) Inmate

From: Underneath a mountain of blankets.
Insane since: Jan 2007

IP logged posted posted 02-14-2007 05:43 Edit Quote

That is something right there. I'd love to hear an explanation of how you planned it out.

Just a 2d array of wall types, and then print it out on the screen?

rukuartic@halflght:~/$ whatis life
life: nothing appropriate.

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

IP logged posted posted 02-14-2007 14:23 Edit Quote

Lovely stuff!

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

IP logged posted posted 02-14-2007 18:27 Edit Quote

rukuartic:

Yes, it's a 2D array, but with a twist: instead of managing it at the pixel level, I render it in blocks of 8-bits. This is because XBM's deal with bytes at a time, so it's smaller and easier to do it that way. Thus, there are 40 rows and 5 columns (40 / 8), and I add each row to the XBM output array at once, instead of a pixel or byte at a time, simply because it's easier in this case.

Also, it's simple to note that I mirror the image vertically, which results in a little less work, since each scene is always going to be symmetrical about that axis.

As for planning it out, it wasn't... it sort of grew organically. I originally had an idea of rendering a 3D first person scene (ala Scarab of Ra, or Phantasy Star...) in XBM, and when I decided to try to make it as small as possible, I tried to come up with an algorithm that would simplify it down a lot. Using 8x8 tiles seemed to be the best and only way to do it in a small amount of space, so that's what I went with.

After doing the renderer, I just tacked on a map and walking code. Honestly, I'm not too happy with the map code, but it works, so I'll live with it!

---
Website

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 02-15-2007 01:02 Edit Quote

Nice.

I generated XBM images when I first tried to do some raycasting in JS, 6-7 years ago. Different versions of these proof of concept are stil online on http://www.p01.org/3dmaze/. Don't look at the source of this page, at the time I was an IE zealot and clueless about XHTML and CSS

I should try to shrink the 360bytes version down to 256b, and get rid of the fish eye distortion.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

IP logged posted posted 02-15-2007 02:42 Edit Quote

I'm almost certain that a raycaster could be done in 256b. I'm not sure it can be done with XBM's, however... there's so much overhead with making the XBM, you pretty much lose ~50-60 bytes before you even start. I suppose the ability to do 8 pixels at a go helps reclaim some of those...

I smell a challenge could come from this... make a 256b raycaster, bonus points to doing it creatively...

---
Website

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 02-15-2007 09:28 Edit Quote

The 8 pixels at a go may be an advantage for a Dungeon Master like renderer, but I think it becomes more painful for a raycaster. Indeed, cramming a raycaster in 256b sounds tough but possible. I found a ~320bytes version in a backup folder.

What do you mean by creatively ? it's gonna be brutal and gore. Not a single byte will be spared

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

IP logged posted posted 02-15-2007 22:59 Edit Quote

FWIW, I have a first draft of raycaster in 256b ( alas w. fish eye and a super crappy map ), and managed to gain ~80 bytes on your dungeon thingy.

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

IP logged posted posted 02-16-2007 00:16 Edit Quote

I've been hacking at my dungeon program... I think it'd be MUCH smaller if I could find a way to render XBM's from the <body onload=""> handler (or, even, using setInterval ("...") instead of setInterval (function() { ... })). I find that it always fails, however, due to an "unterminated string literal," which means something must always get escaped improperly... due to having so many nested strings, I suppose.

---
Website

(Edited by Iron Wallaby on 02-16-2007 00:19)



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu