public void HandleTickChange(NotationTime currentTime) { if (tickUnlockTime.TimeAsTicks() == Metronome.Instance.currentTime.TimeAsTicks()) { tickLock = false; } }
void Awake() { //wait for instrument set up ready = false; metro = this; startTime = AudioSettings.dspTime; //set up audio DSP buffer size and sample rate for whole program sampleRate = AudioSettings.outputSampleRate; ticksPerQuarter = 4; quartersPerBar = 4; ticksPerBar = ticksPerQuarter * quartersPerBar; //set up basic subdivision samplesPerBar = (int)(sampleRate / (BPM / 60.0f)) * 4; samplesPerQuarter = samplesPerBar / 4; samplesPerTick = samplesPerQuarter / ticksPerQuarter; secondsPerTick = (double)samplesPerTick / (double)sampleRate; lastTickTime = startTime; nextTickTime = startTime + secondsPerTick; currentTick = 0; currentQuarter = 0; currentBar = 0; currentTime = new NotationTime(0, 0, 0); notationTick = new NotationTime(0, 0, 1); }
public void HandleBlastZoneInput(Vector2 touchPosition) { if (!tickLock && HasFirepower()) { BlastZone touchedBlastZone = CheckForBlastZones(touchPosition); if (touchedBlastZone != null) { if (touchedBlastZone.CanGrow()) { touchedBlastZone.GrowNextTick(); ticksFired++; } } else if (zoneCount < MAX_ZONES) { Ray ray = Camera.main.ScreenPointToRay(new Vector3(touchPosition.x, touchPosition.y, 0)); RaycastHit hit; if (blastCollider.Raycast(ray, out hit, 1000.0F)) { GameObject zoneMade = GameObject.Instantiate(blastZone, hit.point, Quaternion.identity); BlastZones.Add(zoneMade.GetComponent <BlastZone>()); zoneMade.transform.parent = blastZoneParent; zoneMade.GetComponent <BlastZone>().CreateZone(Metronome.Instance.currentTime); ticksFired++; zoneCount++; } } tickUnlockTime = new NotationTime(Metronome.Instance.currentTime); tickUnlockTime.Add(new NotationTime(0, 0, 1)); tickLock = true; } }
public void CreateZone(NotationTime timeToCreate) { //this.timeToCreate = timeToCreate; gameObject.GetComponent <MeshRenderer>().enabled = true; currentSize++; SFXPlayer.Instance.PlayCircleStart(); }
void Fire() { firing = true; NotationTime firingStart = new NotationTime(Metronome.Instance.currentTime); firingStart.Add(new NotationTime(0, 0, 1)); int pointsGained = 0; int multiplier = 0; foreach (CubeThumper thump in targetedCubes) { if (thump != null) { int lockLength = thump.GetLockLength(); int fireResult = thump.FireCube(firingStart); if (fireResult > 0) { pointsGained += fireResult; multiplier++; } firingStart.Add(new NotationTime(0, 0, lockLength)); } } GameManager.gameScore += pointsGained * multiplier; timeUntilCanFireAgain = Metronome.Instance.GetFutureTime(firingStart.bar, firingStart.quarter, firingStart.tick); targetedCubes.Clear(); numberOfLocks = 0; }
public int FireCube(NotationTime toFire) { hasFired = true; currentHealth -= lockNum; spriteRenderer.enabled = false; AudioClip soundToPlay; if (Destroyed()) { soundToPlay = destroyClips[UnityEngine.Random.Range(0, destroyClips.Length)]; } else { soundToPlay = fireClips[UnityEngine.Random.Range(0, fireClips.Length)]; } if (Destroyed()) { NotationTime timeLeft = new NotationTime(toFire); timeLeft.Add(new NotationTime(0, 1, 0)); timeAlive = Metronome.Instance.GetFutureTime(timeLeft.bar, timeLeft.quarter, timeLeft.tick); return(scoreValue); } lockNum = 0; return(-1); }
public BackgroundClip(AudioClip p_clip, string p_key, int p_numBars) { key = p_key; clip = p_clip; numBars = p_numBars; length = new NotationTime(numBars, 0, 0); clipName = clip.name; }
public void HandleTickChange(NotationTime currentTime) { if (growNextTick) { GrowZone(); growNextTick = false; } }
public double GetFutureTime(NotationTime time) { int tickTime = (time.bar * ticksPerBar) + (time.quarter * ticksPerQuarter) + time.tick; int currentTickTime = (currentBar * ticksPerBar) + (currentQuarter * ticksPerQuarter) + currentTick; if (currentTickTime > tickTime) { return(-1); } int futureTicks = tickTime - currentTickTime; return(lastTickTime + (futureTicks * secondsPerTick)); }
public void BeginGame() { backgroundLoop.GetComponent <BackgroundMusic>().Init("CaptainPlanetBeach"); player.speed = 6f; UpdateText(); //Delay before activating game controller StartCoroutine(StartController(0.01f)); ChangeState(GameState.Playing); tickUnlockTime = new NotationTime(Metronome.Instance.currentTime); tickUnlockTime.Add(new NotationTime(0, 0, 1)); StartCoroutine(StartSpawn(3f)); Metronome.tickChangeDelegate += HandleTickChange; }
public void Init(string p_clip) { SetNextLoop(p_clip); if (Metronome.Instance.ready) { Debug.Log("Error: cannot call StartMusic when metro is already ticking, call StopMusic first"); return; } Metronome.Instance.SetBPM(100.0f); Metronome.Instance.ready = true; nextPlay = new NotationTime(Metronome.Instance.currentTime); nextPlay.AddTick(); HandleTickChange(Metronome.Instance.currentTime); Metronome.tickChangeDelegate += HandleTickChange; }
public void HandleTickChange(NotationTime currentTime) { if (currentTime.TimeAsTicks() == nextPlay.TimeAsTicks() - 1) { double nextPlayTime = Metronome.Instance.GetFutureTime(nextPlay); //sources[nextSource].clip = nextClip.clip; sources[nextSource].clip = nextClip.clip; sources[nextSource].volume = 0.4f; sources[nextSource].PlayScheduled(nextPlayTime); //Set next time to play currentClip = nextClip; nextPlay.Add(currentClip.length); nextSource = (nextSource + 1) % sources.Length; } }
public void Add(NotationTime other) { tick += other.tick; if (tick >= 4) { tick -= 4; quarter++; } quarter += other.quarter; if (quarter >= 4) { quarter -= 4; bar++; } bar += other.bar; }
public void PlayCircleDestroy() { NotationTime nextPlay = new NotationTime(Metronome.Instance.currentTime); nextPlay.AddTick(); double nextPlayTime = Metronome.Instance.GetFutureTime(nextPlay); sources[currentSource].clip = explosions[0]; sources[currentSource].volume = 0.1f; sources[currentSource].pitch = 1.122462f; //up one tone sources[currentSource].PlayScheduled(nextPlayTime); currentSource++; if (currentSource == sources.Length) { currentSource = 0; } }
public void PlayCircleStart() { NotationTime nextPlay = new NotationTime(Metronome.Instance.currentTime); nextPlay.AddTick(); double nextPlayTime = Metronome.Instance.GetFutureTime(nextPlay); NoteChoice(); sources[currentSource].volume = 0.4f; sources[currentSource].pitch = 1.0f; sources[currentSource].PlayScheduled(nextPlayTime); currentSource++; if (currentSource == sources.Length) { currentSource = 0; } }
// Update is called once per frame void Update() { //Otherwise we check if the tick has advanced then release the lock if (!currentTickTime.Equals(Metronome.Instance.currentTime)) { lockedThisTick = false; currentTickTime = new NotationTime((Metronome.Instance.currentTime)); } if (firing && AudioSettings.dspTime >= timeUntilCanFireAgain) { firing = false; } //If an object hasn't been locked on this tick do raycasting //Cannot rely on list count anymore, will have to keep track in method if (numberOfLocks < maxLock && !lockedThisTick) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.SphereCastAll(ray.origin, 1, ray.direction, 1000.0f); for (int i = 0; i < hits.Length; i++) { GameObject obj = hits[i].transform.gameObject; if (obj.CompareTag("Thumper")) { CubeThumper thump = obj.GetComponent <CubeThumper>(); if (thump.Lockable() && !lockedThisTick) { thump.HitCube(); if (!targetedCubes.Contains(thump)) { targetedCubes.Add(thump); } lockedThisTick = true; numberOfLocks++; } } if (!obj.CompareTag("Cleanup") && obj.CompareTag("Player") && !firing) { Fire(); } } } }
public NotationTime(NotationTime other) { this.bar = other.bar; this.quarter = other.quarter; this.tick = other.tick; }
// Use this for initialization void Start() { currentTickTime = new NotationTime(Metronome.Instance.currentTime); }
protected bool Equals(NotationTime other) { return(bar == other.bar && quarter == other.quarter && tick == other.tick); }