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

Avoid tile angles with a value of 999 #106

Merged
merged 2 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Circle.Game/Rulesets/Objects/MidspinTile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class MidspinTile : Tile
public MidspinTile()
: base(TileType.Midspin)
{
Size = new Vector2(50);
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Expand Down
36 changes: 27 additions & 9 deletions Circle.Game/Screens/Play/ObjectContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void createTiles()
{
Floor = i,
Position = positions[i],
Rotation = angleData[i - 1],
Rotation = getAvailableAngle(i),
});

break;
Expand All @@ -75,7 +75,7 @@ private void createTiles()
{
Floor = i,
Position = positions[i],
Rotation = angleData[i],
Rotation = getAvailableAngle(i),
});

break;
Expand All @@ -93,7 +93,7 @@ private IReadOnlyList<TileType> getTileType()
{
if (floor + 1 < angleData.Length)
{
if (angleData[floor + 1] == 999)
if (angleData[floor + 1] == 999 && angleData[floor] != 999)
{
tileTypes.Add(TileType.Short);
continue;
Expand All @@ -114,6 +114,7 @@ private IReadOnlyList<TileType> getTileType()
}
else
{
// 마지막 타일을 의미합니다.
tileTypes.Add(TileType.Circular);
break;
}
Expand All @@ -133,7 +134,6 @@ private IReadOnlyList<TileType> getTileType()
private IReadOnlyList<Vector2> getTilePositions()
{
var types = getTileType();

var positions = new List<Vector2> { Vector2.Zero };
Vector2 offset = Vector2.Zero;

Expand All @@ -148,12 +148,12 @@ private IReadOnlyList<Vector2> getTilePositions()
break;

case TileType.Midspin:

offset -= CalculationExtensions.GetComputedTilePosition(getAvailableAngle(i));
break;

case TileType.Short:
if (types[i + 1] != TileType.Midspin)
offset += newTilePosition;

offset += newTilePosition;
break;

case TileType.Circular:
Expand All @@ -169,7 +169,7 @@ private IReadOnlyList<Vector2> getTilePositions()
return positions;
}

public IReadOnlyList<TileInfo> GetTileInfos()
public IReadOnlyList<TileInfo> GetTilesInfo()
{
TileInfo[] infos = new TileInfo[angleData.Length];
var types = getTileType();
Expand All @@ -181,7 +181,7 @@ public IReadOnlyList<TileInfo> GetTileInfos()
{
TileType = types[floor],
Floor = floor,
Angle = types[floor] == TileType.Midspin ? angleData[floor - 1] : angleData[floor],
Angle = types[floor] == TileType.Midspin ? getAvailableAngle(floor) : angleData[floor],
Position = tilePositions[floor],
};
}
Expand Down Expand Up @@ -276,6 +276,24 @@ private void addActionsToTile()
}
}

private float getAvailableAngle(int index)
{
var availableAngle = 0f;

for (int i = index - 1; i >= 0; i--)
{
if (angleData[i] != 999)
{
availableAngle += angleData[i];
break;
}
else
availableAngle += 180;
}

return availableAngle;
}

/// <summary>
/// 반시계 방향으로 되어있는 각도데이터를 시계방향으로 변환합니다.
/// </summary>
Expand Down
83 changes: 49 additions & 34 deletions Circle.Game/Screens/Play/Playfield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Playfield : Container
private Planet bluePlanet;
private Container<Planet> planetContainer;

private TileInfo[] tileInfos;
private TileInfo[] tilesInfo;

private bool isClockwise;

Expand Down Expand Up @@ -54,10 +54,10 @@ private void load()
}
};

tileInfos = tileContainer.GetTileInfos().ToArray();
tilesInfo = tileContainer.GetTilesInfo().ToArray();
isClockwise = true;
redPlanet.Expansion = bluePlanet.Expansion = 0;
bluePlanet.Rotation = tileInfos.First().Angle - 180;
bluePlanet.Rotation = tilesInfo.First().Angle - 180;
}

protected override void LoadComplete()
Expand All @@ -70,8 +70,10 @@ protected override void LoadComplete()

private void addTransforms(double gameplayStartTime)
{
double startTimeOffset = gameplayStartTime;
// 회전하고 있는 행성.
PlanetState planetState = PlanetState.Ice;

double startTimeOffset = gameplayStartTime;
float previousAngle;
float bpm = currentBeatmap.Settings.Bpm;
int floor = 0;
Expand All @@ -81,41 +83,43 @@ private void addTransforms(double gameplayStartTime)

using (bluePlanet.BeginAbsoluteSequence(startTimeOffset))
{
startTimeOffset += GetRelativeDuration(bluePlanet.Rotation, tileInfos[floor].Angle, bpm);
startTimeOffset += GetRelativeDuration(bluePlanet.Rotation, tilesInfo[floor].Angle, bpm);
bluePlanet.ExpandTo(1, 60000 / bpm, Easing.Out);
bluePlanet.RotateTo(tileInfos[floor].Angle, GetRelativeDuration(bluePlanet.Rotation, tileInfos[floor].Angle, bpm), easing);
bluePlanet.RotateTo(tilesInfo[floor].Angle, GetRelativeDuration(bluePlanet.Rotation, tilesInfo[floor].Angle, bpm), easing);
}

using (bluePlanet.BeginAbsoluteSequence(startTimeOffset))
{
previousAngle = tileInfos[floor].Angle;
previousAngle = tilesInfo[floor].Angle;
floor++;

if (floor < tileInfos.Length)
if (floor < tilesInfo.Length)
{
bluePlanet.ExpandTo(0);
using (planetContainer.BeginAbsoluteSequence(startTimeOffset))
planetContainer.MoveTo(tileInfos[floor].Position);
planetContainer.MoveTo(tilesInfo[floor].Position);

if (tileInfos[floor].TileType != TileType.Midspin)
if (tilesInfo[floor].TileType != TileType.Midspin)
planetState = PlanetState.Fire;
}
}

#endregion

while (floor < tileInfos.Length)
while (floor < tilesInfo.Length)
{
// Camera
using (BeginAbsoluteSequence(startTimeOffset, false))
this.MoveTo(-tileInfos[floor].Position, 400 + 60 / bpm * 500, Easing.OutSine);
this.MoveTo(-tilesInfo[floor].Position, 400 + 60 / bpm * 500, Easing.OutSine);

var (fixedRotation, newRotation) = computeRotation(floor, previousAngle);
bpm = getNewBpm(bpm, floor, tileInfos[floor].SpeedType);
bpm = getNewBpm(bpm, floor, tilesInfo[floor].SpeedType);
previousAngle = newRotation;

if (tileInfos[floor].EventType == EventType.SetPlanetRotation)
easing = tileInfos[floor].Easing;
if (tilesInfo[floor].EventType == EventType.SetPlanetRotation)
easing = tilesInfo[floor].Easing;

#region Planet totation

switch (planetState)
{
Expand All @@ -140,9 +144,14 @@ private void addTransforms(double gameplayStartTime)
break;
}

#endregion

// 회전을 마치면 다른 행성으로 회전할 준비를 해야합니다.
startTimeOffset += GetRelativeDuration(fixedRotation, newRotation, bpm);
floor++;

#region Planet reducation

switch (planetState)
{
case PlanetState.Fire:
Expand All @@ -158,12 +167,16 @@ private void addTransforms(double gameplayStartTime)
break;
}

if (floor < tileInfos.Length)
#endregion

if (floor < tilesInfo.Length)
{
using (planetContainer.BeginAbsoluteSequence(startTimeOffset, false))
planetContainer.MoveTo(tileInfos[floor].Position);
planetContainer.MoveTo(tilesInfo[floor].Position);

if (tileInfos[floor].TileType != TileType.Midspin && tileInfos[floor - 1].TileType != TileType.Midspin)
if (tilesInfo[floor].TileType != TileType.Midspin && tilesInfo[floor - 1].TileType != TileType.Midspin)
planetState = planetState == PlanetState.Fire ? PlanetState.Ice : PlanetState.Fire;
else if (tilesInfo[floor].TileType == TileType.Midspin && tilesInfo[floor - 1].TileType == TileType.Midspin)
planetState = planetState == PlanetState.Fire ? PlanetState.Ice : PlanetState.Fire;
}
else
Expand Down Expand Up @@ -198,18 +211,18 @@ private void addTileTransforms(double gameplayStartTime)
{
double startTimeOffset = gameplayStartTime;
float bpm = currentBeatmap.Settings.Bpm;
float previousAngle = CalculationExtensions.GetSafeAngle(tileInfos.First().Angle - 180);
float previousAngle = CalculationExtensions.GetSafeAngle(tilesInfo.First().Angle - 180);

for (int i = 8; i < tileInfos.Length; i++)
for (int i = 8; i < tilesInfo.Length; i++)
tileContainer.Children[i].Alpha = 0;

// Fade in
for (int i = 8; i < tileInfos.Length; i++)
for (int i = 8; i < tilesInfo.Length; i++)
{
var (fixedRotation, newRotation) = computeRotation(tileInfos[i - 8].Floor, previousAngle);
var (fixedRotation, newRotation) = computeRotation(tilesInfo[i - 8].Floor, previousAngle);

previousAngle = newRotation;
bpm = getNewBpm(bpm, tileInfos[i - 8].Floor, tileInfos[i - 8].SpeedType);
bpm = getNewBpm(bpm, tilesInfo[i - 8].Floor, tilesInfo[i - 8].SpeedType);

using (tileContainer.Children[i].BeginAbsoluteSequence(startTimeOffset, false))
tileContainer.Children[i].FadeTo(0.45f, 60000 / bpm, Easing.Out);
Expand All @@ -219,16 +232,16 @@ private void addTileTransforms(double gameplayStartTime)

startTimeOffset = gameplayStartTime;
bpm = currentBeatmap.Settings.Bpm;
previousAngle = CalculationExtensions.GetSafeAngle(tileInfos.First().Angle - 180);
previousAngle = CalculationExtensions.GetSafeAngle(tilesInfo.First().Angle - 180);
isClockwise = true;

// Fade out
for (int i = 0; i < tileInfos.Length; i++)
for (int i = 0; i < tilesInfo.Length; i++)
{
var (fixedRotation, newRotation) = computeRotation(tileInfos[i].Floor, previousAngle);
var (fixedRotation, newRotation) = computeRotation(tilesInfo[i].Floor, previousAngle);

previousAngle = newRotation;
bpm = getNewBpm(bpm, tileInfos[i].Floor, tileInfos[i].SpeedType);
bpm = getNewBpm(bpm, tilesInfo[i].Floor, tilesInfo[i].SpeedType);

if (i > 3)
{
Expand All @@ -250,23 +263,25 @@ private void addTileTransforms(double gameplayStartTime)
/// <returns>변환된 각도. (회전 전 각도, 회전 후 각도)</returns>
private (float fixedRotation, float newRotation) computeRotation(int floor, float previousAngle)
{
var currentAngle = CalculationExtensions.GetSafeAngle(tileInfos[floor].Angle);
var currentAngle = CalculationExtensions.GetSafeAngle(tilesInfo[floor].Angle);

// 소용돌이 적용.
if (tileInfos[floor].Twirl)
if (tilesInfo[floor].Twirl)
isClockwise = !isClockwise;

float fixedRotation = CalculationExtensions.GetSafeAngle(previousAngle);

// 현재와 이전 타일이 미드스핀 타일일 때 회전각을 반전하면 안됩니다.
if (floor > 0)
{
if (tileInfos[floor].TileType != TileType.Midspin && tileInfos[floor - 1].TileType != TileType.Midspin)
if (tilesInfo[floor].TileType != TileType.Midspin && tilesInfo[floor - 1].TileType != TileType.Midspin)
fixedRotation -= 180;
else if (tilesInfo[floor].TileType == TileType.Midspin && tilesInfo[floor - 1].TileType == TileType.Midspin)
fixedRotation -= 180;
}

if (tileInfos[floor].TileType == TileType.Midspin)
return (fixedRotation, currentAngle);
if (tilesInfo[floor].TileType == TileType.Midspin)
return (fixedRotation, fixedRotation);

float newRotation = currentAngle >= 180 ? currentAngle - 360 : currentAngle;

Expand All @@ -292,10 +307,10 @@ private float getNewBpm(float current, int floor, SpeedType? speedType)
switch (speedType)
{
case SpeedType.Multiplier:
return current * tileInfos[floor].BpmMultiplier;
return current * tilesInfo[floor].BpmMultiplier;

case SpeedType.Bpm:
return tileInfos[floor].Bpm;
return tilesInfo[floor].Bpm;

default:
return current;
Expand Down