
MariOCaml: HTML5 Mario, written exclusively in OCaml - zacharyliu
https://github.com/mahsu/MariOCaml
======
asimjalis
You should put this link to the demo
[https://mahsu.github.io/mariocaml/](https://mahsu.github.io/mariocaml/) at
the beginning of your README.md.

------
i336_
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

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

~~~
yoklov
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).

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

[https://info.sonicretro.org/Sonic_Physics_Guide](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.

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

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

~~~
moron4hire
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.

------
arh68
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

------
robohamburger
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).

------
Scarbutt
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?

~~~
LeonidasXIV
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.

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

------
DiabloD3
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.

~~~
stelonix
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.

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

------
CM30
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.

------
azakai
No link to play the game?

~~~
nononoxd
[https://mahsu.github.io/mariocaml/](https://mahsu.github.io/mariocaml/)

~~~
azakai
thanks!

------
agumonkey
Pretty smooth, even on my old laptop. Kudos.

------
brunoc
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"

~~~
ericssmith
Real World OCaml [https://realworldocaml.org](https://realworldocaml.org)

The Functional Approach to Programming (Cousineau)

