mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Changed Speedup collision checks to benefit from high speed check
added checks for index < 0 Signed-off-by: GreYFoXGTi <GreYFoXGTi@GMaiL.CoM>
This commit is contained in:
parent
d7f5d85362
commit
7f325ed21c
|
@ -148,7 +148,7 @@ int CCollision::GetMapIndex(vec2 PrevPos, vec2 Pos)
|
||||||
|
|
||||||
vec2 CCollision::GetPos(int Index)
|
vec2 CCollision::GetPos(int Index)
|
||||||
{
|
{
|
||||||
if(Index == -1)
|
if(Index < 0)
|
||||||
return vec2(0,0);
|
return vec2(0,0);
|
||||||
int x = Index%m_Width;
|
int x = Index%m_Width;
|
||||||
int y = Index/m_Width;
|
int y = Index/m_Width;
|
||||||
|
@ -511,6 +511,8 @@ int CCollision::IsFNoLaser(int x, int y)
|
||||||
|
|
||||||
int CCollision::IsTeleport(int Index)
|
int CCollision::IsTeleport(int Index)
|
||||||
{
|
{
|
||||||
|
if(Index < 0)
|
||||||
|
return 0;
|
||||||
if(!m_pTele)
|
if(!m_pTele)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -523,6 +525,8 @@ int CCollision::IsTeleport(int Index)
|
||||||
|
|
||||||
int CCollision::IsEvilTeleport(int Index)
|
int CCollision::IsEvilTeleport(int Index)
|
||||||
{
|
{
|
||||||
|
if(Index < 0)
|
||||||
|
return 0;
|
||||||
if(!m_pTele)
|
if(!m_pTele)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -535,32 +539,31 @@ int CCollision::IsEvilTeleport(int Index)
|
||||||
return Tele;
|
return Tele;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCollision::IsSpeedup(int x, int y)
|
int CCollision::IsSpeedup(int Index)
|
||||||
{
|
{
|
||||||
|
if(Index < 0)
|
||||||
|
return 0;
|
||||||
if(!m_pSpeedup)
|
if(!m_pSpeedup)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/*dbg_msg("test", "test");//REMOVE*/
|
/*dbg_msg("test", "test");//REMOVE*/
|
||||||
int nx = clamp(x/32, 0, m_pLayers->SpeedupLayer()->m_Width-1);
|
|
||||||
int ny = clamp(y/32, 0, m_pLayers->SpeedupLayer()->m_Height-1);
|
|
||||||
|
|
||||||
if(m_pSpeedup[ny*m_pLayers->SpeedupLayer()->m_Width+nx].m_Force > 0)
|
if(m_pSpeedup[Index].m_Force > 0)
|
||||||
//{
|
//{
|
||||||
//dbg_msg("IsSpeedup","Index = %d",m_pSpeedup[ny*m_pLayers->SpeedupLayer()->m_Width+nx].m_Type);
|
//dbg_msg("IsSpeedup","Index = %d",m_pSpeedup[ny*m_pLayers->SpeedupLayer()->m_Width+nx].m_Type);
|
||||||
return m_pSpeedup[ny*m_pLayers->SpeedupLayer()->m_Width+nx].m_Type;
|
return m_pSpeedup[Index].m_Type;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCollision::GetSpeedup(int x, int y, vec2 *Dir, int *Force)
|
void CCollision::GetSpeedup(int Index, vec2 *Dir, int *Force)
|
||||||
{
|
{
|
||||||
int nx = clamp(x/32, 0, m_pLayers->SpeedupLayer()->m_Width-1);
|
if(Index < 0)
|
||||||
int ny = clamp(y/32, 0, m_pLayers->SpeedupLayer()->m_Height-1);
|
return;
|
||||||
|
|
||||||
vec2 Direction = vec2(1, 0);
|
vec2 Direction = vec2(1, 0);
|
||||||
float Angle = m_pSpeedup[ny*m_pLayers->SpeedupLayer()->m_Width+nx].m_Angle * (3.14159265f/180.0f);
|
float Angle = m_pSpeedup[Index].m_Angle * (3.14159265f/180.0f);
|
||||||
*Force = m_pSpeedup[ny*m_pLayers->SpeedupLayer()->m_Width+nx].m_Force;
|
*Force = m_pSpeedup[Index].m_Force;
|
||||||
|
|
||||||
vec2 TmpDir;
|
vec2 TmpDir;
|
||||||
TmpDir.x = (Direction.x*cos(Angle)) - (Direction.y*sin(Angle));
|
TmpDir.x = (Direction.x*cos(Angle)) - (Direction.y*sin(Angle));
|
||||||
|
@ -573,6 +576,8 @@ int CCollision::IsCp(int x, int y)
|
||||||
int nx = clamp(x/32, 0, m_Width-1);
|
int nx = clamp(x/32, 0, m_Width-1);
|
||||||
int ny = clamp(y/32, 0, m_Height-1);
|
int ny = clamp(y/32, 0, m_Height-1);
|
||||||
int Index = m_pTiles[ny*m_Width+nx].m_Index;
|
int Index = m_pTiles[ny*m_Width+nx].m_Index;
|
||||||
|
if(Index < 0)
|
||||||
|
return 0;
|
||||||
if (Index >= TILE_CP_D && Index <= TILE_CP_L_F)
|
if (Index >= TILE_CP_D && Index <= TILE_CP_L_F)
|
||||||
return Index;
|
return Index;
|
||||||
else
|
else
|
||||||
|
@ -592,7 +597,8 @@ int CCollision::IsCheckpoint(int Index)
|
||||||
|
|
||||||
vec2 CCollision::CpSpeed(int Index)
|
vec2 CCollision::CpSpeed(int Index)
|
||||||
{
|
{
|
||||||
|
if(Index < 0)
|
||||||
|
return vec2(0,0);
|
||||||
vec2 target;
|
vec2 target;
|
||||||
|
|
||||||
switch(Index)
|
switch(Index)
|
||||||
|
|
|
@ -50,8 +50,8 @@ public:
|
||||||
int IsTeleport(int Index);
|
int IsTeleport(int Index);
|
||||||
int IsEvilTeleport(int Index);
|
int IsEvilTeleport(int Index);
|
||||||
//int IsCheckpoint(int Index);
|
//int IsCheckpoint(int Index);
|
||||||
int IsSpeedup(int x, int y);
|
int IsSpeedup(int Index);
|
||||||
void GetSpeedup(int x, int y, vec2 *Dir, int *Force);
|
void GetSpeedup(int Index, vec2 *Dir, int *Force);
|
||||||
|
|
||||||
int IsSolid(int x, int y);
|
int IsSolid(int x, int y);
|
||||||
int IsThrough(int x, int y);
|
int IsThrough(int x, int y);
|
||||||
|
|
|
@ -926,21 +926,21 @@ void CCharacter::Tick()
|
||||||
m_Core.m_Vel.y += m_Core.m_Vel.y*1.1;
|
m_Core.m_Vel.y += m_Core.m_Vel.y*1.1;
|
||||||
}
|
}
|
||||||
// handle speedup tiles
|
// handle speedup tiles
|
||||||
if(GameServer()->Collision()->IsSpeedup((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y) == TILE_BOOST)
|
if(GameServer()->Collision()->IsSpeedup(MapIndex) == TILE_BOOST)
|
||||||
{
|
{
|
||||||
vec2 Direction;
|
vec2 Direction;
|
||||||
int Force;
|
int Force;
|
||||||
GameServer()->Collision()->GetSpeedup((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y, &Direction, &Force);
|
GameServer()->Collision()->GetSpeedup(MapIndex, &Direction, &Force);
|
||||||
|
|
||||||
m_Core.m_Vel += Direction*Force;
|
m_Core.m_Vel += Direction*Force;
|
||||||
dbg_msg("Direction","%f %f %f %f %f %f",Direction.x,Direction.y,(Direction*Force).x,(Direction*Force).y,m_Core.m_Vel.x,m_Core.m_Vel.y);
|
dbg_msg("Direction","%f %f %f %f %f %f",Direction.x,Direction.y,(Direction*Force).x,(Direction*Force).y,m_Core.m_Vel.x,m_Core.m_Vel.y);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(GameServer()->Collision()->IsSpeedup((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y) == TILE_BOOSTS)
|
else if(GameServer()->Collision()->IsSpeedup(MapIndex) == TILE_BOOSTS)
|
||||||
{
|
{
|
||||||
vec2 Direction;
|
vec2 Direction;
|
||||||
int Force;
|
int Force;
|
||||||
GameServer()->Collision()->GetSpeedup((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y, &Direction, &Force);
|
GameServer()->Collision()->GetSpeedup(MapIndex, &Direction, &Force);
|
||||||
Force/=5;
|
Force/=5;
|
||||||
m_Core.m_Vel = Direction*Force;
|
m_Core.m_Vel = Direction*Force;
|
||||||
m_Core.m_Vel+=Direction;
|
m_Core.m_Vel+=Direction;
|
||||||
|
|
Loading…
Reference in a new issue