Skip to content

Commit

Permalink
Merge pull request #52 from iamtomhewitt/develop
Browse files Browse the repository at this point in the history
2.9 Beta
  • Loading branch information
iamtomhewitt authored Sep 17, 2019
2 parents f6c952b + 51dfcdb commit 02a27e4
Show file tree
Hide file tree
Showing 24 changed files with 938 additions and 194 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Logs/
.vs/vr-pacman/v15/Server/
.vs/vr-pacman/DesignTimeBuild/
/.vscode/settings.json
/ProjectSettings/ProBuilderSettings.json
2 changes: 2 additions & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
<Compile Include="Assets\Scripts\Manager\AudioManager.cs" />
<Compile Include="Assets\Scripts\Manager\GameEventManager.cs" />
<Compile Include="Assets\Scripts\Manager\GameObjectManager.cs" />
<Compile Include="Assets\Scripts\Manager\GameSettingsManager.cs" />
<Compile Include="Assets\Scripts\Manager\HighscoreManager.cs" />
<Compile Include="Assets\Scripts\Pacman\MinimapPacmanIcon.cs" />
<Compile Include="Assets\Scripts\Pacman\PacmanCollision.cs" />
Expand All @@ -240,6 +241,7 @@
<Compile Include="Assets\Scripts\Utility\Debugger.cs" />
<Compile Include="Assets\Scripts\Utility\Highscore\HighscoreDisplayHelper.cs" />
<Compile Include="Assets\Scripts\Utility\Highscore\HighscoreEntry.cs" />
<Compile Include="Assets\Scripts\Utility\JsonHelper.cs" />
<Compile Include="Assets\Scripts\Utility\Powerup.cs" />
<Compile Include="Assets\Scripts\Utility\Utilities.cs" />
<None Include="Assets\Graphics\ImageEffects\Shaders\_BloomAndFlares\BlendOneOne.shader" />
Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/Prefabs/Managers/Game Settings Manager.prefab.meta

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

Binary file modified Assets/Prefabs/Pacman.prefab
Binary file not shown.
Binary file modified Assets/Scenes/Controls.unity
Binary file not shown.
Binary file modified Assets/Scenes/Game Scene.unity
Binary file not shown.
Binary file modified Assets/Scenes/Highscores.unity
Binary file not shown.
Binary file modified Assets/Scenes/Main Menu.unity
Binary file not shown.
3 changes: 2 additions & 1 deletion Assets/Scripts/Manager/GameObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ private void SpawnCherry()

public int CountFood()
{
return GameObject.FindGameObjectsWithTag("Food").Length;
foodCount = GameObject.FindGameObjectsWithTag("Food").Length;
return foodCount;
}

public int GetNumberOfFood()
Expand Down
36 changes: 36 additions & 0 deletions Assets/Scripts/Manager/GameSettingsManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Manager
{
public class GameSettingsManager : MonoBehaviour
{
[SerializeField] private float accelerometerSensitivity;

public static GameSettingsManager instance;

private void Awake()
{
if (instance)
{
DestroyImmediate(this.gameObject);
}
else
{
DontDestroyOnLoad(this.gameObject);
instance = this;
}
}

public void SetAccelerometerSensitivity(float sensitivity)
{
accelerometerSensitivity = sensitivity;
}

public float GetAccelerometerSensitivity()
{
return accelerometerSensitivity;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/Manager/GameSettingsManager.cs.meta

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

86 changes: 50 additions & 36 deletions Assets/Scripts/Manager/HighscoreManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
using UnityEngine;
using Utility;
using UnityEngine.Networking;
using System;

namespace Manager
{
public class HighscoreManager : MonoBehaviour
{
private Highscore[] highscoresList;

private const string privateCode = "YHc0fAncbE-2ieJokE0NIAB9ZEzv8l10WovytuLwzMAw";
private const string publicCode = "5ad0d623d6024519e0be327e";
private Leaderboard leaderboard;

private const string privateCode = "hERKFM6pT0qBOb8ZvypNDQmyok7nHxTkWkM2BFIe7hxQ";
private const string publicCode = "5d810f91d1041303ecafee9f";
private const string url = "http://dreamlo.com/lb/";

public static HighscoreManager instance;
Expand All @@ -27,7 +30,7 @@ private void Awake()
instance = this;
}

//UploadNewHighscore("Tom (The Developer)", 4500);
// UploadNewHighscore("Tom (The Developer)", 4500);
}

/// <summary>
Expand Down Expand Up @@ -65,8 +68,7 @@ public void UploadNewHighscore(string username, int score)
/// </summary>
private IEnumerator UploadNewHighscoreRoutine(string username, int score)
{
string id = System.DateTime.Now.ToString("MMddyyyyhhmmss");
UnityWebRequest request = UnityWebRequest.Post(url + privateCode + "/add/" + UnityWebRequest.EscapeURL(id+username) + "/" + score, "");
UnityWebRequest request = UnityWebRequest.Post(url + privateCode + "/add/" + username + "/" + score, "");
yield return request.SendWebRequest();

if (!request.downloadHandler.text.StartsWith("ERROR"))
Expand All @@ -76,7 +78,9 @@ private IEnumerator UploadNewHighscoreRoutine(string username, int score)
}
else
{
Debug.Log("Error uploading: " + request.error);
Debug.Log("Error uploading: " + request.downloadHandler.text);
FindObjectOfType<HighscoreDisplayHelper>().ClearEntries();
FindObjectOfType<HighscoreDisplayHelper>().DisplayError("Could not upload score. Please try again later.\n\n" + request.downloadHandler.text);
}
}

Expand All @@ -92,54 +96,42 @@ public IEnumerator DownloadHighscores()
{
if (Application.internetReachability == NetworkReachability.NotReachable)
{
FindObjectOfType<HighscoreDisplayHelper>().ShowNoInternetConnection();
FindObjectOfType<HighscoreDisplayHelper>().DisplayError("No internet connection.");
yield break;
}

UnityWebRequest request = UnityWebRequest.Get(url + publicCode + "/pipe/0/10");
UnityWebRequest request = UnityWebRequest.Get(url + publicCode + "/json/0/10");
yield return request.SendWebRequest();

if (!request.downloadHandler.text.StartsWith("ERROR"))
{
highscoresList = ToHighScoreList(request.downloadHandler.text);
string json = JsonHelper.StripParentFromJson(request.downloadHandler.text, 2);
leaderboard = JsonUtility.FromJson<Leaderboard>(json);
highscoresList = ToHighScoreList();
}
else
{
Debug.Log("Error downloading: " + request.error);
Debug.Log("Error downloading: " + request.downloadHandler.text);
FindObjectOfType<HighscoreDisplayHelper>().DisplayError("Could not download highscores. Please try again later.\n\n" + request.downloadHandler.text);
}
}

/// <summary>
/// Coverts a text stream into an array of Highscores.
/// Converts the leaderboard object created by a Json request into a highscore list.
/// </summary>
private Highscore[] ToHighScoreList(string textStream)
{
string[] entries = textStream.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);

Highscore[] list = new Highscore[entries.Length];

for (int i = 0; i < entries.Length; i++)
{
string[] entryInfo = entries[i].Split(new char[] { '|' });

// Get the username from online
string usr = entryInfo[0];

// Replace with spaces
string username = usr.Replace('+', ' ');

// Dont want the date included in the username, so substring itself to show only the username
username = username.Substring(14, (username.Length-14));

int score = int.Parse(entryInfo[1]);

list[i] = new Highscore(username, score);
/// <returns></returns>
private Highscore[] ToHighScoreList()
{
Highscore[] list = new Highscore[leaderboard.entry.Length];

//print(highscoresList[i].username + ": " + highscoresList[i].score + " Date: "+date);
}
for (int i = 0; i < leaderboard.entry.Length; i++)
{
list[i].username = leaderboard.entry[i].name;
list[i].score = leaderboard.entry[i].score;
}

return list;
}
}
}

/// <summary>
Expand All @@ -156,4 +148,26 @@ public Highscore(string username, int score)
this.score = score;
}
}

/// <summary>
/// Data classes used to map the JSON response onto variables.
/// </summary>
[System.Serializable]
public class Leaderboard
{
public HighscoreData[] entry;
}

/// <summary>
/// A data class to hold information retrived from the Dreamlo leaderboard.
/// </summary>
[System.Serializable]
public class HighscoreData
{
public string name;
public int score;
public int seconds;
public string text;
public DateTime date;
}
}
9 changes: 7 additions & 2 deletions Assets/Scripts/Pacman/PacmanCollision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public class PacmanCollision : MonoBehaviour

public int currentLives = 3;

private static PacmanCollision instance;

private Rigidbody rb;
private Debugger debugger;

private static PacmanCollision instance;

private void Awake()
{
instance = this;
Expand All @@ -27,6 +28,7 @@ private void Awake()
private void Start()
{
debugger = GetComponent<Debugger>();
rb = GetComponent<Rigidbody>();
}

private void OnCollisionEnter(Collision other)
Expand Down Expand Up @@ -80,6 +82,9 @@ private void OnTriggerEnter(Collider other)
return;
}

// Reset the velocity to stop pacman drifting away
rb.velocity = Vector3.zero;

if (ghost.IsEdible())
{
ghost.RunHome();
Expand Down
16 changes: 13 additions & 3 deletions Assets/Scripts/Pacman/PacmanMovement.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Utility;
using Manager;

namespace Pacman
{
public class PacmanMovement : MonoBehaviour
public class PacmanMovement : MonoBehaviour
{
[SerializeField] private bool useAccelerometer;
[SerializeField] private bool debug = false;
Expand All @@ -16,6 +16,7 @@ public class PacmanMovement : MonoBehaviour
[SerializeField] private float boostSpeed;
[SerializeField] private float accelerometerSensitivity;

private Rigidbody rb;
private Debugger debugger;

public static PacmanMovement instance;
Expand All @@ -28,6 +29,7 @@ private void Awake()
private void Start()
{
debugger = GetComponent<Debugger>();
rb = GetComponent<Rigidbody>();

if (!SystemInfo.supportsGyroscope)
{
Expand All @@ -37,6 +39,11 @@ private void Start()

originalSpeed = speed;
speed = 0f;

if (GameSettingsManager.instance)
{
accelerometerSensitivity = GameSettingsManager.instance.GetAccelerometerSensitivity();
}
}

private void Update()
Expand All @@ -55,7 +62,10 @@ private void Update()

// Even though rigidbody is checked to lock the y-pos, just ensure here
transform.position = new Vector3(transform.position.x, 0f, transform.position.z);
}

// Reset the velocity to stop pacman drifting away
rb.velocity = Vector3.zero;
}

/// <summary>
/// Boosts Pacmans speed for an amount of time.
Expand Down
39 changes: 27 additions & 12 deletions Assets/Scripts/Utility/Highscore/HighscoreDisplayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,31 @@ private void Start()
/// </summary>
public void PopulateEntries(Highscore[] highscoreList)
{
for (int i = 0; i < highscoreEntries.Length; i++)
{
highscoreEntries[i].Populate(i + 1 + ".", "", "");
if (highscoreList == null)
{
ClearEntries();
}
else
{
for (int i = 0; i < highscoreEntries.Length; i++)
{
highscoreEntries[i].Populate(i + 1 + ".", "", "");

if (highscoreList.Length > i)
{
highscoreEntries[i].Populate(i + 1 + ".", highscoreList[i].username, highscoreList[i].score.ToString());
}
}
if (highscoreList.Length > i)
{
highscoreEntries[i].Populate(i + 1 + ".", highscoreList[i].username, highscoreList[i].score.ToString());
}
}
}
}

/// <summary>
/// Updates the status text.
/// </summary>
public void ShowNoInternetConnection()
{
statusText.text = "No Internet Connection.";
}
public void DisplayError(string message)
{
statusText.text = message;
}

/// <summary>
/// Invoked every x seconds in the start menu to pull new highscores.
Expand Down Expand Up @@ -95,5 +102,13 @@ public void Upload(InputField usernameInputField)
placeholderText.text = "Uploaded!";
}
}

public void ClearEntries()
{
for (int i = 0; i < highscoreEntries.Length; i++)
{
highscoreEntries[i].Populate("", "", "");
}
}
}
}
Loading

0 comments on commit 02a27e4

Please sign in to comment.