0

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)

2 Answers2

0

"How do I get a perfect sync between music and notes that won't delay..."?

If that's the problem it's very much to do with using Scratch.

A couple of tricks:

  • every block happens at a regular interval: scratch runs block, then refreshes the screen, then next block... Each screen refresh is done on a regular period, so each block takes an equal amount of time.

  • if you want a bunch of blocks that go quicker, e.g. for a calculation, use a custom block (pink ones) and as you build it tick "run without a screen refresh". It then runs in the cycle of one screen refresh, but there is no screen updating until after it's done.

  • you could control timing by running a script that acts as a kind of metronome:

     when green flag
        forever
           broadcast tick
           wait 0.2 seconds (<-- or whatever the tempo is)
    

Then music and animation to the beat:

   when i receive tick
      play the_note
      move...
boisvert
  • 3,679
  • 2
  • 27
  • 53
0

there is a block for this in scratch. Add the music extension. It's the wait () beats block You can also set the tempo.

Murcamus21
  • 19
  • 1
  • 5