Write a little game in Ruby!
gosu is a 2D game development library. Gosu features easy to use and game-friendly interfaces to 2D graphics and text (accelerated by 3D hardware), sound samples and music as well as keyboard, mouse and gamepad/joystick input. Also includes demos for integration with RMagick, Chipmunk and OpenGL.
gem "gosu", "~> 0.7.48" to your Gemfile and run
Play around with the example games:
Enough with those examples already!
Copy the repository by opening (a new tab in your) terminal. If you were working on the Rails Girls app in the mean time, make sure you’re in your home directory by running
aaand change into the proper directory using
To play our little game, open it using the terminal:
So how does this work?
Let’s inspect some code, shall we? Open
game.rb in your texteditor. See the
… right at the top of your file? Here we make sure we ‘call’ the necessary gem, so we can move on to our
class (or multiple classes).
So we have our
… thing going on. The
def’s you see within this Game class, are methods. Here we define which instructions the program should follow. Just take a look at the following snippet:
Want to play around a bit? Copy the contents of
game.rb in a new
.rb file. Save it and name it as you’d like. Now try and change some stuff in the game and run it in your terminal to see the changes.
Think you have more graphic skills than Patrick (you probably do)? Then you can try and create a new
sprites.png! Don’t forget to call it here:
And see the
Game.new.show? That creates a new instance. It has no memory, so when you get stuck in the game, you can just start a new game. Have fun!
The assets used in vim adventures, you can find them here
The sounds usedm you’ll find over at Matthew Klingensmith (www.matthewklingensmith.com)