Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
npackard committed Sep 16, 2024
2 parents 5d26f06 + 4020c98 commit f586153
Show file tree
Hide file tree
Showing 175 changed files with 8,223 additions and 25,940 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/Build/
/Builds/
/Library/
/[Oo]bj/
/Logs/
Expand Down
2,764 changes: 2,572 additions & 192 deletions Assets/HandMadeGame/Art/Fonts/Birdgo SDF.asset

Large diffs are not rendered by default.

98 changes: 76 additions & 22 deletions Assets/HandMadeGame/Art/Fonts/Sunny Sunday SDF.asset

Large diffs are not rendered by default.

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

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

146 changes: 146 additions & 0 deletions Assets/HandMadeGame/Code/BirdControllerOld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirdControllerOld : MonoBehaviour
{
// rotation limits for flying
public float minX = 60f;
public float maxX = 120f;
public float speed = .5f;

// speed limits for birds
public float lowSpeedLimit = 0.6f;
public float highSpeedLimit = 1.4f;
public float speedAdjustment = 0.01f;

// movement for flying
public float moveSpeed = 10f;
public float internalMoveSpeed;
public float moveSmoothing = 0.05f;
private Vector3 zeroVec = Vector3.zero;

// access to rigidbody and model
public Rigidbody rb;
public Transform model;
public Transform animModel;

// utility for flying rotation
private float change;
private float smooth;
private float mouse;
private float newX;
private float newY;

// utility for flying speed
private float horizontalMove = 0.0f;

// utility for stopping tilt & hovering
public float tiltSmooth = 0.3f;
private float sinCount = 0f;
private Vector3 startingPos = Vector3.zero;
public bool hovering = true;

private bool Suppressed;

// Start is called before the first frame update
void Start()
{
internalMoveSpeed = moveSpeed;

UiController.UiInteractionStart += () =>
{
Suppressed = true;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
};

UiController.UiInteractionEnd += () =>
{
Suppressed = false;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Confined;
};
}

// Update is called once per frame
void Update()
{
if (Suppressed)
{
rb.velocity = Vector3.zero;
return;
}

// update flying velocity
horizontalMove = Input.GetAxisRaw("Vertical");
if (horizontalMove < 0) horizontalMove = 0;

// check if mouse is far enough from center to look up/down
if (Input.mousePosition.y < Screen.height / 4) {
newX += 2 * speed * (Mathf.Abs(Input.mousePosition.x - Screen.height / 2) / Screen.height);
internalMoveSpeed = Mathf.Clamp(internalMoveSpeed + (horizontalMove * speedAdjustment), lowSpeedLimit, highSpeedLimit);
}
else if (Input.mousePosition.y > 3 * Screen.height / 4) {
newX -= 2 * speed * (Mathf.Abs(Input.mousePosition.x - Screen.height / 2) / Screen.height);
internalMoveSpeed = Mathf.Clamp(internalMoveSpeed - (horizontalMove * speedAdjustment), lowSpeedLimit, highSpeedLimit);
}

// check if mouse is far enough from center to look left/right
if (Input.mousePosition.x < 8 * Screen.width / 20) {
newY -= speed * 2 * (Mathf.Abs(Input.mousePosition.x - Screen.width / 2) / Screen.width);
horizontalMove = 1; // force player to fly forward to turn
}
else if (Input.mousePosition.x > 12 * Screen.width / 20) {
newY += speed * 2 * (Mathf.Abs(Input.mousePosition.x - Screen.width / 2) / Screen.width);
horizontalMove = 1; // force player to fly forward to turn
}

// hide cursor again when clicking into game again
// WILL NEED TO CHANGE THIS! to show cursor when decorating nest
//if (Input.GetMouseButtonDown(0)) Cursor.visible = false;

// avoid big scary numbers
if (newX < -360) newX = 360 + newX;
if (newY < 0) newY = 360 + newY;
if (newY > 360) newY = newY - 360;

// clamp x rotation
newX = Mathf.Clamp(newX, minX, maxX);

// update player rotation
transform.rotation = Quaternion.Euler(newX, newY, transform.rotation.z);
animModel.rotation = Quaternion.Euler(newX, newY, animModel.rotation.z);

// handle movement logic
Vector3 targetVelocity = transform.forward * horizontalMove * internalMoveSpeed;
Vector3 curVelocity = rb.velocity;
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref zeroVec, moveSmoothing);
// make numbers nicer
if (rb.velocity.magnitude < .01){
if (startingPos == Vector3.zero) {
startingPos = this.transform.position;
}
hovering = true;
rb.velocity = Vector3.zero;
sinCount = sinCount + 0.01f;
this.transform.position = new Vector3(startingPos.x, startingPos.y + (Mathf.Sin(sinCount) / 15), startingPos.z);
} else {
sinCount = 0;
startingPos = Vector3.zero;
hovering = false;
}
// check if decelerating to tilt model down
if (horizontalMove == 0 && rb.velocity.magnitude != 0) {
Quaternion target = Quaternion.Euler(-15, 0, 0);
model.rotation = Quaternion.Slerp(model.rotation, target, tiltSmooth);
} else {
Quaternion target = Quaternion.Euler(0, 0, 0);
model.rotation = Quaternion.Slerp(model.rotation, target, tiltSmooth);
}
}

public bool GetHovering() {
return hovering;
}
}
11 changes: 11 additions & 0 deletions Assets/HandMadeGame/Code/BirdControllerOld.cs.meta

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

54 changes: 37 additions & 17 deletions Assets/HandMadeGame/Code/DialogueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public sealed class DialogueController : MonoBehaviour
private Action YesAction;
private Action NoAction;
private Action AdvanceAction;
private bool ButtonsAreVisible = false;

private string RemainingText;
private bool ShowButtonsForFinalText;

private static Action NoOp = () => { };

Expand All @@ -27,17 +31,24 @@ private void Start()
}

private bool _DialogueWasJustShown = false;
private void ShowDialogue(Sprite portrait, string message, bool showButtons, string yesText = "Yes", string noText = "No")
private void ShowDialogue(Sprite portrait, string message, bool showButtons)
{
Portrait.sprite = portrait;
DialogueText.text = UiController.ProcessDisplayString(message);

if (showButtons)
// Check if the message contains a split. If it does then this will be an interim dialogue box with the remainder deferred
const string messageSplit = "###";
int messageSplitIndex = message.IndexOf(messageSplit);
if (messageSplitIndex >= 0)
{
YesText.text = yesText;
NoText.text = noText;
Debug.Assert(RemainingText == null);
RemainingText = message.Substring(messageSplitIndex + messageSplit.Length);
message = message.Substring(0, messageSplitIndex);
ShowButtonsForFinalText = showButtons;
showButtons = false;
}

Portrait.sprite = portrait;
DialogueText.text = UiController.ProcessDisplayString(message);

ButtonsAreVisible = showButtons;
YesButton.gameObject.SetActive(showButtons);
NoButton.gameObject.SetActive(showButtons);

Expand All @@ -60,21 +71,19 @@ public void ShowDialogue(Sprite portrait, string message, Action advanceAction)
public void ShowDialogue(Sprite portrait, string message)
=> ShowDialogue(portrait, message, NoOp);

public void ShowDialogue(Sprite portrait, string message, Action yesAction, Action noAction)
public void ShowDialogue(Sprite portrait, string message, string yesText, Action yesAction, string noText, Action noAction)
{
YesText.text = yesText;
NoText.text = noText;

YesAction = yesAction;
NoAction = noAction;
AdvanceAction = null;
ShowDialogue(portrait, message, true);
}

public void ShowDialogue(Sprite portrait, string message, string yesText, Action yesAction, string noText, Action noAction)
{
YesAction = yesAction;
NoAction = noAction;
AdvanceAction = null;
ShowDialogue(portrait, message, true, yesText, noText);
}
public void ShowDialogue(Sprite portrait, string message, Action yesAction, Action noAction)
=> ShowDialogue(portrait, message, "Yes", yesAction, "No", noAction);

private void HandleAction(Action action)
{
Expand All @@ -91,10 +100,21 @@ private void HandleAction(Action action)

private void Update()
{
if (gameObject.activeInHierarchy && AdvanceAction != null)
if (gameObject.activeInHierarchy && !ButtonsAreVisible)
{
if (UiController.CheckGlobalDismiss())
HandleAction(AdvanceAction);
{
if (RemainingText == null)
{
HandleAction(AdvanceAction);
}
else
{
string text = RemainingText;
RemainingText = null;
ShowDialogue(Portrait.sprite, text, ShowButtonsForFinalText);
}
}
}
}
}
2 changes: 1 addition & 1 deletion Assets/HandMadeGame/Code/FollowPlayer.cs.meta

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

34 changes: 34 additions & 0 deletions Assets/HandMadeGame/Code/FollowPlayerOld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPlayerOld : MonoBehaviour
{
public BirdControllerOld bird;
public Transform target;
public float smoothTime = 0.3f;
public float lookSmoothTime = 0.1f;
private Vector3 refVec = new Vector3(0, 0.5f, -1);
private Vector3 velocity = Vector3.zero;

void Update()
{
// Define a target position above and behind the target transform
Vector3 targetPosition = target.TransformPoint(refVec);
if (targetPosition.y <= 0) targetPosition = new Vector3(targetPosition.x, 0.2f, targetPosition.z);

// Smoothly move the camera towards that target position
if (!bird.GetHovering()){
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}

void LateUpdate()
{
if (!bird.GetHovering()) {
Vector3 lookDirection = target.position - this.transform.position;
lookDirection.Normalize();
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(lookDirection), lookSmoothTime * Time.deltaTime);
}
}
}
11 changes: 11 additions & 0 deletions Assets/HandMadeGame/Code/FollowPlayerOld.cs.meta

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

18 changes: 12 additions & 6 deletions Assets/HandMadeGame/Code/GameFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public sealed class GameFlow : MonoBehaviour

public bool ShowDebugger;


private void Awake()
{
if (Instance != null)
Expand All @@ -34,8 +33,6 @@ private void Awake()

public void HandleInteraction(Quest quest)
{
Debug.Log($"Interacting with quest '{quest.name}'");

switch (quest.CurrentState)
{
case QuestState.NotStarted:
Expand Down Expand Up @@ -67,8 +64,7 @@ public void HandleInteraction(Quest quest)
() =>
{
InfoPopupController.ShowPopup(quest.QuestDescription);
quest.CurrentState = QuestState.Accepted;
CurrentQuest = quest;
AcceptQuest(quest);
}),
() => DialogueController.ShowDialogue(quest.CharacterPortrait, quest.QuestRejectedDialogue)
);
Expand Down Expand Up @@ -103,9 +99,19 @@ public void HandleInteraction(Quest quest)
}
}

private void AcceptQuest(Quest quest)
{
Debug.Assert(CurrentQuest == null);

quest.CurrentState = QuestState.Accepted;
CurrentQuest = quest;

foreach (GameObject gameObject in quest.SpawnOnAccept)
gameObject.SetActive(true);
}

public void HandleInteraction(NestItem item)
{
Debug.Log($"Interacting with nest item '{item.name}'");
Inventory.Add(item);
item.gameObject.SetActive(false);
}
Expand Down
4 changes: 4 additions & 0 deletions Assets/HandMadeGame/Code/Quest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@ private void Awake()
Debug.LogError($"Quest '{name}' does not have a validator!");
Validator = gameObject.AddComponent<NullQuestValidator>();
}

// Ensure spawn items are hidden at start
foreach (GameObject gameObject in SpawnOnAccept)
gameObject.SetActive(false);
}
}
Loading

0 comments on commit f586153

Please sign in to comment.