开发者

General game (RTS) scripting basics

I've been into several tutorials and links for how to integrate scripting into games--but most of these don't start early enough in the process for me. I am trying to wrap my head around the basic structure of an effectively scripted game. Here are the basics:

I'm working on starting a basic 2d RTS game in C++. The mechanics of the game and the graphics are pretty standard/simple, rather the logic and data will be extremely complicated compared to a standard RTS. Obviously, I have a lot of planning to do--and really, the point of this is more to learn C++, scripting, game programming basics rather than actually complete my project.

I'm trying to figure out which elements of my project should be handled by scripting and which should be included in my core "game engine".

For instance, the all powerful "game loop" -- do I program this in C++ as part of the engine, or will my "engine" be solely what I use for displaying graphics (tiles, characters, etc...), processing the large amounts of data, and similar tasks--and these classes get "plugged into" the game loop, which is scripted?

I would like to use C# as a scripting language, from what I've read it offers good speed while still allowing to develop in VS, which I like. But really, I'm more concerned with how it's all supposed to get set up, more from a开发者_JAVA百科 pseudo-code level than the actual coding. There's plenty of resources I can use when I get to this point, I'm just looking for advice on how to structure the whole thing.

Any tutorials, resources, advice would be greatly appreciated! Thanks!


icnivad's recommendation for Programming Game AI by Example is an excellent one, it's chock full of practical information.

In terms of actual engines, Unity does the job and lets you script in C#, but for someone, such as yourself, who wants to learn the nuts and bolts, it may hide too much and do too much for you. Irrlicht is a pretty solid C++ engine and comes with lots of tutorials to get you started; it also has a very clear interface and a pretty active community. In terms of what you want to write in C++ and what you want to script, I suggest taking a hard look at what you actually need to script--if you need to script anything at all. You could write the entire thing in C++, which has the advantage of being more easily debuggable. Speaking of which, if you're still new to C++ and game dev you might want to stick to just C++ at first (if not, just ignore this).

"Debuggability" is one of the things you should be paying attention to, since it can often be extremely hard to debug C++ and script code at the same time (when you're shuttling data and instructions back and forth). That said, once you have your framework up and running, implementing new features and tweaking stuff can be a breeze.

You may want to take a look at Lua as a scripting language, as it's quite popular for game scripting. Luabind, a popular binding library for C++ and Lua, is pretty easy to use. SWIG is also available (a short tutorial on it popped up on a blog at GameDev.net recently).

No matter which scripting language you choose (if any), make sure you work on some separate toy programs with them first. Get used to the language and fiddle around with it. Then try small programs with minimal C++ <-> script interop. Do only a few steps at a time so you can spot errors and note what works and what doesn't. Once you feel ready to start integrating scripts into your game, do only one step at time and test it to death before moving on. Speaking of which, make sure you also plan how and where you'll connect your scripts to the game on paper first--it makes things much easier.

Generally, you'll want to put all the heavy work on C++'s shoulders (like the game loop, graphics, pathfinding, etc.). I've found that scripts are usually best for things like configuration files, behavior code for AI characters, UI, and event handling. Basically, if you're going to tweak/change something a lot or you want other people to be able to change something, it's a candidate for scripting (no recompiles for the win!). Just remember that a lot depends on your specific game--if scripting something would be too slow (use your profiler to check), too cumbersome, etc., don't be afraid to do it in C++ and call it from the script or just do it entirely in C++.

Hope that helps!


The book Programming Game AI By Example is superb, and touches on just what you are looking for regarding game loops, using scripting (like LUA), and tons of examples of stuff that seem especially pertinent to you.

By the way, potentially relevant is the Unity3D game engine that lets you use C# for scripting. And there is also Garage Games engines, including the game builder kits that could help you create an RTS type game, and I believe you may be able to code in C# for Torque as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜