RogueSharp V3 Tutorial – Creating the Project

Next tutorial post – Multiple Consoles
Previous tutorial post – Introduction and Goals

Goal

In this tutorial we’ll get the RogueSharp and RLNET NuGet packages added to a brand new project.

Creating a new Console Project

I’ll be using Visual Studio 2015 for this project. The community edition can be found here: https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx

  1. Go to the File menu and choose New -> Project…
  2. From Templates choose Visual C# -> Windows -> Console Application
  3. Give it any name and location that want.
Console Application

Console Application

Adding NuGet Packages

Both RogueSharp and RLNET are available via NuGet and are easy to add to our project.

  1. Right click on the project (the name of your project will be whatever you named it in step 3 above)
  2. Choose Manage NuGet Packages… from the context menu.
Manage NuGet Packages

Manage NuGet Packages

Now you should be able to choose Browse and search for RogueSharp and RLNET. Make sure that the Package Source dropdown is set to nuget.org Click Install for both packages. As of this writing the latest version of RogueSharp is 3.0.0 and RLNET is 1.0.6. Note RLNet has a dependency on OpenTK so it will also install v1.1.225 of that library.

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.

Save to project directory

Save to 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.

Set Copy Always

Set Copy Always

The Code

A console application always includes a file called Program.cs which has a single Main() function which serves as the entry point.

Rename Program.cs to Game.cs

Now we’re going to add a bit of code to render a RLRootConsole with the text “It worked!” just to prove that we hooked up the NuGet packages correctly. I won’t go into a lot of detail here but if you want more depth check out these other tutorials.

using RLNET;

namespace RogueSharpV3Tutorial
{
  public class Game
  {
    // The screen height and width are in number of tiles
    private static readonly int _screenWidth = 100;
    private static readonly int _screenHeight = 70;

    private static RLRootConsole _rootConsole;

    public static void Main()
    {
      // This must be the exact name of the bitmap font file we are using or it will error.
      string fontFileName = "terminal8x8.png";
      // The title will appear at the top of the console window
      string consoleTitle = "RougeSharp V3 Tutorial - Level 1";
      // Tell RLNet to use the bitmap font that we specified and that each tile is 8 x 8 pixels
      _rootConsole = new RLRootConsole( fontFileName, _screenWidth, _screenHeight, 
        8, 8, 1f, consoleTitle );
      // Set up a handler for RLNET's Update event
      _rootConsole.Update += OnRootConsoleUpdate;
      // Set up a handler for RLNET's Render event
      _rootConsole.Render += OnRootConsoleRender;
      // Begin RLNET's game loop
      _rootConsole.Run();
    }

    // Event handler for RLNET's Update event
    private static void OnRootConsoleUpdate( object sender, UpdateEventArgs e )
    {
      _rootConsole.Print( 10, 10, "It worked!", RLColor.White );
    }

    // Event handler for RLNET's Render event
    private static void OnRootConsoleRender( object sender, UpdateEventArgs e )
    {
      // Tell RLNET to draw the console that we set
      _rootConsole.Draw();
    }
  }
}

If you run your project now you should see something like this:

RootConsoleRender

It Worked!

Here is the link to the final code on BitBucket

Advertisements

21 thoughts on “RogueSharp V3 Tutorial – Creating the Project

  1. Pingback: RogueSharp V3 Tutorial – Introduction and Goals | Creating a Roguelike Game in C#

  2. Pingback: RogueSharp V3 Tutorial – Multiple Consoles | Creating a Roguelike Game in C#

  3. 112madgamer

    I am using the same code that you have in this tutorial but when i run my screen flickers and then throws a ‘NVIDIA OpenGL Driver Too many errors occurred’ error code 1

    Reply
    1. Faron Bracy Post author

      Hello,
      Sorry to hear that you are having trouble running the code. RLNet uses OpenTK for which the repo can be found here -> https://github.com/opentk/opentk. While this is not a problem I’m familiar with, the best information I can find online seems to indicate that you should update your Nvidia drivers.

      If that still doesn’t work for you it help to know what hardware you are using and what driver version you have. Also, it would be helpful to know if you are using any sort of virtualization or are doing your development on a remote desktop. I know there have been some issues with OpenGL over a remote connection.

      Another thing you could try is substituting RLNet with another console like SadConsole and see if that works. https://github.com/Thraka/SadConsole/wiki/Roguelike-Tutorial-Part-1

      –Faron

      Reply
      1. 112madgamer

        I am using the latest NVIDIA Drivers and at the moment I have a 8600GT i have no issues with anything else. also can i port the RogueSharp v3.0 RLNet Tutorials to sadConsole?

  4. 112madgamer

    I am using the latest NVIDIA Drivers and at the moment I have a 8600GT i have no issues with anything else. also can i port the RogueSharp v3.0 RLNet Tutorials to sadConsole?

    Reply
    1. Faron Bracy Post author

      Hello,
      I have already ported the RogueSharp V3 sample game from RLNET to SadConsole. I posted a few weeks ago about it on the roguelikedev subreddit but didn’t really add any information here on this blog. I just added a post with the notes from the porting process. You can find out more about it and get the code here:

      https://roguesharp.wordpress.com/2016/05/02/porting-rlnet-v3-tutorial-to-sadconsole-and-monogame/

      Let me know if that’s what you were looking for when you were asking about a port or if you were wanting to rewrite all the tutorials explicitly for SadConsole.

      Hope that helps,
      Faron

      Reply
  5. clankers

    Hello,
    I’m using this tutorial and I’ve run into an issue. I know you’ve ported over from RLNET to SadConsole for the game but I want to keep using RLNET. Your example code throws a System.MissingMethodException error that occurs in RLNET.dll. This error occurs at line 20 of your script. The method not found is ‘Void OpenTK.NativeWindow.add_MouseMove(System.EventHandler`1)’. Any idea what’s causing this? I’m running the latest versions of RLNET, RogueSharp, and OpenTK. Thanks.

    Reply
    1. Faron Bracy Post author

      Hello and thank you for visiting,

      It’s not a problem that you use RLNET. I just made the port to SadConsole because some people had requested it.

      I haven’t seen that error before but I have a few things to try:
      * If you post your code to Github or Bitbucket I would be happy to take a look at it.
      * Another thing to try is getting my project off of Bitbucket and see if that causes the same issue: https://bitbucket.org/FaronBracy/roguesharpv3tutorial/src/f9ed225023bb22be224553478cbedfecfa7b1652?at=master
      * Although this shouldn’t matter. The exact versions I used are OpenTK 1.1.2225.0, RLNET 1.0.6, RogueSharp 3.0.0. Do those versions match the ones you are using?
      * If none of this helps try posting to the roguelike dev subreddit – https://www.reddit.com/r/roguelikedev Maybe someone else has ran into this issue and knows what is causing it.

      Hope that one of these will help,
      Faron

      Reply
      1. clankers

        I figured out the issue with that error. I was using OpenTK 1.1.2349.61993. I switched over to your recommended version of OpenTK and it no longer threw that error, but it did give this error after a bit of screen flickering (I have an NVidia Quadro FX 570 graphics card with the latest driver, and I’ve heard NVidia can be problematic with these things):

        An unhandled exception of type ‘System.AccessViolationException’ occurred in OpenTK.dll
        Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

        I’m not sure if this is just an NVidia thing or not, but from what I’ve read it is an issue that seems to correlate with this graphics driver. Is there anything I can do to fix this? I have worked with Thraka’s Sad Console, but his tutorials have not been continued and yours seemed more in-depth. If there is something I could do, please let me know. Thanks.

      2. Faron Bracy Post author

        I’m glad that you figured out the first error. I’m sorry that I don’t have more experience with these type of errors. The only things I know about it are what I have searched for online and I probably read the same things you did pointing at a possible driver issue.
        You might consider going to the opentk github repository located at https://github.com/opentk/opentk/issues and opening a new issue to see if they have any other ideas to try.

  6. introsp3ctive

    I’m getting an error when I run the project after following the exact instructions in the tutorial.

    “FileNotFoundException was unhandled”
    “An unhandled exception of type ‘System.IO.FileNotFoundException’ occured in RLNET.dll’
    “Additional information: cannot find bitmapFile”

    I’m using OpenTK 1.1.2225, RLNET 1,0,6, and RogueSharp 3.0.0.

    Reply
    1. Faron Bracy Post author

      The bitmap file it is referring to is terminal8x8.png. It has to have copy to output folder set to “Copy always” on it’s properties. If this doesn’t work for you try browsing directly to your bin/debug folder where the executable is and make sure that the terminal8x8.png file is there.

      Reply
      1. introsp3ctive

        Apparently when I copied it in, it went to a “solution items” folder. I moved it down to the right directory, and then it finally gave me the option to set it to “copy always”. Once that was done, it worked perfectly. Thanks for your help and thanks for writing the tutorial series.

  7. Jerry

    Would it be hard to get RLNET game working on Linux/OS X so that users don’t have have to jump through hoops with dependencies and such?

    Reply
    1. Faron Bracy Post author

      I’m not sure what it would take to port. I haven’t really worked on that codebase other than submitting a pull request for a minor bugfix. The source code is here -> https://bitbucket.org/clarktravism/rlnet. You could try opening a pull request or issue. The author is also on the roguelikedev subreddit so you could also try messaging him there.

      As far as RogueSharp goes, it has been a portable class library since version 1.2 (https://roguesharp.wordpress.com/2015/01/14/roguesharp-1-2-released-portable-class-library/) and I know that people are currently using it on Mac and Linux. From what I have seen they normally use it with MonoGame or Unity.

      If it turns out to be too difficult to port RLNet you could try a different console library. SadConsole is based on MonoGame and may already be cross platform, though I have never tried it on anything other than Windows.

      Reply
    2. Sean

      Hey, you’ve probably long solved this issue or moved on, but just in case anyone else was trying this tutorial on OSX I figured I’d speak up. I’ve started following this tutorial series and I’ve found that the new Visual Studio for Mac allows you to ad in RLNET and RogueSharp as Nuget packages pretty much as described above in this page.

      Reply
  8. sonreintelobos

    Not sure if this effort has been abandoned?… I am getting this error message. An unhandled exception of type ‘System.MissingMethodException’ occurred in RLNET.dll
    Additional information: Method not found: ‘Void OpenTK.NativeWindow.add_MouseMove(System.EventHandler`1)’.

    I copied your code from two different sources and yes I have the references to both RogueSharp and TLNET. I only get the runtime error but show no issues in VS 2013 professional. Hopefully this is not a problem with visual studio versions.

    Reply
    1. Faron Bracy Post author

      Sorry that you are running into problems. I believe it is because you are using a newer version of OpenTK that RLNet does not support. The exact versions that I used for the tutorial are OpenTK 1.1.2225.0, RLNET 1.0.6, RogueSharp 3.0.0. Do those versions match the ones you are using? If you look up in the comments above to one of the first comments, someone else had the same problem and switching OpenTK versions worked for them.

      Also, someone made a fork of RLNET that support the newer versions of OpenTK if you are interested in it here. https://bitbucket.org/clarktravism/rlnet/pull-requests/3/fork-liamwhan/diff#comment-None

      Hope this helps.

      Reply
  9. Bruno

    Hello, Im not as text savy and am new to game design (just finished a beginners game design course) but none the less I wanna try and learn this stuff. I did what I read to do, I went to the nuget thing and downloaded the stuff, then renamed the file to game.cs where it asked me something and moved the packages.config into it but for some reason I’m not able to import RLNET? Any idea? D;

    Reply
    1. Faron Bracy Post author

      Hello Bruno,
      I’m sorry to hear about the difficulties. To add RLNET you should just right click on the project and go to Manage NuGet Dependencies… Make sure the package source is set to Nuget.org then search for RLNET and click install. If it’s not working for you, you could download my code from the end of this tutorial and see if that works for you. https://bitbucket.org/FaronBracy/roguesharpv3tutorial/commits/tag/00HookupNuget

      Click on the download arrow to get the code. http://screencast.com/t/af6RclfRkLuL
      Note that to download the code you’ll have to have a Git client. There is a link provided to the Atlassian one which may be easier than using Git bash which comes with the Git download.

      Hope one of these will help you out.

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s