Skip to content

Commit

Permalink
Implement landmine rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletXF committed Sep 9, 2023
1 parent 6f894bd commit d180acb
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
11 changes: 10 additions & 1 deletion Assets/Scripts/BMSParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Parse(string path, bool addReadyMeasure = false, bool metaOnly = fal

if (!line.StartsWith("#")) continue;

if (char.IsDigit(line[1]) && char.IsDigit(line[2]) && char.IsDigit(line[3]) && char.IsDigit(line[4]) && char.IsDigit(line[5]) && line[6] == ':')
if (char.IsDigit(line[1]) && char.IsDigit(line[2]) && char.IsDigit(line[3]) && line[6] == ':')
{
var measure = int.Parse(line.Substring(1, 3))
+ (addReadyMeasure ? 1 : 0);
Expand Down Expand Up @@ -173,6 +173,7 @@ public void Parse(string path, bool addReadyMeasure = false, bool metaOnly = fal
int totalLongNotes = 0;
int totalScratchNotes = 0;
int totalBackSpinNotes = 0;
int totalLandmineNotes = 0;
var currentBpm = chart.Meta.Bpm;
var minBpm = chart.Meta.Bpm;
var maxBpm = chart.Meta.Bpm;
Expand Down Expand Up @@ -411,6 +412,14 @@ public void Parse(string path, bool addReadyMeasure = false, bool metaOnly = fal

break;
case Channel.P1MineKeyBase:
// landmine
totalLandmineNotes++;
Debug.Log($"landmine: {val}");
if(metaOnly) break;
var damage = DecodeBase36(val)/2f;
timeline.SetNote(
laneNumber, new LandmineNote(damage)
);
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Scripts/BMSRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ void DrawNote(Note note, double offset)
noteObject.transform.localPosition = new Vector3(left, OffsetToTop(offset), 0);
noteObject.transform.localScale = new Vector3(laneWidth, noteHeight, 0);
var spriteRenderer = noteObject.GetComponent<SpriteRenderer>();
spriteRenderer.color = noteColors[note.Lane];
spriteRenderer.color = note is LandmineNote ? Color.magenta : noteColors[note.Lane];

spriteRenderer.sortingLayerName = "Note";
noteObject.name = "Note";
state.noteObjects.Add(note, noteObject);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class GameManager
public static GameManager Instance => instance ??= new GameManager();

public string BmsPath;
public bool AutoPlay = false;
public bool AutoPlay = true;
public bool KeySound = true;
public int KeyMode = 5;
}
11 changes: 11 additions & 0 deletions Assets/Scripts/LandmineNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

public class LandmineNote: Note
{
public float Damage { get; private set; }
public LandmineNote(float damage) : base(0)
{
Damage = damage;
}


}
3 changes: 3 additions & 0 deletions Assets/Scripts/LandmineNote.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Assets/Scripts/LongNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public LongNote(int wav) : base(wav)
}


public new void Press(long time)
public override void Press(long time)
{
Play(time);
IsHolding = true;
Expand All @@ -32,7 +32,7 @@ public void MissPress(long time)

}

public new void Reset()
public override void Reset()
{
base.Reset();
IsHolding = false;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ protected void Play(long time)
PlayedTime = time;
}

public void Press(long time)
public virtual void Press(long time)
{
Play(time);
}

public void Reset()
public virtual void Reset()
{
IsPlayed = false;
IsDead = false;
Expand Down
15 changes: 11 additions & 4 deletions Assets/Scripts/RhythmControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,18 @@ private void Start()
bmsRenderer = GetComponent<BMSRenderer>();
metronomeBytes = Resources.Load<TextAsset>("Sfx/metronome").bytes;
LoadGame();
var token = mainLoopTokenSource.Token;
mainLoopTask = Task.Run(() =>
{
while (true)
{
if (mainLoopTokenSource.IsCancellationRequested) break;
if (token.IsCancellationRequested) break;
if (gameState == null) continue;
if (!gameState.IsPlaying) continue;
try
{
var currentDspTime = gameState.GetCurrentDspTimeMicro(system, channelGroup);
CheckPassedTimeline(currentDspTime);
CheckPassedTimeline(currentDspTime, token);
}
catch (Exception e)
{
Expand All @@ -153,7 +154,7 @@ private void Start()
}
}
Debug.Log("MainLoopTask is canceled");
}, mainLoopTokenSource.Token);
}, token);

}

Expand Down Expand Up @@ -225,15 +226,18 @@ private void FixedUpdate()

}

private void CheckPassedTimeline(long time)
private void CheckPassedTimeline(long time, CancellationToken token)
{
var measures = parser.GetChart().Measures;
if (token.IsCancellationRequested || gameState == null) return;
for (int i = gameState.PassedMeasureCount; i < measures.Count; i++)
{
if (token.IsCancellationRequested) return;
var isFirstMeasure = i == gameState.PassedMeasureCount;
var measure = measures[i];
for (int j = isFirstMeasure ? gameState.PassedTimelineCount : 0; j < measure.Timelines.Count; j++)
{
if (token.IsCancellationRequested) return;
var timeline = measure.Timelines[j];
if (timeline.Timing < time - 200000)
{
Expand All @@ -244,6 +248,7 @@ private void CheckPassedTimeline(long time)
{
if (note == null) continue;
if (note.IsPlayed) continue;
if (note is LandmineNote) continue;


if (note is LongNote { IsTail: false } ln)
Expand All @@ -260,6 +265,7 @@ private void CheckPassedTimeline(long time)
// auto-release long notes
foreach (var note in timeline.Notes)
{
if (token.IsCancellationRequested) return;
if (note == null) continue;
if (note.IsPlayed) continue;
if (note is LongNote { IsTail: true } longNote)
Expand All @@ -277,6 +283,7 @@ private void CheckPassedTimeline(long time)
{
if(GameManager.Instance.AutoPlay)
{
if(note is LandmineNote) continue;
PressNote(note, time);
bmsRenderer.StartLaneBeamEffect(note.Lane);
if (note is not LongNote { IsTail: false })
Expand Down

0 comments on commit d180acb

Please sign in to comment.