mirror of
https://github.com/love2d/love-android.git
synced 2026-08-21 21:15:34 +02:00
actual cool scripting
This commit is contained in:
@@ -2,3 +2,4 @@ bin/
|
||||
libs/
|
||||
obj/
|
||||
.*.swp
|
||||
.*~
|
||||
|
||||
+11
-1
@@ -1,7 +1,17 @@
|
||||
engine.log("logginf from FIIILLLEEEE")
|
||||
engine.log("Log Message from Lua ;D")
|
||||
engine.set_color (1., 0., 0.)
|
||||
|
||||
function on_touch(x, y)
|
||||
engine.log ("got touch at " .. tostring(x) .. "," .. tostring(y))
|
||||
engine.set_color (0., 1., 0.)
|
||||
end
|
||||
|
||||
function update(dt)
|
||||
r,g,b = engine.get_color()
|
||||
|
||||
r = math.max(0., r - dt * 0.4)
|
||||
g = math.max(0., g - dt * 0.4)
|
||||
b = math.max(0., b - dt * 0.4)
|
||||
|
||||
engine.set_color (r, g, b)
|
||||
end
|
||||
|
||||
+25
-2
@@ -43,7 +43,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int l_graphics_setcolor(lua_State *L) {
|
||||
int l_get_color (lua_State *L) {
|
||||
lua_pushnumber (L, graphics->color[0]);
|
||||
lua_pushnumber (L, graphics->color[1]);
|
||||
lua_pushnumber (L, graphics->color[2]);
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
int l_set_color(lua_State *L) {
|
||||
SDL_Log ("[Lua] setcolor was called");
|
||||
|
||||
if (lua_gettop(L) != 3) {
|
||||
@@ -91,7 +99,8 @@ int l_log (lua_State *L) {
|
||||
}
|
||||
|
||||
static const struct luaL_Reg enginelib[] = {
|
||||
{"set_color", l_graphics_setcolor},
|
||||
{"get_color", l_get_color},
|
||||
{"set_color", l_set_color},
|
||||
{"log", l_log},
|
||||
{NULL, NULL}
|
||||
};
|
||||
@@ -138,6 +147,14 @@ void l_call_on_touch (lua_State *L, int x, int y) {
|
||||
}
|
||||
}
|
||||
|
||||
void l_call_update (lua_State *L, float dt) {
|
||||
lua_getglobal (L, "update");
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushnumber (L, dt);
|
||||
lua_pcall (L, 1, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int width = 1080;
|
||||
@@ -190,6 +207,8 @@ int main(int argc, char * argv[])
|
||||
SDL_Log ("could not open file");
|
||||
}
|
||||
|
||||
unsigned int last_time = SDL_GetTicks();
|
||||
|
||||
//Game Loop
|
||||
SDL_Event event;
|
||||
auto done = false;
|
||||
@@ -286,6 +305,10 @@ int main(int argc, char * argv[])
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int current_time = SDL_GetTicks();
|
||||
l_call_update(L, static_cast<float>(current_time - last_time) * 0.001f);
|
||||
last_time = current_time;
|
||||
|
||||
graphics->update();
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user