Commit a730077d authored by Danny Huang's avatar Danny Huang
Browse files

added title scene

parent 19d44d14
......@@ -45,4 +45,9 @@ public class SpeakerCtrl : MonoBehaviour {
float vol = Random.Range (volLowRange, volHighRange);
this.audioPlayer.PlayOneShot (sound, vol);
}
public bool IsPlaying()
{
return this.audioPlayer.isPlaying;
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class HeroAttack : MonoBehaviour {
public HeroInventory heroInventory;
void Start ()
{
}
void Update () {
if (Input.GetMouseButton(0) ) {
/* Don't fire if clicked on a UI element */
if (EventSystem.current.IsPointerOverGameObject())
return;
this.heroInventory.SendMessage("FireWeapon");
}
}
}
\ No newline at end of file
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class HeroInput : MonoBehaviour
{
public Camera camera;
protected HeroInventory heroInventory;
protected HeroMovement heroMovement;
void Start ()
{
this.heroInventory = GetComponent<HeroInventory> ();
this.heroMovement = GetComponent<HeroMovement> ();
}
void Update ()
{
/* Mouse cursor */
Vector3 mouseWorldPos = camera.ScreenToWorldPoint (Input.mousePosition);
GetComponent<HeroInventory> ().UpdateWeaponRotation (mouseWorldPos);
GetComponent<HeroMovement> ().UpdateHeroDirection (mouseWorldPos);
this.heroInventory.UpdateWeaponRotation (mouseWorldPos);
this.heroMovement.UpdateHeroDirection (mouseWorldPos);
/* Inventory Open */
if (Input.GetButtonDown("Inventory"))
this.heroInventory.HandleInventoryButton();
/* Pick up item */
if (Input.GetButtonDown("PickUp"))
this.heroInventory.HandlePickUpButton();
/* Fire weapon */
if (Input.GetMouseButton(0) ) {
/* Don't fire if clicked on a UI element */
if (EventSystem.current.IsPointerOverGameObject())
return;
this.heroInventory.FireWeapon();
}
/* Jump */
if (Input.GetButtonDown("Jump"))
this.heroMovement.HandleJumpButton ();
/* Left and right */
this.heroMovement.HandleHorizontalAxisInput (Input.GetAxis ("Horizontal"));
}
}
\ No newline at end of file
......@@ -15,6 +15,9 @@ public class HeroMovement : MonoBehaviour {
protected bool isFacingRight;
/* Output of Input.GetAxis("Horizontal"). This must be refreshed upon every Update() */
protected float horiAxis;
// Use this for initialization
void Start () {
}
......@@ -22,6 +25,7 @@ public class HeroMovement : MonoBehaviour {
// gets animation and rigidbody component of the Hero object
void Awake ()
{
this.horiAxis = 0f;
this.isFacingRight = true;
anim = GetComponent<Animator>();
......@@ -32,13 +36,13 @@ public class HeroMovement : MonoBehaviour {
// Update is called once per frame
void Update ()
{
// sets variable jump to true if hero is on ground to avoid double jumps
if (Input.GetButtonDown("Jump") && grounded)
{
jump = true;
}
}
public void HandleJumpButton()
{
if (grounded)
this.jump = true;
}
void OnCollisionStay2D(Collision2D coll) {
......@@ -56,16 +60,19 @@ public class HeroMovement : MonoBehaviour {
}
}
void FixedUpdate()
public void HandleHorizontalAxisInput(float horiAxis)
{
float h = Input.GetAxis("Horizontal");
this.horiAxis = horiAxis;
}
void FixedUpdate()
{
// initiates walking animation in Hero
anim.SetFloat("Speed", Mathf.Abs(h));
this.anim.SetFloat("Speed", Mathf.Abs(this.horiAxis));
// adds force to Hero as long as the speed is not above the max speed
if (h * rb2d.velocity.x < maxSpeed)
rb2d.AddForce(Vector2.right * h * moveForce);
if (this.horiAxis * rb2d.velocity.x < maxSpeed)
rb2d.AddForce(Vector2.right * this.horiAxis * moveForce);
// if speed goes above max speed then we set it to max speed we have set
if (Mathf.Abs (rb2d.velocity.x) > maxSpeed)
......@@ -73,10 +80,10 @@ public class HeroMovement : MonoBehaviour {
// if jump is true depending on if user pressses Jump and character is grounded, add force in vertical direction
// and set jump back to false to avoid double jumps
if (jump)
if (this.jump)
{
rb2d.AddForce(new Vector2(0f, jumpForce));
jump = false;
this.jump = false;
}
}
......
......@@ -124,19 +124,7 @@ public class HeroInventory : MonoBehaviour
} else {
this.UI_lootName.SetActive(false);
}
/* If picked up item */
if (item != null && Input.GetButtonDown ("PickUp")) {
PickUpItem(item);
}
/* If opened inventory UI */
if (Input.GetButtonDown("Inventory"))
{
this.is_UI_inventory_opened = ! this.is_UI_inventory_opened;
Toggle_UI_Visibility(is_UI_inventory_opened);
}
/* Update currency display */
this.UI_currency.transform.FindChild("Text").GetComponent<Text>().text = "Coins: " + this.currency;
......@@ -149,6 +137,20 @@ public class HeroInventory : MonoBehaviour
}
public void HandlePickUpButton()
{
GameObject item = radarCtrl.GetClosestNearby ("Item", itemDetectRadius);
if (item != null) {
PickUpItem(item);
}
}
public void HandleInventoryButton()
{
this.is_UI_inventory_opened = ! this.is_UI_inventory_opened;
Toggle_UI_Visibility(is_UI_inventory_opened);
}
/* Toggle the inventory UI. Coin UI will still be shown regardless. */
public void Toggle_UI_Visibility(bool isVisible)
{
......
......@@ -239,25 +239,25 @@ public class GunController : ItemCtrl {
public void CorrectOrientation(Vector3 triggerFingerPos, Vector3 mouseWorldPos=default(Vector3))
{
bool isGunFacingRight = getDirection().x > 0f;
/* Rotate gun towards mouse cursor */
Debug.DrawLine (this.barrelTip.transform.position, mouseWorldPos);
Vector2 fireDirection = mouseWorldPos - this.barrelTip.transform.position;
float fireDirectionDegAngle = Mathf.Atan2 (fireDirection.y, fireDirection.x) * Mathf.Rad2Deg;
this.transform.rotation = Quaternion.Euler (0, 0, fireDirectionDegAngle);
bool isGunFacingRight = getDirection().x > 0f;
//Debug.Log (fireDirection.x + "_" + fireDirection.y + "_ " + fireDirectionDegAngle);
/* Flip gun vertically if facing left */
if (!isGunFacingRight && this.transform.localScale.y > 0) {
Vector3 localScale = this.transform.localScale;
localScale.y = -Mathf.Abs(localScale.y);
localScale.y = -Mathf.Abs (localScale.y);
this.transform.localScale = localScale;
}
else if (isGunFacingRight && this.transform.localScale.y < 0) {
} else if (isGunFacingRight && this.transform.localScale.y < 0) {
Vector3 localScale = this.transform.localScale;
localScale.y = Mathf.Abs(localScale.y);
localScale.y = Mathf.Abs (localScale.y);
this.transform.localScale = localScale;
}
......
fileFormatVersion: 2
guid: 11033b9d8402aaf4595382bee29dc62c
timeCreated: 1479949270
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: aac2dc1a81a482f4583f1ac3044de1c7
timeCreated: 1479949671
licenseType: Free
TrueTypeFontImporter:
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Karma
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 00f5c2c927e93d845903951023f844e0
timeCreated: 1479949674
licenseType: Free
TrueTypeFontImporter:
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Karma
fallbackFontReferences:
- {fileID: 12800000, guid: aac2dc1a81a482f4583f1ac3044de1c7, type: 3}
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 287391dbe3cd9471a9c3a9ae5aa99354
guid: 9f3557ae87752184e80c960f5d86dd51
folderAsset: yes
timeCreated: 1475018641
timeCreated: 1479955315
licenseType: Free
DefaultImporter:
userData:
......
fileFormatVersion: 2
guid: 5d3ee09f5a819a640996af7558305501
timeCreated: 1479956483
licenseType: Free
AudioImporter:
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bb4e251f0456b2645b742f404648ddac
timeCreated: 1479955323
licenseType: Free
AudioImporter:
serializedVersion: 6
defaultSettings:
loadType: 0
sampleRateSetting: 0
sampleRateOverride: 44100
compressionFormat: 1
quality: 1
conversionMode: 0
platformSettingOverrides: {}
forceToMono: 0
normalize: 1
preloadAudioData: 1
loadInBackground: 0
3D: 1
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f42886862011f6a489aa6df587589654
guid: f23edd1525c9e9b4993aa099cf862d30
folderAsset: yes
timeCreated: 1476722356
timeCreated: 1479955826
licenseType: Free
DefaultImporter:
userData:
......
Supports Markdown
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