-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Brought back the old bird controller temporarily due to issues with t…
…he new one. Implemented temporary UI for arrangement mode.
- Loading branch information
1 parent
15b2d97
commit faa1e66
Showing
10 changed files
with
1,025 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
Assets/HandMadeGame/Code/SuperSketchyTemporaryArrangementModeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using UnityEngine; | ||
|
||
public sealed class SuperSketchyTemporaryArrangementModeController : ArrangementModeControllerBase | ||
{ | ||
private Quest Target; | ||
private NestItem CurrentNestItem = null; | ||
|
||
public override void StartArrangementMode(Quest quest) | ||
{ | ||
Debug.Assert(Target == null); | ||
Debug.Assert(CurrentNestItem == null); | ||
UiController.StartUiInteraction(); | ||
Target = quest; | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
if (Target == null) | ||
return; | ||
|
||
GUILayout.BeginArea(new Rect(Screen.width - 200f, 0f, 200f, Screen.height)); | ||
|
||
GUILayout.Label($"Last-second prototype puzzle solving UI because the real one wasn't quite finished sorry <3"); | ||
|
||
GUILayout.Space(10f); | ||
GUILayout.Label("== Inventory =="); | ||
|
||
NestItem putBack = null; | ||
NestItem removeItem = null; | ||
foreach (NestItem item in GameFlow.Instance.Inventory) | ||
{ | ||
if (GUILayout.Button(item.name)) | ||
{ | ||
if (CurrentNestItem != null) | ||
{ | ||
Debug.Assert(putBack == null); | ||
Debug.Assert(removeItem == null); | ||
putBack = CurrentNestItem; | ||
} | ||
|
||
CurrentNestItem = removeItem = item; | ||
} | ||
} | ||
|
||
if (putBack != null) | ||
GameFlow.Instance.Inventory.Add(putBack); | ||
|
||
if (removeItem != null) | ||
GameFlow.Instance.Inventory.Remove(removeItem); | ||
|
||
if (CurrentNestItem != null) | ||
{ | ||
GUILayout.Space(10f); | ||
if (GUILayout.Button($"Put {CurrentNestItem.name} back")) | ||
{ | ||
GameFlow.Instance.Inventory.Add(CurrentNestItem); | ||
CurrentNestItem = null; | ||
} | ||
} | ||
|
||
GUILayout.EndArea(); | ||
|
||
const float w = 200f; | ||
const float h = 200f; | ||
float left = Screen.width * 0.5f - (w * Target.BoardWidth * 0.5f); | ||
float top = Screen.height * 0.5f - (h * Target.BoardHeight * 0.5f); | ||
for (int y = 0; y < Target.BoardHeight; y++) | ||
{ | ||
for (int x = 0; x < Target.BoardWidth; x++) | ||
{ | ||
Rect rect = new(left + x * w, top + y * h, w, h); | ||
NestItem currentItem = Target.Board[x, y]; | ||
if (GUI.Button(rect, currentItem == null ? "" : currentItem.name)) | ||
{ | ||
Target.Board[x, y] = CurrentNestItem; | ||
CurrentNestItem = currentItem; | ||
} | ||
} | ||
} | ||
|
||
if (GUI.Button(new Rect(left, top + 3 * h, w * 3, 30f), "Exit")) | ||
{ | ||
if (CurrentNestItem != null) | ||
{ | ||
GameFlow.Instance.Inventory.Add(CurrentNestItem); | ||
CurrentNestItem = null; | ||
} | ||
|
||
GameFlow.Instance.EndArrangementMode(Target); | ||
Target = null; | ||
UiController.EndUiInteraction(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/HandMadeGame/Code/SuperSketchyTemporaryArrangementModeController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.