1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
| using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FirstSceneController : MonoBehaviour, SceneController, UserAction {
public FlyActionManager actionManager; public DiskFactory diskFactory; public UserGUI userGUI; public ScoreRecorder scoreRecorder;
private Queue<GameObject> diskQueue = new Queue<GameObject>(); private List<GameObject> diskNotshot = new List<GameObject>(); private int diskNumber; private int currentRound; private int roundNumber; private float frequency; private GameState gameState = GameState.PAUSE;
void Start() { Director director = Director.getInstance(); director.currentSceneController = this; diskNumber = 10; currentRound = 1; roundNumber = 3; frequency = 2f; scoreRecorder = Singleton<ScoreRecorder>.Instance; diskFactory = Singleton<DiskFactory>.Instance; actionManager = gameObject.AddComponent<FlyActionManager>(); userGUI = gameObject.AddComponent<UserGUI>() as UserGUI; director.setFPS(60); }
public void LoadResources() { diskQueue.Enqueue(diskFactory.GetDisk(currentRound)); }
private void Update() { if (diskNumber == 0 && currentRound < roundNumber) { CancelInvoke("LoadResources"); } if (diskNumber == 0 && currentRound == roundNumber) { gameState = GameState.FINISH; } else if (diskNumber == 0 && diskNotshot.Count == 0) { diskNumber = 10; frequency -= 0.4f; gameState = GameState.ROUND_FINISH; } if (gameState == GameState.START) { InvokeRepeating("LoadResources", 1f, frequency); gameState = GameState.ROUND_START; } if (gameState == GameState.FINISH || gameState == GameState.ROUND_FINISH || gameState == GameState.PAUSE) { CancelInvoke("LoadResources"); } if (gameState == GameState.ROUND_START) ThrowDisk(); }
public void ThrowDisk() { float position_x = 16; if (diskQueue.Count != 0) { diskNumber--; GameObject disk = diskQueue.Dequeue(); diskNotshot.Add(disk); disk.SetActive(true);
float ran_y = Random.Range(1f, 4f); float ran_x = Random.Range(-1f, 1f) < 0 ? -1 : 1; disk.GetComponent<DiskData>().direction = new Vector3(ran_x, ran_y, 0); Vector3 position = new Vector3(-disk.GetComponent<DiskData>().direction.x * position_x, ran_y, 0); disk.transform.position = position;
float power = Random.Range(10f, 15f); float angle = Random.Range(15f, 28f); actionManager.Fly(disk, angle, power); }
for (int i = 0; i < diskNotshot.Count; i++) { GameObject temp = diskNotshot[i]; if (temp.transform.position.y < -20 && temp.gameObject.activeSelf == true) { diskFactory.FreeDisk(diskNotshot[i]); diskNotshot.Remove(diskNotshot[i]); } } }
public void Hit(Vector3 position) { Ray ray = Camera.main.ScreenPointToRay(position); RaycastHit[] hits; hits = Physics.RaycastAll(ray);
for (int i = 0; i < hits.Length; i++) { RaycastHit hit = hits[i]; if (hit.collider.gameObject.GetComponent<DiskData>() != null) { scoreRecorder.Record(hit.collider.gameObject); hit.collider.gameObject.transform.position = new Vector3(0, -20, 0); } } }
public int GetScore() { return scoreRecorder.score; }
public void Restart() { gameState = GameState.START; scoreRecorder.Reset(); currentRound = 1; diskNumber = 10; frequency = 2f; }
public void Pause() { gameState = GameState.PAUSE; }
public void Begin() { gameState = GameState.START; }
public void NextRound() { gameState = GameState.START; currentRound++; }
public GameState getGameState() { return gameState; }
public void setGameState(GameState gs) { gameState = gs; }
public int GetRound() { return this.currentRound; }
IEnumerator WaitingParticle(float wait_time, RaycastHit hit, DiskFactory disk_factory, GameObject obj) { yield return new WaitForSeconds(wait_time); hit.collider.gameObject.transform.position = new Vector3(0, -20, 0); disk_factory.FreeDisk(obj); } }
|