Hacker News new | past | comments | ask | show | jobs | submit login
MariOCaml: HTML5 Mario, written exclusively in OCaml (github.com/mahsu)
110 points by zacharyliu on Dec 20, 2015 | hide | past | favorite | 35 comments



You should put this link to the demo https://mahsu.github.io/mariocaml/ at the beginning of your README.md.


I'm not sure if it's the fact I'm using a different computer and keyboard to play this than I normally do, but the left/right control seems to be somehow "off". I keep falling in the holes and crashing into enemies.

I have no idea how to word what I mean. Is anyone else experiencing this too?

Also, I can move beyond the beginning of the level. :P


The movement is really hacky (https://github.com/mahsu/MariOCaml/blob/master/object.ml#L16...), whereas the actual game takes a more fine-tuned approach (http://s276.photobucket.com/user/jdaster64/media/smb3_physic...). It was tough to keep things simple and use a single set of rules without making everything too floaty or heavy.


I don't think "simple and use a single set of rules" describes the control code for any shipping (action) game. At least none I've worked on. They're all complex piles of special cases and hacks in an effort to make the movement 'feel' right (which works, but is disheartening at first, until you start to expect it).


The Sonic Physics Guide is how I implemented my first (good) platformer physics.

https://info.sonicretro.org/Sonic_Physics_Guide

It's fairly hack free in the abstract. But reality is often a little different, based on the quirks of your collision detection.


I agree. It's difficult to get platformer physics right the first few times around, though. It's deceptively difficult.


I think Mario has more inertia here than in the actual Mario games, he seems to slide forwards rather than stop as quickly as I would expect.


144hz monitor here. Pretty sure the game is tuned for 60fps and thus 144hz monitor is playing like turbo speed.


Same :) requestAnimationFrame is a very short tick on 144hz monitors.


What would be the best way to throttle fps and ensure compatibility between different refresh rates?


You count the time since the last update, wait for the time to accumulate over the update threshold, run the update loop with a fixed time-slice enough times to match whole number of frames. Let the carry over perpetuate to the next frame.

At 144hz with a fixed time-slice set for 60hz, you'd have one update on the 2nd, 4th, 7th, 9th, 12th, 14th, etc. frames.


The best way is usually to not tie game state to frame ticks. See Bethesda's Creation Engine https://www.youtube.com/watch?v=Yuyp-S7FPNI for why that's a bad idea.


Does RAF really run at 144hz on those monitors? That's surprising... and means I probably need to fix some code before those get more common.


It's a W3C recommendation that it runs at the native refresh rate of the monitor. I made a pen not too long ago for comparing different types update loops for different browsers. http://codepen.io/SeanMcBeth/pen/MaMjbZ

I tried to stick to statically allocated values, but there is clearly some sort of GC happening in Firefox. Chrome is stable, but Internet Explorer is extremely noisy.


If you don't have the 3110 tool installed, you can call ocamlbuild directly just fine:

    ocamlbuild -use-ocamlfind -pkgs js_of_ocaml,js_of_ocaml.syntax -syntax camlp4o main.d.byte


It is impressive the code compiles down to 128K of js! Makes me rethink using haxe for this sort of thing. Interestingly I think haxe is written in ocaml.

The nice thing about haxe is it has cross platform tooling and libraries for games. The language itself is a little weird and seems homegrown but it works.

Hopefully some of this demo can get rolled into some kind of cross platform game library! I would love to write games in ocaml that target mobile/desktop and web (via js).


There should be a better way to refer to 'Ocaml to Javascript' code than js_of_caml, maybe ocamlscript? ;)

Anyway, would be nice to hear the author experience using js_of_caml.

EDIT: Is the canvas api the future of web apps? I mean if someone can write such an interactive web app with no 'javascript library of the month' makes you think of all these JS libs doing the same thing over and over, or is Ocaml such a nice language that makes working with the browser much nicer?


I don't get your criticism, what is the problem?

I think naming it this way makes a lot of sense, since OCaml has a lot of <target-type>_of_<source-type> functions, so it is a pretty clever nod to OCamls conventions.


Oh didn't know that, thanks for clarifying, received my ocaml book last week but haven't started.


jsoo certainly takes some getting used to, especially when it comes to actually having to care about the return types of things. Online documentation is painfully sparse and the ocaml type checker was vague at times, so there was quite a bit of trial and error. It does help that all the library bindings are parallel to their javascript counterparts.

Pattern matching with Ocaml is definitely a plus :P, but I definitely felt that working with Ocaml was substantially more challenging. Especially since none of us had prior experience in game development, much less functional game development, the code we produced was riddled with mutability. It would've helped to look at established design patterns first.


I personally found the jsoo documentation almost unusable (same with Ocsigen). OCaml still has a pretty serious shortage of up-to-date, descriptive documentation, especially outside the Jane Street Core bubble.

I'm really excited to see this project because it's the first jsoo program I've seen with a logical structure and a considerable amount of logic implemented in OCaml that ties into JS.


js_of_ocaml is very Ocaml-idiomatic.


It is sometimes referred to as `jsoo` which confused me the first time I saw it without context ;)


Nintendo tends to sue people using the Mario name or any likeness of the character. This is an interesting project, but you are going to get a DMCA pretty quickly.


Nintendo is actually known for not being a PITA to fans who derive their IP, as long as it has no adult nuances. Even then, I've yet to see a DMCA from them.


This is not true for their Pokemon IP. They have DMCA'd fansites and fan-made Pokemon MMOs aggressively in the past.


It's a nice proof of concept, though I think the random level generator thing needs a lot of work here. The best you get seems like a random assortment of objects with no rhyme or reason to them, the worst pretty much kills you right away by putting an enemy next to the start position.

Movement definitely feels a bit off, although not the worst I've ever seen in a Mario fan game, not by a long shot.


No link to play the game?



thanks!


Pretty smooth, even on my old laptop. Kudos.


I'm just about to start a course that uses OCaml for teaching. Any book or website recommendations?

The textbooks are "OCaml from the very beginning" and "More OCaml: Algorithms, Methods & Diversions"


Real World OCaml https://realworldocaml.org

The Functional Approach to Programming (Cousineau)


I didn't try it but given the labs and research interests of the teachers who made it, it is probably good: https://www.france-universite-numerique-mooc.fr/courses/pari...


which univ ?

#ocaml on irc.freenode.net might be of help for adequate suggestions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: