Thanks to visit codestin.com
Credit goes to github.com

Skip to content

kevinmaes/eggdrop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Egg Drop Game ๐Ÿฅš

React TypeScript Vite XState Konva Howler

Egg Drop Title

๐ŸŽฎ Play the Egg Drop game

๐Ÿ“– About the Game

Egg Drop is a fun web-based game where you control Chef Rafi who tries to catch eggs dropped by hens to make his egg drop soup. It was inspired by the old Atari 2600 game, Kaboom. Additionally, this version of game features a genetic algorithm that evolves the characteristics of the hens over time, making each playthrough unique and progressively challenging.

โœจ Features

๐ŸŽฎ Gameplay ๐Ÿงฌ Evolution ๐ŸŽฏ Challenge
Catch eggs with Chef Rafi Hens evolve over time Increasing difficulty
Dynamic movement patterns Genetic algorithm Unique each playthrough

๐ŸŽค Conference Presentations

This project was originally created as a demo for my talk, "Evolving Game Development with Genetic Algorithms" that was delivered at:

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (v18 or higher recommended)
  • pnpm package manager

Installation

  1. Clone the repository:

    git clone https://github.com/kevinmaes/eggdrop.git
    cd eggdrop
  2. Install dependencies:

    pnpm install
  3. Start the development server:

    pnpm dev
  4. Open your browser and navigate to:

    http://localhost:5173
    

๐Ÿ› ๏ธ Development Commands

Command Description
pnpm dev Start the development server
pnpm build Build the production-ready app
pnpm preview Preview the production build locally
pnpm tsc Run TypeScript type checking
pnpm lint Run ESLint to check for code issues
pnpm format Format code with Prettier
pnpm test Run unit tests (Vitest)
pnpm test:watch Run unit tests in watch mode
pnpm test:e2e Run E2E tests (regular, headless)
pnpm test:automated Run automated E2E tests (ChefBot)
pnpm test:all Run all Playwright tests
pnpm ci Run CI checks locally (lint, type check, test)
pnpm check Run comprehensive checks (lint, type check, test, build)

For more testing commands and details, see TESTING.md.

๐ŸŽญ End-to-End Testing with Playwright

See TESTING.md for a complete guide to running tests.

Why State Machine Testing?

Canvas games are notoriously hard to test. Traditional approaches have significant limitations:

  • Visual/screenshot testing - Brittle, slow, breaks on any UI change
  • Fake DOM elements - Extra maintenance, test drift, doesn't guarantee canvas output matches tested state
  • No DOM representation - Can't query or assert on canvas state directly

Our solution: Test the state machines directly instead of the canvas rendering.

Using XState, we expose a test API (window.__TEST_API__) that provides:

  • Direct access to state machine contexts (positions, velocities, game state)
  • Event sending to trigger state transitions
  • Snapshot queries for assertions

Benefits:

  • Tests are deterministic and fast
  • Only break when game logic changes, not UI
  • Can test internal state that isn't visible
  • Enable complex scenarios like the ChefBot AI playing full games

Further reading: XState Testing Docs โ€ข MDN Canvas Testing

๐Ÿงช CI/CD Pipeline

This project uses GitHub Actions for Continuous Integration. The CI workflow:

  1. Runs on all Pull Requests to the main branch
  2. Verifies code quality with TypeScript and ESLint checks
  3. Ensures all tests pass before merging
  4. Confirms the build process works correctly

You can run these checks locally before pushing with:

pnpm ci

๐Ÿงฐ Technology Stack

Core Technologies

  • React - UI library for building the game interface
  • TypeScript - Type-safe JavaScript for robust code
  • Vite - Fast build tool and development server

Game Development Libraries

  • Konva - Canvas library for 2D graphics and animations
  • React Konva - React integration for Konva
  • XState - State management using state machines and the actor model
  • Howler - Audio library for game sounds

State Machines

Several XState state machines are used throughout the game:

  • Application (loading and overall coordination)
  • Game Play (levels)
  • Chef - Player character controlled by the user
  • Hen
  • Egg (hatching into chicks)
  • Egg Points - Points won when catching an egg
  • Sounds

Chef machine

Game State Machine

Egg Caught Points machine

Game State Machine

๐Ÿงฌ Genetic Algorithm

The game features a genetic algorithm that evolves the characteristics of the hens who drop eggs. Each hen (referred to as a "Hendividual") has DNA composed of traits related to:

  • Movement patterns and speed
  • Egg-laying frequency and timing
  • Other behavioral characteristics

As the game progresses, hens evolve based on their performance, creating a dynamic and increasingly challenging gameplay experience.

๐Ÿ”ง Developer Tools

Dev Panel

The game includes a developer panel to track statistics related to the genetic algorithm:

  • Press cmd-d (Mac) or ctrl-d (Windows/Linux) to toggle the Dev Panel visibility
  • Monitor hen population statistics and evolution metrics
  • Track game performance and state

Project Structure

eggdrop/
โ”œโ”€โ”€ public/               # Static assets (images, sounds, fonts)
โ”œโ”€โ”€ src/                  # Source code
โ”‚   โ”œโ”€โ”€ App.tsx           # Main application component
โ”‚   โ”œโ”€โ”€ app.machine.ts    # Main state machine
โ”‚   โ”œโ”€โ”€ Hen/              # Hen components and logic
โ”‚   โ”œโ”€โ”€ Egg/              # Egg components and logic
โ”‚   โ”œโ”€โ”€ Chef/             # Chef (player) components
โ”‚   โ”œโ”€โ”€ GameLevel/        # Level management
โ”‚   โ”œโ”€โ”€ geneticAlgorithm/ # Genetic algorithm implementation
โ”‚   โ”œโ”€โ”€ DevPanel/         # Developer panel components
โ”‚   โ””โ”€โ”€ ...               # Other components and utilities
โ”œโ”€โ”€ package.json          # Dependencies and scripts
โ””โ”€โ”€ vite.config.ts        # Vite configuration

๐ŸŽจ Asset Creation Tools

The following tools were used to create game assets:

๐Ÿšง Development Status

THIS GAME IS STILL IN ACTIVE DEVELOPMENT

See the Issues for a list of upcoming features, fixes, and enhancements.

Current limitations:

  • No instructions screen
  • No defined end-game condition
  • Genetic algorithm still being refined

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“ฌ Contact

Kevin Maes - @kvmaes

About

Egg Drop Game built with React, Konva, XState, and TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages