🧀The Cheese Chase🐭 - My First Game Ever

on 2025-08-02

cheese_chase

I started this project with a simple goal of building a small game from scratch. As a kid, I used to love playing mini games like Red Beard, Bubble Trouble, Zed, and was always curious about how game development works. This post is a short write-up on my experience building one.

You can play the game in your browser here.

Learning SDL2


Before diving into building the game, I spent time learning SDL2 fundamentals by porting the Lazy Foo' Productions SDL tutorials to Rust. I documented this learning journey in a separate blog post. Each tutorial covered a specific concept, from rendering textures to handling input events and managing game loops.

It helped me understand:

  • Texture loading and rendering
  • Event handling and user input processing
  • How the game loop works (update, render, repeat)
  • Audio playback
  • Collision detection

Building The Cheese Chase


With some basic understanding of SDL2, I started building The Cheese Chase. The concept is simple — help a rat collect cheese pieces from a plate on the left side of the screen while avoiding rat repellent sprays. The rat starts on the right and must make multiple trips to collect all 5 pieces without getting hit.

Designing Game Assets

One of the most enjoyable aspects was designing all the game assets myself. Using Procreate, I designed:

  • Character images
  • Cheese collectibles
  • Rat repellent obstacles
  • Background tiles
  • UI elements

The Joy of Building

Building the game was genuinely fun. Every small milestone — the first time the character moved, the first successful collision detection — was exciting.

Making the game feel right took more work than I expected. Adjusting movement speed, collision boundaries, and repellent spray timing required multiple iterations. Small tweaks to these values significantly changed the gameplay.

The WASM Challenge


Once I had a working desktop version, I wanted to make the game accessible to anyone with a browser. This is where things got complicated.

SDL2 and WASM in Rust

I attempted to compile my SDL2 code to WebAssembly using Emscripten. The process wasn't straightforward. It required additional code changes beyond just compiling for a different target.

The biggest issue was managing texture lifetimes in the WASM build. This is specifically a challenge when compiling SDL2 Rust code to WASM with Emscripten — the additional code required made handling lifetimes difficult. After spending considerable time trying to fix these issues, I decided to look for a different approach.

Switching to Macroquad

I discovered Macroquad, a simple and easy-to-use game library for Rust with first-class WASM support. Macroquad's API structure was similar to SDL2's, which made the switch easier. The core concepts remained the same:

// SDL2 game loop
loop {
    // Handle events
    for event in event_pump.poll_iter() {
        // Handle input
    }

    // Update game state
    update();

    // Render
    canvas.clear();
    render();
    canvas.present();
}

// Macroquad game loop
loop {
    // Handle input
    if is_key_pressed(KeyCode::Space) {
        // Handle input
    }

    // Update game state
    update();

    // Render
    clear_background(WHITE);
    render();

    next_frame().await;
}

With similarities between the two libraries, I could translate most of my code with minimal changes.

The main differences were:

  • Event polling became simple key state checks
  • Resource loading used async/await in Macroquad

The core game loop structure and rendering functions remained nearly identical, which made the transition smooth.

WASM Compilation

With Macroquad, compiling to WASM was incredibly simple:

cargo build --release --target wasm32-unknown-unknown

No complex build configurations, no dependency conflicts — it just worked.

Conclusion


Building and publishing 🧀The Cheese Chase🐭 was a fun experience. Seeing people play something I created was satisfying.

If you're interested in game development with Rust, I recommend:

  • Starting with small, focused tutorials
  • Choosing tools with good WASM support if web deployment matters to you
  • Switching libraries if something isn't working

The full source code will be available on Github soon! 😊

$ whoami
I build high-performance systems, distributed architectures, and low-latency applications in Rust.
$ cat availability.txt
Need help auditing, optimizing, or building Rust infrastructure?
I'm available for remote contract, consulting, or full-time roles.
$ mail -s "let's talk about your systems" [email protected]