Commit 98b01539 authored by nedboy3's avatar nedboy3
Browse files

Added the piece of paper to ground and an indicator for the player to move.

parent efac6456
This diff is collapsed.
fileFormatVersion: 2
guid: 4346df7619dd5b243903fe487a906add
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PaperSpeech : MonoBehaviour, Character {
private Queue<string> conversation = new Queue<string>();
private Queue<string[]> responseQueue = new Queue<string[]>();
private string[] currentResponses;
private bool AskingForName;
public float getLevel()
{
return GameManager.AhavaLevel;
}
public string getName()
{
return "Ahava";
}
public string GreetingMessage()
{
loadConversation();
if (GameManager.ConversationStage == 1)
{
currentResponses = new string[] { "Hi there", "Who are you", "what is this place" };
return "Hello Player, I am Ahava";
}
else if (GameManager.ConversationStage == 2)
{
currentResponses = new string[] { "stage 2 greeting response" };
return "well done on your performances!";
}
else if (GameManager.ConversationStage == 3)
{
currentResponses = new string[] { "stage 3 greeting response" };
return "stage 3 greeting";
}
else if (GameManager.ConversationStage == 4)
{
currentResponses = new string[] { "stage 4 greeting response" };
return "stage 4 greeting";
}
return "Something has gone terribly wrong: The stage is: " + GameManager.ConversationStage;
}
public string GoodbyeMessage()
{
currentResponses = new string[] { };
return "The piece of paper attempts to say goodbye, but struggles, because it's a piece of paper.";
}
public string ProximityMessage()
{
currentResponses = new string[] { };
return "My beard sense is tingling...";
}
public string butthurtGoodbye()
{
currentResponses = new string[] { };
return "Didnt want to admire my glorious beard?";
}
public string nothingMoreToSay()
{
currentResponses = new string[] { };
if (Random.Range(0, 1f) < 0.8)
{
return "my beard grows tired of your chitter chatter";
}
else
{
return "Dennis the mennis!";
}
}
public string converse()
{
if (conversation.Count > 0)
{
GameManager.speechState = conversation.Count;
currentResponses = responseQueue.Dequeue();
return conversation.Dequeue();
}
else
{
GameManager.HasTalkedToAhava = true;
return nothingMoreToSay();
}
}
private void loadConversation()
{
conversation.Clear();
responseQueue.Clear();
}
public string[] getResponses()
{
return currentResponses;
}
private void Start()
{
conversation.Enqueue("You feel compelled to read the piece of paper by pressing the W or up arrow key.");
responseQueue.Enqueue(new string[] { "response 1" });
//GameManager.speechState will be the size of the queue when this dequeued
//make sure to change the check integer in CharacterInteractins when changing dialogue
conversation.Enqueue("What Is Your Name");
responseQueue.Enqueue(new string[] { "okay" });
conversation.Enqueue("Great Name! How about we call you John Smith instead");
responseQueue.Enqueue(new string[] { "I Love it!", "I Hate it!", "I know a guy called John Smith" });
conversation.Enqueue("Maybe we'll just call you Dennnis");
responseQueue.Enqueue(new string[] { "fine", "not Dennis!" });
conversation.Enqueue("No Takebacksies");
responseQueue.Enqueue(new string[] { "..." });
}
private void conversationStage2()
{
conversation.Enqueue("youre fitting in nicely here " + GameManager.playerName + ", you remind me of Myself when i was younger");
responseQueue.Enqueue(new string[] { "great", "you were young once?", "thanks mum" });
}
private void conversationStage3()
{
conversation.Enqueue("Stage 3 conversation stuff");
responseQueue.Enqueue(new string[] { "Stage 3 response 1", "stage 3 resposne 2" });
}
private void conversationStage4()
{
conversation.Enqueue("Stage 4 conversation stuff");
responseQueue.Enqueue(new string[] { "Stage 4 response 1", "stage 4 resposne 2" });
}
}
fileFormatVersion: 2
guid: 6d2b3dd588f89844392271b23cb7a367
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PaperController : MonoBehaviour {
private GameObject DialogueUI;
private GameObject player;
public Button interactButton;
private Text speechBox;
private GameObject faceCamDisplay;
private Image LevelMeter;
private InputField inputName;
//character response stuff
private Image responsePanel;
public Button[] playerResponses;
private int state = 0;
//Components
public Character characterScript;
private CharacterMovement moveScript;
public Camera faceCam;
private Animator anim;
//utility
private bool interactable;
private bool interacting;
private float speechBoxTimer;
private bool wasInteracting;//prevents other characters from removing the dialogue box that this character is using
private bool playerMoveFade;
public Text movementText;
public Image leftArrow;
public Image rightArrow;
// Use this for initialization
void Awake()
{
moveScript = GetComponent<CharacterMovement>();
characterScript = GetComponent<Character>();
anim = GetComponentInChildren<Animator>();
faceCamDisplay = GameObject.FindWithTag("FaceCam");
DialogueUI = GameObject.FindWithTag("DialogueUI");
responsePanel = GameObject.FindWithTag("ResponsePanel").GetComponent<Image>();
speechBox = GameObject.FindWithTag("CharacterSpeech").GetComponent<Text>();
LevelMeter = GameObject.FindWithTag("LevelMeter").GetComponent<Image>();
inputName = GameObject.FindWithTag("playerInput").GetComponent<InputField>();
player = GameObject.FindWithTag("Player").GetComponent<GameObject>();
}
private void Start()
{
interactButton.gameObject.SetActive(false);
DialogueUI.gameObject.SetActive(false);
inputName.gameObject.SetActive(false);
//playerbutton1.gameObject.SetActive(false);
ButtonPress(1);
}
// Update is called once per frame
void Update()
{
if(state == 0 && (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow)))
{
ButtonPress(1);
playerMoveFade = true;
}
if(playerMoveFade == true)
{
Color old = movementText.color;
old.a -= 0.01f;
movementText.color = old;
old = leftArrow.color;
old.a -= 0.01f;
leftArrow.color = old;
old = rightArrow.color;
old.a -= 0.01f;
rightArrow.color = old;
if(old.a <= 0)
{
movementText.gameObject.SetActive(false);
}
}
//do things while the player is in range of the character
if (interactable)
{
if (!interacting)
{
//if player presses up, begin the interaction.
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.E))
{
interacting = true;
setText(speechBox, characterScript.GreetingMessage(), Mathf.Infinity, characterScript.getResponses());
interactButton.gameObject.SetActive(false);
GameManager.setLeveledUp(characterScript.getName(), false);
}
//generate speech every so often while the player is nearby
if (Time.time % 5 < 0.01)
{
if (Random.Range(0f, 1f) < 0.3)
{
setText(speechBox, characterScript.ProximityMessage(), 2, characterScript.getResponses());
}
}
}
else
{//if the player is currently interacting
if (!DaytimeManager.enteringName)
{//conversing
if (Input.GetKeyDown(KeyCode.Alpha1))
{
ButtonPress(1);
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
ButtonPress(2);
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
ButtonPress(3);
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
ButtonPress(4);
}
}
}
}
//deactivate the dialogue UI
if (wasInteracting)
{
if (Time.time > speechBoxTimer)
{
speechBoxTimer = Time.time + 5;
DialogueUI.gameObject.SetActive(false);
wasInteracting = false;
}
}
}
//characterMovement script sets this for us when the player
//enters or exits characters range
public void setInteractable(bool value)
{
interactable = value;
if (interactable)
{
enterInteractable();
}
else
{
exitInteractable();
}
}
//player enters characters range
void enterInteractable()
{
//speechBox.gameObject.SetActive(false);
interactButton.gameObject.SetActive(true);
faceCam.gameObject.SetActive(true);
updateFaceCamDisplay();
DialogueUI.gameObject.SetActive(false);
}
//player exits characters range
void exitInteractable()
{
interactButton.gameObject.SetActive(false);
faceCam.gameObject.SetActive(false);
DialogueUI.gameObject.SetActive(false);
if (interacting)
{
setText(speechBox, characterScript.GoodbyeMessage(), 2, characterScript.getResponses());
}
else
{
setText(speechBox, characterScript.butthurtGoodbye(), 2, characterScript.getResponses());
}
interacting = false;
}
//sets the text of a given text box and sets it to active.
void setText(Text box, string text, float uptime, string[] replies)
{
//speechBoxTimer = Time.time + uptime;
speechBoxTimer = Mathf.Infinity;
wasInteracting = true;
DialogueUI.gameObject.SetActive(true);
updateFaceCamDisplay();
box.text = text;
LevelMeter.fillAmount = characterScript.getLevel() % 1;
print(text);
//setting player reply options
for (int i = 0; i < playerResponses.Length; i++)
{
//find spacing to arrange buttons
float spacing = responsePanel.rectTransform.rect.width / (replies.Length + 1);
//set the text on the reply buttons
if (i < replies.Length)
{
//arrange buttons
Vector2 newPos = playerResponses[i].GetComponent<RectTransform>().localPosition;
float panelEdge = responsePanel.rectTransform.rect.xMin;
newPos.x = panelEdge + (spacing * (i + 1));
playerResponses[i].GetComponent<RectTransform>().localPosition = newPos;
playerResponses[i].gameObject.SetActive(true);
playerResponses[i].GetComponentInChildren<Text>().text = "(" + (i + 1) + ") " + replies[i];
}
else
{
playerResponses[i].gameObject.SetActive(false);
}
}
}
public void updateFaceCamDisplay()
{
//set the sign of the scale of the faceDisplay to be equal to the sign of the characters transform
if (DialogueUI.gameObject.activeSelf)
{
Vector3 newScale = faceCamDisplay.transform.localScale;
if (transform.localScale.x > 0)
{
newScale.x = Mathf.Abs(newScale.x);
}
else
{
newScale.x = (-1) * Mathf.Abs(newScale.x);
}
faceCamDisplay.transform.localScale = newScale;
}
}
public void ButtonPress(int buttonNum)
{
if (state == 0)
{
converse();
}
}
private void converse()
{
setText(speechBox, characterScript.converse(), Mathf.Infinity, characterScript.getResponses());
}
private bool askPlayerForName()
{
if (GameManager.speechState == 5)
{
//create input field for player name
DaytimeManager.enteringName = true;
inputName.gameObject.SetActive(true);
inputName.ActivateInputField();
return true;
}
return false;
}
}
fileFormatVersion: 2
guid: 643f1bd0e9a5f5543befb6e42d812ac2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PaperInteract : MonoBehaviour {
private float groundLevel;
private float colliderBottom;
private GameObject player;
private BoxCollider2D thisCollider;
private PaperController interactions;
private ContactFilter2D filter = new ContactFilter2D();
private bool facingRight = true;
private bool wandering = true;
//private GameObject faceCam;
//public Vector3 faceCamScale;
// Use this for initialization
void Start()
{
thisCollider = GetComponent<BoxCollider2D>();
groundLevel = DaytimeManager.groundLevel;
player = GameObject.FindWithTag("Player");
interactions = GetComponent<PaperController>();
filter.SetLayerMask(LayerMask.GetMask("Player"));
//faceCam = GameObject.FindWithTag("FaceCam");
//faceCamScale = faceCam.transform.localScale;
}
// Update is called once per frame
void Update()
{
//walk around randomly. if character enters their hitbox stop and face character.
keepOnGround();
checkNearbyPlayers();
}
void findColliderBottom()
{
float colliderPositionY = transform.position.y + thisCollider.offset.y;
colliderBottom = colliderPositionY - (thisCollider.size.y / 2);
}
void keepOnGround()
{
findColliderBottom();
//if feet(bottom of collider) on ground or bellow
if (colliderBottom <= groundLevel)
{
//reset position to the ground;
Vector2 newPos = transform.position;
newPos.y += (groundLevel - colliderBottom);
transform.position = newPos;
}
}
void checkNearbyPlayers()
{
CapsuleCollider2D playerCol = player.GetComponent<CapsuleCollider2D>();
Collider2D[] foundPlayers = new Collider2D[1];
if (thisCollider.OverlapCollider(filter, foundPlayers) > 0)
{
Wandering = false;
}
else
{
Wandering = true;
}
}
// accessor for variable wandering(does extra things when its changed)
public bool Wandering
{
set
{
if (wandering != value)
{
//transition interactable
interactions.setInteractable(!value);
}
wandering = value;
}
get
{
return wandering;
}
}
void flipDirection()
{
//flip rotation without having to mess with quaternions
facingRight = !facingRight;
Vector2 newScale = transform.localScale;
newScale.x *= -1;
transform.localScale = newScale;
interactions.updateFaceCamDisplay();
}
}
fileFormatVersion: 2
guid: 11416723da168974ba4f0c127930bf8d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment