I am trying hopelessly to recreate a DDR-style rhythm game clone in Scratch. (however, the language is irrelevant because this question is about math.)
I am wondering; How do I get a perfect sync between music and notes that won't delay- and won't break synchronicity when the note speed is manipulated (pre-game).
Needed variables:
"math": Going directly to the "change y by" in the notes.
"dist": Going directly to the "wait _ seconds" that's directly below its' definition.
Sprite: Note Interpreter
when ️ clicked
set map to "q w p op op owp ..."
set crawl to 8
set bpm to 100
set math to ((280 / crawl) / (bpm / 60) //needs improved formula!!
set dist to ((math * (bpm / 60)) / 100) //needs improved formula!!
comment "Y BOTTOM TO Y NOTE PRESSER DISTANCE IS 280px"
set misses to 0
set action to 0
for each v in length of map
if (letter v of map) = "q" then
broadcast SENDLEFT
else
if (letter v of map) = "w" then
broadcast SENDDOWN
else
if (letter v of map) = "o" then
broadcast SENDUP
else
if (letter v of map) = "p" then
broadcast SENDRIGHT
else
if (letter v of map) = "" then
wait dist seconds //wait until it can process next note
This is where "math" is going...
Sprite: Down Note
when I start as a clone
go to front layer
show
repeat until (act = "down") and (touching down?) or (touching edge?) // detects when the "DOWN" (qWop) key is pressed
change y by math //go up towards top of stage (Or note clickers if player is fast enough)
if (touching edge?) then
change misses by 1
set act to 0
delete this clone
Here's what the Stage looks like:
Stage appearance Stage appearance (with helper)
Running Scratch 3.21.0 on Modern Microsoft Edge 89.0.774.76; Windows 10 Home 20H2/2009 (according to Edge)