š Factorio-like Game
A 2D web-based game inspired by Factorio, built with Svelte and Vite. Features a complete resource production and transportation system with conveyor belts, automatic item generation, and intelligent flow management.
š Features
Grid & Building System
- ā
Parametrizable Grid: Default 20x20, configurable from 5x5 up to 50x50
- ā
Multiple Building Tools: Walls, resource nodes, factories, and conveyor belts
- ā
Click-to-Place System: Intuitive building interface
- ā
Auto-Save: Automatic persistence to localStorage
- ā
Adjustable Cell Size: 10-50px for optimal visibility
- ā
GitHub Pages Ready: Configured for static deployment
Resource & Transportation System
- ā
Resource Nodes: Automatically generate resources every 2 seconds when connected to belts
- ā
Conveyor Belts: Realistic item transportation with directional flow
- ā
Belt Capacity: Maximum 3 items per belt cell with visual stacking
- ā
Smart Flow Control: Items stop when destination is full or unreachable
- ā
Automatic Balancing: Belt junctions use round-robin to distribute items evenly between outputs
- ā
Dead-End Handling: Items stack up to 3 when belts have no outlet
Visual Feedback System
- ā
Moving Items: š” Golden dots flowing smoothly through belts
- ā
Blocked Items: š“ Red-orange pulsing dots when stuck or at capacity
- ā
Stored Items: š¢ Green dots in factory storage
- ā
Full Belt Indicator: Red border highlights when belt reaches 3-item capacity
- ā
Factory Counter: Numeric display of stored item count
- ā
Directional Movement: Items move correctly horizontal/vertical based on belt direction
- ā
Position-Based Stacking: Multiple items visible in same cell at different positions
Simulation & Game Loop
- ā
Real-Time Simulation: 200ms tick rate for smooth gameplay
- ā
Pause/Resume Controls: Full simulation control
- ā
Item Tracking: Live counter of items in transit
- ā
Smart Pathfinding: Items remember previous position and prefer straight paths
- ā
No-Backtrack Logic: Items never return to where they came from
š® Available Building Types
- Remove any building from the grid
- Clears space for redesigning your factory
Wall (Gray)
- Decorative/blocking element
- Currently no collision (future feature)
Resource Node (Green)
- Auto-Generation: Creates items every 2 seconds
- Smart Output: Only generates when adjacent belt has space
- Capacity Aware: Stops production when connected belts are full
Factory (Blue)
- Item Storage: Accepts and stores unlimited items
- Visual Counter: Shows stored item count in top-right
- End Point: Items turn green when stored
Conveyor Belt (Orange)
- Item Transport: Moves items at consistent speed
- 3-Item Capacity: Holds maximum 3 items per cell
- Visual Distribution: Items spread across cell (10%, 50%, 90% positions)
- Junction Balancing: Automatically alternates between multiple outputs
- Blockage System: Items stop and turn red when unable to proceed
šÆ How to Play
Basic Setup
- Place a Resource Node (green) - This will generate items
- Connect Conveyor Belts (orange) - Create a path from the resource
- Add a Factory (blue) - Place at the end to collect items
- Watch It Run: Resources automatically flow from node ā belt ā factory
Advanced Techniques
Creating Storage Buffers
- Place a belt with no outlet to create a 3-item buffer
- Items will stack and wait (shown in red)
Building Splitters
- Connect one belt to multiple outputs
- Items automatically alternate between paths (Item 1 ā Left, Item 2 ā Right, etc.)
Flow Control
- Use the Pause button to stop simulation
- Clear All to reset the entire grid
- Monitor "Items in transit" counter
š ļø Development
Installation
npm install
Run Development Server
npm run dev
Server will start at http://localhost:5173/factorio-like/
Build for Production
npm run build
Output will be in the dist/ folder
Preview Production Build
npm run preview
š¦ Deploying to GitHub Pages
Option 1: Automatic Deployment (Recommended)
The project includes a GitHub Actions workflow (.github/workflows/deploy.yml) that automatically deploys on push to main.
Setup:
- Go to repository Settings ā Pages
- Source: Select "GitHub Actions"
- Push to
main branch
- Workflow will build and deploy automatically
Option 2: Manual Deployment
- Ensure
base in vite.config.js matches your repo name
- Run
npm run build
- Deploy
dist/ folder to gh-pages branch
š¾ Save System
Automatic Saving
- Grid state saves to localStorage on every change
- No manual save required
- Persists between browser sessions
What Gets Saved
- Grid dimensions (width Ć height)
- All placed buildings and their positions
- Building types (wall, resource, factory, belt)
What Doesn't Get Saved (Yet)
- Items in transit on belts
- Items stored in factories
- Simulation state (paused/running)
š Project Structure
factorio-like/
āāā src/
ā āāā lib/
ā ā āāā Grid.svelte # Main grid component with simulation
ā ā āāā gridUtils.js # Grid creation & localStorage helpers
ā ā āāā beltSystem.js # Item movement & belt logic
ā āāā App.svelte # Root component with settings
ā āāā app.css # Global styles
ā āāā main.js # Entry point
āāā .github/
ā āāā workflows/
ā āāā deploy.yml # GitHub Actions deployment
āāā index.html # HTML template
āāā vite.config.js # Vite configuration (GitHub Pages base)
āāā svelte.config.js # Svelte preprocessor config
āāā package.json # Dependencies & scripts
š§ Technical Details
Belt System Architecture
Item Flow
- Each item tracks: position (x, y), previous position, progress (0-1), blocked state
- Progress advances 0.15 per tick (200ms intervals)
- Items transition between cells when progress >= 1.0
Capacity Management
MAX_ITEMS_PER_BELT = 3
canAcceptItem() checks destination capacity before allowing movement
- Items block at 90% progress when next cell is full
Balancing Algorithm
outputTracker object stores last-used output index per cell position
- Round-robin selection:
(lastIndex + 1) % availableOutputs.length
- Prioritizes straight paths but alternates with side paths when both exist
Visual Positioning
- Items at progress 0.0-0.33 ā position 1 (-33% of cell)
- Items at progress 0.34-0.66 ā position 2 (center)
- Items at progress 0.67-1.0 ā position 3 (+33% of cell)
šØ Visual States
| State |
Color |
Animation |
Meaning |
| Moving |
š” Gold (#FFD700) |
Smooth transition |
Item flowing normally |
| Blocked |
š“ Red-Orange (#FF5722) |
Pulsing (1s) |
Cannot advance (full/dead-end) |
| Stored |
š¢ Green (#4CAF50) |
Static |
Safely in factory storage |
š§ Future Enhancements
Planned Features
š License
MIT