Game Development Reference
In-Depth Information
Gosu Basics
By now Gosu should be installed and ready for a spin. But before we rush into building
our game, we have to get acquainted with our library. We will go through several simple
examples, familiarize ourselves with Gosu architecture and core principles, and take a
couple of baby steps towards understanding how to put everything together.
To make this chapter easier to read and understand, I recommend watching Writing Games
With Ruby talk given by Mike Moore at LA Ruby Conference 2014. In fact, this talk pushed
me towards rethinking this crazy idea of using Ruby for game development, so this topic
wouldn't exist without it. Thank you, Mike.
Hello World
To honor the traditions, we will start by writing “Hello World” to get a taste of what Gosu
feels like. It is based on Ruby Tutorial that you can find in Gosu Wiki .
01-hello/hello_world.rb
1 require 'gosu'
2
3 class GameWindow < Gosu :: Window
4 def initialize (width =320 , height =240 , fullscreen = false )
5 super
6
self . caption = 'Hello'
@message = Gosu :: Image . from_text(
7
self , 'Hello, World!' , Gosu . default_font_name, 30 )
8
9 end
10
11 def draw
12 @message . draw( 10 , 10 , 0 )
13 end
14 end
15
16 window = GameWindow . new
17 window . show
Run the code:
Search WWH ::




Custom Search