Leanpub Header

Skip to main content

Beginning Game Programming with Go and Ebitengine

A hands-on, project-based guide to 2D game development in Golang

This book is 100% completeLast updated on 2026-07-12

Build a game from scratch in Go—no engine magic, just code you understand. You'll create Gopher Survivor, a Vampire Survivors–style action game, one concept per chapter: enemies, weapons, XP and level-ups, particles, a state machine, and a build you can ship.

Minimum price

$9.99

$9.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
Discussion Forum
About

About

About the Book

Build a real game in Go — and understand every line of it.

Most game tutorials hand you an engine and ask you to fill in the blanks. This book does the opposite. Starting from an empty window, you build Gopher Survivor — a complete, Vampire Survivors–style action game — in Go and Ebitengine, writing the game loop, the scene graph, the camera, collisions, and everything else yourself. No drag-and-drop editor, no black boxes: just code you can read, reason about, and reshape into your own game.

The book grows one project across fourteen chapters. Every chapter is the previous chapter plus a small, deliberate diff, and the game compiles at every step — so you're never lost in a wall of code, and you always have something you can run.

What you'll build

A polished survivors-style game: a gopher that moves across an infinite tiled world, auto-firing weapons that unlock and upgrade, waves of scaling enemies and a mini-boss, XP orbs and level-ups, health and upgrade panels, a main-menu / pause / options state machine, music and sound effects, particles, screen shake, and floating damage numbers — packaged into a native executable and a browser (WebAssembly) build you can hand to anyone.

What you'll learn

  • The Ebitengine game loop and frame-rate-independent updates
  • A scene graph of nodes with local and world transforms, a camera, and draw layers
  • An input layer that maps named actions to keys
  • Circle-based collision detection with layer masks
  • Weapons built with the Strategy pattern, object pooling, and a level-up upgrade system
  • Enemy difficulty curves, a state machine for game flow, audio, and game-feel polish
  • Packaging and shipping to desktop and the web

Who this book is for

You already know Go; you've never built a game. This book won't teach you syntax — it teaches game development: the patterns, the architecture, and the small tricks that make a game feel alive. If you can write Go and you're curious how a game actually works under the hood, this is for you.

Why Go and Ebitengine? Fast compiles, a single shippable binary, trivial cross-platform builds, and a clean 2D library that stays out of your way. You spend your time building your game, not fighting the framework.

Get the code — every chapter's complete, runnable project is on GitHub, one directory per chapter: https://github.com/LuigiVanacore/beginning-game-programming-go-ebitengine

Author

About the Author

Luigi Vanacore

I'm Luigi Vanacore, a software developer focused on backend development, with years of experience building systems for large companies in the banking, finance, and utility sectors. I've loved video games — and making them — for as long as I can remember, and I keep a steady stream of game projects going in my spare time. I've worked with the major engines (Unity, Unreal Engine, Godot) and built games from scratch in C++ and Go. This book is where those two sides of me meet.

Contents

Table of Contents

Introduction

  1. What This Book Is About
  2. What Is Go (Golang)?
  3. What Is Ebitengine?
  4. Why Go for Games?
  5. Conventions Used in This Book
  6. The Game We Are Building: Gopher Survivor
  7. What Comes Next

Chapter 1: Ebiten Basics

  1. Technical requirements
  2. Getting Go on Your Machine
  3. A Quick Sanity Check: Hello, World
  4. What Is Ebiten?
  5. The Ebiten Game Interface
  6. Creating a Go Module for Your Project
  7. Building the Code Step by Step
  8. Full Source Code
  9. Summary

Chapter 2: The Scene Graph and Framework Structure

  1. Technical requirements
  2. Why a Scene Graph?
  3. Vector2D: 2D Coordinates and a Bit of Vector Math
  4. The SceneNode Interface
  5. The Node Struct: Base Implementation
  6. Transform and Transformable
  7. Node2D: Nodes with Transforms
  8. The Drawable Interface
  9. The Sprite: A Drawable Node2D
  10. The Engine: Delegating to the World
  11. How the World Traverses the Scene
  12. Complete Example: Rotating Logo
  13. Summary
  14. Code Structure for Chapter 2

Chapter 3: Resource Manager, Layers and Sprites

  1. Technical requirements
  2. Part 1: The Resource Manager and asset loading
  3. Part 2: The Layer Structure
  4. Part 3: Load Textures and Create Sprites
  5. Part 4: Draw Order — Floor First, Player Centered
  6. Code Structure
  7. Summary

Chapter 4: Input and Player Movement

  1. Technical requirements
  2. Overview of the Input System
  3. 1. rawinput.go — Physical Input Abstraction
  4. 2. action.go — Action with Trigger Mode
  5. 3. actionmap.go — ActionID to Action Mapping
  6. 4. statebuffer.go — Tracking State Across Frames
  7. 5. inputmanager.go — Two Input APIs
  8. 6. engine.go — Adding InputManager and Update
  9. 7. Game Setup and Movement
  10. 8. run.go and cmd/main.go — Entry Point
  11. Code Structure
  12. Summary

Chapter 5: Tileset, Tilemap, and Camera

  1. Technical requirements
  2. Part 1: Tileset - Cutting Tiles from a Spritesheet
  3. Part 2: Tilemap - From a Finite Pattern to an Infinite Floor
  4. Part 3: Camera - The Moving Window over the World
  5. Part 4: World - Orchestrating the Render Pass
  6. Part 5: Chapter 5 Setup - File by File
  7. Part 6: Optional Extensions
  8. Code Structure
  9. Summary

Chapter 6: Enemy and Collisions

  1. Technical requirements
  2. Understanding collisions in 2D games
  3. Part 1: node2d.go — Add GetWorldPosition
  4. Part 2: collision.go — CollisionCircle and Overlap Test
  5. Part 3: collisionMask.go — Layers and Collision Filtering
  6. Part 4: collider.go — Node2D with Collision
  7. Part 5: collisionManager.go — CheckCollision
  8. Part 6: spawnEnemyFarFrom — Enemy Spawn for Infinite Map
  9. Part 7: game.go — Setup and Logic
  10. Part 8: Running the chapter
  11. Part 9: go.mod — Dependencies
  12. Summary

Chapter 7: Weapons and Projectiles

  1. Technical requirements
  2. Weapons and projectiles in games
  3. The cursor: a pointer that follows the mouse
  4. The timer: a cooldown for the weapon
  5. The projectile: layers and spawn logic
  6. Collision: a projectile kills an enemy
  7. Projectile movement and cleanup
  8. Enemy waves: the spawner and the EnemyManager
  9. Summary

Chapter 8: UI, Health, XP, and Level Up

  1. Technical requirements
  2. Drawing the UI in screen space
  3. The reusable progress bar
  4. The floating message
  5. Composing the HUD
  6. Giving the player health, XP, and level
  7. Adding pickup collision layers
  8. Spawning and collecting XP orbs
  9. Wiring it together in game.go
  10. Running the chapter
  11. Summary

Chapter 9: Health Potion, Sacred Book, and Holy Shield

  1. Technical requirements
  2. How loot drops on enemy death
  3. Loading the potion and sacred-book sprites
  4. Extending the PickupManager
  5. Modeling the health potion
  6. Dropping loot when an enemy dies
  7. Collecting orbs and potions
  8. A common interface for player weapons
  9. The Sacred Book: an orbiting weapon
  10. The Holy Shield: a static ring weapon
  11. Mounting all three weapons
  12. Keeping XP and the level-up popup
  13. Running the chapter
  14. Summary

Chapter 10: Weapon Upgrade UI, Additional Weapons, and a Survival Timer

  1. Technical requirements
  2. Centralizing weapon stats in WeaponManager
  3. Threading the manager through the weapon interface
  4. Reading multipliers inside each weapon
  5. The Flying Axe: a spinning projectile weapon
  6. Mounting all four weapons
  7. The upgrade flow and pausing the world
  8. An exponential XP curve
  9. Modeling upgrades: options, factories, and random sampling
  10. From options to HUD choices
  11. The HUD: panels, input, and overlays
  12. The upgrade panel and stable icons
  13. Drawing gameplay versus the upgrade screen
  14. The survival timer and game over
  15. Restarting from the game-over screen
  16. Running the chapter
  17. File layout (highlights)
  18. Full listing pointers
  19. Summary

Chapter 11: Weapon Unlock and Gated Upgrades

  1. Technical requirements
  2. What changes since Chapter 10
  3. Setting the upgrade caps and weapon IDs
  4. Reusing the infinite floor, input, and movement
  5. From mount-all to construct-all, mount-one
  6. Counting upgrades and scaling difficulty over time
  7. Surviving longer: enemy variety and time scaling
  8. From flat factories to gated strategies
  9. Biasing the panel toward bonus items
  10. Writing the strategies
  11. One-time bonus items
  12. Falling back when the pool is capped
  13. Splitting display from apply
  14. Loading the new sprites
  15. Drawing: unchanged from Chapter 10
  16. Full listing reference
  17. Summary

Chapter 12: Audio and a State Machine for Menus, Gameplay, and Pause

  1. Technical requirements
  2. Sound: looping music
  3. What is a state machine, and why games use it
  4. Understanding the state machine
  5. Decoupling the core from the game package
  6. The State and StateMachine types
  7. App: the single ebiten.Game
  8. Shared menu helpers
  9. The main menu state
  10. The game state: delegating to Game
  11. The pause state
  12. The options state
  13. The pause action and IsPausePressed
  14. The main package
  15. Transition diagram
  16. File layout (new and changed)
  17. Full listing reference
  18. Summary

Chapter 13: Game Feel — Particles and Visual Effects

  1. Technical requirements
  2. Understanding game feel
  3. Sound effects
  4. The particle system
  5. Emitting effects on damage
  6. Weapon trails
  7. Floating damage numbers
  8. Flashing enemies white
  9. Shaking the camera
  10. Wiring it into the frame loop
  11. Full listing reference
  12. Summary

Chapter 14: Packaging, Distribution, and the Road Ahead

  1. Technical requirements
  2. What you have built
  3. Preparing for a production build
  4. Building native executables
  5. Shipping to the web with WebAssembly
  6. Measuring performance
  7. Extending Gopher Survivor
  8. Resources and community
  9. Summary

Conclusion

  1. The journey, chapter by chapter
  2. What you actually learned
  3. Thank you
  4. Where you go now

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub