Skip to content

Commit

Permalink
Use Random in Confetti Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
davesmith00000 committed Nov 10, 2024
1 parent 0496851 commit 5cd29fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb
val viewportHeight: Int = gameHeight * magnificationLevel // 256

def initialScene(bootData: SandboxBootData): Option[SceneName] =
Some(CaptureScreenScene.name)
Some(ConfettiScene.name)

def scenes(bootData: SandboxBootData): NonEmptyList[Scene[SandboxStartupData, SandboxGameModel, SandboxViewModel]] =
NonEmptyList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object ConfettiScene extends Scene[SandboxStartupData, SandboxGameModel, Sandbox
Outcome(
model
.spawn(
context.frame.dice,
context.services.random,
pos.x,
pos.y,
spawnCount
Expand Down Expand Up @@ -108,16 +108,16 @@ object ConfettiScene extends Scene[SandboxStartupData, SandboxGameModel, Sandbox
)

final case class ConfettiModel(color: Int, particles: js.Array[js.Array[Particle]]):
def spawn(dice: Dice, x: Int, y: Int, count: Int): ConfettiModel =
def spawn(random: Context.Services.Random, x: Int, y: Int, count: Int): ConfettiModel =
this.copy(
particles = js.Array((0 until count).toJSArray.map { _ =>
Particle(
x,
y,
dice.rollFloat * 2.0f - 1.0f,
dice.rollFloat * 2.0f,
random.nextFloat * 2.0f - 1.0f,
random.nextFloat * 2.0f,
color,
((dice.rollFloat * 0.5f) + 0.5f) * 0.5f
((random.nextFloat * 0.5f) + 0.5f) * 0.5f
)
}) ++ particles
)
Expand Down

0 comments on commit 5cd29fd

Please sign in to comment.