Skip to content

Commit

Permalink
Changed Tilemap folder to Sprites
Browse files Browse the repository at this point in the history
Added more comments
Added icon to build settings
might want to confirm before building.
  • Loading branch information
gilp06 committed Jan 4, 2023
1 parent b6c1cdb commit 7d91f2b
Show file tree
Hide file tree
Showing 27 changed files with 412 additions and 119 deletions.
14 changes: 13 additions & 1 deletion Assets/Scenes/Level 6 Hard.unity
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,21 @@ PrefabInstance:
propertyPath: pushable
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9194016850709582857, guid: a66eb99e70385d8479fb12dc6057aeed, type: 3}
propertyPath: target.x
value: -3
objectReference: {fileID: 0}
- target: {fileID: 9194016850709582857, guid: a66eb99e70385d8479fb12dc6057aeed, type: 3}
propertyPath: target.y
value: -3
objectReference: {fileID: 0}
- target: {fileID: 9194016850709582857, guid: a66eb99e70385d8479fb12dc6057aeed, type: 3}
propertyPath: current.x
value: 3
value: -3
objectReference: {fileID: 0}
- target: {fileID: 9194016850709582857, guid: a66eb99e70385d8479fb12dc6057aeed, type: 3}
propertyPath: current.y
value: -3
objectReference: {fileID: 0}
- target: {fileID: 9194016850709582861, guid: a66eb99e70385d8479fb12dc6057aeed, type: 3}
propertyPath: m_Name
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Box.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void UpdateVisualsAndProperties()
{
//Appearance
_spriteRenderer.color = preset.boxColor;
_text.text = letter;
_text.text = letter.ToUpper();
_text.color = preset.textColor;

pushable = preset.pushable;
Expand Down
175 changes: 98 additions & 77 deletions Assets/Scripts/LevelHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

public class LevelHandler : MonoBehaviour
{
[Header("Level Properties")]
[SerializeField] private string goalWord;
[SerializeField] public string levelTitle;
public bool solved = false;

private BoxHandler _boxHandler;
private Dictionary<GridPosition, Vector2> _startingLocations = new Dictionary<GridPosition, Vector2>();

public bool solved = false;
private bool _firstSolved = false;

[Header("Score Stuff")]
Expand All @@ -23,13 +22,14 @@ public class LevelHandler : MonoBehaviour
private LevelEndController _levelEndController;
private SceneHandler _sceneHandler;

//Ran at start of level.
private void Start()
{
timer.Pause();
togglePlayerInput(true);
buildIndex = SceneManager.GetActiveScene().buildIndex;
AudioManager.Play($"Level {buildIndex}");
// Doing this because I am too lazy to add a custom inspector button
//When enabled in editor will delete save file.
if (debugResetOnStart)
{
SaveSystem.DeleteLevelSaveFile(this);
Expand All @@ -40,84 +40,37 @@ private void Start()
_sceneHandler = GetComponent<SceneHandler>();
}

public void Reset()
{
timer.Reset();
_boxHandler.playerPosition.target = _boxHandler.playerPosition.positionHistory[0];
_boxHandler.playerPosition.positionHistory.Clear();
_boxHandler.playerPosition.positionHistory.Add(_boxHandler.playerPosition.target);
foreach (var box in _boxHandler.boxes)
{
box.target = box.positionHistory[0];
box.positionHistory.Clear();
box.positionHistory.Add(box.target);
}
}



private void OnUndo(InputValue value)
{
if (value.isPressed)
{
Undo();
}
}
public void Undo()
{
if (_boxHandler.playerPosition.positionHistory.Count == 1)
{
return;
}

_boxHandler.playerPosition.target = _boxHandler.playerPosition.positionHistory[^2];
_boxHandler.playerPosition.positionHistory.RemoveAt(_boxHandler.playerPosition.positionHistory.Count-1);
foreach (var box in _boxHandler.boxes)
{
box.target = box.positionHistory[^2];
box.positionHistory.RemoveAt(box.positionHistory.Count-1);
}
}

public string GetTitle()
{
return levelTitle;
}

private void OnAnyKey(InputValue value)
{
if (value.isPressed)
{
GameObject.FindGameObjectWithTag("FadeTransition").GetComponent<Animator>().SetTrigger("FadeIn");
GameObject.FindGameObjectWithTag("FadeTransition").transform.GetChild(0).GetComponent<Animator>().SetTrigger("FadeOut");
StartCoroutine(_sceneHandler.delay(0.4f, () => timer.Unpause()));
}
}

private void Update()
//Every frame checks if the level is solved.
private void Update()
{
//Loops through every box.
foreach (var startBox in _boxHandler.boxes)
{
//Checks words from top to bottom. Finds the first box in a chain by checking if it has one below and not above.
if (!_boxHandler.CheckBoxCollision(startBox.target, Vector2.up) && _boxHandler.CheckBoxCollision(startBox.target, Vector2.down))
{
var currentString = "";
var cur = startBox;
currentString += cur.letter;
//Follows the chain of boxes and adds their letters to the word.
while (_boxHandler.CheckBoxCollision(cur.target, Vector2.down))
{
cur = _boxHandler.CheckBoxCollision(cur.target, Vector2.down);
currentString += cur.letter;
}
//Checks if the target word is the same as the current word.
if (string.Equals(currentString, goalWord, StringComparison.CurrentCultureIgnoreCase))
{
//Makes sure the end screen and sound effect are only played once.
if (!solved)
{
OnSolve();
}
solved = true;
}
}

//SEE ABOVE
//Same as above but goes from left to right. Checks if there are none to the left.
if (!_boxHandler.CheckBoxCollision(startBox.target, Vector2.left) && _boxHandler.CheckBoxCollision(startBox.target, Vector2.right))
{
var currentString = "";
Expand All @@ -139,32 +92,69 @@ private void Update()
}
}
}


private void OnSolve()
// For Save System
private void OnSolve()
{
UpdateBestScore();
timer.Pause();
togglePlayerInput(false);
AudioManager.Play("LevelComplete");
StartCoroutine(_sceneHandler.delay(0.4f, () => _levelEndController.Enable()));
Debug.Log("level beat");
}

//Called on reset button press. Resets timer and positions. Reset undo list.
public void Reset()
{
UpdateBestScore();
timer.Pause();
togglePlayerInput(false);
AudioManager.Play("LevelComplete");
StartCoroutine(_sceneHandler.delay(0.4f, () => _levelEndController.Enable()));
Debug.Log("level beat");
timer.Reset();
//Finds initial position in undo list.
_boxHandler.playerPosition.target = _boxHandler.playerPosition.positionHistory[0];
_boxHandler.playerPosition.positionHistory.Clear();
_boxHandler.playerPosition.positionHistory.Add(_boxHandler.playerPosition.target);

//Gets boxes in current level.
foreach (var box in _boxHandler.boxes)
{
box.target = box.positionHistory[0];
box.positionHistory.Clear();
box.positionHistory.Add(box.target);
}
}

public void togglePlayerInput(bool setActive)
public void Undo()
{
if (setActive)
GetComponent<PlayerInput>().ActivateInput();
else
GetComponent<PlayerInput>().DeactivateInput();
//Checks if in initial position
if (_boxHandler.playerPosition.positionHistory.Count == 1)
{
return;
}

//Finds the previous position of every box and changes their target position back to them.
//Removes the current position from the list
_boxHandler.playerPosition.target = _boxHandler.playerPosition.positionHistory[^2];
_boxHandler.playerPosition.positionHistory.RemoveAt(_boxHandler.playerPosition.positionHistory.Count-1);
foreach (var box in _boxHandler.boxes)
{
box.target = box.positionHistory[^2];
box.positionHistory.RemoveAt(box.positionHistory.Count-1);
}
}

// For Save System

//Bound in Player Input
private void OnUndo(InputValue value)
{
if (value.isPressed)
{
Undo();
}
}

public void UpdateBestScore()
{
double currentAttempt = timer.GetTimerSeconds();
LevelData savedScore = SaveSystem.LoadLevelData(this);

//Checks if there is a high score.
if (savedScore != null)
{
if (savedScore.seconds > currentAttempt)
Expand All @@ -175,8 +165,39 @@ public void UpdateBestScore()
}
else
{
//Creates a new save file for the level.
SaveSystem.SaveLevelData(this);
Debug.Log("New time to beat is: " + SaveSystem.LoadLevelScore(this).ToString(@"mm\:ss"));
}
}



public string GetTitle()
{
return levelTitle;
}

//Causes the level to fade in when anything is pressed. Set up in Player Input
private void OnAnyKey(InputValue value)
{
if (value.isPressed)
{
//Starts the animation for the fade in and out.
GameObject.FindGameObjectWithTag("FadeTransition").GetComponent<Animator>().SetTrigger("FadeIn");
GameObject.FindGameObjectWithTag("FadeTransition").transform.GetChild(0).GetComponent<Animator>().SetTrigger("FadeOut");
StartCoroutine(_sceneHandler.delay(0.4f, () => timer.Unpause()));
}
}



public void togglePlayerInput(bool setActive)
{
if (setActive)
GetComponent<PlayerInput>().ActivateInput();
else
GetComponent<PlayerInput>().DeactivateInput();
}

}
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
Binary file added Assets/Sprites/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 7d91f2b

Please sign in to comment.