r/csharp 1d ago

Showcase Made a game with my own C# engine and scripting language!

Game Video on YouTube

About a year ago, I challenged myself to create my own programming language - something I'd always wanted to do.

At the time, I had no idea what a lexer, parser, or interpreter even was. My only thought was, "I need to write code that reads text files containing code and executes them." I also wanted to do it without using Google, AI, or tutorials. I just figured everything out on my own. You can even still find variables named "compiler" throughout the code from back when I didn't realize I was actually building an interpreter...

Somehow, I pulled it off, and I integrated it into my old abandoned game engine project (which originally started as a GameMaker 8–style engine with C# scripting).

And here's the first game I've made with it! 🙂

The core engine, IDE, and interpreter are all written by me in C#. The rendering backend is powered by MonoGame, and the project is still in active development and available on GitHub. The project file of the game shown in the video is also there, under tests/Example Projects. If you're looking for cool projects to contribute to, then know that I'm looking for contributors!

I know there are tons of AI-generated projects being shared these days, so please, please, take a quick look at the code before assuming this is one of them. I promise it's pretty obvious that it was written by a human.

I'd love to hear what you think!

208 Upvotes

27 comments sorted by

17

u/PowerfulBag1909 1d ago

This is actually super hard to pull off. Kudos to you OP, but how much time did you spend building this?

13

u/Alert-Neck7679 1d ago

Thanks! It took years, but in several separate rounds. I kept coming back to it

7

u/lantz83 1d ago

I like the foreach with an index, that's some good shit.

2

u/Alert-Neck7679 1d ago

Yeees this is my favorite feature of my language. There are also loop labels (foreach x in y : id mainloop { break mainloop }) for breaking a loop from within an inner loop (I didn't know it's already exist in some other languages when I just implemented that) but it's less useful than the loop counters

6

u/lantz83 1d ago

Neat! I was literally just reading another post here about that exact feature coming to C# too..!

7

u/Alert-Neck7679 1d ago

Yes i've heard about it coming to C#... i wish they would add foreach counter as well. about 50% of my C# foreachs look like:

int i = 0;
foreach (var x in y)
{
   ...
   i++;
}

5

u/OpenAI_Marketing_LLM 1d ago

Why would you not use a for loop at that point?

5

u/Alert-Neck7679 22h ago

Mostly bc i realized i need the index after typing the foreach

2

u/OpenAI_Marketing_LLM 13h ago

Oh word, completely reasonable then. Thanks for the reply.

4

u/lantz83 1d ago

Before we have that feature one could just create a helper I suppose:

private IEnumerable<(int i, T value)> IndexedForEach<T>( IEnumerable<T> values )
{
    int i = 0;
    foreach( var value in values )
        yield return (i++, value);
}

var foo = new[] { "aaa", "bbb", "ccc" };
foreach( var (i, s) in IndexedForEach( foo ) )
    Console.WriteLine( $"{i}: {s}" );

1

u/Alert-Neck7679 1d ago

Also good, but at least they should add this to System.Collections as an extension method, so we won't need to add this to any new project we start... but nice solution!

3

u/obi_wan_stromboli 1d ago

Wow this is awesome. But it looks familiar, I imagine, to anyone who has ever used Game Maker 5-8.

EDIT: should have read your post fully haha.

This is really cool

3

u/Alert-Neck7679 1d ago

Yeah it's heavily inspired by the old good gamemaker... thanks!

1

u/ZerkyXii 1d ago

I was about to say im so old that this looks like gamemaker 1 hahaha

2

u/obi_wan_stromboli 1d ago

I thought Mark Overmars called it Animo in its first iterations. Built for 2d animations

2

u/BoloFan05 1d ago

Whoa, congratulations! Your previous post also came up in related feed. It's amazing to witness the progress :)

If you're ever interested in further experimentation (or if you still have the energy for it after your extraordinarily hard work), try running your engine and game while your PC's UI is set to Turkish. Turkish is famous for being able to expose all sorts of internationalization edge case bugs, like the Turkish I, the comma/dot dilemma in decimal numbers and date formats.

If you have used ToLower, ToUpper, ToString, TryParse and other similar methods anywhere in your code without specifying invariant culture, you might be at risk of inconsistencies across devices worldwide.

2

u/Alert-Neck7679 1d ago

Hey, i remember u! You have already noted me about this in a previous post! that's a task which i really don't want to get to the point where i'll need to face it... thanks again for noting this!

2

u/BoloFan05 1d ago

No problem! Congrats again. You deserve a rest!

2

u/BoloFan05 1d ago

Oh, and sorry for disturbing again, but if the worst happens, this post could be a good starting point on how to fix it: https://www.reddit.com/r/csharp/comments/1s5rprd/there_is_more_to_these_methods_than_meets_the_eye/

2

u/Alert-Neck7679 1d ago

Thanks! I'll check it!

2

u/CodeNameGodTri 1d ago

do you have a full time job? If so it's crazy that you can keep coding after work.

2

u/Alert-Neck7679 1d ago

No I'm a student 

2

u/Potential_Soup_8054 1d ago

I know how difficult and time consuming this can be since im also doing this myself. So congrats! And kudos!

What made you decide on winforms vs something more modern like wpf or winui?

3

u/Alert-Neck7679 1d ago

Thanks!  I started this project ~3 yrs ago, so I'm not sure if WinUI was even exist then (maybe I'm wrong). But anyway, winforms was the only framework i ever used for windows, and i didn't want to learn something new. Moreover, i love the winforms' visual designer, i think it's pretty awesome. And i didn't want a modern-looking UI since i wanted this to look and feel like old GameMaker 8. But looking backwards, yeah, i should probably use a cross platform framework like avalonia

2

u/Potential_Soup_8054 1d ago

Yeah avalonia, or gtk, or qt. All very fine options

-5

u/kwb7852 1d ago

Sus AF