O'Reilly logo

Game Programming Using Qt by Lorenz Haas, Witold Wysota

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – implementing the heartbeat event

The heart of AI is the heartbeat function that is executed at equal intervals of time to allow the AI to decide about the actions of the object. The script that is executed will have access to the creature that it operates on as well as its environment. It can also use anything that it defines in the this object. Now, add a heartbeat function to AIScript:

void AIScript::heartbeat(QScriptEngine *engine, QObject *personObject, QObject *otherObject) { QScriptValueList params; params << engine->newQObject(personObject); m_thisObject.setProperty("enemy", engine->newQObject(otherObject)); heartbeatFunction.call(m_thisObject, params); m_thisObject.setProperty("enemy", QScriptValue::UndefinedValue); } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required