Skip to content

Commit

Permalink
Add support for touch input.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jun 24, 2024
1 parent 49123e5 commit 0c33b8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
14 changes: 10 additions & 4 deletions examples/flappy-bird/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,19 @@ def close
super
end

def jump
play_sound("quack") if rand > 0.5

@bird&.jump
end

def handle(event)
case event[:type]
when "touchstart"
self.jump
when "keypress"
if event.dig(:detail, :key) == " "
play_sound("quack") if rand > 0.5

@bird&.jump
self.jump
end
end
end
Expand Down Expand Up @@ -358,7 +364,7 @@ def run!(dt = 1.0/10.0)
end

def render(builder)
builder.tag(:div, class: "flappy", tabIndex: 0, onKeyPress: forward_keypress) do
builder.tag(:div, class: "flappy", tabIndex: 0, onKeyPress: forward_keypress, onTouchStart: forward_keypress) do
if @game
builder.inline_tag(:div, class: "score") do
builder.text(@score)
Expand Down
42 changes: 21 additions & 21 deletions examples/flappy-bird/gems.locked
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ PATH
GEM
remote: https://rubygems.org/
specs:
async (2.12.0)
async (2.12.1)
console (~> 1.25, >= 1.25.2)
fiber-annotation
io-event (~> 1.6)
io-event (~> 1.6, >= 1.6.5)
async-container (0.18.2)
async (~> 2.10)
async-http (0.67.1)
async-http (0.69.0)
async (>= 2.10.2)
async-pool (>= 0.6.1)
io-endpoint (~> 0.10, >= 0.10.3)
async-pool (~> 0.7)
io-endpoint (~> 0.11)
io-stream (~> 0.4)
protocol-http (~> 0.26.0)
protocol-http1 (~> 0.19.0)
protocol-http2 (~> 0.18.0)
traces (>= 0.10.0)
protocol-http (~> 0.26)
protocol-http1 (~> 0.19)
protocol-http2 (~> 0.18)
traces (>= 0.10)
async-http-cache (0.4.3)
async-http (~> 0.56)
async-pool (0.6.1)
async-pool (0.7.0)
async (>= 1.25)
async-service (0.12.0)
async
async-container (~> 0.16)
async-websocket (0.26.1)
async-websocket (0.26.2)
async-http (~> 0.54)
protocol-rack (~> 0.5)
protocol-websocket (~> 0.11)
protocol-websocket (~> 0.14)
console (1.25.2)
fiber-annotation
fiber-local (~> 1.1)
json
falcon (0.47.6)
falcon (0.47.7)
async
async-container (~> 0.18)
async-http (~> 0.66, >= 0.66.3)
Expand All @@ -54,9 +54,9 @@ GEM
fiber-annotation (0.2.0)
fiber-local (1.1.0)
fiber-storage
fiber-storage (0.1.1)
io-endpoint (0.10.3)
io-event (1.6.4)
fiber-storage (0.1.2)
io-endpoint (0.11.0)
io-event (1.6.5)
io-stream (0.4.0)
json (2.7.2)
live (0.11.0)
Expand All @@ -69,18 +69,18 @@ GEM
console (~> 1.8)
samovar (~> 2.1)
protocol-hpack (1.4.3)
protocol-http (0.26.5)
protocol-http (0.26.6)
protocol-http1 (0.19.1)
protocol-http (~> 0.22)
protocol-http2 (0.18.0)
protocol-hpack (~> 1.4)
protocol-http (~> 0.18)
protocol-rack (0.5.1)
protocol-rack (0.6.0)
protocol-http (~> 0.23)
rack (>= 1.0)
protocol-websocket (0.13.0)
protocol-websocket (0.14.0)
protocol-http (~> 0.2)
rack (3.1.3)
rack (3.1.4)
samovar (2.3.0)
console (~> 1.0)
mapping (~> 1.0)
Expand All @@ -98,4 +98,4 @@ DEPENDENCIES
sqlite3

BUNDLED WITH
2.5.9
2.5.11

0 comments on commit 0c33b8a

Please sign in to comment.