Skip to content

credyt/coffeeshoptycoon

Repository files navigation

Coffee Shop Tycoon

A browser-based tycoon game built with Godot 4.x where players manage a coffee shop, serve customers, and upgrade equipment. Uses Credyt wallet API for the in-game economy.

Prerequisites

For Backend

For Game Client

Project Structure

coffeeshoptycoon/
├── project.godot          # Godot project file
├── scenes/                # Godot scenes (.tscn files)
├── scripts/               # GDScript files
├── assets/                # Sprites, audio, fonts
├── backend/               # Node.js API server
│   ├── src/
│   │   ├── routes/        # API endpoints
│   │   ├── services/      # Business logic (Credyt integration)
│   │   ├── middleware/    # Auth middleware
│   │   ├── db/            # Database queries and setup
│   │   └── index.js       # Server entry point
│   ├── package.json
│   └── .env               # Configuration (copy from .env.example)
└── README.md

Quick Start with Docker

The easiest way to get started is using Docker Compose:

# Start PostgreSQL database
docker-compose up -d

# Install backend dependencies
cd backend
npm install

# Initialize database tables
npm run db:init

# Start the backend server
npm run dev

The database will be available at localhost:5432 with:

  • User: coffeeshop
  • Password: coffeeshop123
  • Database: coffeeshoptycoon

Backend Setup (Manual)

1. Install Dependencies

cd backend
npm install

2. Configure Environment

Edit backend/.env with your settings:

# Database - PostgreSQL connection string
# If using Docker Compose:
DATABASE_URL=postgresql://coffeeshop:coffeeshop123@localhost:5432/coffeeshoptycoon

# If using your own PostgreSQL:
# DATABASE_URL=postgresql://user:password@localhost:5432/coffeeshoptycoon

# Database SSL (optional) - Set to 'true' to enable SSL, 'false' to disable
# Default: auto-detect based on NODE_ENV (enabled in production, disabled in development)
# DATABASE_SSL=false

# JWT Secret - use a strong random string in production
JWT_SECRET=your-super-secret-jwt-key-change-in-production

# Credyt API - get credentials from https://credyt.ai
CREDYT_API_URL=https://api.credyt.ai
CREDYT_API_KEY=your-credyt-api-key
CREDYT_PRODUCT_ID=your-credyt-product-id

# Server
PORT=3000
NODE_ENV=development

3. Set Up PostgreSQL Database

# From project root
docker-compose up -d

Initialize the tables:

cd backend
npm install
npm run db:init

4. Start the Backend Server

Development mode (auto-reload):

npm run dev

Production mode:

npm start

The API will be available at http://localhost:3000.

API Endpoints

Method Endpoint Description
POST /api/auth/register Create account + Credyt wallet
POST /api/auth/login Login, returns JWT
GET /api/auth/validate Validate JWT token
GET /api/shop Get shop state
GET /api/shop/costs Get equipment upgrade and restock costs
GET /api/shop/limits Get inventory capacity and consumption limits
PUT /api/shop/inventory Update inventory
POST /api/shop/restock Purchase inventory
POST /api/shop/upgrade Purchase equipment upgrade
POST /api/shop/reset Reset shop to initial state
POST /api/shop/serve Log customer transaction and update balance
POST /api/day/complete Submit day results
GET /api/wallet/balance Get wallet balance
POST /api/wallet/billing-portal Create billing portal session

Godot Game Setup

1. Open Project in Godot

  1. Open Godot Engine 4.6+
  2. Click "Import"
  3. Navigate to the project folder and select project.godot
  4. Click "Import & Edit"

2. Configure API URL

For development, the game connects to http://localhost:3000/api by default.

3. Run the Game

Press F5 or click the Play button in Godot to run the game.

Web Export

1. Install Export Templates

In Godot: Editor → Manage Export Templates → Download and Install

2. Configure Export Preset

  1. Project → Export
  2. Add Preset → Web
  3. Configure settings (defaults should work)

3. Export

  1. Click "Export Project"
  2. Choose destination folder
  3. Name the file (e.g., index.html)

4. Serve the Web Build

Web exports require a local server due to browser security. Use one of:

# Python
python -m http.server 8080

# Node.js (npx)
npx serve .

# PHP
php -S localhost:8080

Credyt API Setup

Option A: Automatic Setup (Recommended)

  1. Sign up at https://credyt.ai and get your API key
  2. Add your API key to backend/.env:
    CREDYT_API_KEY=your-api-key-here
    
  3. Run the setup script:
    cd backend
    npm run credyt:setup

The script will:

  • Check if "Coffee Shop Tycoon" product exists in your Credyt account (by product code)
  • If exists: Create a new version with updated prices and make it the default
  • If not exists: Create a new product with all prices
  • Automatically update your .env file with the CREDYT_PRODUCT_ID

Requirements: curl and jq must be installed. On macOS: brew install jq

Option B: Manual Setup

  1. Sign up at https://credyt.ai
  2. Create a new product named "Coffee Shop Tycoon"
  3. Copy the Product ID
  4. Add both to backend/.env:
    CREDYT_API_KEY=your-api-key
    CREDYT_PRODUCT_ID=your-product-id
    

The game uses Credyt for:

  • Creating player wallets on registration
  • Granting starting funds ($50)
  • Crediting revenue at end of day
  • Debiting purchases (restocks, upgrades)
  • Transaction tracking and billing

Game Mechanics

Core Loop

  1. Morning Prep: Restock pastries, review shop
  2. Service Phase: 60-second session serving customers
  3. End of Day: Revenue credited, view stats, upgrade shop

Menu Items

  • Coffee (made on demand): Espresso ($3.25), Latte ($5.72), Cappuccino ($5.95), Americano ($4.75)
  • Pastries (require restocking): Croissant ($5.15), Muffin ($4.75), Cookie ($4.75), Cake Slice ($5.55)

Equipment Tiers

Equipment Level 1 Level 2 ($500) Level 3 ($1500)
Espresso Machine Basic Brewer Pro Barista Master Roaster
1x speed, 1x quality 1.3x speed, 1.2x quality 1.6x speed, 1.5x quality
Equipment Level 1 Level 2 ($60) Level 3 ($100)
Display Case Small (5 items) Medium (10 items) Large (20 items)
1x freshness 1.2x freshness 1.5x freshness

Economy

  • Starting funds: $50
  • Tips scale with customer patience and equipment quality
  • Equipment quality and freshness affect customer satisfaction

Development

Project Layout Notes

  • Autoloads (scripts/autoloads/): Singletons for global state

    • GameManager: Game state, shop data, menu items
    • AuthManager: Authentication state
    • APIClient: HTTP requests to backend
    • Events: Signal bus for decoupled events
  • Systems (scripts/systems/): Game logic

    • day_cycle_system.gd: Phase state machine
    • customer_spawner.gd: Customer generation
    • order_system.gd: Order fulfillment

Troubleshooting

"Failed to connect to database"

  • Ensure PostgreSQL is running
  • Verify DATABASE_URL in .env is correct
  • Check that the database exists

"Credyt API error"

  • Verify CREDYT_API_KEY and CREDYT_PRODUCT_ID in .env
  • Check you're using test mode credentials for development
  • Ensure your Credyt account is active

"CORS error" in browser

  • Ensure backend ALLOWED_ORIGINS includes your game's URL
  • For development, the backend allows all origins by default

Game won't load scenes

  • Ensure all .tscn and .gd files are in the correct paths
  • Check Godot console for error messages
  • Verify autoloads are configured in Project Settings

Credits

The fonts Edit Undo and EXEPixelPerfect were found on 1001fonts.com and are available here:

About

Demo game: coffee shop tycoon with real-time credits billing via the Credyt API. Shows custom credit assets (coins, beans, gems), usage tracking, prepaid wallet flows, and balance enforcement. Reference for in-app economies and game monetization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors