'Vancouver - Pacific Gateway', 'lat' => 49.2827, 'lon' => -123.1207, 'description' => 'Start your journey at Pacific Central Station, gateway to the Canadian Rockies.', 'image' => 'images/canadian1.jpg'],
['name' => 'Kamloops - Desert Oasis', 'lat' => 50.6745, 'lon' => -120.3273, 'description' => 'Semi-arid landscape and confluence of rivers in the Thompson Valley.', 'image' => 'images/canadian2.jpg'],
['name' => 'Jasper - Rocky Mountain Jewel', 'lat' => 52.8737, 'lon' => -118.0814, 'description' => 'UNESCO World Heritage site in the heart of the Canadian Rockies.', 'image' => 'images/canadian3.jpg'],
['name' => 'Edmonton - Festival City', 'lat' => 53.5461, 'lon' => -113.4938, 'description' => 'Alberta\'s capital, known for West Edmonton Mall and river valley parks.', 'image' => 'images/canadian4.jpg'],
['name' => 'Saskatoon - City of Bridges', 'lat' => 52.1332, 'lon' => -106.6700, 'description' => 'Saskatchewan\'s largest city spanning the South Saskatchewan River.', 'image' => 'images/canadian5.jpg'],
['name' => 'Winnipeg - Heart of the Continent', 'lat' => 49.8951, 'lon' => -97.1384, 'description' => 'Manitoba\'s capital at the forks of the Red and Assiniboine Rivers.', 'image' => 'images/canadian6.jpg'],
['name' => 'Sioux Lookout - Hub of the North', 'lat' => 50.1000, 'lon' => -91.9167, 'description' => 'Gateway to Ontario\'s northern wilderness and lake country.', 'image' => 'images/canadian7.jpg'],
['name' => 'Sudbury - Nickel Capital', 'lat' => 46.4917, 'lon' => -81.0000, 'description' => 'Mining heritage city with unique geological features and the Big Nickel.', 'image' => 'images/canadian8.jpg'],
['name' => 'Ottawa - The Capital', 'lat' => 45.4215, 'lon' => -75.6972, 'description' => 'Canada\'s capital city with Parliament Hill and the Rideau Canal.', 'image' => 'images/canadian9.jpg'],
['name' => 'Toronto - Union Station', 'lat' => 43.6532, 'lon' => -79.3832, 'description' => 'Complete your transcontinental journey at Canada\'s largest city.', 'image' => 'images/canadian10.jpg']
];
$dataFile = 'transcanadian_data.json';
$gameData = file_exists($dataFile) ? json_decode(file_get_contents($dataFile), true) : ['players' => []];
$playerId = $_COOKIE['convaya_id'] ?? null;
$playerName = $_COOKIE['convaya_name'] ?? '';
$currentPlayer = null;
if ($playerId && isset($gameData['players'][$playerId])) {
$currentPlayer = $gameData['players'][$playerId];
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'join') {
$name = trim($_POST['name'] ?? '');
if ($name) {
$playerId = uniqid('player_');
$gameData['players'][$playerId] = [
'name' => $name,
'discovered' => [],
'joined' => date('Y-m-d H:i:s'),
'lat' => null,
'lon' => null
];
file_put_contents($dataFile, json_encode($gameData, JSON_PRETTY_PRINT));
setcookie('convaya_id', $playerId, time() + 86400 * 365, '/');
setcookie('convaya_name', $name, time() + 86400 * 365, '/');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
}
if ($action === 'update_position' && $playerId) {
$lat = floatval($_POST['lat'] ?? 0);
$lon = floatval($_POST['lon'] ?? 0);
if ($lat && $lon && isset($gameData['players'][$playerId])) {
$gameData['players'][$playerId]['lat'] = $lat;
$gameData['players'][$playerId]['lon'] = $lon;
$gameData['players'][$playerId]['last_update'] = date('Y-m-d H:i:s');
foreach ($treasures as $index => $treasure) {
$distance = haversine($lat, $lon, $treasure['lat'], $treasure['lon']);
if ($distance < 50 && !in_array($index, $gameData['players'][$playerId]['discovered'])) {
$gameData['players'][$playerId]['discovered'][] = $index;
}
}
file_put_contents($dataFile, json_encode($gameData, JSON_PRETTY_PRINT));
}
header('Content-Type: application/json');
echo json_encode(['success' => true, 'discovered' => $gameData['players'][$playerId]['discovered']]);
exit;
}
}
function haversine($lat1, $lon1, $lat2, $lon2) {
$R = 6371;
$dLat = deg2rad($lat2 - $lat1);
$dLon = deg2rad($lon2 - $lon1);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2);
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
return $R * $c;
}
if ($currentPlayer) {
$discovered = $currentPlayer['discovered'] ?? [];
$progress = (count($discovered) / count($treasures)) * 100;
?>
Route Stops
$treasure):
$isDiscovered = in_array($index, $discovered);
?>
Join the Adventure
Enter your name to start tracking your journey across Canada
Route Preview