Skip to content

Commit

Permalink
added comments to improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
karinakozarova committed Jun 10, 2018
1 parent 4cc5837 commit 2809b06
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 95 deletions.
10 changes: 7 additions & 3 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/Apply_Shader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using System.Collections;

public class Apply_Shader : MonoBehaviour {
Expand All @@ -9,25 +9,29 @@ public class Apply_Shader : MonoBehaviour {

[Range(0, 1)]
public float verts_force = 0.0f;

[Range(0, 1)]
public float verts_force_2 = 0.0f;

protected Material material
{
get
{
if (_material == null) _material.hideFlags = HideFlags.HideAndDontSave;
if (_material == null)
_material.hideFlags = HideFlags.HideAndDontSave; // Creates a material that is explicitly created & destroyed by the component.
return _material;
}
}

private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (shader == null) return;

Material mat = material;
mat.SetFloat("_VertsColor", 1 - verts_force);
mat.SetFloat("_VertsColor2", 1 - verts_force_2);
Graphics.Blit(source, destination, mat);
Graphics.Blit(source, destination, mat); //Source texture,The destination RenderTexture,Material to use.

}

void OnDisable()
Expand Down
12 changes: 6 additions & 6 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/Arrow_Movement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Arrow_Movement : MonoBehaviour {
public enum direction { left, down, up, right };
private const float strumOffset = 0.075f;
private const float despawnTime = 1.5f;

void Start () {
gen = GameObject.FindGameObjectWithTag("GameManager").GetComponent<Step_Generator>();
scoreHandler = GameObject.FindGameObjectWithTag("GameManager").GetComponent<Score_Handler>();
Expand All @@ -44,23 +44,23 @@ void Update() {
{
// move arrow
arrowSpeed = gen.arrowSpeed;
Vector3 tempPos = transform.position;
Vector3 tempPos = transform.position;
tempPos.y -= arrowSpeed;
transform.position = tempPos;

// support both WASD and arrows from keyboard as input
// support both WASD and arrows from keyboard as input
bool isPressedDownKeyboardLeft = Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A);
bool isPressedDownKeyboardDown = Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S);
bool isPressedDownKeyboardUp = Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W);
bool isPressedDownKeyboardRight = Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D);
if (Input.GetKeyDown(KeyCode.Q)) SceneManager.LoadScene("ingame");

if (Input.GetKeyDown(KeyCode.Q)) SceneManager.LoadScene("ingame");
if (isPressedDownKeyboardLeft && dir == direction.left) CheckLocation();
if (isPressedDownKeyboardDown && dir == direction.down) CheckLocation();
if (isPressedDownKeyboardUp && dir == direction.up) CheckLocation();
if (isPressedDownKeyboardRight && dir == direction.right) CheckLocation();

//Missed
//Missed the arrows
if (transform.position.y < arrowBack.transform.position.y - strumOffset)
{
GetComponent<Renderer>().material.SetColor("_Color", new Color(0.5f, 0.0f, 0.0f)); //decolorize arrow
Expand Down
6 changes: 3 additions & 3 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/BG_Audio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BG_Audio : MonoBehaviour {
/// </summary>
public static BG_Audio Instance
{
get { return instance; }
get { return instance; } // returns the property value or the indexer element
}

/// <summary>
Expand All @@ -24,8 +24,8 @@ void Awake()
Destroy(this.gameObject);
return;
}
else instance = this;
else instance = this;

DontDestroyOnLoad(this.gameObject);
DontDestroyOnLoad(this.gameObject); // dont destroy automatically when loading a new scene
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class BG_Colour_Changer : MonoBehaviour {
void Start () {
camera = GetComponent<Camera>();
}

void Update () {
int hue = Mathf.PingPong(Time.time * speed, 1); //a value between the time in seconds since the start of the frame * 0.5 < 1
HSBColor randCol = new HSBColor(hue, 1, 1);
int hue = Mathf.PingPong(Time.time * speed, 1); // time in seconds since the start of the frame * 0.5< value < 1
HSBColor randCol = new HSBColor(hue, 1, 1);
randCol.s = randCol.s / 2; //desaturate
camera.backgroundColor = randCol.ToColor(); // change background color
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@

public class Difficulty_Menu_Handler : MonoBehaviour {

string sceneToLoad = "Song Selection";
string selectSongScene = "Song Selection";
/// <summary>
/// Sets difficulty to beginner
/// </summary>
public void SetBeginner() {
public void SetBeginner() {
Game_Data.difficulty = Song_Parser.difficulties.beginner;
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneToLoad);
UnityEngine.SceneManagement.SceneManager.LoadScene(selectSongScene);
}

/// <summary>
/// Sets difficulty to easy
/// </summary>
public void SetEasy() {
public void SetEasy() {
Game_Data.difficulty = Song_Parser.difficulties.easy;
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneToLoad);
UnityEngine.SceneManagement.SceneManager.LoadScene(selectSongScene);
}

/// <summary>
/// Sets difficulty to medium
/// </summary>
public void SetMedium() {
public void SetMedium() {
Game_Data.difficulty = Song_Parser.difficulties.medium;
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneToLoad);
UnityEngine.SceneManagement.SceneManager.LoadScene(selectSongScene);
}

/// <summary>
/// Sets difficulty to hard
/// </summary>
public void SetHard() {
public void SetHard() {
Game_Data.difficulty = Song_Parser.difficulties.hard;
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneToLoad);
UnityEngine.SceneManagement.SceneManager.LoadScene(selectSongScene);
}

/// <summary>
/// Sets difficulty to extreme
/// </summary>
public void SetChallenge() {
Game_Data.difficulty = Song_Parser.difficulties.challenge;
UnityEngine.SceneManagement.SceneManager.LoadScene(sceneToLoad);
UnityEngine.SceneManagement.SceneManager.LoadScene(selectSongScene);
}
}
1 change: 0 additions & 1 deletion src/DesktopApp/ArduinoDancer/Assets/Scripts/Game_Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Text;


public static class Game_Data
{
public static string songDirectory = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ IEnumerator LoadTrack(string path, Song_Parser.Metadata meta)
string url = string.Format("file://{0}", path);
WWW www = new WWW(url);

while (!www.isDone) yield return null;
while (!www.isDone) yield return null; // download isnt finished

AudioClip clip = www.GetAudioClip(false, false);
AudioClip clip = www.GetAudioClip(false, false); // doesnt matter if it's 2d or 3d, no need to be downloaded completely
audioSource.clip = clip;

songLoaded = true;
Expand All @@ -68,8 +68,7 @@ void HeartBeat()
{
if (songLoaded && !editingBPM)
{
//Calc how long a beat is in seconds
float secondsPerBeat = frames / currentBPM;
float secondsPerBeat = frames / currentBPM; //Calc how long a beat is in seconds

//If the time has passed for one beat, beat the heart and reset
animCounter += Time.deltaTime;
Expand All @@ -89,9 +88,11 @@ void ControllerHandler()
if (anim.GetBool("isBeat")) anim.SetBool("isBeat", false);

if (Input.GetKeyDown(KeyCode.N)){
// restore pitch to the normal
audioSource.pitch = 1;
editingBPM = false;
}else if(Input.GetKeyDown(KeyCode.Space)) {
// changing BPM
editingBPM = true;
anim.SetBool("isBeat", true);

Expand All @@ -112,11 +113,11 @@ void ControllerHandler()
/// </summary>
void SongBPMChange()
{

float newPitch = currentBPM / originalBPM;
if (Mathf.Abs(audioSource.pitch - newPitch) > lerpLimit)
if (Mathf.Abs(audioSource.pitch - newPitch) > lerpLimit) // smooth change
audioSource.pitch = Mathf.Lerp(audioSource.pitch, currentBPM / originalBPM, Time.deltaTime);
else
else // just change
audioSource.pitch = currentBPM / originalBPM;
}
}
}
4 changes: 2 additions & 2 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/IngameMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class IngameMenu : MonoBehaviour {

string mainMenuScene = "Main Menu";
string controlsScene = "Controls";
string scoreScene = "Score";


/// <summary>
/// loads the main meni
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/Menu_Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void StartGameClick()
StartCoroutine(DespawnWarning());
}
else SceneManager.LoadScene(1);

}

/// <summary>
Expand Down Expand Up @@ -67,12 +67,11 @@ public void FindSongsClick()
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();

System.Windows.Forms.DialogResult result = fbd.ShowDialog(); // shows dialog to select songs
if (result == System.Windows.Forms.DialogResult.OK)
if (result == System.Windows.Forms.DialogResult.OK)
{
Game_Data.songDirectory = fbd.SelectedPath; // make the selected path the song directory
if(Song_Parser.IsNullOrWhiteSpace(Game_Data.songDirectory)) Game_Data.validSongDir = false;
else Game_Data.validSongDir = true;

}
}
}
8 changes: 4 additions & 4 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/PauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine;

public class PauseMenu : MonoBehaviour {

public static bool isPaused = false;
public GameObject pauseMenuUI;

Expand All @@ -13,13 +13,13 @@ void Start()
Time.timeScale = 1f;
isPaused = false;
}
void Update ()

void Update ()
{
if (Input.GetKeyDown(KeyCode.P)) // pause is triggered
{
if(isPaused) Resume();
else Pause();
else Pause();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/DesktopApp/ArduinoDancer/Assets/Scripts/Quit_Tutorial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Quit_Tutorial : MonoBehaviour {

void Update () {
if (Input.GetKeyDown(KeyCode.Q)) SceneManager.LoadScene("Main Menu");
if (Input.GetKeyDown(KeyCode.Q))
SceneManager.LoadScene("Main Menu");
}
}
11 changes: 5 additions & 6 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/Resoultion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

public class Resoultion : MonoBehaviour
{

void Update()
{
Screen.SetResolution(1600, 800, false);
}
}
void Update()
{
Screen.SetResolution(1600, 800, false);
}
}
2 changes: 0 additions & 2 deletions src/DesktopApp/ArduinoDancer/Assets/Scripts/Score_Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public class Score_Handler : MonoBehaviour
private const float scoreVal = 100.0f;
private const float strumOffset = 0.1f;

// Use this for initialization
void Start()
{
heart = GameObject.FindGameObjectWithTag("Player");
heartAudio = heart.GetComponent<AudioSource>();
}

// Update is called once per frame
void Update()
{
multiplier = heartAudio.pitch;
Expand Down
Loading

0 comments on commit 2809b06

Please sign in to comment.