Skip to content

About

Incremental clicker where you restore a 3D Earth. React, Three.js and Zustand.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

EcoProject

An incremental clicker game where you restore a polluted 3D Earth, built with React, Three.js and Zustand.

Game screen with upgrades placed on the planet

About

EcoProject is a browser idle/clicker game with an environmental theme. You click to earn Impact, then spend it on upgrades like trees, solar farms and fusion reactors. Each one shows up as a 3D model on a rotating Earth while the brown smog around the planet slowly clears. It also sketches an ad-supported donation model: a pledge counter and sponsor slots show how play time could fund charities. The ads, pledges, player count and leaderboard are all simulated.

Features

  • Interactive 3D Earth (react-three-fiber) with an atmosphere that shifts from smog-brown to clear blue as you progress
  • 11 upgrades (3 click boosts, 8 passive generators) with 15% cost scaling per level; passive upgrades appear on the globe as trees, solar panels, spinning wind turbines, cleanup rigs, fusion reactors, rings and particle swarms
  • Random bonus orbs: energy orbs pay out right away, trivia orbs open a 44-question environmental quiz with a larger reward
  • Stat cards convert the simulated pledge into meals, trees and liters of water
  • Progress saved in localStorage, with a reset button and a demo mode that speeds everything up
  • Mock leaderboard with an editable player name, plus rotating simulated sponsor ads
  • "How it works" and "Charities" pages via React Router
  • Two sample Netlify Functions (/stats, /actions) that return mock global stats
How it works Charities
How it works page Charities page

Tech stack

React 18 · Vite 5 · Three.js with @react-three/fiber and @react-three/drei · Zustand · Framer Motion · Tailwind CSS · React Router · lucide-react · Netlify Functions · ESLint + Prettier

Architecture

ecoproject/
├── index.html
├── netlify.toml              # build command, publish dir, functions dir, SPA redirect
├── netlify/functions/        # serverless endpoints (mock data, not called by the UI yet)
├── public/                   # Earth texture, favicon
├── docs/screenshots/
└── src/
    ├── main.jsx, App.jsx     # entry point and routes
    ├── pages/                # MainGamePage, HowItWorksPage, CharityPage
    ├── components/           # EarthVisualization, ShopPanel, GlobalLeaderboard,
    │                         # GlobalImpactDashboard, TriviaModal, AdPanel, Navigation
    ├── store/useGameStore.js # Zustand store: game state, actions, localStorage persistence
    ├── hooks/useGameLoop.js  # interval timers: pledge, passive income, demo mode
    ├── lib/                  # pure helpers: upgrade maths, sphere placement, formatting
    └── data/                 # static content: upgrades, trivia, sponsors, mock leaders

State management. All persistent game state lives in one Zustand store (useGameStore). It holds actions (lifetime Impact, which drives the visuals), currentImpact (spendable balance), dollarsPledged, upgrades (id to level) and username. Every store action that changes progress writes that slice to localStorage under a single versioned key. demoMode is session-only. Old saves that used placeholder upgrade ids are migrated when they load.

Data flow.

  1. MainGamePage handles clicks and bonus orbs, then calls addAction(n). The store multiplies n by the click power worked out from owned upgrades.
  2. useGameLoop runs the timers. It adds passive Impact in 100 ms slices, adds $0.005 / 60 to the pledge every second, and speeds everything up in demo mode.
  3. Components subscribe to the store. ShopPanel reads the balance and levels to show costs. GlobalImpactDashboard shows totals. EarthVisualization turns actions into smog intensity and glow, and turns upgrade levels into how many models to render.
  4. In the 3D scene, placements come from a Fibonacci sphere distribution (lib/sphere.js) and are memoized per count. Animation runs inside useFrame by mutating refs, so the frame loop doesn't trigger React re-renders.

Serverless functions. netlify/functions/stats.js (GET) and actions.js (POST { count }) are Lambda-style handlers that return mock global totals. There's no database behind them. The frontend doesn't call them yet; they're a starting point for a shared global counter. Their base numbers can be set with environment variables (see .env.example), and neither one uses secrets.

Getting started

Requires Node.js 18 or newer.

npm install
npm run dev        # http://localhost:5173

Other scripts:

npm run build      # production build to dist/
npm run preview    # serve the production build
npm run lint       # ESLint
npm run format     # Prettier (write); format:check to verify only

To run the site together with the functions locally, use the Netlify CLI: npx netlify dev. Optional function settings go in .env (copy .env.example).

License

MIT

About

Incremental clicker where you restore a 3D Earth. React, Three.js and Zustand.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages