background scroll logic rework

This commit is contained in:
Rapandrasmus 2024-01-26 20:03:56 +01:00
parent 14c8ba7d1a
commit fbd975de52
2 changed files with 25 additions and 4 deletions

View file

@ -35,6 +35,7 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
public float moveSpeed = 1.0f; public float moveSpeed = 1.0f;
private List<Transform> _objects = new(); private List<Transform> _objects = new();
private List<float> _objectOffsets = new();
private float _xDistance; private float _xDistance;
private float GetDistance() private float GetDistance()
@ -46,25 +47,34 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
{ {
_xDistance = GetDistance(); _xDistance = GetDistance();
_objects.Add(first); _objects.Add(first);
_objectOffsets.Add(first.localPosition.x);
_objects.Add(second); _objects.Add(second);
_objectOffsets.Add(second.localPosition.x);
for (int i = 0; i < BACKGROUND_OBJECT_AMOUNT; i++) for (int i = 0; i < BACKGROUND_OBJECT_AMOUNT; i++)
{ {
Transform spawnedObject = Instantiate(first, parent); Transform spawnedObject = Instantiate(first, parent);
spawnedObject.localPosition = new Vector3(second.localPosition.x + (_xDistance * (i + 1)), first.localPosition.y, first.localPosition.z); spawnedObject.localPosition = new Vector3(second.localPosition.x + (_xDistance * (i + 1)), first.localPosition.y, first.localPosition.z);
_objects.Add(spawnedObject); _objects.Add(spawnedObject);
_objectOffsets.Add(spawnedObject.localPosition.x);
} }
} }
public void ScrollClones() public void ScrollClones()
{ {
foreach (var b in _objects) for (int i = 0; i < _objects.Count; i++)
{ {
b.localPosition += new Vector3(-Time.deltaTime * moveSpeed, 0); var b = _objects[i];
var bOffset = _objectOffsets[i];
float songPos = Conductor.instance.songPosition;
if (b.localPosition.x <= _xDistance * -(BACKGROUND_OBJECT_AMOUNT + 2) / 2) b.localPosition = new Vector3(bOffset - (songPos * moveSpeed), b.localPosition.y);
float fullDistance = (BACKGROUND_OBJECT_AMOUNT + 2) * _xDistance;
if (b.localPosition.x <= -fullDistance / 2)
{ {
b.localPosition = new Vector3(_xDistance * (BACKGROUND_OBJECT_AMOUNT + 2) / 2, b.localPosition.y, b.localPosition.z); _objectOffsets[i] = bOffset + fullDistance;
} }
} }
} }

View file

@ -18,8 +18,10 @@ namespace HeavenStudio.Games.Loaders
{ {
new("start", "Start Jumping") new("start", "Start Jumping")
{ {
preFunction = delegate { if (eventCaller.currentEntity["cue"]) TotemClimb.StartCueIn(eventCaller.currentEntity.beat); },
parameters = new List<Param>() parameters = new List<Param>()
{ {
new("cue", true, "Cue-In"),
new("hide", false, "Hide Fence") new("hide", false, "Hide Fence")
} }
}, },
@ -386,6 +388,15 @@ namespace HeavenStudio.Games
public Transform EndJumperPoint => _totemManager.EndJumperPoint; public Transform EndJumperPoint => _totemManager.EndJumperPoint;
public static void StartCueIn(double beat)
{
MultiSound.Play(new MultiSound.Sound[]
{
new("totemClimb/beatchange", beat - 2),
new("totemClimb/beatchange", beat - 1),
});
}
public static void TripleJumpSound(double beat, float length, bool enterSound, bool exitSound) public static void TripleJumpSound(double beat, float length, bool enterSound, bool exitSound)
{ {
if (!enterSound && !exitSound) return; if (!enterSound && !exitSound) return;