|
1 | | -# 🏎️ Crypto Racer |
2 | | - |
3 | | -A React-based racing game where players earn ERC-20 tokens based on their racing performance. Built with Next.js and integrated with thirdweb API for authentication and token distribution. |
4 | | - |
5 | | -## 🎮 Features |
6 | | - |
7 | | -- **Real-time Racing Game**: Smooth 2D racing with obstacle avoidance |
8 | | -- **Performance-based Rewards**: Earn tokens based on race completion time and performance |
9 | | -- **Anti-cheat System**: Server-side verification before token distribution |
10 | | -- **thirdweb Integration**: Secure authentication and smart contract interactions |
11 | | -- **Modern UI**: Beautiful, responsive design with Tailwind CSS |
12 | | -- **Achievement System**: Track progress and unlock milestones |
13 | | - |
14 | | -## 🚀 Getting Started |
15 | | - |
16 | | -### Prerequisites |
17 | | - |
18 | | -- Node.js 18+ |
19 | | -- npm or yarn |
20 | | -- thirdweb account and API keys |
21 | | - |
22 | | -### Installation |
23 | | - |
24 | | -1. **Clone the repository** |
25 | | - ```bash |
26 | | - git clone <your-repo-url> |
27 | | - cd crypto-racer |
28 | | - ``` |
29 | | - |
30 | | -2. **Install dependencies** |
31 | | - ```bash |
32 | | - npm install |
33 | | - ``` |
34 | | - |
35 | | -3. **Set up environment variables** |
36 | | - Create a `.env.local` file in the root directory: |
37 | | - ```env |
38 | | - # Thirdweb API Configuration |
39 | | - THIRDWEB_SECRET_KEY=your_secret_key_here |
40 | | - TOKEN_CONTRACT_ADDRESS=0x...your_token_contract_address |
41 | | - CHAIN_ID=84532 |
42 | | - ADMIN_ADDRESS=0x...your_admin_wallet_address |
43 | | - |
44 | | - # Game Configuration |
45 | | - GAME_REWARD_BASE=100 |
46 | | - GAME_REWARD_MAX=500 |
47 | | - GAME_VERIFICATION_WINDOW=86400000 |
48 | | - ``` |
49 | | - |
50 | | -4. **Run the development server** |
51 | | - ```bash |
52 | | - npm run dev |
53 | | - ``` |
54 | | - |
55 | | -5. **Open your browser** |
56 | | - Navigate to [http://localhost:3000](http://localhost:3000) |
| 1 | +# 🐦 Crypto Flappy Bird |
| 2 | + |
| 3 | +A Web3 Flappy Bird game where players earn real cryptocurrency tokens by playing! Collect $ORBS tokens, unlock NFT bird skins, and experience the future of play-to-earn gaming. |
| 4 | + |
| 5 | +## 🎮 Game Features |
| 6 | + |
| 7 | +- **Play-to-Earn**: Earn $ORBS tokens for every coin you collect |
| 8 | +- **NFT Bird Skins**: Own unique bird characters as NFTs |
| 9 | +- **Power-ups**: Speed boost, shield, magnet, and slow-motion abilities |
| 10 | +- **Special Coins**: Multiplier coins (2x, 5x) for bigger rewards |
| 11 | +- **Cyberpunk Aesthetics**: Futuristic design with neon effects and animations |
| 12 | +- **Real-time Rewards**: Tokens sent directly to your wallet |
| 13 | + |
| 14 | +## 🪙 How Rewards Work |
| 15 | + |
| 16 | +### NFT Bird Collection |
| 17 | +- **Neon Ronin**: Cyberpunk warrior bird |
| 18 | +- **Circuitwing**: Tech-enhanced flying machine |
| 19 | +- **Chainlord**: Blockchain-powered avian |
| 20 | +- **Orb Sentinel**: Mystical energy guardian |
| 21 | +- **Default Bird**: Classic cyberpunk design |
57 | 22 |
|
58 | 23 | ## 🎯 How to Play |
59 | 24 |
|
60 | | -1. **Login**: Enter your email to authenticate with thirdweb |
61 | | -2. **Start Racing**: Press SPACE to begin a race |
62 | | -3. **Control**: Use A/D or Arrow Keys to move left/right |
63 | | -4. **Objective**: Avoid red obstacles and reach 1000 points |
64 | | -5. **Earn Tokens**: Complete races to earn ERC-20 tokens |
65 | | -6. **Claim Rewards**: Use the reward system to claim your tokens |
66 | | - |
67 | | -## 🏗️ Architecture |
68 | | - |
69 | | -### Frontend Components |
70 | | -- **RacingGame**: Main game logic with collision detection and scoring |
71 | | -- **AuthComponent**: thirdweb authentication integration |
72 | | -- **RewardSystem**: Token claiming and distribution |
73 | | -- **GameStats**: Performance tracking and achievements |
74 | | - |
75 | | -### Backend API |
76 | | -- **`/api/claim-rewards`**: Server-side verification and token distribution |
77 | | -- **Anti-cheat Protection**: Validates game performance before rewards |
78 | | -- **thirdweb Integration**: Secure smart contract interactions |
79 | | - |
80 | | -### Game Mechanics |
81 | | -- **Scoring System**: Points based on survival time and obstacle avoidance |
82 | | -- **Difficulty Scaling**: Obstacles move faster as score increases |
83 | | -- **Performance Tracking**: Records best times and total races |
84 | | -- **Reward Calculation**: Tokens based on time, performance, and race count |
85 | | - |
86 | | -## 🔐 Security Features |
87 | | - |
88 | | -- **Server-side Verification**: All game completions verified before rewards |
89 | | -- **Timestamp Validation**: Prevents replay attacks |
90 | | -- **Performance Validation**: Ensures reasonable game statistics |
91 | | -- **Rate Limiting**: Built-in protection against abuse |
92 | | - |
93 | | -## 🪙 Token System |
94 | | - |
95 | | -### Reward Structure |
96 | | -- **Base Reward**: 100 tokens per completed race |
97 | | -- **Time Bonus**: Up to 50 tokens for faster completion |
98 | | -- **Performance Bonus**: 10 tokens per race completed |
99 | | -- **Maximum Reward**: Capped at 500 tokens per session |
100 | | - |
101 | | -### Distribution Process |
102 | | -1. Game completion data sent to server |
103 | | -2. Server verifies performance and calculates rewards |
104 | | -3. thirdweb API called to mint/transfer tokens |
105 | | -4. Transaction hash returned to user |
106 | | - |
107 | | -## 🛠️ Configuration |
108 | | - |
109 | | -### Environment Variables |
110 | | -- `THIRDWEB_SECRET_KEY`: Your thirdweb API secret key |
111 | | -- `TOKEN_CONTRACT_ADDRESS`: ERC-20 token contract address |
112 | | -- `CHAIN_ID`: Target blockchain network ID |
113 | | -- `ADMIN_ADDRESS`: Admin wallet for token distribution |
114 | | - |
115 | | -### Game Settings |
116 | | -- `GAME_REWARD_BASE`: Base tokens per race |
117 | | -- `GAME_REWARD_MAX`: Maximum tokens per session |
118 | | -- `GAME_VERIFICATION_WINDOW`: Time window for valid sessions |
119 | | - |
120 | | -## 🚧 Development |
121 | | - |
122 | | -### Project Structure |
123 | | -``` |
124 | | -crypto-racer/ |
125 | | -├── app/ # Next.js app directory |
126 | | -│ ├── api/ # API routes |
127 | | -│ ├── components/ # React components |
128 | | -│ ├── globals.css # Global styles |
129 | | -│ ├── layout.tsx # Root layout |
130 | | -│ └── page.tsx # Main page |
131 | | -├── components/ # Shared components |
132 | | -├── package.json # Dependencies |
133 | | -├── tailwind.config.ts # Tailwind configuration |
134 | | -└── tsconfig.json # TypeScript configuration |
135 | | -``` |
136 | | - |
137 | | -### Available Scripts |
138 | | -- `npm run dev`: Start development server |
139 | | -- `npm run build`: Build for production |
140 | | -- `npm run start`: Start production server |
141 | | -- `npm run lint`: Run ESLint |
142 | | - |
143 | | -## 🔧 Customization |
144 | | - |
145 | | -### Game Difficulty |
146 | | -Modify obstacle spawn rates and speeds in `RacingGame.tsx`: |
147 | | -```typescript |
148 | | -// Obstacle spawn rate |
149 | | -if (Math.random() < 0.02) { ... } |
150 | | - |
151 | | -// Speed increase |
152 | | -setObstacleSpeed(prev => Math.min(prev + 0.5, 8)) |
153 | | -``` |
| 25 | +1. **Connect Wallet**: Link your Web3 wallet to start |
| 26 | +2. **Fly**: Press SPACE to make your bird jump |
| 27 | +3. **Collect**: Gather coins and avoid cyberpunk barriers |
| 28 | +4. **Earn**: Watch your $ORBS balance grow in real-time |
| 29 | +5. **Shop**: Spend $ORBS to unlock new bird skins and power-ups |
154 | 30 |
|
155 | | -### Reward System |
156 | | -Adjust token calculations in `RewardSystem.tsx`: |
157 | | -```typescript |
158 | | -const baseReward = 100 |
159 | | -const timeBonus = Math.max(0, 50 - Math.floor(gameStats.bestTime / 1000)) |
160 | | -const performanceBonus = Math.floor(gameStats.totalRaces * 10) |
161 | | -``` |
| 31 | +## 🚀 Game Mechanics |
162 | 32 |
|
163 | | -### Visual Styling |
164 | | -Customize colors and animations in `tailwind.config.ts`: |
165 | | -```typescript |
166 | | -colors: { |
167 | | - 'race-red': '#e74c3c', |
168 | | - 'race-blue': '#3498db', |
169 | | - 'race-green': '#2ecc71', |
170 | | -} |
171 | | -``` |
| 33 | +## 🛒 CyberShop |
172 | 34 |
|
173 | | -## 🚀 Deployment |
| 35 | +Spend your hard-earned $ORBS to unlock amazing content: |
174 | 36 |
|
175 | | -### Vercel (Recommended) |
176 | | -1. Connect your GitHub repository |
177 | | -2. Set environment variables in Vercel dashboard |
178 | | -3. Deploy automatically on push |
| 37 | +### Bird Skins |
| 38 | +- **Neon Ronin**: 30 $ORBS - Cyberpunk warrior bird |
| 39 | +- **Circuitwing**: 40 $ORBS - Tech-enhanced flying machine |
| 40 | +- **Chainlord**: 50 $ORBS - Blockchain-powered avian |
| 41 | +- **Orb Sentinel**: 20 $ORBS - Mystical energy guardian |
179 | 42 |
|
180 | | -### Other Platforms |
181 | | -1. Build the project: `npm run build` |
182 | | -2. Set environment variables |
183 | | -3. Deploy the `out` directory |
| 43 | +### Power-ups |
| 44 | +- **SLOWMO**: 10 $ORBS - Slow down time for 5 seconds |
| 45 | +- **SHIELD**: 10 $ORBS - Protection from all collisions for 5 seconds |
| 46 | + |
| 47 | +## 🎨 NFT Bird Skins |
| 48 | + |
| 49 | +Each bird NFT has unique characteristics: |
| 50 | +- **Visual Design**: Distinct cyberpunk aesthetic |
| 51 | +- **Ownership**: True ownership on the blockchain |
| 52 | +- **Purchasable**: Buy with $ORBS earned through gameplay |
| 53 | + |
| 54 | +## 💰 Token Economics |
| 55 | + |
| 56 | +### $ORBS Token |
| 57 | +- **Utility**: In-game currency earned through gameplay |
| 58 | +- **Distribution**: Automatic rewards for coin collection |
| 59 | +- **Transparency**: All transactions recorded on-chain |
| 60 | + |
| 61 | +### Reward System |
| 62 | +- **Instant Payouts**: No waiting, rewards sent immediately |
| 63 | +- **Fair Distribution**: Based on actual gameplay performance |
184 | 64 |
|
185 | | -## 🤝 Contributing |
| 65 | +## 🌟 Why Play? |
186 | 66 |
|
187 | | -1. Fork the repository |
188 | | -2. Create a feature branch |
189 | | -3. Make your changes |
190 | | -4. Add tests if applicable |
191 | | -5. Submit a pull request |
| 67 | +- **True Ownership**: Your NFT birds are yours forever |
| 68 | +- **Fair Rewards**: Transparent, performance-based token distribution |
| 69 | +- **Web3 Native**: Built for the decentralized future |
192 | 70 |
|
193 | | -## 📝 License |
| 71 | +## ⚡ Powered by thirdweb API |
194 | 72 |
|
195 | | -This project is licensed under the MIT License - see the LICENSE file for details. |
| 73 | +This game is built on the powerful thirdweb infrastructure for seamless Web3 integration: |
196 | 74 |
|
197 | | -## 🆘 Support |
| 75 | +### Authentication & Wallet Management |
| 76 | +- **Email Authentication**: Simple login without complex wallet setup |
| 77 | +- **Wallet Integration**: Automatic wallet creation and management |
| 78 | +- **Session Management**: Secure user sessions with JWT tokens |
198 | 79 |
|
199 | | -- **Issues**: Create a GitHub issue |
200 | | -- **Documentation**: Check the thirdweb API docs |
201 | | -- **Community**: Join our Discord server |
| 80 | +### Smart Contract Integration |
| 81 | +- **Token Contract**: ERC-20 $ORBS token on Base Sepolia testnet |
| 82 | +- **NFT Contract**: Bird skin NFTs for unique character ownership |
| 83 | +- **Automatic Distribution**: Real-time token rewards sent to player wallets |
202 | 84 |
|
203 | | -## 🔮 Future Enhancements |
| 85 | +### thirdweb API Endpoints Used |
| 86 | +- **`/v1/wallets/me`**: Get user wallet address and details |
| 87 | +- **`/v1/contracts/write`**: Mint $ORBS tokens to player wallets |
| 88 | +- **`/v1/transactions`**: Execute NFT purchases and token approvals |
204 | 89 |
|
205 | | -- [ ] Multiplayer racing |
206 | | -- [ ] NFT car skins |
207 | | -- [ ] Leaderboards |
208 | | -- [ ] Tournament system |
209 | | -- [ ] Mobile optimization |
210 | | -- [ ] More game modes |
211 | 90 |
|
212 | | ---- |
| 91 | +### Blockchain Features |
| 92 | +- **Base Sepolia Testnet**: Fast, low-cost transactions |
| 93 | +- **Real-time Balance Updates**: Live token balance tracking |
| 94 | +- **Gasless Transactions**: Seamless user experience |
213 | 95 |
|
214 | | -**Built with ❤️ using Next.js, React, and thirdweb** |
| 96 | +**Experience the future of gaming - where every jump earns you real rewards!** 🚀 |
0 commit comments