0% found this document useful (0 votes)
131 views11 pages

Developing Games With Ruby Sample

Developing Games With Ruby Sample
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views11 pages

Developing Games With Ruby Sample

Developing Games With Ruby Sample
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Developing Games With Ruby

For those who write code for living

Tomas Varaneckas
This book is for sale at http://leanpub.com/developing-games-with-ruby

This version was published on 2014-10-30

This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and
many iterations to get reader feedback, pivot until you have the right book and build traction once
you do.

©2014 Tomas Varaneckas


Tweet This Book!
Please help Tomas Varaneckas by spreading the word about this book on Twitter!
The suggested hashtag for this book is #DevelopingGamesWithRuby.
Find out what other people are saying about the book by clicking on this link to search for this
hashtag on Twitter:
https://twitter.com/search?q=#DevelopingGamesWithRuby
Also By Tomas Varaneckas
Automation and Monitoring with Hubot
Contents

A Boy Who Wanted To Create Worlds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Why Ruby? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

What You Should Know Before Reading This Book . . . . . . . . . . . . . . . . . . . . . . 3

What Are We Going To Build? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4


Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Game Development Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Theme And Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
A Boy Who Wanted To Create Worlds
Once there was a boy who fell in love with this magical device that could bring things to life inside
a glaring screen. He spent endless hours exploring imaginary worlds, fighting strange creatures,
shooting pixelated spaceships, racing boxy cars. The boy kept pondering. “How is this made? I want
to create my own worlds…”.
Then he discovered programming. “I can finally do it!” - he thought. And he tried. And failed. Then
he tried harder. He failed again and again. He was too naive to realize that those worlds he was
trying to create were too sophisticated, and his knowledge was too limited. He gave up creating
those worlds.
What he didn’t give up is writing code for this magical device. He realized he isn’t smart enough to
create worlds, yet he found out he could create simpler things like small applications - web, desktop,
server side or whatnot. Few years later he found himself getting paid to make those.
Applications got increasingly bigger, they spanned across multiple servers, integrated with each
other, became pats of huge infrastructures. The boy, now a grown man, was all into it. It was fun
and challenging enough to spend over 10000 hours learning and building what others wanted him
to build.
Some of these things were useful, some where boring and pointless. Some were never finished. There
were things he was proud of, there were others that he wouldn’t want to talk about, nonetheless
everything he built made him a better builder. Yet he never found the time, courage or reason to
build what he really wanted to build since he was a little boy - his own worlds.
Until one day he realized that no one can stop him from following his dream. He felt that equipped
with his current knowledge and experience he will be able to learn to create worlds of his own. And
he went for it.
This boy must live in many software developers, who dream about creating games, but instead sell
their software craftsmanship skills to those who need something else. This boy is me, and you. And
it’s time to set him free.
Welcome to the world of game development that was waiting for you all these years.
Why Ruby?
When it comes to game development, everyone will tell you that you should go with C++ or some
other statically typed language that compiles down to bare metal instructions. Or that you should go
with full blown game development platform like Unity¹. Slow, dynamic languages like Ruby seem
like the last choice any sane game developer would go for.
A friend of mine said² “There’s little reason to develop a desktop game with Ruby”, and he was
absolutely right. Perhaps this is the reason why there are no books about it. All the casual game
action happens in mobile devices, and desktop games are for seasoned gamers who demand fast
and detailed 3D graphics, motion-captured animations and sophisticated game mechanics - things
we know we are not going to be able to build on our own, without millions from VC pockets and
Hollywood grade equipment.
Now, bear with me. Your game will not be a 3D MMORPG set in huge, photo realistic representation
of Middle-earth. Let’s leave those things to Bethesda, Ubisoft and Rockstar Games. After all,
everyone has to start somewhere, and you have to be smart enough to understand, that even though
that little boy in you wants to create an improved version of Grand Theft Auto V, we will have to
go for something that resembles lesser known Super Nintendo titles instead.
Why not go mobile then? Those devices seem perfect for simpler games. If you are a true gamer at
heart, you will agree that touch screen games you find in modern phones and tablets are only good
for killing 10 minutes of your time while taking a dump. You have to feel the resistance when you
click a button! Screen size also does matter. Playing anything on mobile phone is a torture for those
who know what playing real games should feel like.
So, your game will have to be small enough for you to be able to complete it, it will have to have
simple 2D graphics, and would not require the latest GeForce with at least 512MB of RAM. This
fact gives you the benefit of choice. You don’t have to worry about performance that much. You can
choose a friendly and productive language that is designed for programmer happiness. And this is
where Ruby starts to shine. It’s beautiful, simple and elegant. It is close to poetry.
¹http://unity3d.com/
²https://twitter.com/mmozuras/status/476240137199054848
What You Should Know Before
Reading This Book
As you can read on the cover, this book is “for those who write code for living”. It’s not a requirement,
and you will most likely be able to understand everything even if you are a student or hobbyist, but
this book will not teach you how to be a good programmer. If you want to learn that, start with
timeless classic: The Pragmatic Programmer: From Journeyman to Master³.
You should understand Ruby at least to some extent. There are plenty of books and resources
covering that subject. Try Why’s Poignant Guide To Ruby⁴ or Eloquent Ruby⁵. You can also learn
it while reading this book. It shouldn’t be too hard, especially if you already write code for living.
After all programming language is merely a tool, and when you learn one, others are relatively easy
to switch to.
You should know how to use the command line. Basic knowledge of Git⁶ can also be handy.
You don’t have to know how to draw or compose music. We will use media that is available for free.
However, knowledge of graphics and audio editing software won’t hurt.
³https://www.goodreads.com/book/show/4099.The_Pragmatic_Programmer
⁴http://mislav.uniqpath.com/poignant-guide/
⁵https://www.goodreads.com/book/show/9364729-eloquent-ruby
⁶http://git-scm.com/
What Are We Going To Build?
This question is of paramount importance. The answer will usually determine if you will likely to
succeed. If you want to overstep your boundaries, you will fail. It shouldn’t be too easy either. If you
know something about programming already, I bet you can implement Tic Tac Toe, but will you feel
proud about it? Will you be able to say “I’ve built a world!”. I wouldn’t.

Graphics
To begin with, we need to know what kind of graphics we are aiming for. We will instantly rule out
3D for several reasons:

• We don’t want to increase the scope and complexity


• Ruby may not be fast enough for 3D games
• Learning proper 3D graphics programming requires reading a separate book that is several
times thicker than this one.

Now, we have to swallow our pride and accept the fact that the game will have simple 2D graphics.
There are three choices to go for:

• Parallel Projection
• Top Down
• Side-Scrolling

Parallel Projection (think Fallout 1 & 2) is pretty close to 3D graphics, it requires detailed art if you
want it to look decent, so we would have a rough start if we went for it.
Top Down view (old titles of Legend of Zelda) offers plenty of freedom to explore the environment
in all directions and requires less graphical detail, since things look simpler from above.
Side Scrolling games (Super Mario Bros.) usually involve some physics related to jumping and
require more effort to look good. Feeling of exploration is limited, since you usually move from
left to right most of the time.
Going with Top Down view will give us a chance to create our game world as open for exploration
as possible, while having simple graphics and movement mechanics. Sounds like the best choice for
us.
Since you are probably as bad in drawing things as I am, you could still wonder how we are going
to get our graphics. Thankfully, there is this opengameart.org⁷. It’s like GitHub of game media, we
will surely find something there. It also contains audio samples and tracks.
⁷http://opengameart.org
What Are We Going To Build? 5

Game Development Library


Implement it all yourself or harness the power of some game development library that offers you
boilerplates and convenient access to common functions? If you’re like me, you would definitely
want to implement it all yourself, but that may be the reason why I failed to make a decent game
so many times.
If you will try to implement it all yourself, you will most likely end up reimplementing some existing
game library, poorly. It won’t take long while you reach a point where you need to interface with
underlying operating system libraries to get graphics. And guess if those bindings will work in a
different operating system?
So, swallow your pride again, because we are going to use an existing game development library.
Good news is that you will be able to actually finish the game, and it will be portable to Windows,
Mac and Linux. We will still have to build our own game engine for ourselves on top of it, so don’t
think it won’t be fun.
There are several game libraries⁸ available for Ruby, but it’s a simple choice, because Gosu⁹ is head
and shoulders above others. It’s very mature, has a large and active community, and it is mainly
written in C++ but has first class Ruby support, so it will be both fast and convenient to use.
Many of other Ruby game libraries are built on top of Gosu, so it’s a solid choice.

Theme And Mechanics


Choosing the right theme is undoubtedly important. It should be something that appeals to
you, something you will want to play, and it should not imply difficult game mechanics. I love
MMORPGs, and I always dreamed of making an open world game where you can roam around,
meet other players, fight monsters and level up. Guess how many times I started building such a
game? Even if I wouldn’t have lost the count, I wouldn’t be proud to say the number.
This time, equipped with logic and sanity, I’ve picked something challenging enough, yet still pretty
simple to build. Are you ready?
Drumroll…
We will be building a multi directional shooter arcade game where you control a tank, roam around
an island, shoot enemy tanks and try not to get destroyed by others.
If you have played Battle City¹⁰ or Tank Force¹¹, you should easily get the idea. I believe that
implementing such a game (with several twists) would expose us to perfect level of difficulty and
provide substantial amount of experience.
⁸https://www.ruby-toolbox.com/categories/game_libraries
⁹http://www.libgosu.org/
¹⁰http://en.wikipedia.org/wiki/Battle_City_(video_game)
¹¹http://en.wikipedia.org/wiki/Tank_Force
What Are We Going To Build? 6

We will use a subset of these gorgeous graphics¹² which are available on opengameart.org¹³,
generously provided by Csaba Felvegi¹⁴.

¹²http://www.praire-chicken.com/chabull/tr.html
¹³http://opengameart.org/users/chabull
¹⁴https://www.google.com/search?q=Csaba+Felvegi

You might also like