All Projects → ChrisPritchard → Tetris

ChrisPritchard / Tetris

Licence: Unlicense License
Tetris in F#, dotnet core and MonoGame. Arcade sounds included!

Programming Languages

F#
602 projects

Projects that are alternatives of or similar to Tetris

MonoGame.Primitives2D
Easy-to-use 2D primitives
Stars: ✭ 44 (+51.72%)
Mutual labels:  xna, monogame
Quaver
🎶 The ultimate community-driven, and open-source competitive rhythm game.
Stars: ✭ 282 (+872.41%)
Mutual labels:  xna, monogame
Gamedevelopmentlinks
This is a collection of useful game-development links including, but not restricted to, development with MonoGame.
Stars: ✭ 257 (+786.21%)
Mutual labels:  xna, monogame
Myra
UI Library for MonoGame, FNA and Stride
Stars: ✭ 348 (+1100%)
Mutual labels:  xna, monogame
Simplexrpgengine
Modular game engine built with MonoGame, with GMS2-like workflow and advanced level editor
Stars: ✭ 122 (+320.69%)
Mutual labels:  xna, monogame
Monogame
One framework for creating powerful cross-platform games.
Stars: ✭ 8,014 (+27534.48%)
Mutual labels:  xna, monogame
Xnagamestudio
The Education library from the Xbox Live Indie games repository, valuable for MonoGame Developers for advanced samples
Stars: ✭ 332 (+1044.83%)
Mutual labels:  xna, monogame
Magicallife
A 2d game that aspires to be similar to Rimworld, with more depth, magic, and RPG concepts.
Stars: ✭ 145 (+400%)
Mutual labels:  xna, monogame
Wallop
Extensible, living/animated wallpaper engine built in C# using Silk.NET's OpenGL wrapper at its core.
Stars: ✭ 27 (-6.9%)
Mutual labels:  xna, monogame
MonoGame.SplineFlower
Create wonderful smooth Bézier-, CatMulRom- and Hermite-Splines with Trigger Events for your MonoGame project.
Stars: ✭ 18 (-37.93%)
Mutual labels:  monogame
Apos.Gui
UI library for MonoGame.
Stars: ✭ 77 (+165.52%)
Mutual labels:  monogame
Super-Pete-The-Pirate
Source code of the game "Super Pete, The Pirate"
Stars: ✭ 37 (+27.59%)
Mutual labels:  monogame
Spritesheet
Simple helper for creating sprite based animations for Monogame.
Stars: ✭ 27 (-6.9%)
Mutual labels:  monogame
PaperMarioBattleSystem
Recreation of the turn-based battle system from the first two Paper Mario games
Stars: ✭ 37 (+27.59%)
Mutual labels:  monogame
Tetris
A (incomplete) terminal Tetris. Written in Haskell.
Stars: ✭ 26 (-10.34%)
Mutual labels:  tetris
MonoGame.Forms
MonoGame.Forms is the easiest way of integrating a MonoGame render window into your Windows Forms project. It should make your life much easier, when you want to create your own editor environment.
Stars: ✭ 183 (+531.03%)
Mutual labels:  monogame
nvim-tetris
Bringing emacs' greatest feature to neovim - Tetris!
Stars: ✭ 114 (+293.1%)
Mutual labels:  tetris
CppTetris
Tetris made within an hour
Stars: ✭ 104 (+258.62%)
Mutual labels:  tetris
Danmaku-no-Kyojin
Danmaku no Kyojin (弾幕の巨人) is a 2D danmaku developed in C# with XNA.
Stars: ✭ 14 (-51.72%)
Mutual labels:  xna
tetris
轻松10步用es6写出俄罗斯方块🎉
Stars: ✭ 30 (+3.45%)
Mutual labels:  tetris

Tetris

Classic tetris, implemented in F# with MonoGame. An exercise in functional programming and game solution design.

screenshot

Supported platforms

Being dotnet core 2.1, it should work on all platforms that supports (Windows, Linux, Mac). Tested (and largely coded on) Windows 10. A full list of dotnet core supported platforms can be found from here: https://github.com/dotnet/core/blob/master/release-notes/2.1/2.1-supported-os.md

I built this using VS Code, but have also tested opening and running on Visual Studio 2017.

A note for mac users: part of the compilation of this game involves building the content, done using a MonoGame content builder referenced via Nuget. On OSX, this component does not work with just dotnet core. I have managed to get it going by doing the following:

After the build succeeded, a sudo dotnet run started the game without issue.

Acknowledgements

The game and code is Unilicense, but I have used two sets of external resources:

Unfortunately I got this sound set a long time ago (five plus years) and can't find the exact provenance.

Guide to components

The five code files in this project are described below, in decreasing game importance. Aside from code, there is also the Content folder which contains images, sounds, fonts etc and the Content.mgcb file, which MonoGame uses to compile assets into the game exe. This compilation is triggered by a line in the Tetris.fsproj file (MonoGameContentReference Include="***.mgcb") and done by the builder referenced as a nuget package (MonoGame.Content.Builder). Should be automatic on build (though sometimes you need to build twice).

Model.fs

This file contains a pure F# representation of Tetris: types and DUs to represent the current game state, and functions to transition from one state to the next. It knows nothing of MonoGame, of inputs, resolutions or views - even Colour is an enum defined in Model.fs (which is later translated by View.fs)

The top of the file contains constants for the game, like score amounts, the game width, shape templates etc. The bulk of the file contains methods for transitioning different parts of the state, like processCommand and drop, while the final method AdvanceGame is the primary point of entry. This final method takes the previous/current state, an optional command (translated from Keys by Controller.fs) and an elapsed game time, and returns a new state.

Controller.fs

The controller's job is to control when the Model should be advanced, and to feed inputs into it. Primarily, if the game isnt over it will map user keys to Model commands, and pass through the current game time to the controller. Ultimately, the tiny Controller.fs file could be buried in Model.fs if it wasnt for a desire to keep Model.fs purity and hide the MonoGame keys construct. By splitting these out, how the game is controlled becomes an abstraction: blocks could be rotated or moved with the mouse if necessary, by modifying Controller.fs alone.

View.fs

If Controller.fs was about inputs, then View.fs is about outputs. It takes a model, and translates it to rendered sprites on the screen and sounds to be played. Despite this job, it is still largely agnostic of XNA, translating the model to abstractions which the GameLoop then uses. It is aware of the MonoGame colour construct, however, as mentioned.

GameCore.fs

GameCore is where all the MonoGame stuff is kept, and is basically the MonoGame.Game game loop class plus a bunch of abstraction types used to keep the other files pure. MonoGame is a class-based, imperative game development framework, that needs mutable types aplenty to work, and in order to keep my game largely free of these impurities, its all buried in here. GameLoop, the key class, is given the entry methods and model type from the other files, and orchestrates them. It could be viewed as the Imperative shell of the game.

Program.fs

This instantiates the GameLoop, passing through the methods and types from the other files, and handles disposal

CoreRT

There is a branch of this project called corert, that has CoreRT enabled. This has been tested to build on Windows, if you have the necessary requisites installed. Feel free to try it, but for support on getting it to build on Windows or Linux/OSX you will need to seek help at the CoreRT site.

Note on development sequence

This project was the first developed after Battleship here.

The next project developed after this, and using the lessons learned, was MiniKnight here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].