Skip to content

Commit

Permalink
Add entity:apply_force
Browse files Browse the repository at this point in the history
Co-authored-by: griffi-gh <[email protected]>
  • Loading branch information
rollerozxa and griffi-gh committed May 10, 2024
1 parent 2575232 commit 40833e6
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/src/escript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,27 @@ extern "C" {
return 0;
}

/* entity:apply_force(x, y) */
static int l_entity_apply_force(lua_State *L)
{
ESCRIPT_VERSION_ERROR(L, "entity:apply_force", "1.5.1", LEVEL_VERSION_1_5_1);

entity *e = *(static_cast<entity**>(luaL_checkudata(L, 1, "EntityMT")));
float x = luaL_checknumber(L, 2);
float y = luaL_checknumber(L, 3);

b2Vec2 force(x, y);

for (uint32_t x = 0; x < e->get_num_bodies(); ++x) {
b2Body *b = e->get_body(x);

if (b)
b->ApplyForceToCenter(force);
}

return 0;
}

/* entity:set_velocity(x, y) */
static int l_entity_set_velocity(lua_State *L)
{
Expand Down Expand Up @@ -3565,8 +3586,8 @@ static const luaL_Reg entity_methods[] = {
LUA_REG(is_static),
LUA_REG(absorb),
LUA_REG(apply_torque),
LUA_REG(apply_force),
LUA_REG(set_velocity),
//LUA_REG(apply_force),
LUA_REG(warp),
LUA_REG(show),
LUA_REG(hide),
Expand Down

0 comments on commit 40833e6

Please sign in to comment.