Add interactive dome view and five-chapter story

This commit is contained in:
josh
2026-12-04 20:52:05 -05:00
parent bd48847a5b
commit b883ff858d
12 changed files with 1402 additions and 96 deletions

View File

@@ -8,7 +8,8 @@ namespace DomeShift
Playing,
Paused,
Won,
Lost
Lost,
Viewer
}
public enum PlayableCharacter
@@ -21,6 +22,8 @@ namespace DomeShift
[RequireComponent(typeof(DomeEnvironment))]
public sealed class DomeGame : MonoBehaviour
{
private enum RunMode { Challenge, Explore, Story }
private const int AllRepaired = 0b111;
private const int Airlock = 6;
private const float WalkSpeed = 8.2f;
@@ -55,9 +58,12 @@ namespace DomeShift
Footprint(5, 0f, 0.44f, 0.44f)
};
private readonly DomeStory story = new();
private readonly DomeCameraRig cameraRig = new();
private DomeEnvironment environment;
private Transform environmentRoot;
private DomeWorld world;
private DomeStoryProps storyProps;
private DomeHud hud;
private DomeAudio audioBus;
private Camera domeCamera;
@@ -67,10 +73,24 @@ namespace DomeShift
private float worldTime;
private float displayTransitionUntil = -1f;
private int nearby = -1;
private RunMode mode;
public GamePhase Phase { get; private set; } = GamePhase.Title;
public PlayableCharacter Character { get; private set; } = PlayableCharacter.Bud;
public bool Exploring { get; private set; }
public bool Exploring => mode == RunMode.Explore;
public bool InStory => mode == RunMode.Story;
public DomeEnvironment Profile => environment;
public string StoryTitle => story.Title;
public string StoryBrief => story.Brief;
public string StoryGoal => story.Goal;
public string StoryStatus => story.Status;
public float Homeostasis => story.Homeostasis;
public int StoryChapter => story.ChapterNumber;
public int StoryChapterCount => story.ChapterCount;
public int StoryDone => story.Done;
public int StoryTotal => story.Total;
public int StoryPinCount => story.PinCount;
public int StoryCarried => story.HeldPart;
public bool MapOpen { get; private set; }
public bool Cutaway { get; private set; }
public bool Overview { get; private set; }
@@ -85,11 +105,16 @@ namespace DomeShift
public bool CanToggleFullscreen => !Application.isEditor;
public string Dispatch { get; private set; } = "";
public Vector2 MapPoint(int index) => DomeEnvironment.MapCoordinates(DomeEnvironment.Site(index));
public Vector2 StoryPin(int index) => DomeEnvironment.MapCoordinates(story.Pin(index).Point);
public string StoryPinName(int index) => story.Pin(index).Name;
public string Prompt
{
get
{
if (InStory)
return story.Prompt(nearby);
if (nearby == -1)
return RepairedMask == AllRepaired ? "Head to the airlock" : "";
@@ -112,9 +137,7 @@ namespace DomeShift
private void Awake()
{
environment = GetComponent<DomeEnvironment>();
environmentRoot = environment.BuildForGame();
world = DomeWorld.Create(environmentRoot, environment);
world.SetCharacter(Character);
BuildWorld();
hud = new DomeHud();
audioBus = gameObject.AddComponent<DomeAudio>();
audioBus.Muted = PlayerPrefs.GetInt(MuteKey, 0) == 1;
@@ -159,7 +182,7 @@ namespace DomeShift
PlayFrame();
break;
case GamePhase.Paused:
if (Exploring && Input.GetKeyDown(KeyCode.B))
if (Input.GetKeyDown(KeyCode.B))
ChooseCharacter();
else if (escape || enter)
Resume();
@@ -171,6 +194,12 @@ namespace DomeShift
else if (enter || Input.GetKeyDown(KeyCode.R))
Restart();
break;
case GamePhase.Viewer:
if (escape || Input.GetKeyDown(KeyCode.B))
ExitViewer();
else if (Input.GetKeyDown(KeyCode.V))
ToggleRoof();
break;
}
FrameDome();
@@ -192,23 +221,86 @@ namespace DomeShift
public void StartShift()
{
EnterDome(false);
EnterDome(RunMode.Challenge);
}
public void StartExplore()
{
EnterDome(true);
EnterDome(RunMode.Explore);
}
private void EnterDome(bool explore)
public void StartStory()
{
EnterDome(RunMode.Story);
}
public void StartViewer()
{
if (Phase != GamePhase.Title)
return;
ResetRun();
mode = RunMode.Challenge;
Overview = true;
SetCutaway(false);
world.SetShiftEquipmentVisible(false);
world.Player.gameObject.SetActive(false);
Phase = GamePhase.Viewer;
}
public void ExitViewer()
{
if (Phase == GamePhase.Viewer)
ReturnToTitle();
}
public void ApplyViewParameters(float width, float depth, float roofHeight, int bays,
float glass, float density, float relief, int seed)
{
if (Phase != GamePhase.Viewer || !environment.ApplyViewportSettings(width, depth, roofHeight,
bays, glass, density, relief, seed))
return;
BuildWorld();
SetPlayerPosition(DomeEnvironment.Spawn);
world.SetShiftEquipmentVisible(false);
world.Player.gameObject.SetActive(false);
world.Tick(Vector2.zero, -1, 0, 0f);
SetCutaway(Cutaway);
}
public void ResetCamera()
{
cameraRig.Reset();
}
private void BuildWorld()
{
environmentRoot = environment.BuildForGame();
world = DomeWorld.Create(environmentRoot, environment);
world.SetCharacter(Character);
storyProps = null;
}
private void EnterDome(RunMode newMode)
{
ResetRun();
Exploring = explore;
mode = newMode;
Overview = false;
SetCutaway(true);
Dispatch = explore
? $"{Character}, wander the dome at your own pace. Press Tab for the map."
: $"{Character}, match the spares on the stands to the station colors.";
world.SetShiftEquipmentVisible(!InStory);
if (InStory)
{
story.Reset();
ShowStoryChapter();
Dispatch = $"{Character}, check the main airlock. Tab opens the map.";
}
else
{
Dispatch = Exploring
? $"{Character}, wander the dome at your own pace. Press Tab for the map."
: $"{Character}, match the spares on the stands to the station colors.";
}
Phase = GamePhase.Playing;
audioBus.Play(DomeAudio.Cue.Start);
}
@@ -225,19 +317,25 @@ namespace DomeShift
public void ChooseCharacter()
{
if (Phase != GamePhase.Won && Phase != GamePhase.Lost && !(Phase == GamePhase.Paused && Exploring))
if (Phase != GamePhase.Won && Phase != GamePhase.Lost && Phase != GamePhase.Paused)
return;
ReturnToTitle();
}
private void ReturnToTitle()
{
ResetRun();
Exploring = false;
mode = RunMode.Challenge;
Overview = false;
world.SetShiftEquipmentVisible(true);
SetCutaway(false);
Phase = GamePhase.Title;
}
public void Restart()
{
EnterDome(Exploring);
EnterDome(mode);
}
public void Resume()
@@ -299,7 +397,7 @@ namespace DomeShift
private void Pause()
{
Phase = GamePhase.Paused;
world.Tick(Vector2.zero, Carried, RepairedMask, worldTime);
UpdateCrew(Vector2.zero);
}
private void ResetRun()
@@ -311,6 +409,9 @@ namespace DomeShift
worldTime = 0f;
MapOpen = false;
Dispatch = "";
cameraRig.Reset();
storyProps?.Hide();
world.Player.gameObject.SetActive(true);
SetPlayerPosition(DomeEnvironment.Spawn);
world.Tick(Vector2.zero, Carried, RepairedMask, worldTime);
}
@@ -322,7 +423,11 @@ namespace DomeShift
else if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2))
SelectCharacter(PlayableCharacter.Doyle);
if (Input.GetKeyDown(KeyCode.X))
if (Input.GetKeyDown(KeyCode.S))
StartStory();
else if (Input.GetKeyDown(KeyCode.P))
StartViewer();
else if (Input.GetKeyDown(KeyCode.X))
StartExplore();
else if (enter)
StartShift();
@@ -336,9 +441,9 @@ namespace DomeShift
if (Input.GetKeyDown(KeyCode.V)) ToggleRoof();
if (Input.GetKeyDown(KeyCode.C)) ToggleOverview();
if (!Exploring)
if (mode == RunMode.Challenge)
TimeLeft = Mathf.Max(0f, TimeLeft - Time.deltaTime);
if (!Exploring && TimeLeft <= 0f)
if (mode == RunMode.Challenge && TimeLeft <= 0f)
{
Phase = GamePhase.Lost;
Dispatch = "The safety timer locked out the dome.";
@@ -351,13 +456,16 @@ namespace DomeShift
Axis(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow),
Axis(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow));
Vector2 positionBefore = playerPosition;
Move(Vector2.ClampMagnitude(input, 1f) * (WalkSpeed * Mathf.Min(Time.deltaTime, 0.08f)));
Move(CameraRelative(input) * (WalkSpeed * Mathf.Min(Time.deltaTime, 0.08f)));
nearby = ClosestPoint();
if (Input.GetKeyDown(KeyCode.E))
nearby = InStory ? story.Closest(playerPosition) : ClosestPoint();
if (nearby >= 0 && Input.GetKeyDown(KeyCode.E))
{
Interact();
nearby = ClosestPoint();
if (InStory)
InteractWithStory();
else
Interact();
nearby = InStory ? story.Closest(playerPosition) : ClosestPoint();
}
Vector2 displacement = playerPosition - positionBefore;
@@ -371,10 +479,28 @@ namespace DomeShift
return forward - backward;
}
private Vector2 CameraRelative(Vector2 input)
{
Transform view = domeCamera.transform;
Vector3 forward = Vector3.ProjectOnPlane(view.forward, Vector3.up).normalized;
Vector3 right = Vector3.ProjectOnPlane(view.right, Vector3.up).normalized;
Vector3 local = environmentRoot.InverseTransformVector(forward * input.y + right * input.x);
return new Vector2(local.x, local.z).normalized;
}
private void AnimateWorld(Vector2 motion)
{
worldTime += Time.deltaTime;
world.Tick(motion, Carried, RepairedMask, worldTime);
UpdateCrew(motion);
if (InStory)
storyProps.Animate(worldTime);
}
private void UpdateCrew(Vector2 motion)
{
int carry = InStory ? story.HeldPart : Carried;
int repairs = InStory && Phase == GamePhase.Won ? AllRepaired : RepairedMask;
world.Tick(motion, carry, repairs, worldTime);
}
private void Move(Vector2 movement)
@@ -390,10 +516,13 @@ namespace DomeShift
private bool CanWalk(Vector2 position)
{
foreach (Rect obstacle in Obstacles)
if (!InStory)
{
if (obstacle.Contains(position))
return false;
foreach (Rect obstacle in Obstacles)
{
if (obstacle.Contains(position))
return false;
}
}
return environment.CanWalk(position);
@@ -493,26 +622,53 @@ namespace DomeShift
audioBus.Play(DomeAudio.Cue.Repair);
}
private void FrameDome()
private void ShowStoryChapter()
{
bool title = Phase == GamePhase.Title;
float aspect = Mathf.Max(domeCamera.aspect, 0.1f);
if (title || Overview)
storyProps ??= DomeStoryProps.Create(environmentRoot, environment);
storyProps.Hide();
for (int i = 0; i < story.Total; i++)
{
float shift = title ? Mathf.Min(environment.Width * 0.18f, aspect * 9f) : 0f;
Vector3 center = environmentRoot.position + new Vector3(-shift, environment.RoofHeight * 0.23f, -1f);
float projectedWidth = environment.Width * 0.5f + environment.Depth * 0.09f + 4.5f + shift;
domeCamera.transform.position = center + new Vector3(15f, 67f, -79f);
domeCamera.transform.LookAt(center);
domeCamera.orthographicSize = Mathf.Max(environment.Depth * 0.35f + environment.RoofHeight * 0.62f + 3f,
projectedWidth / aspect);
DomeStory.Task task = story.Target(i);
Vector2 point = task.Point;
Vector3 position = new(point.x, environment.SurfaceY(point) + 0.025f, point.y);
storyProps.Show(i, task.Kind, position, DomeStory.Accent);
}
}
private void InteractWithStory()
{
DomeStory.Task task = story.Target(nearby);
StoryAction result = story.Interact(nearby, out string feedback);
Dispatch = feedback;
if (result == StoryAction.Blocked)
{
audioBus.Play(DomeAudio.Cue.Denied);
return;
}
Vector3 lookAt = world.Player.position + new Vector3(0f, 0.5f, 1.15f);
domeCamera.transform.position = lookAt + new Vector3(0f, 16f, -20f);
domeCamera.transform.LookAt(lookAt);
domeCamera.orthographicSize = Mathf.Max(9.4f, 11.5f / aspect);
storyProps.Complete(nearby);
if (result == StoryAction.ChapterFinished && story.IsLastChapter)
{
Phase = GamePhase.Won;
audioBus.Play(DomeAudio.Cue.Won);
return;
}
if (result == StoryAction.ChapterFinished)
{
story.Advance();
ShowStoryChapter();
}
bool pickup = task.Kind == StoryPropKind.Supply || task.Kind == StoryPropKind.Litter;
audioBus.Play(pickup ? DomeAudio.Cue.Pickup : DomeAudio.Cue.Repair);
}
private void FrameDome()
{
bool allowInput = Phase == GamePhase.Viewer || (Phase == GamePhase.Playing && !MapOpen);
cameraRig.Frame(domeCamera, environment, environmentRoot, world.Player, Phase == GamePhase.Title,
Overview, Phase == GamePhase.Viewer, allowInput);
}
private void DrawMarkers()
@@ -527,6 +683,19 @@ namespace DomeShift
markerStyle.fontSize = Mathf.RoundToInt(12f * scale);
Color previousColor = GUI.color;
if (InStory)
{
for (int i = 0; i < story.Total; i++)
{
if (!story.IsOpen(i) && nearby != i)
continue;
DomeStory.Task task = story.Target(i);
DrawMarker(task.Point, 1.85f, task.Name, DomeStory.Accent, nearby == i, scale);
}
GUI.color = previousColor;
return;
}
for (int i = 0; i < PointRanges.Length; i++)
{
if (i == Airlock)
@@ -550,8 +719,12 @@ namespace DomeShift
private void DrawMarker(int index, string label, Color accent, float scale)
{
Vector2 point = DomeEnvironment.Site(index);
Vector3 worldPoint = environmentRoot.TransformPoint(new Vector3(point.x, environment.SurfaceY(point) + MarkerHeights[index], point.y));
DrawMarker(DomeEnvironment.Site(index), MarkerHeights[index], label, accent, index == nearby, scale);
}
private void DrawMarker(Vector2 point, float height, string label, Color accent, bool active, float scale)
{
Vector3 worldPoint = environmentRoot.TransformPoint(new Vector3(point.x, environment.SurfaceY(point) + height, point.y));
Vector3 projected = domeCamera.WorldToScreenPoint(worldPoint);
if (projected.z <= 0f || projected.x < 2f || projected.x > Screen.width - 2f
|| projected.y < 2f || projected.y > Screen.height - 2f)
@@ -559,7 +732,6 @@ namespace DomeShift
float width = Mathf.Max(52f, label.Length * 7 + 20f) * scale;
Rect rect = new(projected.x - width * 0.5f, Screen.height - projected.y - 9f * scale, width, 20f * scale);
bool active = index == nearby;
GUI.color = active ? accent : new Color32(27, 39, 49, 235);
GUI.DrawTexture(rect, Texture2D.whiteTexture);
GUI.color = accent;