This commit is contained in:
Gerard Gascón 2025-02-02 23:44:44 +01:00
commit f5c1616018
679 changed files with 188502 additions and 0 deletions

View file

@ -0,0 +1,19 @@
using System;
using DG.Tweening;
using UnityEngine;
public class CameraHeight : MonoBehaviour {
private float _currentHeight;
private void Start() {
SetHeight(0f);
}
public void SetHeight(float height) {
if (height <= _currentHeight)
return;
_currentHeight = height;
transform.DOMoveY(height, 1f).SetEase(Ease.OutCubic);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5a261899af60f3c459d19060f0ed8bf7

View file

@ -0,0 +1,19 @@
using System;
using UnityEngine;
using Random = UnityEngine.Random;
public class Casteller : MonoBehaviour {
[SerializeField] private float indexCagat;
[SerializeField] private float shakeAmplitude = .1f;
[SerializeField] private float shakeFrequency = 1f;
[SerializeField] private Transform childPivot;
private void Awake() {
shakeAmplitude = Random.Range(.001f, .01f);
shakeFrequency = Random.Range(1f, 10f);
}
private void Update() {
childPivot.localPosition = new Vector3(Mathf.Cos(Time.time * shakeFrequency) * 2f - 1f, 0, Mathf.Sin(Time.time * shakeFrequency) * 2f - 1f) * shakeAmplitude;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 649811b99a98c064589b40a16ff20c9a

View file

@ -0,0 +1,10 @@
using UnityEngine;
public class GroundDetector : MonoBehaviour {
private void OnTriggerEnter(Collider other) {
if (other.CompareTag("Ground")) {
FindAnyObjectByType<Interface>().Die();
FindAnyObjectByType<PlayerRotate>().Die();
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e56cae8d83baa7745938520f676e6fd3

View file

@ -0,0 +1,47 @@
using System;
using System.Collections;
using DG.Tweening;
using SimpleTools.SceneManagement;
using TMPro;
using UnityEngine;
public class Interface : MonoBehaviour {
private static readonly int FadeOut = Animator.StringToHash("Fade");
[SerializeField] private TMP_Text title;
private bool _titleHidden;
[SerializeField] private CanvasGroup gameOver;
private bool _dead;
[SerializeField] private Animator anim;
private void Start() {
gameOver.alpha = 0;
}
public void PlacePiece() {
if (_titleHidden)
return;
_titleHidden = true;
title.DOFade(0f, 2f);
}
public void Die() {
if (_dead)
return;
_dead = true;
gameOver.DOFade(1f, 1f);
}
public void Retry() {
StartCoroutine(RetryRoutine());
}
private IEnumerator RetryRoutine() {
anim.SetTrigger(FadeOut);
yield return new WaitForSeconds(1f);
Loader.Load("Level 1");
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 49825a11ded5aca4e8450cb4eac54532

10
Assets/Scripts/Music.cs Normal file
View file

@ -0,0 +1,10 @@
using System;
using SimpleTools.AudioManager;
using UnityEngine;
public class Music : MonoBehaviour
{
private void Start() {
AudioManager.instance.Play("Music");
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0b996b2d14d1303458b21824bf7c37d8

View file

@ -0,0 +1,63 @@
using UnityEngine;
public class PlayerRotate : MonoBehaviour {
[SerializeField] private float rotateStep = 15f;
[SerializeField] private LayerMask groundMask;
[Space]
[SerializeField] private GameObject placer;
[SerializeField] private GameObject casteller;
private float _pieceRotation;
private bool _canPlace;
private Vector2Int _pressPosition;
private bool _dead;
private void Update() {
if (_dead)
return;
Debug.Assert(Camera.main != null, "Camera.main != null");
SetPlacerPosition();
_pieceRotation += Input.mouseScrollDelta.y * rotateStep;
placer.transform.rotation = Quaternion.Euler(0f, _pieceRotation, 0f);
CheckPress();
}
private void SetPlacerPosition() {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out RaycastHit hit, 300f, groundMask)){
if (Vector3.Dot(hit.normal, Vector3.up) >= .9f) {
placer.SetActive(true);
placer.transform.position = hit.point;
_canPlace = true;
return;
}
}
_canPlace = false;
placer.SetActive(false);
}
private void CheckPress() {
Vector2Int pressPosition = new((int)Input.mousePosition.x, (int)Input.mousePosition.y);
if (Input.GetMouseButtonDown(0)){
_pressPosition = pressPosition;
}
if (Input.GetMouseButtonUp(0) && _pressPosition == pressPosition && _canPlace) {
FindAnyObjectByType<CameraHeight>().SetHeight(placer.transform.position.y);
FindAnyObjectByType<Interface>().PlacePiece();
Instantiate(casteller, placer.transform.position, Quaternion.Euler(0f, _pieceRotation, 0f));
}
}
public void Die() {
placer.SetActive(false);
_dead = true;
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8b70bd82dc2f626469d41b1f309afa50