Skip to content

bramford/2d-exploration-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2D Exploration Game

This is a simple 2d exploration game written in OCaml.

It is intended to be a learning project and in time will hopefully serve as an example of how to write simple [terminal-based] games in OCaml.

Build and Launch

  1. Build dune build @install
  2. Launch 2d-exploration-game

How to Play

  • Use vim-style movement keys h, j, k, l (left, down, up, right) to move
  • Esc, Ctrl-C or 'q' to quit

Features

Current

  • Terminal graphics
  • Single-player
  • Movement using vim-style direction keys (H,J,K,L)
  • World generation with procedural psuedo-randomness
  • Entities - Humans and Trees
  • Items - Rocks
  • Players inventories
  • Centered game window
  • Worlds are not persistent and can't be saved

Ideas for Future

  • Multiplayer
  • World item interaction
  • Inventory item interaction
  • World entity interaction
  • Persistent worlds / save game
  • World size > 128x128
  • AI for world entities
  • User interface
  • Many more entities and items
  • Wearable and weildable items
  • Key binding configuration
  • Terrain
  • Turns
  • Optional high-res mode using GL

OCaml Program Notes

Structure and Code

For those interested in how this program is written/structured:

  • Uses notty for terminal graphics
  • Uses core.command for CLI parsing
  • World is stored in a list with items referenced via association
  • Everything is immutable
  • Modules are used and inherited
  • result and option types are used heavily to avoid exceptions where possible
  • No use of imperative language features

Program Improvement Ideas

  • Refactor randomness which is not really random
  • Use a better suited container (other than list association) for World
  • Move modules to their own source files
  • Define and use module interfaces
  • Use functors to generate various types/modules
  • Refactor rendering logic which feels a bit clunky
  • Logging with levels and UI/file output

If you have any work or suggestions that improve the way this program is written, feel free to contact me or make a PR.

About

A simple 2d exploration game written in OCaml

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages