Get Safe Position
Path Parameters
The unique player ID requesting a safe spawn position
Response
Horizontal position as a percentage of map width (0-95)
Vertical position as a percentage of map height (0-95)
Indicates whether a safe position was found within 20 attempts. If
false, the position may be close to other players.Example
Understanding the Safe Position Algorithm
Percentage-Based Coordinate System
The game uses normalized coordinates where positions are stored as percentages (0-100) of the map size. This provides several benefits:- Responsive Design: Works seamlessly across different screen sizes
- Scalability: Map can be rendered at any resolution
- Consistency: Same relative positions regardless of display dimensions
Positions are limited to 0-95% to leave room at the edges of the map, preventing players from spawning at the very border.
Safe Distance Calculation
The algorithm uses a 20% safe distance radius (game-state.mdx:299). Distance is calculated using the Euclidean distance formula:
distance >= 20 (percentage points) from all other players.
Algorithm Flow
- Generate random coordinates (0-95% range)
- Check distance from all existing players with defined positions
- If any player is within 20% distance, reject position
- Repeat up to 20 times
- Return the position with
safe: trueif found, orsafe: falseafter 20 attempts
Update Player Position
Path Parameters
The unique player ID whose position is being updated
Request Body
New horizontal position as a percentage of map width (0-100)
New vertical position as a percentage of map height (0-100)
Response
Array of enemy player objects currently in the game
Example
Understanding Position Updates
Filtering Logic
The endpoint filters players to include in theenemies array based on these criteria (game-state.mdx:345-352):
- Exclude Self:
player.id !== playerId - Has Mokepon:
player.mokeponexists - Has Position: Both
xPercentandyPercentare defined - All Player Types: Includes both human players (
isCPU: false) and CPU players (isCPU: true)
Players who have joined but not yet selected a Mokepon or set their position will not appear in the enemies list.
Real-Time Synchronization
This endpoint serves dual purposes:- Update Own Position: Stores the current player’s new position on the server
- Retrieve Enemy Positions: Gets the latest positions of all other players
CPU Player Positioning
CPU players are positioned when they’re generated:- X Position: Evenly distributed across segments with randomization
- Y Position: Random value between 30% and 70% of map height
- Segment Calculation:
segment = 100 / (CPU_COUNT + 1)ensures spacing
When to Call This Endpoint
Recommended usage patterns:- Movement: Every time the player moves
- Polling: At regular intervals (e.g., every 100-500ms) to track enemy positions
- Before Battle: To ensure enemy position is current before initiating combat
Performance Considerations
The endpoint:- Returns all players on every call (no pagination)
- Performs array filtering on each request
- Does not implement rate limiting
For games with many players, consider implementing client-side caching and only requesting updates when needed to reduce server load.