2020-11-01 16:45:29 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TOneway.h"
|
2021-01-08 16:50:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "control.h"
|
|
|
|
#include "loader.h"
|
|
|
|
#include "TBall.h"
|
|
|
|
#include "TLine.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
|
|
|
|
TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false)
|
|
|
|
{
|
|
|
|
visualStruct visual{};
|
|
|
|
vector_type linePt1{}, linePt2{};
|
|
|
|
|
|
|
|
loader::query_visual(groupIndex, 0, &visual);
|
|
|
|
if (visual.FloatArrCount == 2)
|
|
|
|
{
|
|
|
|
linePt2.X = visual.FloatArr[0];
|
|
|
|
linePt2.Y = visual.FloatArr[1];
|
|
|
|
linePt1.X = visual.FloatArr[2];
|
|
|
|
linePt1.Y = visual.FloatArr[3];
|
|
|
|
|
2021-01-28 16:01:26 +01:00
|
|
|
auto line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt2, &linePt1);
|
2021-01-08 16:50:12 +01:00
|
|
|
if (line)
|
|
|
|
{
|
|
|
|
line->Offset(table->CollisionCompOffset);
|
|
|
|
line->place_in_grid();
|
2021-10-01 17:55:44 +02:00
|
|
|
EdgeList.push_back(line);
|
2021-01-08 16:50:12 +01:00
|
|
|
}
|
|
|
|
|
2021-01-28 16:01:26 +01:00
|
|
|
line = new TLine(this, &ActiveFlag, visual.CollisionGroup, &linePt1, &linePt2);
|
2021-01-08 16:50:12 +01:00
|
|
|
Line = line;
|
|
|
|
if (line)
|
|
|
|
{
|
|
|
|
line->Offset(-table->CollisionCompOffset * 0.8f);
|
|
|
|
Line->place_in_grid();
|
2021-10-01 17:55:44 +02:00
|
|
|
EdgeList.push_back(Line);
|
2021-01-08 16:50:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TOneway::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction, float coef, TEdgeSegment* edge)
|
|
|
|
{
|
|
|
|
if (edge == Line)
|
|
|
|
{
|
|
|
|
ball->not_again(edge);
|
|
|
|
ball->Position.X = nextPosition->X;
|
|
|
|
ball->Position.Y = nextPosition->Y;
|
|
|
|
ball->RayMaxDistance -= coef;
|
|
|
|
if (!PinballTable->TiltLockFlag)
|
|
|
|
{
|
2021-01-23 11:33:30 +01:00
|
|
|
if (HardHitSoundId)
|
|
|
|
loader::play_sound(HardHitSoundId);
|
2021-01-08 16:50:12 +01:00
|
|
|
control::handler(63, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PinballTable->TiltLockFlag)
|
|
|
|
{
|
2021-01-23 11:33:30 +01:00
|
|
|
maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
|
2021-01-08 16:50:12 +01:00
|
|
|
}
|
|
|
|
else if (maths::basic_collision(
|
|
|
|
ball,
|
|
|
|
nextPosition,
|
|
|
|
direction,
|
2021-01-23 11:33:30 +01:00
|
|
|
Elasticity,
|
|
|
|
Smoothness,
|
|
|
|
Threshold,
|
2021-02-18 10:53:25 +01:00
|
|
|
Boost) > 0.2f)
|
2021-01-08 16:50:12 +01:00
|
|
|
{
|
2021-01-23 11:33:30 +01:00
|
|
|
if (SoftHitSoundId)
|
|
|
|
loader::play_sound(SoftHitSoundId);
|
2021-01-08 16:50:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TOneway::put_scoring(int index, int score)
|
|
|
|
{
|
|
|
|
if (index < 6)
|
|
|
|
Scores[index] = score;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TOneway::get_scoring(int index)
|
|
|
|
{
|
|
|
|
return index < 6 ? Scores[index] : 0;
|
|
|
|
}
|