# 3D Walking Game

A 3D first-person walking game built with three.js where you explore different levels in a 3D environment.

## Quick Start

```bash
# Install dependencies
npm install

# Start the local HTTP server (runs on http://localhost:8080)
npm start
```

The game will automatically open in your browser at `http://127.0.0.1:8080/level1.html`.

## Game Controls

- **Click** anywhere on the page to enable mouse look and start playing
- **WASD** or **Arrow Keys** to move around
- **Mouse** to look around
- **ESC** to release mouse control

## Project Structure

```
maxime-pokemon-game/
├── level1.html          # First level - flat green field with trees
├── package.json         # Project configuration and scripts
├── package-lock.json    # Dependency lock file
├── models/              # Directory for 3D models (currently empty)
└── README.md           # This file
```

## Technology Stack

- **three.js** v0.160.0 - 3D graphics library loaded via CDN
- **PointerLockControls** - First-person camera controls
- **http-server** - Local development server

## Level Architecture

Each level is a standalone HTML file that includes:
- Complete three.js scene setup
- Custom 3D environment (terrain, objects, lighting)
- Player movement and camera controls
- Level-specific game logic

### Current Levels

1. **Level 1** (`level1.html`) - Flat green field with randomly placed trees

## Development Notes

### Adding New Levels

To create a new level:
1. Copy `level1.html` to `levelX.html`
2. Modify the scene setup in the `init()` function
3. Customize the environment (terrain, objects, colors)
4. Update the info panel with level-specific instructions

### Server Management

The HTTP server is required because three.js modules use ES6 imports which need to be served via HTTP (not `file://` protocol).

**Start server:**
```bash
npm start
```

**Stop server:**
Press `CTRL+C` in the terminal running the server

**Access different levels:**
- Level 1: `http://127.0.0.1:8080/level1.html`
- Level X: `http://127.0.0.1:8080/levelX.html`

### Key Code Sections

**Scene Setup** - Creates the 3D world, lighting, and environment:
```javascript
function init() {
    // Scene, camera, renderer setup
    // Ground/terrain creation
    // Lighting configuration
    // Object placement
}
```

**Movement System** - Handles player input and physics:
```javascript
function animate() {
    // Update velocity based on input
    // Apply movement to controls
    // Render scene
}
```

**Controls** - Keyboard and mouse event handlers:
```javascript
onKeyDown() / onKeyUp() // WASD movement
PointerLockControls      // Mouse look
```

## Game Features

### Current Features
- First-person camera controls
- WASD/Arrow key movement
- Mouse look with pointer lock
- Flat terrain with grass texture
- Environmental objects (trees)
- Dynamic lighting and shadows
- Sky with fog effect

### Planned Features
- Multiple levels with different environments
- Interactive objects
- Collectibles
- Level transitions
- Sound effects
- Better character controller (collision, jumping)

## Troubleshooting

**Game won't load:**
- Make sure you're running the HTTP server (`npm start`)
- Check browser console for errors
- Ensure you're accessing via `http://127.0.0.1:8080`, not `file://`

**Controls not working:**
- Click on the page to enable pointer lock
- Check browser console for JavaScript errors
- Try refreshing the page

**Server won't start:**
- Check if port 8080 is already in use
- Try `npm install` to reinstall dependencies
- Check that Node.js is installed (`node --version`)

## Browser Compatibility

Works best in modern browsers:
- Chrome/Edge (recommended)
- Firefox
- Safari

Requires WebGL support and ES6 module support.

## Repository

GitHub: `git@github.com:airscont/games.git`

## Next Steps

When continuing development:
1. Run `npm start` to launch the server
2. Open browser to `http://127.0.0.1:8080/level1.html`
3. Create new levels by copying and modifying existing level files
4. Commit changes with `git add .` and `git commit`
5. Push to GitHub with `git push origin main`
