本文整理汇总了C++中Door::setScript方法的典型用法代码示例。如果您正苦于以下问题:C++ Door::setScript方法的具体用法?C++ Door::setScript怎么用?C++ Door::setScript使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Door
的用法示例。
在下文中一共展示了Door::setScript方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processEvents
// process all events that are specified in the level file
void Script::processEvents(const vector<World::scriptPos>& scripts){
//vector<World::scriptPos>::iterator it = scripts.begin();
//while (it != scripts.end()){
for (unsigned i = 0; i < scripts.size(); i++){
World::scriptPos sp = scripts[i];
ScriptInfo* si = new ScriptInfo;
//a trap?
if (islower(sp.script[0])){
if (sp.script[0] < 'n')
lua_getglobal(L, "trapScheduler");
else
lua_getglobal(L, "eventScheduler");
si->isTrap = true;
}
else{
lua_getglobal(L, "eventScheduler");
si->isTrap = false;
}
lua_pushstring(L, sp.script);
if (lua_pcall(L, 1, 1, 0) != 0){
cerr << lua_tostring(L, -1);
}
string event = luaL_checkstring(L, -1);
lua_pop(L, 1);
si->pos = sp.pos;
si->script[0] = sp.script[0];
si->script[1] = sp.script[1];
if (event == "OnInit"){
lua_getglobal(L, sp.script);
lua_pushnumber(L, sp.pos.x);
lua_pushnumber(L, sp.pos.y);
if (lua_pcall(L, 2, 0, 0) != 0){
cerr << lua_tostring(L, -1);
}
}
else if (event == "OnTreasure"){
si->event = OnTreasure;
scripts_.push_back(si);
Field& f = wrld.getField(si->pos);
f.script = scripts_.back();
}
else if (event == "OnWalkAt"){
si->event = OnWalkAt;
scripts_.push_back(si);
Field& f = wrld.getField(si->pos);
f.script = scripts_.back();
}
else if (event == "OnOpen"){
si->event = OnOpen;
scripts_.push_back(si);
Door* d = wrld.getDoor(si->pos, TOP);
if (d)
d->setScript(scripts_.back());
d = wrld.getDoor(si->pos, RIGHT);
if (d)
d->setScript(scripts_.back());
d = wrld.getDoor(si->pos, BOTTOM);
if (d)
d->setScript(scripts_.back());
d = wrld.getDoor(si->pos, LEFT);
if (d)
d->setScript(scripts_.back());
}
else{
cerr << "Unknown script event: "+event;
}
//TODO
/*
lua_getglobal(L, sp.script);
lua_pushnumber(L, sp.pos.x);
lua_pushnumber(L, sp.pos.y);
if (lua_pcall(L, 2, 0, 0) != 0){
cerr << lua_tostring(L, -1);
}
*/
//it++;
}
}