15 ms·
Show HN: 3D shooter in your terminal using raycasting in Awk
- bliti 11y agoThis is very cool. The code is very readable. I honestly expected a bit of mess. It's easy to follow and managed to learn a bit about awk. Nice job!
- Upvoter33 11y agothat is crazy awesome awk
- deleted 11y ago[deleted]
- mysterydip 11y agoVery cool! And easily modifiable, thanks to readable code as bliti said. Seems well thought/laid out.
- tunesmith 11y agoThis is hilarious. Is there any technical reason it couldn't have been written twenty years ago?
- TheMozg 11y agoI guess 20 years ago CS students weren't told to "write a Doom-like game" as an awk homework =)
- foota 11y ago.....where do you go to school and how many credits can you transfer in with? :p
- ethbro 11y agoWell, there were those bored days with a TI-83... shudders at TI-BASIC
- bobwaycott 11y agoMy son spends a ton of his class time programming games into his TI-83. He even built his own Final Fantasy type game (when he really should have been doing classwork). He built a battle system, and even a merchant/vendor for buying upgrades. I had a lot of fun playing his game, and offered him some ideas for improvement (which, again, were made during class time). And yet, I can't get him to sit down and put any time into programming on a computer. Sigh.
- qwertyuiop924 11y agoTI-BASIC is a blessing and a curse. You can get the most non-technical people to write code in it, but if you've had experience in a REAL language, you can't bring yourself to.
- brlewis 11y agohunt was written 30 years ago -- not 3D, but a reasonably sophisticated multiplayer terminal action game.
- redthrowaway 11y agoWhose idea was it to have the gun reload slower if you're running away? Deliciously evil. Anyway, really cool project. Good work!
- seivan 11y agoI think that's from the old original operation flashpoint. :-). It's a cool design idea anyway.
- tunnuz 11y agoAmazing!
- quacker 11y agoHaving never looked at awk aside from its usage in shell one-liners, that code looks really nice. I might have to go learn awk for a bit.
- n0us 11y agoIt's amazing what you can do in so few lines of code. If you have the time you ought to do a tutorial on how to make this sort of game, it would be a great read.
- TheMozg 11y agoThere is a great tutorial (it's actually a series of them) which I used: http://lodev.org/cgtutor/raycasting.html http://lodev.org/cgtutor/raycasting.html It's old and C++ but explains raycasting very well. And there is also a similar project in just 265 JS lines: http://www.playfuljs.com/a-first-person-engine-in-265-lines/ http://www.playfuljs.com/a-first-person-engine-in-265-lines/
- n0us 11y agoThanks, I'll check it out.
- qwertyuiop924 11y agoLike a sculpture made out of snot,you can applaud the elegance of the sculpture, and the elegance of the construction, but you have to wonder about the building material...
- ricksplat 11y agoAh but awk is great! It's parsimony when processing structured text files is hard to beat. Such a pity the next step on from it is perl. Perl is snot certainly.
- qwertyuiop924 11y agoNo, the next step from awk is ruby :-D. Anyways, I was talking about how this thing totally misappropriated awk, not awk itself.
- ricksplat 11y agoIn all seriousness, Ruby is Awk's grandchild borne of a virtuous union between Perl and Python. After looking at the code I'd agree that it's not really idiomatic Awk. But come on, snot? I would've said a humble yet more dignified medium, such as match-sticks.
- qwertyuiop924 11y agoBut I'd say that ideologically, ruby is far closer to awk than perl is. And yeah, matchsticks would have been better. I do actually LIKE awk, and will defend it from anybody who says that it is useless or badly designed. This is your father's awk. An elegant weapon for a more... civilized age. :-)
- david-given 11y agoI so wish I had written this (and I've done some really evil shit in my time). So, so wish. It's awesome.
- executesorder66 11y ago
- dTal 11y agoMan, that AWK looks a helluva lot like Javascript.
- minimax 11y agoAs in Javascript, awk represents all numeric values using double precision floating point. I have always thought that was a strange (but not necessarily bad) choice for a language that is basically all about text processing. I guess it works out pretty well if you need to do 3D graphics math. There is a bit of cheating going on here though. Awk doesn't support true multidimensional arrays. They are depending on a Gawk extension for that bit of functionality.
- TheMozg 11y agoActually I tried to do without true multidimensional arrays, but deleting and sorting elements would be a pain.
- david-given 11y agoDouble precision floats can losslessly manipulate integers with up to 56 bits precision, so you get the best of both worlds with no extra effort.
- pacomerh 11y agoThis could actually be used to build a file explorer, not sure for what, but it would be fun to explore directories this way.
- andrewflnr 11y ago"It's an AWK system. I know this."
- dawnbreez 11y agoI want this and I don't know how to make it.
- mcculley 11y agoThis is beautiful. I'm reminded of an administration tool I wrote using AWK and ANSI command sequences. It was the most powerful programming language available on the machines available to me for that project. It worked great, but in the end meant that I had to fly back out to that site every time it needed maintenance or new features as nobody else there knew AWK.
- i336_ 11y agoDepending on whether the flights were stressful or a nice step away from home turf, that might be considered a feature, not a bug. It was a nice bit of job security, in any case. I also hesitate to say that the site in question deserved to pay for the tickets, since AWK is reasonably easy to learn, even in the case of 4- or 5-digit-SLOC applications. But if AWK was the most capable system available, that's saying a bit... :p
- mcculley 11y agoWhile the job security was nice, I considered it a personal failure as I had made a choice that resulted in less flexibility for personnel allocation for my organization. The site in question was isolated from the Internet for security reasons. This was ~1994 and I would have had to submit significant paperwork to get permission to use one of the phone lines for a modem. As I remember it, the site had a hodgepodge of SCO Unix, SunOS, IRIX, and Linux systems. SCO Unix was the least equipped of them. Configuration management had them all stuck at an old version. Perl wasn't even installed on all of the systems. I remember feeling that AWK was a good choice because, being interpreted, it allowed for fast development. Another obvious option would have been C with X for the GUI, but that would have taken much longer to implement.
- i336_ 11y ago> While the job security was nice, I considered it a personal failure as I had made a choice that resulted in less flexibility for personnel allocation for my organization. Good way to put it, and point conceded (and filed away for future reference in my own life). > The site in question was isolated from the Internet for security reasons. This was ~1994 and I would have had to submit significant paperwork to get permission to use one of the phone lines for a modem. I figured as much. Usually flying someone out only happens when the core infrastructure is out (and the tiny DSL emergency modem failed as well), when something's being so annoying/intermittent it has to be poked onsite, or when something's airgapped. > As I remember it, the site had a hodgepodge of SCO Unix, SunOS, IRIX, and Linux systems. SCO Unix was the least equipped of them. Configuration management had them all stuck at an old version. Perl wasn't even installed on all of the systems. Ouch, wow. (I'm not sure whether to be more impressed that Linux made an appearance at all only 3 years after entering existence, or that it was apparently stable enough at that point to not be laughed out of the building.) > I remember feeling that AWK was a good choice because, being interpreted, it allowed for fast development. A problem that's still a toss-up for many people :) hah. I'm not even sure what to use half the time... > Another obvious option would have been C with X for the GUI, but that would have taken much longer to implement. Ah, the joys of Xlib. I've poked it briefly but not too much, although I can resonate with the "much longer to implement" part... heh
- __jal 11y agoGeneral greatness aside, I have to say that's the best quality awk code I've seen. Too many people treat writing awk like picking up after your dog - something to get done quickly, when you have to. Which leads to write-only line noise code, which leads to people treating awk like picking up...
- Stratoscope 11y agoI used to write a fair amount of AWK code back in the day. It was great for one-liners, but I wrote some more elaborate programs in it too. I treated it seriously, like a real programming language, and it served me well. My favorite AWK program was probably my LaserJet II code listing program from 1991. I wrote this out of frustration with the terrible default listings I got when I printed source code. The AWK code did a "two-up" printout of source code: two pages of code per page of paper in landscape mode. It used a nice font and drew graphic boxes around the pages. I was in the habit of using separator lines like this in my code: //------------------------------------- So the program found these and changed them to graphic line separators. It also avoided splitting a function onto two pages if it could - it would leave whitespace at the bottom of a page instead, filled in with a faint dot pattern. Somewhere I have a printout I made with this program; I was hoping to find it and scan it in to show what it looked like. I know it's here somewhere, but in the meantime the source code will have to do: https://github.com/geary/awk/blob/master/LJPII.AWK https://github.com/geary/awk/blob/master/LJPII.AWK Of course, these days I hardly ever print out any code. But back then we printed everything.
- david-given 11y agoYears ago I wrote a compiler (for bytecode) in awk. Ummm... http://cowlark.com/mercat http://cowlark.com/mercat, although you'll need to wade through zip files to get at the source. It was 1.6kloc for a fully typed algolish language producing stack-based bytecode. awk's a lovely little language, and deserves to be better known than it is. Its two big failings are local variable syntax and absence of structured types... and the standard library's a bit mad in places (gsub, sigh). But it's expressive and concise and still readable, and meets its core competency of doing easy text processing beautifully. The most recent thing I wrote in it was this: https://github.com/EtchedPixels/FUZIX/blob/master/Applications/util/fforth.c https://github.com/EtchedPixels/FUZIX/blob/master/Applicatio... That's a C file which is also an executable shell script which contains an embedded awk script. The whole thing's a Forth interpreter. Running the file uses the awk script to compile a Forth subset into bytecode and patch the source file with the new bytecode, which allows me to keep the whole thing in a single source file. It's not what I'd call good awk, but it's incredibly effective awk...
- thevibesman 11y agoMy go-to-awk-guru-friend and I had fun playing with your game---if you couldn't tell by the PRs ;)
- TheMozg 11y agoThanks to you and everyone for contribution. Seeing people care about this little project reminds me why I decided to do programming for a living. As for the PRs, apparently I've slept through all the action =) I'll get back to them as soon as I can.
- Gnouc 11y agoGreat work! PS: You need gawk to run this.
- emmelaich 11y agoI was wondering how you'd read a key in raw mode in awk. The answer, I found with a mix of horror and admiration is 3 forks. Two stty and one bash (presuming read and echo are builtins)
- i336_ 11y agoNow it's been updated to use dd, and can run with /bin/sh. It's sad that languages rise and fall by the feature base present in their standard libraries.
- myztic 11y agoNeeds bash and gawk, bash you can avoid by changing cmd = "bash -c 'read -n 1 input; echo $input'" to cmd = "saved=$(stty -g); stty raw; var=$(dd bs=1 count=1 2>/dev/null); stty \"$saved\"; echo \"$var\"" all credit to izabera from #bash on freenode
- TheMozg 11y agoFinally merged that.
- latenightcoding 11y agoThis is amazing.
- kirang1989 11y agoI was inspired to check out AWK after reading this sentence from the book Masterminds of Programming: "If I had to choose a word to describe our centering forces in language design, I’d say Kernighan emphasized ease of learning; Weiberger, soundness of implementation; and I, utility. I think AWK has all three of these properties."
- baldfat 11y agoNow I have a new example to show AWK as a language. I usually get into arguments about AWK not being a program.
- arca_vorago 11y agoAwk is seriously awesome and too often forgotten or underrated. Ill never forget the day I realized its true power was in shortness of code. I took a one page perl script I couldnt get to work and turned it into a one line awk script that worked.
- ragnar123 11y agoAdd more dragons