• Stars
    star
    167
  • Rank 218,519 (Top 5 %)
  • Language
    F#
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

XNA + Elmish - 2D game development framework with F#

Xelmish - XNA + Elmish!

Nuget

Xelmish is a small project that creates an XNA Game loop (via Mono Game) and connects it to the Elmish MVU architecture, via a custom setState method in its own version of the classic Elmish.Program module (Xelmish.Program).

In this way, you can develop games using the excellent Elmish architecture, with all the power of an XNA renderer! You can also convert existing Elmish applications to use Xelmish by rewriting their view functions.

To use Xelmish, the Elmish program must provide a view function that returns a list of 'viewables', functions which take an XNA SpriteBatch. A set of common such functions like colour, image and text are provided in the Xelmish Viewables helper module.

Xelmish is for 2D games (the SpriteBatch object is for drawing textures, not rendering vertices). Hopefully it allows users to develop such games rapidly using the Elm architecture and F#!

Update: Available on Nuget here

Update Update: the project and its samples were recently upgraded to .NET 5. The older, dotnet core 2.2 version can be found in this branch, though its mainly just the framework that changed, not any code effectively.

Update Update Update: the project and its samples are now .NET 6, along with a MonoGame version bump.

Simple Example of Usage

The simplest usage of Xelmish is shown in the first sample, xelmish-first. This sample renders a square to the screen, and allows you to move and resize it with key presses. It doesnt have any loaded assets like textures, fonts or sound, and therefore also doesn't require the monogame content pipeline. Nice and simple.

I have decorated the code of Xelmish-first (what little there is) to give some general notes on Xelmish development, that will hopefully be useful in your own projects.

Once you have processed that, see the samples section below for a guide on the other, progressively more involved samples in the project.

Note: As Xelmish uses monogame, eventually you will have to learn about the monogame content pipeline. I suggest using the Monogame official documentation for this.

Development Info

Xelmish was developed first with Visual Studio Community 2017, then later with Visual Studio Community 2019, on various Windows 10 machines. A Visual Studio solution file is in the root of the project if you wish to build using these IDEs. However, it should be fully compilable from the command line and other IDEs if that is your preference.

It has been built with pure dotnet core 2.2, but has been upgraded without issue to .NET 5. So you will need to have the SDK for .NET 5 in order to compile. Xelmish and its samples have been tested on Windows 10, Mac OSX and Ubuntu 18.

It has been upgraded since to MonoGame 3.8, and the core Xelmish project made cross-platform. As part of this, the solution has been tested using Visual Studio 2022.

NOTE even with .NET 5 and official support for this as of MonoGame 3.8, I still needed to install Net Core 3.1 in order for the content builder to work. Not sure why... kind of annoying. Maybe the next version will fix this.

A note for Linux builders

On Linux the Monogame Content Pipeline may not work by default. If you get mono failure errors, try installing mono-complete, e.g. sudo apt install mono-complete. I was able to compile and run the samples on Ubuntu 18.04 after this without issue.

Note you also need the .NET 5 SDK to be installed on Linux in order to compile Xelmish and the samples.

Samples description

Under /samples, there are numerous projects that use Elmish and Xelmish. These are described below, in their order of complexity.

0. Xelmish-first

The most basic sample, described above. Just a coloured rectangle on the screen with move/resize commands.

1. Simple-Counter

The 'hello world' of Elmish, this sample should be almost identical (except for the Xelmish view) to other counters in other Elmish-* projects

There is also a Windows DX (Direct X API instead of OpenGL) version of this, to demonstrate cross platform support.

2. Sub-Model

An app with two sub components, each containing a counter and a clock. Pretty similar to other samples in Elmish projects, but with Xelmish views

3. Tetris-Clone

The game tetris, implemented using several elmish components for screens, with a relatively simple Xelmish view. Much more involved than prior samples, but still simple enough to follow easily I hope.

4. Space-Invaders-Clone

A clone of 1979's space invaders, though not a hundred percent accurate to the old version. Compared to Tetris, Space Invaders requires a great deal more events, animations and individual entities, so it serves as a good demonstration of how the bulky (compared to direct imperative style) Elmish eventing model performs in such a context.

This is also the first sample that uses audio, with retro beeps and explosions based on game events. Sounds and music are a little complex to handle in the Elmish/Monogame structure, due to their temporal differences from textures, which makes it worth seeing a real world example.

History and Reasoning

Xelmish has been built for the 2019 F# Applied Competition, but also as a replacement architecture for my prior fsharp-gamecore experimental engine.

Update: While Xelmish unfortunately did not win in the competition, my other submission did. Full results here.

While I have successfully built several small games with gamecore, I was finding that as my games increased in complexity the very simplistic model/view architecture in gamecore started to get stretched and warp. Things which were view-specific started to leak into model, and vice versa.

In contrast the battle-tested Elmish model has, so far, proved a pleasure to work with. Much more elegant, and it has also achieved in a far better way my goal of having games being purely functional (where performance permits) and agnostic of engine. The MVU architecture, and parent-child relationships that the Elm architecture handles so well, mean that a game can be designed and theorised without having the engine get in the way, which is (in my opinion) ideal.

License

Xelmish is provided under the MIT license. PLease contact me if you have issue with this. In addition, many if not all of the sample projects use fonts that are provided under the SIL Open Font License, a copy of which is in the root of the solution.

Credits

Everything in this repo has been built solely by me, in line with the requirements of the competition. That said, it references the Elmish library over Nuget, created by @et1975 and others. The ease of use of their library was what inspired the creation of this. I also learnt how to integrate with Elmish via Elmish.WPF, and how to use it well via this excellent article by @MangelMaxime, "My tips for working with Elmish"

More Repositories

1

FSH

F# Shell with integrated F# scripting. Like Bash or Powershell, but better 'cause F#.
F#
254
star
2

ctf-writeups

Write-ups of the vulnhub VMs I have done, and interesting TryHackMe rooms
Python
86
star
3

MiniKnight

A pixel-art platformer in F#, where you must fight your way to the portal, collecting coins and slaying orcs along the way!
F#
50
star
4

Tetris

Tetris in F#, dotnet core and MonoGame. Arcade sounds included!
F#
27
star
5

2d-games-with-unity-in-fsharp

My work through the 2D games with unity book by Jared Halpern and Apress, but using F# instead of C#
F#
26
star
6

golang-shellcode-runner

A shellcode runner / injector / hollower in Go, for windows
Go
23
star
7

DungeonRaider

A top-down action RPG prototype with a procedural dungeon, written in F# and MonoGame
F#
22
star
8

tiny-ray-caster

A tiny ray caster game rendered using raw SDL2, written in F#
F#
14
star
9

fsharp-gamecore

A fleshed out MonoGame core loop, that wraps all the mutable bits and provides hooks to construct a 2D game around.
F#
13
star
10

GiraffeBlog

A blog template made using Giraffe, dotnet core and entity framework core
F#
12
star
11

AdventOfCode

My solutions to the Advent of Code across various years
F#
10
star
12

RecklessDotNet

A remake of the 1998 game Ruthless.Com, in F# and MonoGame
F#
8
star
13

My-Exercism-Solutions

My exercism solutions to exercises on https://Exercism.io
C#
7
star
14

FSharpMonogameTemplate

F# + Dotnet Core + MonoGame + CoreRT starter project. Handles getting the config for the various bits right, while still leaving you with an F# blank Game class
F#
7
star
15

Wandering-Triangles

A JavaScript background animation of falling, wandering triangle lines
JavaScript
5
star
16

Battleship

The classic game Battleship, implemented in F# over a MonoGame core. Plays against AI
F#
5
star
17

slack-yara-scanner

A Slack App (AWS Lambda) for detecting and notifying on secret disclosure
YARA
4
star
18

Codex

fiction-focused word processor
F#
4
star
19

astar-search

A* Search algorithm in F#
F#
4
star
20

RealmOfFSharp

Realm of Racket exercises in F# instead of Racket. An exercise in functional programming against an imperative game engine (MonoGame)
F#
4
star
21

GrislyGrotto

Personal blog of Chris Pritchard and Peter Coleman
Rust
3
star
22

fsharp-gamecore-imgui

ImGui wrapper for use with Fsharp.GameCore
F#
3
star
23

HexMapTutorials

Experiemental 4X, following through the tutorials from catlike coding: https://catlikecoding.com/unity/tutorials/hex-map/part-1/
C#
3
star
24

Heightmaps

A collection of heightmap generators, along with some bmp/ppm image format savers
F#
2
star
25

my-aura-and-client-credentials

easy access for my creds - DONT MAKE PUBLIC
2
star
26

Substrate

A port to immutable and functional F# from the original Java implementation by j.tarbell (http://www.complexification.net/gallery/machines/substrate/)
F#
2
star
27

hack-weight

A web app designed to be accessed using mobiles for tracking weight and calorie consumption. Based on the 'Hacker Diet' methodology.
Go
2
star
28

JindoshRiddle

The Jindosh Riddle from Dishonered 2, solved using a F# bruteforce search
F#
2
star
29

godot-learning-games

Godot Learning Projects
GDScript
2
star
30

iced-experiments

Rust
2
star
31

bring

very small rust port forwarder
Rust
1
star
32

proposal-tetris

A tetris clone I used to surprise propose to my Wife.
C#
1
star
33

rosalind

My solutions to rosalind exercises, in Rust (formerly F#)
F#
1
star
34

shellcoders-handbook

My workings and experiments while working through the Shellcoder's Handbook.
C
1
star
35

UnitySpriteMetaParser

Simple project to pull the name, x, y, width and height values out of a sprite map meta file from Unity.
F#
1
star
36

five-card-draw-poker

A simple implementation of a simple variant of Poker, in F# and Elmish, for educational purposes.
F#
1
star
37

go-su-bru

Go based su password bruteforcer
Go
1
star
38

ZalgoTS

Small typescript library to C͕ͭ̆Ă̧̭͇̱̔͢L͎̲͙͕͓̃ͪ͑Lͬ҉̻ ̝̈̐̇THE͎̗̳͞ PȌ̢̄ͧ̎͏̩̳͔NY̴̼̏ͤ̂̽͂ H̨̜͙͚͍̞́͠E ͍̫̘̊C̐̊̂҉̣Ő̠͞MES ̸̟̦̳ͩ̏̄H̢̺̥̱͑̿E̘͛ ̏҉̬̣̺C̡O͉̖͈̲̯͖͌ͤMEṢ̷ͪ̀̑̓
TypeScript
1
star
39

NztmHelper

A small set of classes for the conversion of New Zealand Transverse Mercator coordinates to Latitude/Longitude, and back again. Entry point is the static class NztmHelper.
C#
1
star
40

over-the-rusty-wire

Rust
1
star