#How would music based combat work?

2 messages · Page 1 of 1 (latest)

knotty island
#

I’m trying to make a game where if the player attacks on beat with the music, they do more damage. How would one accomplish this? (I haven’t started yet, I just want to see if it’s feasible)

hybrid swallow
# knotty island I’m trying to make a game where if the player attacks on beat with the music, th...

Let's say for testing you have a 1 beat every 4 seconds.

Pseudo-code
var current_count: float
signal beat()

func process(delta):
  current_count += delta
  if current_count >= 4
    beat.emit()
    #Set timer back to 0, plus any leftover time from that frame
    current_count = current_count - 4 

Now, whenever your player attacks, send a signal to a "BeatMatcher" class (but don't actually deal any damage).
The BeatMatcher holds on to that info, and if a beat signal comes in or already came in within say, 0.2 of a second, increase damage of the attack, and then apply it.