Using RogueSharp with RLNET Console
v2 RLNET Tutorials
People have asked me if it is possible to use RogueSharp without using MonoGame. They’ve also asked how to use RogueSharp to make a classic ASCII game. Though MonoGame is a great framework there are plenty of other ways to create games in C#. Today I’m going to show how to use RogueSharp with RLNET which is a lightweight API to help quickly create tile-based games for .NET.
Goal
In this tutorial we’ll get RogueSharp and RLNET added to a brand new project. We’ll render the console which will be a cave-like map and intercept keyboard commands to be able to move the player represented by an ‘@’ through the ASCII cave. We’ll calculate field-of-view and render what the player can see as well as what they have previously explored. Best of all we’ll do this in just a few lines of code.
Creating a new Console Project
I’ll be using Visual Studio for this Project.
- Go to the File menu and choose New -> Project…
- From Templates choose Visual C# -> Windows Desktop -> Console Application
- Give it any name and location that you want.
Adding NuGet Packages
Both RogueSharp and RLNET are available via NuGet and are easy to add to our project.
- Right click on the project (the name of your project will be whatever you named it in step 3 above)
- Choose Manage NuGet Packages… from the context menu.
Now you should be able to choose Online -> nuget.org and search for RogueSharp and RLNET. Click Install for both packages. As of this writing the latest version of RogueSharp is 2.0.0.0
Adding a Font File
RLNET needs a special font file like libtcod uses. If you aren’t familiar with this and want to know more about it there is good information here.
But for our purposes just right click and download this image and place it in your project directory.
Once the file is in your project directory, you should be able to Right Click on your project in Visual Studio and choose Add -> Existing Item… Choose the image that you saved and it should show up in the project. Make sure to set the Properties of this file to Copy always.
The Code
Because I’ve already produced a bunch of tutorials for RogueSharp and RLNET has it’s own set of tutorials I’m not going to explain each step. The code is only about 100 lines with comments and extra spacing and hopefully my comments are sufficient to help you out. Just copy and paste the code block below into Program.cs
If you run your project now you should see something like this:
Here is the link to the final code on BitBucket
Additional Fun
The eleventh Seven Day Roguelike Challenge is nearly upon us! I urge you to participate. If you don’t like RogueSharp or C# there are plenty of other RogueLike libraries out there for most languages.
There are also more .NET console libraries that should work well with RougeSharp. Why don’t you give them a try, or go further with RLNET. If you haven’t used C# before maybe try it for your 7DRL this year.
- SadConsole – Works with MonoGame! I haven’t tried it yet but want to soon.
- Malison – I have not tried this one yet either but it looks promising.
- RLNET – What we used in this tutorial.