MARIO.GAME
en

MariOCaml

A Super Mario platformer written in OCaml with random levels

MariOCaml

About MariOCaml

MariOCaml was created at Cornell University by Matthew Hsu, Liam Bui and Ashley Xue as a final project for a functional programming course, and it grew into one of the most popular OCaml projects on GitHub.

The whole game — physics, enemies, items, the camera and the renderer — is written in OCaml and cross-compiled to JavaScript with js_of_ocaml, so it runs in a normal web page. Underneath is a “director” that owns the game state and runs the main loop, while a procedural generator builds each level on a grid, taking care to keep it playable.

The result looks like a SNES-era Mario game with a twist: every time you load it you get a different arrangement of brick towers, coin clouds and Koopa troopas. Some layouts are elegant, some are chaotic — that is the charm of a random level.

Controls

InputAction
← → or A DMove
Space, ↑ or WJump
↓ or SDuck

Features

  • Written 100% in the functional language OCaml
  • Random level generator that places blocks, coins, enemies and gaps
  • Score, coin counter, game over and game win screens
  • Particle effects when blocks break and enemies are stomped

Tips

  1. The counter in the top-left corner is the frame rate, not a timer — take your time.
  2. Shells can be kicked into other enemies for a chain of points.
  3. If a level generates in an awkward way, reload the frame with the restart button for a new layout.

Frequently asked questions

What is OCaml?

OCaml is a functional programming language used in academia and industry. MariOCaml shows that it can power a complete real-time game when compiled to JavaScript.

Are the levels always different?

Yes — the level is generated randomly on every load, so each restart gives you a new map.

Who made MariOCaml?

Matthew Hsu, Liam Bui and Ashley Xue. The project is open source under the MIT license.

More games to play