Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorTomas Varaneckas

At day you have to wrangle with legacy code, fix bugs, struggle with APIs, deploy services and integrate things. Yet you wish you could create worlds, animate dragons, break laws of physics and design artificial intelligence. You can.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Developing Games With Ruby: For Those Who Write Code for Living ## 【One-Line Pitch】 A practical, project-based guide that shows working programmers how to build a complete 2D tank game in Ruby using the Gosu library, proving that game development is accessible even with a "slow" dynamic language. Perfect for developers who want a creative weekend project that exercises real software engineering skills. ## 【Book Arc】 - **Opening (~0%–10%)**: Makes the case for Ruby game development, acknowledging that C++ or Unity are "better" choices but arguing that Ruby's elegance and productivity matter more for small 2D games. Sets up the toolchain and walks through first Gosu programs—hello world, keyboard movement, and sprite animation. - **Early (~10%–23%)**: Covers core Gosu mechanics: the update/draw loop, event handling, sound and music, tile-based maps (both hand-crafted Tiled maps and procedurally generated Perlin noise maps), and the crucial distinction between world coordinates, viewport coordinates, and screen coordinates. - **Early-to-Middle (~23%–39%)**: Introduces proper game architecture with the State pattern for menu/play states, a Camera system for scrolling and zooming, and the first game entities—Map, Tank, Bullet, and Explosion. The tank prototype becomes playable with 8-directional movement and shooting mechanics. - **Middle (~39%–48%)**: Shifts to performance engineering. Profiling reveals bottlenecks in camera view-checking and window caption updates. Introduces optimization techniques: short-circuiting expensive checks, frame skipping for slow update rates, and adaptive cursor display when framerate drops. - **Late (~48%–end)**: Refactors the monolithic prototype using the Component pattern, decoupling concerns like rendering, physics, and input. Adds enemy AI with finite state machines, collision detection with bounding boxes, health/damage systems, and gameplay polish (radar, respawning, sound panning, camera look-ahead). ## 【Key Takeaways】 - **Ruby is a legitimate game development choice for small 2D games** (Early): The author openly admits a friend said "there's little reason to develop a desktop game with Ruby"—and agrees—but argues that for simple 2D games, programmer happiness and productivity outweigh raw performance. This sets realistic expectations from the start. - **The update/draw separation is the heart of Gosu games** (Early): `update` should only advance object state, while `draw` should be as lightweight as possible. The order of these calls is unpredictable, so time (via `Gosu.milliseconds`) is the only reliable reference. This rule prevents common frame-rate bugs. - **Coordinate systems matter even in 2D** (Early): The book clearly distinguishes world coordinates (the game map), viewport coordinates (what the camera sees), and screen coordinates (the display). Implementing a "camera man" that follows action and zooms requires basic math but pays off in game feel. - **Procedural generation is achievable with Perlin noise** (Early): Rather than hand-crafting every map, the book shows how to use the Perlin noise algorithm to generate natural-looking terrain with water, sand, and grass tiles. Applying cubic contrast sharpens the result—without it, maps look like "a boring golf course." - **Profile before optimizing** (Middle): Initial profiling shows `Camera#viewport` and `Camera#can_view?` as top CPU burners. The author tests hypotheses by short-circuiting methods, discovering that checking visibility was slower than just drawing off-screen. Even the window caption update consumes 1/3 of CPU cycles—low-hanging fruit worth picking. - **Frame skipping prevents unrealistic slow-motion at low FPS** (Middle): When framerates drop, animations like explosions appear frame-by-frame and seem too slow. The solution is to advance animation frames based on elapsed time rather than per-render, so effects stay consistent regardless of performance. - **Component pattern keeps game objects maintainable** (Late): The monolithic Tank and Explosion classes violate single responsibility—they load graphics, handle rendering, animation, and sound. Splitting into components with a shared `GameObject` base class makes each piece testable and reusable, a lesson that transfers directly to day-job code. ## 【Reading Tips】 - **Skim the opening rationale** (~0–3%): The "Why Ruby?" discussion is motivational but not technical. If you're already convinced, jump to the first code example. - **Deep-read the coordinate system chapter** (~23%): This is the conceptual foundation for everything that follows. Understanding world/viewport/screen coordinates will save you hours of debugging later. - **Study the profiling section carefully** (~39–48%): The author demonstrates a real optimization workflow—measure, hypothesize, test, verify. This is the most transferable skill for your day job, even if you never write another game. - **Don't skip the refactoring chapter** (~48%+): The Component pattern refactor shows how to restructure working-but-messy code into something maintainable. This mirrors real-world legacy code scenarios. - **Expect some rough edges**: The book is honest about its scope—this is a prototype, not a polished commercial game. The Tiled map JSON excerpts are dense; skim them and focus on the Ruby logic. ## 【Coverage Limits】 This guide covers the book's progression from first Gosu programs through performance optimization and architectural refactoring. The excerpts do not cover the final AI implementation details, collision detection specifics, or the complete gameplay polish chapters in depth. ##
Page 7
elop 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 i...
View in text
Excerpt 2
( 14 window, SPRITE, 128, 128, false) 15 end 16 17 def self.load_sound(window) 18 Gosu::Sample.new( 19 window, media_path('explosi...
View in text
Excerpt 3
around, and each bullet will eventually cause an Explosion. Having all that taken care of, PlayState should look pretty simple: 03-prototype/states/play_stat...
View in text
Excerpt 4
let ourselves leave this low hanging fruit remain unpicked. We will update the caption once per second, it should remove the bottleneck: class PlayState < Ga...
View in text
Excerpt 5
ed up writing: module Utils # http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html def self.point_in_poly(testx, testy, *poly)
View in text
Excerpt 6
ad? 28 @gun.adjust_angle 29 now = Gosu.milliseconds 30 return if now - @last_update < UPDATE_RATE 31 @last_update = now 32 @vision.update...
View in text
Excerpt 7
driving_sound ||= StereoSample.new( 36 $window, Utils.media_path('tank_driving.mp3')) 37 end 38 39 def crash_sound 40 @@crash_sound ||= Stereo...
View in text
Excerpt 8
. Visual representation of quadtree Implementing A Quadtree There are some implementations of quadtree available for Ruby - rquad, rubyquadtree and rubyquad,...
View in text
Tags
AI categories
Programminggame developmentRuby
ruby
Publish Year: 2015
Language: English
File Format: PDF
File Size: 11.8 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…