Skip to content

Commit

Permalink
adds possibility of reading and changing gravity x and y for a world
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Dec 28, 2019
1 parent c1a6ad5 commit 64ad7b5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
17 changes: 17 additions & 0 deletions agsbox2d/AgsWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ AgsContact* AgsWorld::GetContact(int32 i) {
return new AgsContact(contact, ID);
}

float32 AgsWorld::GetGravityX(){
return Scale::ScaleUp(B2AgsWorld->GetGravity().x);
}

float32 AgsWorld::GetGravityY(){
return Scale::ScaleUp(B2AgsWorld->GetGravity().y);
}

void AgsWorld::SetGravityX(float32 g_x){
B2AgsWorld->SetGravity(b2Vec2( Scale::ScaleDown(g_x),B2AgsWorld->GetGravity().y));
}

void AgsWorld::SetGravityY(float32 g_y){
B2AgsWorld->SetGravity(b2Vec2( B2AgsWorld->GetGravity().x,Scale::ScaleDown(g_y)));

}

AgsWorld::~AgsWorld(void)
{
}
Expand Down
5 changes: 5 additions & 0 deletions agsbox2d/AgsWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class AgsWorld
AgsFixtureArray* BoundingBoxQuery(float32 lx, float32 ly, float32 ux, float32 uy);
AgsRaycastResult* RaycastQuery(float32 x0, float32 y0, float32 x1, float32 y1, RaycastType raycastType, AgsFixtureArray* agsFixtureArray);

float32 GetGravityX();
float32 GetGravityY();
void SetGravityX(float32 g_x);
void SetGravityY(float32 g_y);

int32 GetContactCount();
AgsContact* GetContact(int32 i);
};
Expand Down
28 changes: 28 additions & 0 deletions agsbox2d/agsbox2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@ const char *ourScriptHeader =
" /// Returns a sprite with debug data. Set as GUI Background over screen for debugging your physics. \r\n"
" import int GetDebugSprite(int camera_x = 0, int camera_y = 0); \r\n"
" \r\n"
" /// World Gravity X axis. \r\n"
" import attribute float GravityX; \r\n"
" \r\n"
" /// World Gravity Y axis. \r\n"
" import attribute float GravityY; \r\n"
" \r\n"
" /// Returns array of fixtures which their bounding boxes are overlapped by the supplied box. \r\n"
" import FixtureArray* BoundingBoxQuery(float lower_x, float lower_y, float upper_x, float upper_y); \r\n"
" \r\n"
Expand Down Expand Up @@ -1011,6 +1017,24 @@ AgsContact* AgsWorld_GetContacts(AgsWorld* self, int32 i) {
return contact;
}

uint32_t AgsWorld_GetGravityX(AgsWorld* self) {
return ToAgsFloat(self->GetGravityX());
}

uint32_t AgsWorld_GetGravityY(AgsWorld* self) {
return ToAgsFloat(self->GetGravityY());
}

void AgsWorld_SetGravityX(AgsWorld* self, uint32_t g_x) {
float32 f_g_x = ToNormalFloat(g_x);
self->SetGravityX(f_g_x);
}

void AgsWorld_SetGravityY(AgsWorld* self, uint32_t g_y) {
float32 f_g_y = ToNormalFloat(g_y);
self->SetGravityY(f_g_y);
}

#pragma endregion // AgsWorld_ScriptAPI
//-----------------------------------------------------------------------------
#pragma region AgsContact_ScriptAPI
Expand Down Expand Up @@ -1869,6 +1893,10 @@ void AGS_EngineStartup(IAGSEngine *lpEngine)
engine->RegisterScriptFunction("World::Raycast^6", (void*)AgsWorld_Raycast);
engine->RegisterScriptFunction("World::get_ContactCount", (void*)AgsWorld_GetContactCount);
engine->RegisterScriptFunction("World::geti_Contacts", (void*)AgsWorld_GetContacts);
engine->RegisterScriptFunction("World::set_GravityX", (void*)AgsWorld_SetGravityX);
engine->RegisterScriptFunction("World::get_GravityX", (void*)AgsWorld_GetGravityX);
engine->RegisterScriptFunction("World::set_GravityY", (void*)AgsWorld_SetGravityY);
engine->RegisterScriptFunction("World::get_GravityY", (void*)AgsWorld_GetGravityY);

engine->RegisterScriptFunction("RaycastResult::get_Length", (void*)AgsRaycastResult_GetLength);
engine->RegisterScriptFunction("RaycastResult::geti_PointX", (void*)AgsRaycastResult_GetPointX);
Expand Down

0 comments on commit 64ad7b5

Please sign in to comment.