added ag::isKeyDown; Engine keeping track of which keys are currently pressed
git-svn-id: svn://anubis/anaglym/trunk@99 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
parent
c63a4bb808
commit
c6319a3a1b
@ -256,6 +256,11 @@ int Engine::loadModel(const string & name, bool static_data, float scale)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Engine::isKeyDown(const std::string & key)
|
||||
{
|
||||
return m_keysDown.find(key) != m_keysDown.end();
|
||||
}
|
||||
|
||||
/* called by SDL when the update timer expires */
|
||||
Uint32 Engine::updateCallback(Uint32 interval, void * param)
|
||||
{
|
||||
@ -336,6 +341,10 @@ void Engine::update()
|
||||
|
||||
void Engine::key_event(int keysym, bool pressed)
|
||||
{
|
||||
if (pressed)
|
||||
m_keysDown[sdl_keymap[keysym]] = true;
|
||||
else
|
||||
m_keysDown.erase(sdl_keymap[keysym]);
|
||||
lua_getfield(m_luaState, LUA_GLOBALSINDEX,
|
||||
pressed ? "key_pressed_event" : "key_released_event");
|
||||
if (lua_type(m_luaState, -1) == LUA_TFUNCTION)
|
||||
|
2
Engine.h
2
Engine.h
@ -84,6 +84,7 @@ class Engine
|
||||
void endFrame();
|
||||
int loadModel(const std::string & name, bool static_data,
|
||||
float scale = 1.0f);
|
||||
bool isKeyDown(const std::string & key);
|
||||
|
||||
/* lua services */
|
||||
int setCamera(lua_State * L);
|
||||
@ -119,6 +120,7 @@ class Engine
|
||||
bool m_autoStartFrame;
|
||||
bool m_autoEndFrame;
|
||||
bool m_autoDrawObjects;
|
||||
std::map<std::string, bool> m_keysDown;
|
||||
};
|
||||
|
||||
extern Engine * g_engine;
|
||||
|
11
ag.cc
11
ag.cc
@ -36,6 +36,7 @@ namespace ag
|
||||
{ "setAutoStartFrame", setAutoStartFrame },
|
||||
{ "setAutoEndFrame", setAutoEndFrame },
|
||||
{ "setAutoDrawObjects", setAutoDrawObjects },
|
||||
{ "isKeyDown", isKeyDown },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
luaL_register(L, "ag", functions);
|
||||
@ -245,6 +246,16 @@ namespace ag
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isKeyDown(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
if (argc == 1 && lua_isstring(L, 1))
|
||||
lua_pushboolean(L, g_engine->isKeyDown(lua_tostring(L, 1)));
|
||||
else
|
||||
lua_pushboolean(L, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
namespace object
|
||||
{
|
||||
static Engine::Object * getObject(lua_State * L, int index)
|
||||
|
1
ag.h
1
ag.h
@ -22,6 +22,7 @@ namespace ag
|
||||
int setAutoStartFrame(lua_State * L);
|
||||
int setAutoEndFrame(lua_State * L);
|
||||
int setAutoDrawObjects(lua_State * L);
|
||||
int isKeyDown(lua_State * L);
|
||||
|
||||
namespace object
|
||||
{
|
||||
|
@ -2,6 +2,9 @@
|
||||
function update_event()
|
||||
ballx, bally, ballz = ball:getPosition()
|
||||
ag.setCamera(7, -6, 15, ballx, bally, ballz, 0, 0, 1)
|
||||
if (ag.isKeyDown("m")) then
|
||||
ball:setPosition(-7, 7.4, 12)
|
||||
end
|
||||
end
|
||||
|
||||
function key_pressed_event(key)
|
||||
|
Loading…
x
Reference in New Issue
Block a user