1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-11-17 23:20:19 +01:00
SpaceCadetPinball/SpaceCadetPinball/TCollisionComponent.cpp

121 lines
2.7 KiB
C++
Raw Normal View History

2020-11-21 16:14:40 +01:00
#include "pch.h"
#include "TCollisionComponent.h"
#include "loader.h"
#include "maths.h"
#include "objlist_class.h"
#include "TEdgeSegment.h"
#include "TPinballTable.h"
TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) : TPinballComponent(
table, groupIndex, true)
{
visualStruct visual{};
EdgeList = new objlist_class(4, 4);
UnknownBaseFlag2 = 1;
if (GroupName != nullptr)
UnknownBaseFlag1 = 1;
if (groupIndex <= 0)
{
loader::default_vsi(&visual);
}
else
{
loader::query_visual(groupIndex, 0, &visual);
if (createWall)
{
float offset = table->CollisionCompOffset;
float* floatArr = loader::query_float_attribute(groupIndex, 0, 600);
TEdgeSegment::install_wall(floatArr, this, &UnknownBaseFlag2, visual.Flag, offset, 0);
}
}
2021-01-23 11:33:30 +01:00
Threshold = visual.Kicker.Threshold;
Elasticity = visual.Elasticity;
Smoothness = visual.Smoothness;
Boost = visual.Kicker.Boost;
HardHitSoundId = visual.Kicker.HardHitSoundId;
SoftHitSoundId = visual.SoftHitSoundId;
GroupIndex = groupIndex;
}
TCollisionComponent::~TCollisionComponent()
{
for (TEdgeSegment* edge; EdgeList->Count() > 0;)
{
edge = static_cast<TEdgeSegment*>(EdgeList->Get(0));
EdgeList->Delete(edge);
delete edge;
}
delete EdgeList;
}
void TCollisionComponent::port_draw()
{
for (int index = EdgeList->Count() - 1; index >= 0; index--)
{
static_cast<TEdgeSegment*>(EdgeList->Get(index))->port_draw();
}
}
2021-01-07 17:00:38 +01:00
int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction)
{
if (PinballTable->TiltLockFlag)
{
2021-01-23 11:33:30 +01:00
maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
return 0;
}
2021-01-23 11:33:30 +01:00
auto projSpeed = maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, Threshold, Boost);
if (projSpeed <= Threshold)
{
if (projSpeed > 0.2)
{
2021-01-23 11:33:30 +01:00
if (SoftHitSoundId)
loader::play_sound(SoftHitSoundId);
}
return 0;
}
2021-01-23 11:33:30 +01:00
if (HardHitSoundId)
loader::play_sound(HardHitSoundId);
return 1;
}
2021-01-07 17:00:38 +01:00
void TCollisionComponent::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction,
float coef, TEdgeSegment* edge)
{
int soundIndex;
if (PinballTable->TiltLockFlag)
{
2021-01-23 11:33:30 +01:00
maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
return;
}
double projSpeed = maths::basic_collision(
ball,
2021-01-07 17:00:38 +01:00
nextPosition,
direction,
2021-01-23 11:33:30 +01:00
Elasticity,
Smoothness,
Threshold,
Boost);
if (projSpeed <= Threshold)
{
if (projSpeed <= 0.2)
return;
2021-01-23 11:33:30 +01:00
soundIndex = SoftHitSoundId;
}
else
{
2021-01-23 11:33:30 +01:00
soundIndex = HardHitSoundId;
}
if (soundIndex)
loader::play_sound(soundIndex);
}
int TCollisionComponent::FieldEffect(TBall* ball, vector_type* vecDst)
{
return 0;
}