Using Lua with C++ in practice. Part 2. Implementing the basics

Source code for this article

Hello, this is a second part of “Using Lua with C++ in Practice” series. I recommend to read the first part to know what’s going on and why using Lua with C++ is awesome! (You’ll see it in this arcticle too, of course).

This tutorial will implement a simple ECS model which I’ll improve and use in other parts of tutorials. Note that this is not the best way to implement ECS. I’m making the most basic ECS which can be used to show the main principles of how things work in my game and how you can use them in general. This is not a tutorial about C++, so I won’t spend too much time discussing C++ parts and I’ll mostly focus on Lua/C++ interaction and binding. Let’s start!

Continue reading

Advertisements

Using Lua with C++ in practice. Part 1. Intro to ECS and basic principles

There are many reasons to use Lua with C++. One of them is that you can put some of the logic from C++ code into scripts, so you can easily change them without the need or recompilation. You can also write some good interfaces, so the scripts are easy enough for even non-coders to write them. Lua is free, Lua is fast, Lua is used in game development quite often.

While there are plenty of good articles about using Lua with C++, I think there are not enough articles about how to use Lua in real projects.

This article is one of the many articles I plan to write. Here are some topics which my articles will cover:

  •  Entity creation and other basic stuff (you’re reading this now)
  •  How to implement entity creation
  •  Managing Lua state and cleaning up
  •  Scriptable state machines
  •  Events and callbacks

The stuff described in the articles was mostly discovered during the development of my game called Re:creation.
I don’t think the methods here are perfect, but they’re good enough, fast and work well for me. So, your feedback is welcome. Feel free to leave comments and write e-mails to me about the stuff I can do better. I’m interested in hearing about your Lua/C++ usage!

While this is a C++ article, I think you can implement most of the things mentioned here in your favourite language. I’ll use Lua C API and LuaBridge for examples, so I recommend to read the following articles if you’re not familiar with them:

Continue reading

Re:creation dev log. March 2015. Graphics improvements, entity inheritance, improved state machines and more!

This month was great. I finally got in the flow of development and managed to get lots of things done. I worked hard to make game look better and here’s the result. Compare old screens with new screens:

October 2014

 

March 2015

Continue reading

Re:creation dev log. December 2014 – February 2015. Bigger levels, boss and heavy attack

A long time has passed since I’ve written the last dev log! Is Re:creation dead? Is it stagnating? No, not at all. It’s more alive than ever now!
I haven’t written a new part of dev log because I had to study a lot in December and January. I had some time to develop some stuff during these month and had a lot of stuff done in February.
I’ve decided to write the dev log in two forms

  • First one will be about the features I’ve implemented recently and it will have a lot of pretty screenshots and gifs. (You’re reading this part right now).
  • Second one will be more specific and I’ll focus more on technical parts of the game and implementation details of some interesting features. This part is a lot harder to write so it’ll be less frequent than the first one.
    If you’re wondering about how I’ve implemented one or another feature of the game or its engine, feel free to write an email and ask about it! I’m always glad to answer.

Well, let’s start.

Continue reading

2014 – Games, TV, Books and Music

2014 was a pretty good year. Oh, all games, movies, albums and books I’ve discovered… This post is about the best ones. Not all of them came out in 2014. This post is about things I’ve found this year.

Let’s start with games.

Games

Super Smash Bros. [3DS] (2014)

When Super Smash Bros. was announced for 3DS, I was very excited just as almost everyone who had 3DS. And what did we get? An amazing game which just nailed Smash Bros. feel and was filled with awesome content! The controls are very responsive, graphics are beautiful (and it runs in 60 fps!), music is amazing, online is good what more to ask? This game is awesome.

I didn’t play Super Smash Bros. for Wii U yet because I don’t have a Wii U.

Continue reading

Re:creation dev log. November 2014. Core game mechanic explained and more.

Re:creation info/press kit | Previous dev log

 

I did a lot of stuff this month and I’ll start with the most important thing.
I’m ready to present the core game mechanic in the game!

Recreation

I call this mechanic “recreation“. Here’s how it works.

First, you kill someone

Then you can become a ghost and travel around the screen without taking any damage and colliding with anything

You can’t get too far away from your body though!

When you are in the ghost form you can become the enemy you just killed

It gets revived in the zombie form. You don’t have many health in this form so you can’t complete an entire level like that, you’re most likely to die. When you die, you return to your original body.

This mechanic is used to solve puzzles and progress forward. Each enemy will have unique skills which will help you on your way.
Here’s an example of solving a simple puzzle.

I have some other puzzles but I can’t show them right now because they need to be polished! I also don’t want to spoil too much for people who read my dev logs.
There are lots of puzzles which can be invented with this mechanic and I’m really excited to work on puzzles involved it!

And now I’ll tell you about other things I’ve done

Continue reading

Using Lua with C++. Using Lua scripts with C++ classes.

Read the first part about LuaBridge here to see how to install it and use it for basic things.

You can find the complete source code of this article here

This part will show you how to register C++ classes in Lua, call member functions and how to apply scripts to something practical like putting object behaviour code in scripts.
I’m a game developer, so I’ve used examples related to gamedev but you can use Lua almost everywhere, so take a look even if you’re not interested in gamedev.
The code used in this article is as simple as possible while also remaining a complete example which you can run and compile.
I leave out the details which are irrelevant to focus on the main topic: scripts.

Continue reading