Skip to content

00202210/GameOfLife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Game Of Life

A fast, clean implementation of Conway’s Game of Life built in Roblox Luau.
It renders the grid using EditableImage:WritePixelsBuffer with a single RGBA buffer, supports mouse painting, and runs at a configurable tick rate.

Features

  • High-performance rendering using EditableImage + buffer (RGBA pixels)
  • 🧠 Precomputed neighbor table (8 neighbors per cell) for fast stepping
  • 🎨 Click-and-drag painting (LMB) to toggle cells
  • ⏯️ Play/Pause, ⏭️ Step, 🧹 Clear, 🎲 Randomize
  • 🧩 Modular structure: Config, LifeGrid, ImageRenderer, InputController
  • 🔧 --!strict and --!optimize 2 used throughout

Controls

  • LMB: Paint cells (click sets a paint mode, drag continues painting)
  • Space: Play / Pause
  • Enter: Step (only when paused)
  • C: Clear
  • R: Randomize

How it works (quick overview)

  • LifeGrid

    • Stores alive + next_alive boolean arrays
    • Builds a flat neighbor index array (neighbors) once at startup
    • Step() counts live neighbors and applies Conway’s rules
    • Returns a list of changed cell indices for minimal updates
  • ImageRenderer

    • Creates UI (ScreenGui, buttons, status label)
    • Creates an EditableImage sized to the grid (W×H)
    • Maintains a single RGBA pixel buffer (GRID_WIDTH * GRID_HEIGHT * 4)
    • Updates pixels and flushes via WritePixelsBuffer
  • InputController

    • Converts screen mouse position → grid index based on the ImageLabel bounds

Project Structure

Suggested layout inside your Roblox place (or Rojo project):


GameOfLife/
Client/
Main.client.lua
Modules/
Config.lua
LifeGrid.lua
ImageRenderer.lua
InputController.lua

If you’re using Rojo, keep the modules together and require them exactly as your setup expects (your code uses require'@self/...').

Configuration

Edit Config.lua:

  • GRID_WIDTH, GRID_HEIGHT — grid size
  • WRAP_EDGES — wrap neighborsoroidal edges on/off
  • TICK_RATE — simulation steps per second when running
  • RANDOM_DENSITY — random fill chance
  • DISPLAY_SCALE — how large the grid is displayed in UI
  • Colors + RGBA values:
    • ALIVE_RGBA
    • DEAD_RGBA

Notes / Performance

  • Rendering is done by writing RGBA bytes into a buffer and flushing it to the EditableImage.
  • The sim step loops the full grid each tick; most UI work is minimized by only rewriting changed cells (then flushing once).

About

Conway’s Game of Life in Roblox Luau; high-performance grid simulation rendered via EditableImage + buffer, with mouse painting + step/play controls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages