private static void QueueFlyingEffect(ScoreEffect scoreEffect) { scoreEffect.spawnTime = Time.GameTimeTotalSeconds; scoreEffect.start = scoreEffect.curr = scoreEffect.end; scoreEffect.end = Vector3.Zero; flyingEffects.Add(scoreEffect); }
private static void UpdateQuietEffects(Camera camera) { double currTime = Time.GameTimeTotalSeconds; for (int i = 0; i < quietEffects.Count; ++i) { ScoreEffect scoreEffect = quietEffects[i]; float timeElapsed = (float)(currTime - scoreEffect.spawnTime); if (timeElapsed >= kQuietEffectSeconds) { quietEffects.RemoveAt(--i + 1); ReleaseScoreEffect(scoreEffect); continue; } Score score = scores[(int)scoreEffect.color]; Viewport viewport = BokuGame.bokuGame.GraphicsDevice.Viewport; Vector3 pos = new Vector3( (float)viewport.Width * 0.9f, y_margin + ScoreBoardFont().LineSpacing *score.order, 1f); scoreEffect.curr = scoreEffect.start = scoreEffect.end = viewport.Unproject( pos, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); } }
private static void RenderEffect(ScoreEffect scoreEffect, Camera camera, Vector3 forward) { if (scoreEffect.crts == null) { return; } GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; Vector3 diff = scoreEffect.curr - camera.ActualFrom; float dist = diff.Length(); Parameter(EffectParams.ScoreAlpha).SetValue(scoreEffect.alpha); Parameter(EffectParams.ScoreColor).SetValue(Classification.ColorVector4(scoreEffect.color)); Parameter(EffectParams.ScoreColorDarken).SetValue(kScoreColorDarken); device.SetVertexBuffer(vertexBuf); device.Indices = UI2D.Shared.QuadIndexBuff; Matrix translation = new Matrix(); Matrix world = Matrix.CreateBillboard( scoreEffect.curr, camera.ActualFrom, camera.ViewUp, forward); float distanceScalar = kEffectScalar * dist; float offset = 0; for (int i = 0; i < scoreEffect.crts.Length; ++i) { CharRenderTarget crt = scoreEffect.crts[i]; if (i > 0) { offset += crt.charWidth / 2; } translation = Matrix.CreateTranslation(world.Left * offset * distanceScalar); Matrix worldViewProj = world * translation * camera.ViewMatrix * camera.ProjectionMatrix; Vector2 scoreSize = new Vector2(crt.surface.Width, crt.surface.Height) * distanceScalar; Parameter(EffectParams.WorldViewProj).SetValue(worldViewProj); Parameter(EffectParams.ScoreSize).SetValue(scoreSize); Parameter(EffectParams.ScoreTexture).SetValue(crt.surface); Effect.CurrentTechnique.Passes[0].Apply(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2); offset += crt.charWidth / 2; } }
private static void ReleaseScoreEffects() { while (quietEffects.Count > 0) { ScoreEffect scoreEffect = quietEffects[0]; ReleaseScoreEffect(scoreEffect); quietEffects.RemoveAt(0); } while (flyingEffects.Count > 0) { ScoreEffect scoreEffect = flyingEffects[0]; ReleaseScoreEffect(scoreEffect); flyingEffects.RemoveAt(0); } }
[SerializeField] ScoreEffect efePre; //エフェクト //----------------------------------------------------- // 得点を表示 //----------------------------------------------------- public void ScoreDraw(int point) { int score = ScoreManager.instance.GetScore(); int num = score * 10; for (int i = 2; i >= 0; i--) { int spriteNo = (int)(num / Mathf.Pow(10, i)); num -= (int)(spriteNo * Mathf.Pow(10, i)); numberImage[i].sprite = numberSprite[spriteNo]; } if (point == 0) { return; } //Effect ScoreEffect efe = Instantiate(efePre, transform); efe.PointSet(point); }
private static void RenderEffects(List <ScoreEffect> scoreEffects, Camera camera, Vector3 forward) { if (scoreEffects.Count > 0) { GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; Effect.CurrentTechnique = Effect.Techniques[0]; ShaderGlobals.FixExplicitBloom(0.15f); for (int i = 0; i < Effect.CurrentTechnique.Passes.Count; ++i) { EffectPass pass = Effect.CurrentTechnique.Passes[i]; pass.Apply(); for (int j = 0; j < scoreEffects.Count; ++j) { ScoreEffect scoreEffect = scoreEffects[j]; RenderEffect(scoreEffect, camera, forward); } } ShaderGlobals.ReleaseExplicitBloom(); } }
public void Play(GameMatch match, UIMatch uiMatch, UBasketball ball, int cnt) { m_initPos = (Vector3)match.mCurScene.mBasket.m_vShootTarget; if (match is GameMatch_PVP) { m_endPos = ball.m_actor.m_team == match.mainRole.m_team ? uiMatch.leftScoreBoard.transform.parent.localPosition : uiMatch.rightScoreBoard.transform.parent.localPosition; } else { m_endPos = ball.m_actor.m_team.m_side == Team.Side.eHome ? uiMatch.leftScoreBoard.transform.parent.localPosition : uiMatch.rightScoreBoard.transform.parent.localPosition; } m_endPos.z = 0.0f; m_uiMatch = uiMatch; for (int idx = 0; idx != cnt; idx++) { GameObject goItem = new GameObject(); ScoreEffect effect = goItem.AddComponent <ScoreEffect>(); m_effects.Add(effect); effect.m_effect = this; effect.Play(); } }
// Hierarchy of actions: only one action per update: one gem breaking or one gem spawning void Update() { // Check if can update something in this frame if (dontUpdate) { // Reset flag dontUpdate = false; // Don't allow players to input myCollider.enabled = true; return; } // Needs to break gems if (gemsToDestroy.Count > 0) { // Check if a new move was made if (moveMade) { // Clear flag moveMade = false; // Disable player input by putting a collider in front of the gems myCollider.enabled = true; // Reset combo counter comboCounter = 0; } // Update combo counter comboCounter++; // Destroy gems and get the points int score = destroyer.DestroyGems() * basePoints * comboCounter; gemsToDestroy.Clear(); // Make score effects audioSource.PlayOneShot(destroySound); if (scorePF) { ScoreEffect effect = Instantiate( scorePF, transform.position + Vector3.up * ROW_NUM * .6f, Quaternion.identity ).GetComponent <ScoreEffect>(); effect.SetScore(score); effect.transform.SetParent(transform); } // Add points to total totalScore += score; // Flag to move and spawn gems needToSpawnGems = true; } // Needs to move and spawn gems else if (needToSpawnGems) { // Clear flag needToSpawnGems = false; spawner.SpawnGems(); // Check if more matches were made gemsToDestroy = MatchLib.CheckMatches(gemTable); // If not, check if new moves are possible if (gemsToDestroy.Count == 0 && !MatchLib.MovementIsPossible(gemTable)) { // Shuffle until a new board with possible moves and no matches is made MatchLib.Shuffle(gemColumns, gemTable); } } // Else, nothing is happening. Allow player Input else { myCollider.enabled = false; } }
private static void QueueLoudEffect(ScoreEffect scoreEffect) { scoreEffect.spawnTime = Time.GameTimeTotalSeconds; //loudEffects.Add(scoreEffect); flyingEffects.Add(scoreEffect); }
private static void QueueQuietEffect(ScoreEffect scoreEffect) { scoreEffect.spawnTime = Time.GameTimeTotalSeconds; quietEffects.Add(scoreEffect); }
private static void ReleaseScoreEffect(ScoreEffect scoreEffect) { scoreEffect.thing = null; freeEffects.Push(scoreEffect); }
private static void UpdateFlyingEffects(Camera camera) { double currTime = Time.GameTimeTotalSeconds; for (int i = 0; i < flyingEffects.Count; ++i) { ScoreEffect scoreEffect = flyingEffects[i]; float timeElapsed = (float)(currTime - scoreEffect.spawnTime); if (timeElapsed > kFlyingEffectSeconds) { flyingEffects.RemoveAt(--i + 1); ReleaseScoreEffect(scoreEffect); continue; } Score score; scores.TryGetValue((int)scoreEffect.color, out score); Viewport viewport = BokuGame.bokuGame.GraphicsDevice.Viewport; float pct = timeElapsed / kFlyingEffectSeconds; // If the thing went to the recycle bin, remove our reference to it. if (scoreEffect.thing != null && scoreEffect.thing.CurrentState == GameThing.State.Inactive) { scoreEffect.thing = null; } // If we still have a reference to the thing, update the source position of the flying score's path. if (scoreEffect.thing != null) { scoreEffect.thingPosition = scoreEffect.thing.Movement.Position; } Vector3 pt0 = scoreEffect.thingPosition + new Vector3(0, 0, scoreEffect.thingBoundingRadius * 2); Vector3 pt1 = new Vector3( (float)viewport.Width * 0.5f, (float)viewport.Height * 0.3f, 0.75f); pt1 = viewport.Unproject( pt1, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); Vector3 pt2 = new Vector3( (float)viewport.Width * 0.6f, (float)viewport.Height * 0.1f, 0.5f); pt2 = viewport.Unproject( pt1, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); Vector3 pt3 = new Vector3( (float)viewport.Width * 0.9f, y_margin + ScoreBoardFont().LineSpacing *score.order, 0.5f); pt3 = viewport.Unproject( pt3, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); scoreEffect.curr = MyMath.CubicBezier(pt0, pt1, pt2, pt3, pct); scoreEffect.alpha = MyMath.Clamp((1f - pct) * 5, 0, 1); } }
/// <summary> /// Set the current value of a score. /// </summary> /// <param name="bucket">The bucket of the score register</param> /// <param name="value">The value the score should become</param> /// <param name="targetThing">The thing from which the score effect should originate</param> public static void SetScore(ScoreBucket bucket, int value, GameThing targetThing) { Score score = scores[(int)bucket]; score.Curr = value; int delta = score.Curr - score.Prev; if (delta != 0) { GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice; if (score.Visibility == ScoreVisibility.Loud && IsColorBucket(bucket)) { if (delta > 0) { Foley.PlayScore(null); } else { Foley.PlayScoreDown(null); } if (targetThing != null && !(targetThing is NullActor)) { ScoreEffect scoreEffect = AllocScoreEffect(); scoreEffect.thing = targetThing; scoreEffect.thingPosition = targetThing.Movement.Position; scoreEffect.thingBoundingRadius = targetThing.BoundingSphere.Radius; scoreEffect.color = (Classification.Colors)bucket; scoreEffect.start = scoreEffect.curr = targetThing.Movement.Position + targetThing.BoundingSphere.Center + new Vector3(0, 0, targetThing.BoundingSphere.Radius); scoreEffect.end = scoreEffect.start + new Vector3(0, 0, kFloatUpHeight); scoreEffect.alpha = 1f; setScoreCrtList.Clear(); /* * // Convert score delta to chars without creating a temporary string so that we don't * // create junk to be garbage collected (preserving XBOX perf on score-heavy levels). * * if (delta > 0) * setScoreCrtList.Add(charRenderTargets['+']); * else if (delta < 0) * setScoreCrtList.Add(charRenderTargets['-']); * * delta = Math.Abs(delta); * delta = Math.Min(delta, 1000); * * int thou = (delta % 10000) / 1000; * int hund = (delta % 1000) / 100; * int tens = (delta % 100) / 10; * int ones = (delta % 10); * * if (thou > 0) * setScoreCrtList.Add(charRenderTargets[(char)('0' + thou)]); * if (hund > 0 || thou > 0) * setScoreCrtList.Add(charRenderTargets[(char)('0' + hund)]); * if (tens > 0 || hund > 0 || thou > 0) * setScoreCrtList.Add(charRenderTargets[(char)('0' + tens)]); * * setScoreCrtList.Add(charRenderTargets[(char)('0' + ones)]); * */ // Not as memory clean but overcomes the limitations. // Score values are no longer limited to +- 1000 // We don't throw when exceeding max int. string deltaStr = delta.ToString(); setScoreCrtList.Clear(); foreach (char c in deltaStr) { setScoreCrtList.Add(charRenderTargets[c]); } scoreEffect.crts = setScoreCrtList.ToArray(); QueueLoudEffect(scoreEffect); } else { ScoreEffect scoreEffect = AllocScoreEffect(); scoreEffect.color = (Classification.Colors)bucket; QueueQuietEffect(scoreEffect); } } else if (score.Visibility == ScoreVisibility.Quiet) { ScoreEffect scoreEffect = AllocScoreEffect(); scoreEffect.color = (Classification.Colors)bucket; QueueQuietEffect(scoreEffect); } } }
void CreateEffect(Vector3 pos, string eff) { ScoreEffect effect = PoolManager.Instance.GetObject <ScoreEffect>(eff); effect.Initialize(pos + new Vector3(Random.Range(-50, 50), 130, 0)); }