• Tutorials
  • Using existing Game Model Code (from other platforms) in Godot

Hi All,

-----boring preamble - skip the next two paragraphs----- Ok, probably some seriously naive questions coming up... First a bit of history: I started programming in BASIC on my old Sinclair ZX81 in the late 80s (a fair bit of BBC Micro too at school). My first proper computer was an Amiga 500 around 1989/1990, where I got big into 68K asm and coding games on the bare metal :-) By the mid/late 90's I was mostly using SAS C/C++ for all coding (still heavily Amiga based, but got into the habit of making code portable around this time). Then I moved into a different field entirely.

Around a decade ago, I got back into coding with Obj-C on the iPhone, and developed a little 2D RTS (very rigidly adhering to the MVC paradigm) which managed to bring in a nice little income... Again life moved on and I dropped coding for a while. When my first child was born in 2017, I had a bit of spare time so I ported my little RTS game model code from Obj-C to C# for use in Unity3D. This worked quite well, but Unity is a very "heavy" engine really geared towards 3D, and now Godot support C# I have decided I want try using Godot which is far better served with UI components.

----here begins the discussion topic---- So I have a collection of classes in C# which expose an interface via the "Game" class, the game runs pretty much as a black box (only needing a timer to call the Update() method at a defined interval), and can be queried to update the interface with information about the state of the world (I have implemented callbacks, so the game model code can update the interface etc...), etc...

My first instinct has been to load the game model code as a script in the Scene root node; This can then create an instance of the Game class, which then using the _Process() method to run the game model. Now I have built a UI (and I think figured out "signals") in the Node2D tree which can provide user input back into game object, but to give the user feedback about the state of the game world I am trying to use a Canvas object which will query the Game object and updates its graphical state as required... can't really get this to work at the moment...

This seems to be a very clumsy approach to structuring a game in Godot, negating the use of the engine, would I be better served rebuilding my game model using Godot nodes, or some other way? Godot is quite different to how I normally think.

Ok, so after a bit of playing with Godot, I have made a few observations (please correct where I have made mistakes); Scenes are not actually scenes, rather they are "Constructs", and can be used to build game components. These constructs are trees of nodes to define the construct's properties and behaviours. The biggest conceptual leap is the differentiation of a scene definition from the instance of a scene. When editing a scene it is also instantiated, this can be confusing.

The game model code should reside in a "singleton" node, this can then be referenced (GetNode("/root/whatever")) by other nodes for ""world data" and common databases. This is seems pretty logical.

Making signal connections in the editor is confusing, doing it is code is tedious but makes the structure far clearer.

The anim sprite editor appears to be rather rudimentary, and unhappy with sprite sheets which are not neatly structured as regular rectangles... :s

I don't get on well with GDScript (probably due to over 20 years of C/C++ experience) and the C# documentation is horrible :)

a month later

I’m new to Godot and I’ve worked with both dynamic and static typing languages (C, Obj-C, JS, TS)

I like GDScript so far as it makes for very rapid prototyping. But I’d probably move to C# once support is better just to learn the language in case I needed to move to Unity or Unreal

The sprite support you’re looking for may be Atlas - https://godotengine.org/article/atlas-support-returns-godot-3-2

Not used it yet myself, I came across the same issue importing a sprite sheet and had to remap it to use equally sized sprites, but atlas might be the better route to achieve that

my experience is a bit similar as well, i started on zx81, as on apple-ii and cp-m machines in my childhood, and often used some of the 8bit computers from the 80s (zx-spectrum, msx, coco, etc.) - 16 bit was mostly on Amiga (used Amos a lot) and Apple, and my first i386 machine (a pentium 2) i bought because those GNU/Linux CDs always found abundantly on journal kiosks (that time that downloading iso files were terribly slow and expensive)

for what i found around all object-based game engines, i guess that the best is trying everything (and here is Godot, taking less of 1% of the disk space Unity takes, and able to do almost the same thing), and being able to develop whatever code in whatever language, so i guess that, instead of moving, the best thing to do is to be able to code on every language as possible, as we never know when a language might get obsolete (like happened with Cobol and others)

for me, c# is a huge headache (sometimes makes very simple things extremely complicated unnecessarily ), and Python-based languages (like cgscript is?) seem way neater compared to it - another very good language could be used in object-based game engines is Lua (i guess that Cry engine uses it?)

about Python language, i have some few examples at http://nitrofurano.altervista.org/python/ (i don't use pep-8 norm, but you can see there how is the syntax used there)

a month later

@nitrofurano said: for me, c# is a huge headache (sometimes makes very simple things extremely complicated unnecessarily ), and Python-based languages (like cgscript is?) seem way neater compared to it - another very good language could be used in object-based game engines is Lua (i guess that Cry engine uses it?)

about Python language, i have some few examples at http://nitrofurano.altervista.org/python/ (i don't use pep-8 norm, but you can see there how is the syntax used there)

I’ve spent so long using C/C++/Obj-C that when I try to use GDScript, it feels like trying to draw using jumbo crayons while wearing boxing gloves... at least with C# I don’t feel like I’m wearing boxing gloves :)

I guess I spent a lot of time using Flash back in the day and Godot feels very similar in how it's set up and easy to script. Initially I looked at Godot (maybe 2 years ago) and didn't even consider it because it used a custom language. However, after giving it a good go I realized that GDScript is actually very good and purpose fit for game development. So I like it.

I've also done a lot of C++ coding lately, and the easy of productivity in Godot is a breath of fresh air. In C++ I feel you can do a whole lot, but you can also struggle with things that become overly complex for no reason. Like when you have a problem and think templates will fix it, and I love templates, but the code can become monstrous because you are bending things too far.

The boxing gloves are there so you don't hurt yourself. :p

I am making an open source C# job system, similar to that found in unity: https://github.com/jasonswearingen/godot-csharp-tech

part of the reason is that I want to build up the simulation/rules stand-alone, with the presentation being abstracted away to godot.

Bringing it back to your topic: I think this is the only way to "bring in code from other platforms". you need some kind of abstraction layer.