Need help with dare?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

124 Stars 5 Forks MIT License 106 Commits 3 Opened issues


Ruby Web Game library on top of Opal

Services available


Need anything else?

Contributors list

# 368,132
88 commits
# 222,290
6 commits
# 186,712
3 commits

Dare Logo Dare

Gem Version Build Status Dependency Status Code Climate

This Gem is still in alpha! Breaking and changes are expected everywhere!

Ruby Web Game library on top of Opal


$ gem install dare

and then

$ dare new gamename
    create  gamename/Gemfile
    create  gamename/Rakefile
    create  gamename/gamename.rb
    create  gamename/gamename.html
$ cd gamename
gamename$ rake build

Which will create a game.js file and an game.html file. Open game.html in your favorite browser, and play your game!


Open up game.rb and add a rectangle to draw every frame:

class Game < Dare::Window
  def draw
    draw_rect(top_left: [0,0], width: 50, height: 50, color: 'red') #API subject to change

Save it, run

rake build
again, and refresh your game.html! There's a red square there! That's so cool!

Just keep in mind the "change ruby code" => "rake build" => "refresh browser" development cycle. This can be shortened to "change ruby code" => "refresh browser" if you set up guard, but I'll save that for the future. If you already know how, feel free to set that up!

Keyboard and Mouse input

You can respond to user input with a couple of helper methods Change just a few lines in your app.rb file

class Game < Dare::Window

def initialize super width: 800, height: 600, border: true #lets add an instance variable to store where our box is @x = 10 end

def draw # if the right arrow is being held down, add 5 to the position if button_down? Dare::KbRight @x += 5 end # if the position gets too large, reset it if @x > 600 @x = 10 end @y = mouse_y # mouse_y is a helper method which returns the y-position off the mouse #be sure to set the x position to @x and the y position to @y in the draw_rect method! draw_rect(top_left: [@x,@y], width: 50, height: 50, color: 'red') end



rake build
, refresh the browser, and voila! You can press the right arrow on your keyboard, and the box will move to the right! Move your mouse up and down and watch your box rise and fall!

Images and Sound

Adding images and sound is straightforward:

class Game < Dare::Window

def initialize super width: 800, height: 600, border: true @meow ='meow.mp3', volume: 0.5) @cat_picture ='cat_picture.jpg') @x = 10 end

def draw if button_down? Dare::KbRight @x += 5 end if @x > 600 @x = 10 end @cat_picture.draw(@x, 20) end

def update if @x > 500 end end


Now if you have a meow.mp3 file and a cat_picture.jpg file in the same directory as your html file, they will get loaded and played just like that!


To see more, go follow the tutorial in the wiki! I'm constantly adding new features, so be sure to check back often!

And go make a game!


Huge shoutout to jlnr for his Gosu gem which fueled a major part of this API. Go check out his work!

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.