2020-12-02 18:12:34 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "nudge.h"
|
|
|
|
|
2020-12-27 16:19:36 +01:00
|
|
|
|
|
|
|
#include "pb.h"
|
|
|
|
#include "render.h"
|
|
|
|
#include "TBall.h"
|
|
|
|
#include "timer.h"
|
2021-09-21 12:14:39 +02:00
|
|
|
#include "TPinballTable.h"
|
2020-12-27 16:19:36 +01:00
|
|
|
|
|
|
|
int nudge::nudged_left;
|
|
|
|
int nudge::nudged_right;
|
|
|
|
int nudge::nudged_up;
|
|
|
|
int nudge::timer;
|
|
|
|
float nudge::nudge_count;
|
|
|
|
|
|
|
|
void nudge::un_nudge_right(int timerId, void* caller)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
if (nudged_right)
|
|
|
|
_nudge(-2.0, -1.0);
|
|
|
|
nudged_right = 0;
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 16:19:36 +01:00
|
|
|
void nudge::un_nudge_left(int timerId, void* caller)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
if (nudged_left)
|
|
|
|
_nudge(2.0, -1.0);
|
|
|
|
nudged_left = 0;
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 16:19:36 +01:00
|
|
|
void nudge::un_nudge_up(int timerId, void* caller)
|
2020-12-02 18:12:34 +01:00
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
if (nudged_up)
|
|
|
|
_nudge(0.0, -1.0);
|
|
|
|
nudged_up = 0;
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void nudge::nudge_right()
|
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
_nudge(2.0, 1.0);
|
|
|
|
if (timer)
|
|
|
|
timer::kill(timer);
|
|
|
|
timer = timer::set(0.4f, nullptr, un_nudge_right);
|
|
|
|
nudged_right = 1;
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void nudge::nudge_left()
|
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
_nudge(-2.0, 1.0);
|
|
|
|
if (timer)
|
|
|
|
timer::kill(timer);
|
|
|
|
timer = timer::set(0.4f, nullptr, un_nudge_left);
|
|
|
|
nudged_left = 1;
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void nudge::nudge_up()
|
|
|
|
{
|
2020-12-27 16:19:36 +01:00
|
|
|
_nudge(0.0, 1.0);
|
|
|
|
if (timer)
|
|
|
|
timer::kill(timer);
|
|
|
|
timer = timer::set(0.4f, nullptr, un_nudge_up);
|
|
|
|
nudged_up = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nudge::_nudge(float xDiff, float yDiff)
|
|
|
|
{
|
|
|
|
vector_type accelMod;
|
|
|
|
float invAccelX, invAccelY;
|
|
|
|
|
|
|
|
accelMod.X = xDiff * 0.5f;
|
|
|
|
accelMod.Y = yDiff * 0.5f;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto ball : pb::MainTable->BallList)
|
2020-12-27 16:19:36 +01:00
|
|
|
{
|
2021-01-28 16:01:26 +01:00
|
|
|
if (ball->ActiveFlag && !ball->CollisionComp)
|
2020-12-27 16:19:36 +01:00
|
|
|
{
|
|
|
|
ball->Acceleration.X = ball->Acceleration.X * ball->Speed;
|
|
|
|
ball->Acceleration.Y = ball->Acceleration.Y * ball->Speed;
|
|
|
|
maths::vector_add(&ball->Acceleration, &accelMod);
|
|
|
|
ball->Speed = maths::normalize_2d(&ball->Acceleration);
|
2021-02-18 10:53:25 +01:00
|
|
|
if (ball->Acceleration.X == 0.0f)
|
2020-12-27 16:19:36 +01:00
|
|
|
invAccelX = 1000000000.0;
|
|
|
|
else
|
|
|
|
invAccelX = 1.0f / ball->Acceleration.X;
|
|
|
|
ball->InvAcceleration.X = invAccelX;
|
2021-02-18 10:53:25 +01:00
|
|
|
if (ball->Acceleration.Y == 0.0f)
|
2020-12-27 16:19:36 +01:00
|
|
|
invAccelY = 1000000000.0;
|
|
|
|
else
|
|
|
|
invAccelY = 1.0f / ball->Acceleration.Y;
|
|
|
|
ball->InvAcceleration.Y = invAccelY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-25 15:52:19 +02:00
|
|
|
render::shift(static_cast<int>(floor(xDiff + 0.5f)), static_cast<int>(floor(0.5f - yDiff)));
|
2020-12-02 18:12:34 +01:00
|
|
|
}
|