You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.1 KiB

2 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2 years ago
using UnityEngine.SceneManagement;
public class Game : MonoBehaviour
{
// Start is called before the first frame update
[SerializeField] GameObject _cloudPrefab;
2 years ago
[SerializeField] GameObject _birdPrefab;
[SerializeField] GameObject _pterodactylPrefab;
2 years ago
const int NUM_CLOUDS = 8;
const float START_X = 1300;
const float PTERODACTYL_CHANCE = .15f;
[SerializeField] Text _victoryMessage;
[SerializeField] Text _restartMessage;
bool _victory = false;
2 years ago
float _timeToNextBird = 0f;
2 years ago
void Start()
{
_victoryMessage.enabled = false;
_restartMessage.enabled = false;
for (int i = 0; i < NUM_CLOUDS; ++i)
{
GameObject cloud = GameObject.Instantiate(_cloudPrefab);
2 years ago
cloud.transform.position = new Vector3(Random.Range(START_X, START_X + 1920 + CloudWraparound.DISTANCE_OFF_LEFT_EDGE), cloud.transform.position.y, cloud.transform.position.z);
}
2 years ago
}
public void Victory(string dragonName, Color color)
{
if (_victory)
return;
_victory = true;
_restartMessage.enabled = true;
_victoryMessage.enabled = true;
_victoryMessage.text = dragonName.ToUpper() + " WINS!";
_victoryMessage.color = color;
}
2 years ago
void SpawnBird()
{
GameObject bird;
if (Random.Range(0f,1f)< PTERODACTYL_CHANCE)
{
bird = GameObject.Instantiate(_pterodactylPrefab);
}
else
{
bird = GameObject.Instantiate(_birdPrefab);
}
2 years ago
float y = Random.Range(0f, 1080f);
bird.transform.position = new Vector3(2000f, y, 0f);
_timeToNextBird = Random.Range(0f, 4f);
}
2 years ago
// Update is called once per frame
void Update()
{
2 years ago
_timeToNextBird -= Time.deltaTime;
if (_timeToNextBird < 0f)
{
SpawnBird();
}
2 years ago
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}