Skip to content

Commit

Permalink
Fix bonus reset and sounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed May 15, 2024
1 parent 3b3a4f8 commit e0d11a2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions examples/flappy-bird/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,22 @@ def reset!
Pipe.new(WIDTH * 1/2, HEIGHT/2),
Pipe.new(WIDTH * 2/2, HEIGHT/2)
]
@bonus = nil
@score = 0
end

def play_sound(name)
path = "/_static/#{name}.mp3"
self.script("new Audio(#{JSON.dump(path)}).play()")
self.script(<<~JAVASCRIPT)
if (!this.sounds) {
this.sounds = {};
}
if (!this.sounds[#{JSON.dump(name)}]) {
this.sounds[#{JSON.dump(name)}] = new Audio('/_static/#{name}.mp3');
}
this.sounds[#{JSON.dump(name)}].play();
JAVASCRIPT
end

def play_music
Expand Down

0 comments on commit e0d11a2

Please sign in to comment.