diff --git a/Assets/Scripts/flappy_bird - přejmenovat.meta b/Assets/Scripts/flappy_bird - přejmenovat.meta new file mode 100644 index 0000000..a26768e --- /dev/null +++ b/Assets/Scripts/flappy_bird - přejmenovat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 078ea16f7b9620d4f839c1d44f968b45 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/flappy_bird - přejmenovat/flappy bird.cs b/Assets/Scripts/flappy_bird - přejmenovat/flappy bird.cs new file mode 100644 index 0000000..edda4dc --- /dev/null +++ b/Assets/Scripts/flappy_bird - přejmenovat/flappy bird.cs @@ -0,0 +1,214 @@ +using System; +using UnityEngine; +using UnityEngine.SceneManagement; +using TMPro; + +public class FlappyBirdAllInOne : MonoBehaviour, ITask +{ + + [Header("Player")] + public Rigidbody2D rb; + public float jumpForce = 5f; + public bool isDead = false; + + + [Header("Pipes")] + public GameObject pipePrefab; + public Transform spawnPoint; + public float spawnRate = 2f; + public float heightOffset = 2f; + public float pipeSpeed = 2f; + + private float timer = 0; + + + [Header("UI")] + public TextMeshProUGUI scoreText; + public GameObject gameOverPanel; + + private int score = 0; + + + private Action _onCompleted; + private Action _onExit; + + public string TaskID { get; set; } + public TaskType TaskType { get; set; } + public string TaskName { get; set; } + public (double, double) TaskLocation { get; set; } + public bool IsCompleted { get; private set; } + + + void Start() + { + Time.timeScale = 1f; + score = 0; + UpdateScore(); + } + + void Update() + { + if (isDead) return; + + HandleInput(); + HandleSpawning(); + } + + + void HandleInput() + { + if (Input.GetMouseButtonDown(0)) + { + Jump(); + } + } + + void Jump() + { + rb.velocity = Vector2.zero; + rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse); + } + + + void HandleSpawning() + { + timer += Time.deltaTime; + + if (timer >= spawnRate) + { + SpawnPipe(); + timer = 0; + } + } + + void SpawnPipe() + { + float yOffset = UnityEngine.Random.Range(-heightOffset, heightOffset); + + GameObject pipe = Instantiate( + pipePrefab, + spawnPoint.position + new Vector3(0, yOffset, 0), + Quaternion.identity + ); + + pipe.AddComponent().Init(pipeSpeed, this); + } + + + public void AddScore() + { + score++; + UpdateScore(); + } + + void UpdateScore() + { + scoreText.text = score.ToString(); + } + + + public void GameOver() + { + isDead = true; + gameOverPanel.SetActive(true); + Time.timeScale = 0f; + } + + public void Restart() + { + Time.timeScale = 1f; + SceneManager.LoadScene(SceneManager.GetActiveScene().name); + } + + + private void OnCollisionEnter2D(Collision2D collision) + { + GameOver(); + } + + public void Initialize(Action onCompleted) + { + IsCompleted = false; + _onCompleted = onCompleted; + } + + public void Complete() + { + if (IsCompleted) return; + + IsCompleted = true; + _onCompleted?.Invoke(this); + ExitTask(_onExit); + } + + public void ExitTask(Action onExit) + { + onExit?.Invoke(this); + } +} + +public class PipeMover : MonoBehaviour +{ + private float speed; + private FlappyBirdAllInOne game; + + public void Init(float moveSpeed, FlappyBirdAllInOne gm) + { + speed = moveSpeed; + game = gm; + } + + void Update() + { + transform.position += Vector3.left * speed * Time.deltaTime; + + if (transform.position.x < -10f) + { + Destroy(gameObject); + } + } +} + +public class ScoreTrigger : MonoBehaviour +{ + private void OnTriggerEnter2D(Collider2D collision) + { + FlappyBirdAllInOne gm = FindObjectOfType(); + + if (collision.CompareTag("Player") && gm != null) + { + gm.AddScore(); + } + } +} + +// ===================== +// navod pro desing t�m +// ===================== +/* +1. Player: + - Sprite + Rigidbody2D (Gravity ~2-3) + - BoxCollider2D + - PlayerController script + - Tag = Player + +2. Pipes: + - Prefab se 2 kolidery (top/bottom) + - Mezera mezi nimi + - PipeMove script + +3. Score Zone: + - Trigger collider mezi trubkami + - ScoreZone script + +4. Spawner: + - Empty GameObject + - PipeSpawner script + +5. UI: + - TextMeshPro pro score + - GameOver panel + restart button + +6. Mobile: + - Input.GetMouseButtonDown funguje i na tap +*/ \ No newline at end of file diff --git a/Assets/Scripts/flappy_bird - přejmenovat/flappy bird.cs.meta b/Assets/Scripts/flappy_bird - přejmenovat/flappy bird.cs.meta new file mode 100644 index 0000000..e86d446 --- /dev/null +++ b/Assets/Scripts/flappy_bird - přejmenovat/flappy bird.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 19096191e142d154e956c7169cca9a1e \ No newline at end of file diff --git a/Assets/Scripts/insert key/insertkeys.cs b/Assets/Scripts/insert key/insertkeys.cs index 481c28a..9d68ced 100644 --- a/Assets/Scripts/insert key/insertkeys.cs +++ b/Assets/Scripts/insert key/insertkeys.cs @@ -12,6 +12,7 @@ public class DraggableKey : MonoBehaviour, public string correctSlotID; public string previousSceneName; + [Header("Visual")] public Color wrongAttemptColor = Color.red; public float blinkDuration = 0.2f;