2023-09-02 18:28:46 -07:00
|
|
|
/**
|
|
|
|
|
* Background.cs
|
|
|
|
|
* Set various properties of the drawn background.
|
|
|
|
|
*
|
|
|
|
|
* by muskit
|
|
|
|
|
* July 1, 2022
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
using Godot;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2023-09-02 20:11:50 -07:00
|
|
|
namespace WacK.Things.TunnelObjects
|
2023-09-02 18:28:46 -07:00
|
|
|
{
|
|
|
|
|
|
2023-09-13 01:33:01 -07:00
|
|
|
public enum DrawDirection {
|
|
|
|
|
CounterClockwise, Clockwise, Center
|
|
|
|
|
}
|
|
|
|
|
public partial class Background : Node
|
|
|
|
|
{
|
|
|
|
|
[Export]
|
2023-09-29 22:37:40 -07:00
|
|
|
private TextureRect firstSegment;
|
|
|
|
|
private List<TextureRect> segments = new(60);
|
2023-09-02 18:28:46 -07:00
|
|
|
|
2023-09-13 01:33:01 -07:00
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
2023-09-17 16:26:08 -07:00
|
|
|
var segmentsNode = FindChild("Segment Masks");
|
2023-09-29 22:37:40 -07:00
|
|
|
firstSegment.Visible = false;
|
2023-09-17 16:26:08 -07:00
|
|
|
segments.Add(firstSegment);
|
|
|
|
|
for (int i = 1; i < 60; ++i)
|
2023-09-13 01:33:01 -07:00
|
|
|
{
|
2023-09-29 22:37:40 -07:00
|
|
|
var n = (TextureRect)firstSegment.Duplicate();
|
2023-09-17 16:26:08 -07:00
|
|
|
segmentsNode.AddChild(n);
|
|
|
|
|
segments.Add(n);
|
|
|
|
|
n.Name = i.ToString();
|
2023-09-29 22:37:40 -07:00
|
|
|
n.SetPosition(new Vector2(i * Constants.BASE_2D_RESOLUTION / 60, Constants.BASE_2D_RESOLUTION));
|
2023-09-13 01:33:01 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-02 18:28:46 -07:00
|
|
|
|
2023-09-13 01:33:01 -07:00
|
|
|
// draw in 6/60 frames (0.1s)
|
|
|
|
|
// TODO: figure out how WACCA handles animation speed
|
|
|
|
|
public async void SetSegments(int pos, int size, bool state, DrawDirection direction)
|
|
|
|
|
{
|
|
|
|
|
// GD.Print($"{direction} = {state}. Even? {size % 2 == 0}");
|
2023-09-02 18:28:46 -07:00
|
|
|
|
2023-09-13 01:33:01 -07:00
|
|
|
double timer = 0;
|
2023-09-29 22:37:40 -07:00
|
|
|
double time = .1f;
|
2023-09-02 18:28:46 -07:00
|
|
|
|
2023-09-13 01:33:01 -07:00
|
|
|
int centerSeg = pos + size/2;
|
2023-09-17 16:26:08 -07:00
|
|
|
while (timer < time)
|
2023-09-13 01:33:01 -07:00
|
|
|
{
|
|
|
|
|
timer = Mathf.Clamp(timer + GetProcessDeltaTime(), 0, time);
|
|
|
|
|
var timerRatio = (float)(timer / time);
|
|
|
|
|
int steps = Mathf.CeilToInt(size*timerRatio);
|
2023-09-02 18:28:46 -07:00
|
|
|
|
2023-09-13 01:33:01 -07:00
|
|
|
switch(direction)
|
|
|
|
|
{
|
|
|
|
|
case DrawDirection.CounterClockwise:
|
|
|
|
|
for (int i = 0; i < steps; ++i)
|
|
|
|
|
{
|
|
|
|
|
segments[(i + pos)%60].Visible = state;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DrawDirection.Center: // add: center to edge. rem: edge to center.
|
|
|
|
|
for (int i = centerSeg; i < Util.InterpInt(centerSeg, pos+size, timerRatio); ++i)
|
|
|
|
|
{
|
|
|
|
|
segments[i % 60].Visible = state;
|
|
|
|
|
}
|
|
|
|
|
for (int i = centerSeg; i >= Util.InterpInt(centerSeg, pos, timerRatio); --i)
|
|
|
|
|
{
|
|
|
|
|
segments[i % 60].Visible = state;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DrawDirection.Clockwise:
|
|
|
|
|
for (int i = 0; i < steps; ++i)
|
|
|
|
|
{
|
|
|
|
|
segments[(pos + size - i - 1)%60].Visible = state;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-09-17 16:26:08 -07:00
|
|
|
await ToSignal(GetTree(), "process_frame");
|
2023-09-13 01:33:01 -07:00
|
|
|
}
|
2023-09-29 22:37:40 -07:00
|
|
|
GD.Print("Finished BG anim!");
|
2023-09-13 01:33:01 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-02 18:28:46 -07:00
|
|
|
}
|