Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: #745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions testbed/tests/pinball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class Pinball : public Test
ground = m_world->CreateBody(&bd);

b2Vec2 vs[5];
vs[0].Set(-8.0f, 6.0f);
vs[0].Set(-8.0f, 0.0f);
vs[1].Set(-8.0f, 20.0f);
vs[2].Set(8.0f, 20.0f);
vs[3].Set(8.0f, 6.0f);
vs[4].Set(0.0f, -2.0f);
vs[3].Set(8.0f, 0.0f);
// vs[4].Set(-.0f, 0.0f);

b2ChainShape loop;
loop.CreateLoop(vs, 5);
loop.CreateLoop(vs, 4);
b2FixtureDef fd;
fd.shape = &loop;
fd.density = 0.0f;
Expand Down Expand Up @@ -113,19 +113,25 @@ class Pinball : public Test
m_ball->CreateFixture(&fd);
}

m_button = false;
m_leftFlipperButton = m_rightFlipperButton = m_plunge = false;
}

void Step(Settings& settings) override
{
if (m_button)
if (m_leftFlipperButton)
{
m_leftJoint->SetMotorSpeed(20.0f);
m_rightJoint->SetMotorSpeed(-20.0f);
}
else
{
m_leftJoint->SetMotorSpeed(-10.0f);
}
if(m_rightFlipperButton)
{
m_rightJoint->SetMotorSpeed(-20.0f);
}
else
{
m_rightJoint->SetMotorSpeed(10.0f);
}

Expand All @@ -140,8 +146,14 @@ class Pinball : public Test
{
switch (key)
{
case GLFW_KEY_A:
m_button = true;
case GLFW_KEY_LEFT_CONTROL:
m_leftFlipperButton = true;
break;
case GLFW_KEY_RIGHT_CONTROL:
m_rightFlipperButton = true;
break;
case GLFW_KEY_SPACE:
m_plunge = true;
break;
}
}
Expand All @@ -150,8 +162,14 @@ class Pinball : public Test
{
switch (key)
{
case GLFW_KEY_A:
m_button = false;
case GLFW_KEY_LEFT_CONTROL:
m_leftFlipperButton = false;
break;
case GLFW_KEY_RIGHT_CONTROL:
m_rightFlipperButton = false;
break;
case GLFW_KEY_SPACE:
m_plunge = false;
break;
}
}
Expand All @@ -164,7 +182,7 @@ class Pinball : public Test
b2RevoluteJoint* m_leftJoint;
b2RevoluteJoint* m_rightJoint;
b2Body* m_ball;
bool m_button;
bool m_leftFlipperButton, m_rightFlipperButton, m_plunge;
};

static int testIndex = RegisterTest("Examples", "Pinball", Pinball::Create);