private void RotateCheck(RotateTile obj, bool _dir) { if (!obj.isRotate) { obj.isRotate = true; shouldRotate.Add(obj.GetComponent <RotateTile>()); obj.dir = _dir; for (int i = 0; i < 4; i++) { int tmpx = obj.posx, tmpy = obj.posy; if (i < 2) { tmpx += (int)Mathf.Pow(-1, i); } else { tmpy += (int)Mathf.Pow(-1, i); } if (tmpx > -1 && tmpy > -1 && tmpx < MAX_BOUND && tmpy < MAX_BOUND) { if (tileState[tmpx, tmpy] != null) { if (tileState[tmpx, tmpy].tileClass == 2) { obj.surround[i] = tileState[tmpx, tmpy].GetComponent <RotateTile>(); } } else { obj.surround[i] = null; } } } for (int j = 0; j < 4; j++) { if (obj.surround[j] != null) { RotateCheck(obj.surround[j], !_dir); } } } }
// Update is called once per frame void Update() { foreach (Character c in game_chars) { if (c != player && player_exists == true) { float distance = Vector3.Distance(player.transform.position, c.transform.position); if (distance < (player.radius + c.radius)) { player_exists = false; DestroyImmediate(player.gameObject); DestroyImmediate(player); dead = true; Camera.main.GetComponent <Camera>().backgroundColor = new Color((38f / 255f), (38f / 255f), (38f / 255f)); game_chars = FindObjectsOfType <Character>(); RotateTile[] rotate_tiles = FindObjectsOfType <RotateTile>(); foreach (RotateTile rt in rotate_tiles) { SpriteRenderer sr = rt.GetComponent <SpriteRenderer>(); sr.color = new Color((128f / 255f), (128f / 255f), (128f / 255f)); rt.characters = game_chars; } restart_visible = true; restart_text.SetActive(restart_visible); } } } if (Input.GetKeyDown("escape")) { foreach (RotateTile t in tiles) { if (!menu_visible) { if (t.rotatable) { selected = t; } } t.rotatable = false; if (menu_visible) { selected.rotatable = true; } } menu_visible = !menu_visible; change_selection = !menu_visible; foreach (Character c in game_chars) { c.paused = menu_visible; } pause_menu.SetActive(menu_visible); } if (Input.GetKey(KeyCode.Space)) { foreach (Character c in game_chars) { if (c.timefactor == 1) { c.timefactor = 2; c.MaxProgress = c.MaxProgress / 2; c.progress = c.progress / 2; } } } else { foreach (Character c in game_chars) { if (c.timefactor == 2) { c.timefactor = 1; c.MaxProgress = c.MaxProgress * 2; c.progress = c.progress * 2; } } } if (Input.GetKeyDown(KeyCode.R)) { EndGame(DEFEAT); } }