File size: 41,144 Bytes
267028b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Indian Railways Simulator</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background-color: #111827;
color: white;
overflow: hidden;
}
.train-body {
background: linear-gradient(90deg, #d10a11 60%, white 60%);
border-radius: 8px;
}
.coach-body {
background: linear-gradient(90deg, #003580 60%, white 60%);
border-radius: 8px;
}
.platform-tiles {
background: repeating-linear-gradient(
90deg,
#d1d5db,
#d1d5db 20px,
#9ca3af 20px,
#9ca3af 40px
);
}
.signal-green {
box-shadow: 0 0 20px 5px rgba(74, 222, 128, 0.7);
}
.signal-yellow {
box-shadow: 0 0 20px 5px rgba(234, 179, 8, 0.7);
}
.signal-red {
box-shadow: 0 0 20px 5px rgba(239, 68, 68, 0.7);
}
.fog-effect {
position: absolute;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(5px);
pointer-events: none;
}
.rain-effect {
position: absolute;
width: 100%;
height: 100%;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"><line x1="0" y1="0" x2="200" y2="200" stroke="rgba(255,255,255,0.2)" stroke-width="1"/></svg>');
animation: rain 0.5s linear infinite;
pointer-events: none;
}
@keyframes rain {
0% { background-position: 0 0; }
100% { background-position: 200px 200px; }
}
.gauge-fill {
transition: height 0.3s ease;
}
.cabin-panel {
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}
.button-glow:active {
box-shadow: 0 0 15px 5px rgba(59, 130, 246, 0.5);
}
#gameCanvas {
border-radius: 8px;
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}
.passenger {
animation: passenger-walk 4s infinite linear;
}
@keyframes passenger-walk {
0% { transform: translateX(-50px); opacity: 0; }
10% { opacity: 1; }
90% { opacity: 1; }
100% { transform: translateX(50px); opacity: 0; }
}
.blinking {
animation: blink 1s infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
</style>
</head>
<body class="h-screen flex flex-col">
<!-- Header -->
<header class="bg-red-800 py-2 px-4 flex justify-between items-center border-b-2 border-yellow-500">
<div class="flex items-center">
<img src="https://upload.wikimedia.org/wikipedia/en/thumb/3/37/Indian_Railways.svg/1200px-Indian_Railways.svg.png" alt="Indian Railways Logo" class="h-12 mr-3">
<h1 class="text-2xl font-bold">INDIAN RAILWAYS TRAIN SIMULATOR</h1>
</div>
<div class="flex items-center space-x-4">
<div class="bg-black bg-opacity-50 px-3 py-1 rounded-full flex items-center">
<i class="fas fa-rupee-sign text-yellow-400 mr-2"></i>
<span id="score">12,450</span>
</div>
<div class="bg-black bg-opacity-50 px-3 py-1 rounded-full flex items-center">
<i class="fas fa-user-tie text-blue-400 mr-2"></i>
<span>Asst. Loco Pilot</span>
</div>
<button class="bg-yellow-500 hover:bg-yellow-600 text-black px-4 py-1 rounded-full font-semibold">
<i class="fas fa-cog mr-2"></i>Settings
</button>
</div>
</header>
<!-- Main Game Area -->
<main class="flex-1 flex overflow-hidden relative">
<!-- Left Panel - Controls -->
<div class="w-80 bg-gray-900 p-4 flex flex-col border-r border-gray-700">
<div class="cabin-panel p-4 mb-4">
<h2 class="text-lg font-semibold mb-3 text-center border-b border-gray-600 pb-2">LOCO CONTROLS</h2>
<div class="mb-4">
<div class="flex justify-between items-center mb-1">
<span class="text-sm">THROTTLE</span>
<span class="text-xs bg-blue-900 px-2 py-1 rounded" id="throttle-value">0%</span>
</div>
<input type="range" min="0" max="100" value="0" class="w-full h-2 bg-gray-700 rounded-lg appearance-none cursor-pointer" id="throttle">
</div>
<div class="mb-4">
<div class="flex justify-between items-center mb-1">
<span class="text-sm">BRAKE</span>
<span class="text-xs bg-red-900 px-2 py-1 rounded" id="brake-value">0%</span>
</div>
<input type="range" min="0" max="100" value="0" class="w-full h-2 bg-gray-700 rounded-lg appearance-none cursor-pointer" id="brake">
</div>
<div class="grid grid-cols-3 gap-3 mb-4">
<button class="bg-blue-700 hover:bg-blue-600 py-2 rounded button-glow" id="horn">
<i class="fas fa-bullhorn"></i>
<div class="text-xs mt-1">HORN</div>
</button>
<button class="bg-gray-700 hover:bg-gray-600 py-2 rounded button-glow" id="headlight">
<i class="fas fa-lightbulb"></i>
<div class="text-xs mt-1">LIGHTS</div>
</button>
<button class="bg-green-700 hover:bg-green-600 py-2 rounded button-glow" id="pantograph">
<i class="fas fa-bolt"></i>
<div class="text-xs mt-1">PANTO</div>
</button>
<button class="bg-purple-700 hover:bg-purple-600 py-2 rounded button-glow" id="doors">
<i class="fas fa-door-open"></i>
<div class="text-xs mt-1">DOORS</div>
</button>
<button class="bg-yellow-700 hover:bg-yellow-600 py-2 rounded button-glow" id="sand">
<i class="fas fa-filter"></i>
<div class="text-xs mt-1">SAND</div>
</button>
<button class="bg-red-700 hover:bg-red-600 py-2 rounded button-glow" id="emergency">
<i class="fas fa-exclamation-triangle"></i>
<div class="text-xs mt-1">E-STOP</div>
</button>
</div>
<div class="border-t border-gray-600 pt-3">
<div class="flex justify-between text-sm mb-1">
<span>SPEED</span>
<span id="speed-value">0 km/h</span>
</div>
<div class="h-2 bg-gray-700 rounded-full mb-3">
<div class="h-2 bg-green-500 rounded-full" id="speed-bar" style="width: 0%"></div>
</div>
<div class="flex justify-between text-sm mb-1">
<span>POWER</span>
<span id="power-value">0%</span>
</div>
<div class="h-2 bg-gray-700 rounded-full">
<div class="h-2 bg-blue-500 rounded-full" id="power-bar" style="width: 0%"></div>
</div>
</div>
</div>
<div class="cabin-panel p-4 mb-4">
<h2 class="text-lg font-semibold mb-3 text-center border-b border-gray-600 pb-2">TRAIN INFO</h2>
<div class="space-y-2">
<div class="flex justify-between">
<span class="text-gray-400">Train No.:</span>
<span>12952</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Name:</span>
<span>Rajdhani Express</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Loco:</span>
<span>WAP-7 #30242</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Route:</span>
<span>NDLS - CSTM</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Next Stop:</span>
<span class="text-yellow-300">Bhopal (BPL)</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Distance:</span>
<span>148.3 km</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Time:</span>
<span>2h 18m</span>
</div>
<div class="flex justify-between">
<span class="text-gray-400">Punctuality:</span>
<span class="text-green-400">+3 min</span>
</div>
</div>
</div>
<div class="cabin-panel p-4 flex-1">
<h2 class="text-lg font-semibold mb-3 text-center border-b border-gray-600 pb-2">SIGNALS & ATC</h2>
<div class="flex justify-center mb-4">
<div class="signal-red w-8 h-8 rounded-full bg-red-600 border border-gray-400 mr-2"></div>
<div class="signal-yellow w-8 h-8 rounded-full bg-yellow-500 border border-gray-400 mr-2"></div>
<div class="signal-green w-8 h-8 rounded-full bg-green-500 border border-gray-400"></div>
</div>
<div class="bg-black bg-opacity-50 p-2 rounded mb-3">
<div class="text-xs text-gray-400 mb-1">CURRENT SIGNAL</div>
<div class="text-xl font-mono text-center blinking">RED</div>
</div>
<div class="bg-black bg-opacity-50 p-2 rounded">
<div class="text-xs text-gray-400 mb-1">ATC SPEED LIMIT</div>
<div class="text-xl font-mono text-center">110 km/h</div>
</div>
</div>
</div>
<!-- Center Panel - Game View -->
<div class="flex-1 relative overflow-hidden">
<!-- Weather effects will be added here dynamically -->
<div id="weather-effects"></div>
<!-- Canvas for 3D rendering -->
<canvas id="gameCanvas" class="absolute inset-0 w-full h-full"></canvas>
<!-- Station Announcement Banner -->
<div class="absolute bottom-4 left-1/2 transform -translate-x-1/2 bg-black bg-opacity-70 px-6 py-2 rounded-full flex items-center">
<i class="fas fa-bullhorn text-yellow-400 mr-3"></i>
<div class="marquee">
<span class="announcement-text">Attention please! Train number 12952 Rajdhani Express arriving shortly on platform number 3. Passengers are requested to...</span>
</div>
</div>
<!-- Speed Limit Indicator -->
<div class="absolute top-4 right-4 bg-black bg-opacity-70 border-2 border-white rounded-full w-16 h-16 flex items-center justify-center">
<div class="text-2xl font-bold">110</div>
</div>
<!-- Mini Map -->
<div class="absolute top-4 left-1/2 transform -translate-x-1/2 bg-black bg-opacity-50 p-2 rounded-lg">
<div class="w-48 h-24 bg-gray-800 relative">
<div class="absolute inset-0 bg-green-900 opacity-30"></div>
<div class="absolute top-1/2 left-0 right-0 h-1 bg-yellow-400"></div>
<div class="absolute top-1/2 left-1/4 transform -translate-y-1/2 -translate-x-1/2 w-2 h-2 bg-white rounded-full"></div>
<div class="absolute top-1/2 left-3/4 transform -translate-y-1/2 -translate-x-1/2 w-3 h-3 bg-red-500 rounded-full"></div>
<div class="absolute bottom-1 left-2 text-xs">BPL</div>
<div class="absolute bottom-1 right-2 text-xs">NDLS</div>
</div>
</div>
</div>
<!-- Right Panel - Coach View and Tasks -->
<div class="w-80 bg-gray-900 p-4 flex flex-col border-l border-gray-700">
<div class="cabin-panel p-4 mb-4">
<h2 class="text-lg font-semibold mb-3 text-center border-b border-gray-600 pb-2">COACH VIEW</h2>
<div class="flex overflow-x-auto pb-2 space-x-2">
<div class="flex-shrink-0 w-16 h-24 bg-blue-900 rounded flex flex-col items-center justify-center">
<div class="w-12 h-16 train-body mb-1"></div>
<div class="text-xs">WAP-7</div>
</div>
<div class="flex-shrink-0 w-16 h-24 bg-blue-900 rounded flex flex-col items-center justify-center">
<div class="w-12 h-16 coach-body mb-1"></div>
<div class="text-xs">S1</div>
</div>
<div class="flex-shrink-0 w-16 h-24 bg-blue-900 rounded flex flex-col items-center justify-center">
<div class="w-12 h-16 coach-body mb-1"></div>
<div class="text-xs">S2</div>
</div>
<div class="flex-shrink-0 w-16 h-24 bg-blue-900 rounded flex flex-col items-center justify-center">
<div class="w-12 h-16 coach-body mb-1"></div>
<div class="text-xs">S3</div>
</div>
<div class="flex-shrink-0 w-16 h-24 bg-blue-900 rounded flex flex-col items-center justify-center">
<div class="w-12 h-16 coach-body mb-1"></div>
<div class="text-xs">S4</div>
</div>
<div class="flex-shrink-0 w-16 h-24 bg-blue-900 rounded flex flex-col items-center justify-center">
<div class="w-12 h-16 coach-body mb-1"></div>
<div class="text-xs">S5</div>
</div>
</div>
<div class="mt-4 bg-black bg-opacity-30 p-2 rounded">
<div class="flex justify-between text-sm mb-1">
<span class="text-gray-400">Passengers:</span>
<span>432/480</span>
</div>
<div class="h-2 bg-gray-700 rounded-full">
<div class="h-2 bg-green-500 rounded-full" style="width: 90%"></div>
</div>
<div class="flex justify-between text-sm mt-2">
<span class="text-gray-400">Satisfaction:</span>
<span class="text-yellow-300">84%</span>
</div>
</div>
</div>
<div class="cabin-panel p-4 mb-4 flex-1">
<h2 class="text-lg font-semibold mb-3 text-center border-b border-gray-600 pb-2">TASKS & OBJECTIVES</h2>
<div class="space-y-3">
<div class="flex items-start">
<div class="w-5 h-5 rounded-full bg-green-500 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-check text-xs text-white"></i>
</div>
<div>
<div class="text-sm">Depart New Delhi on time</div>
<div class="text-xs text-gray-400">+250 points</div>
</div>
</div>
<div class="flex items-start">
<div class="w-5 h-5 rounded-full bg-green-500 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-check text-xs text-white"></i>
</div>
<div>
<div class="text-sm">Maintain speed through Ghaziabad</div>
<div class="text-xs text-gray-400">+180 points</div>
</div>
</div>
<div class="flex items-start">
<div class="w-5 h-5 rounded-full bg-yellow-500 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-spinner text-xs text-white"></i>
</div>
<div>
<div class="text-sm">Arrive Bhopal within ±5 minutes</div>
<div class="text-xs text-gray-400">0/300 points</div>
</div>
</div>
<div class="flex items-start">
<div class="w-5 h-5 rounded-full bg-gray-600 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-clock text-xs text-white"></i>
</div>
<div>
<div class="text-sm">Complete journey to Mumbai</div>
<div class="text-xs text-gray-400">0/1000 points</div>
</div>
</div>
<div class="flex items-start">
<div class="w-5 h-5 rounded-full bg-gray-600 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-clock text-xs text-white"></i>
</div>
<div>
<div class="text-sm">Keep passenger satisfaction >80%</div>
<div class="text-xs text-gray-400">0/400 points</div>
</div>
</div>
</div>
</div>
<div class="cabin-panel p-4">
<h2 class="text-lg font-semibold mb-3 text-center border-b border-gray-600 pb-2">ENVIRONMENT</h2>
<div class="grid grid-cols-3 gap-2 mb-3">
<button class="bg-blue-800 hover:bg-blue-700 py-2 rounded" id="weather-clear">
<i class="fas fa-sun"></i>
<div class="text-xs mt-1">CLEAR</div>
</button>
<button class="bg-gray-700 hover:bg-gray-600 py-2 rounded" id="weather-fog">
<i class="fas fa-smog"></i>
<div class="text-xs mt-1">FOG</div>
</button>
<button class="bg-indigo-800 hover:bg-indigo-700 py-2 rounded" id="weather-rain">
<i class="fas fa-cloud-rain"></i>
<div class="text-xs mt-1">RAIN</div>
</button>
</div>
<div class="flex justify-between items-center">
<div>
<div class="text-sm">TIME OF DAY</div>
<div class="text-xs text-gray-400" id="time-display">10:42 AM</div>
</div>
<input type="range" min="0" max="1439" value="642" class="w-32 h-1 bg-gray-700 rounded-lg appearance-none cursor-pointer" id="time-slider">
</div>
</div>
</div>
</main>
<!-- Bottom Status Bar -->
<footer class="bg-gray-800 py-1 px-4 flex justify-between items-center text-sm border-t border-gray-700">
<div class="flex items-center space-x-4">
<div class="flex items-center">
<div class="w-3 h-3 rounded-full bg-green-500 mr-2"></div>
<span>POWER: ON</span>
</div>
<div class="flex items-center">
<div class="w-3 h-3 rounded-full bg-red-500 mr-2"></div>
<span>PANTO: DOWN</span>
</div>
<div class="flex items-center">
<div class="w-3 h-3 rounded-full bg-yellow-500 mr-2"></div>
<span>DOORS: LOCKED</span>
</div>
</div>
<div class="flex items-center space-x-4">
<div class="flex items-center">
<i class="fas fa-map-marker-alt text-red-400 mr-2"></i>
<span>KM 342.7 • BPL 148.3 km</span>
</div>
<div class="flex items-center">
<i class="fas fa-clock text-blue-400 mr-2"></i>
<span>DELAY: +3 min</span>
</div>
</div>
</footer>
<script>
// Game state
const gameState = {
speed: 0,
throttle: 0,
brake: 0,
power: 0,
pantograph: false,
headlights: false,
doors: false,
weather: 'clear',
time: 642, // 10:42 AM in minutes
signal: 'red',
score: 12450,
announcements: [
"Attention please! Train number 12952 Rajdhani Express arriving shortly on platform number 3.",
"Passengers are requested to board the train only after it comes to a complete halt.",
"Please keep your belongings safe and secure during the journey.",
"The next station is Bhopal Junction. We will arrive in approximately 2 hours.",
"Lunch will be served shortly in all AC coaches. Please contact your coach attendant.",
"This is a non-smoking train. Smoking is strictly prohibited.",
"Passengers are requested to cooperate with railway staff for a comfortable journey."
],
currentAnnouncement: 0
};
// DOM elements
const elements = {
throttle: document.getElementById('throttle'),
throttleValue: document.getElementById('throttle-value'),
brake: document.getElementById('brake'),
brakeValue: document.getElementById('brake-value'),
horn: document.getElementById('horn'),
headlight: document.getElementById('headlight'),
pantograph: document.getElementById('pantograph'),
doors: document.getElementById('doors'),
emergency: document.getElementById('emergency'),
speedValue: document.getElementById('speed-value'),
speedBar: document.getElementById('speed-bar'),
powerValue: document.getElementById('power-value'),
powerBar: document.getElementById('power-bar'),
weatherEffects: document.getElementById('weather-effects'),
weatherClear: document.getElementById('weather-clear'),
weatherFog: document.getElementById('weather-fog'),
weatherRain: document.getElementById('weather-rain'),
timeSlider: document.getElementById('time-slider'),
timeDisplay: document.getElementById('time-display'),
score: document.getElementById('score'),
announcementText: document.querySelector('.announcement-text')
};
// Initialize canvas
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
function resizeCanvas() {
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
renderScene();
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Event listeners for controls
elements.throttle.addEventListener('input', function() {
gameState.throttle = parseInt(this.value);
elements.throttleValue.textContent = `${gameState.throttle}%`;
updatePower();
});
elements.brake.addEventListener('input', function() {
gameState.brake = parseInt(this.value);
elements.brakeValue.textContent = `${gameState.brake}%`;
updateSpeed();
});
elements.horn.addEventListener('click', function() {
playHornSound();
// Visual feedback
this.classList.add('bg-blue-600');
setTimeout(() => {
this.classList.remove('bg-blue-600');
}, 200);
});
elements.headlight.addEventListener('click', function() {
gameState.headlights = !gameState.headlights;
this.classList.toggle('bg-gray-600');
this.classList.toggle('bg-blue-600');
renderScene();
});
elements.pantograph.addEventListener('click', function() {
gameState.pantograph = !gameState.pantograph;
this.classList.toggle('bg-green-600');
this.classList.toggle('bg-gray-600');
updatePower();
});
elements.doors.addEventListener('click', function() {
gameState.doors = !gameState.doors;
this.classList.toggle('bg-purple-600');
this.classList.toggle('bg-gray-600');
});
elements.emergency.addEventListener('click', function() {
gameState.brake = 100;
elements.brake.value = 100;
elements.brakeValue.textContent = '100%';
updateSpeed();
// Visual feedback
this.classList.add('bg-red-800');
setTimeout(() => {
this.classList.remove('bg-red-800');
}, 1000);
});
elements.weatherClear.addEventListener('click', function() {
gameState.weather = 'clear';
updateWeather();
});
elements.weatherFog.addEventListener('click', function() {
gameState.weather = 'fog';
updateWeather();
});
elements.weatherRain.addEventListener('click', function() {
gameState.weather = 'rain';
updateWeather();
});
elements.timeSlider.addEventListener('input', function() {
gameState.time = parseInt(this.value);
updateTimeDisplay();
renderScene();
});
// Game logic functions
function updatePower() {
if (gameState.pantograph) {
gameState.power = Math.floor(gameState.throttle * 0.9 - gameState.brake * 0.2);
if (gameState.power < 0) gameState.power = 0;
} else {
gameState.power = 0;
}
elements.powerValue.textContent = `${gameState.power}%`;
elements.powerBar.style.width = `${gameState.power}%`;
updateSpeed();
}
function updateSpeed() {
// Simplified physics - in a real game this would be more complex
const acceleration = gameState.power * 0.02;
const deceleration = gameState.brake * 0.05 + 0.1; // Base friction + brake
gameState.speed += acceleration - deceleration;
if (gameState.speed < 0) gameState.speed = 0;
if (gameState.speed > 110) gameState.speed = 110; // Speed limit
elements.speedValue.textContent = `${Math.round(gameState.speed)} km/h`;
elements.speedBar.style.width = `${(gameState.speed / 110) * 100}%`;
// Update score based on speed (simplified)
if (gameState.speed > 0) {
gameState.score += Math.floor(gameState.speed / 10);
elements.score.textContent = gameState.score.toLocaleString();
}
}
function updateWeather() {
elements.weatherEffects.innerHTML = '';
switch (gameState.weather) {
case 'fog':
const fog = document.createElement('div');
fog.className = 'fog-effect';
elements.weatherEffects.appendChild(fog);
break;
case 'rain':
const rain = document.createElement('div');
rain.className = 'rain-effect';
elements.weatherEffects.appendChild(rain);
break;
}
// Update button states
elements.weatherClear.classList.remove('bg-blue-700', 'bg-blue-800');
elements.weatherFog.classList.remove('bg-gray-700', 'bg-gray-800');
elements.weatherRain.classList.remove('bg-indigo-700', 'bg-indigo-800');
if (gameState.weather === 'clear') {
elements.weatherClear.classList.add('bg-blue-700');
} else {
elements.weatherClear.classList.add('bg-blue-800');
}
if (gameState.weather === 'fog') {
elements.weatherFog.classList.add('bg-gray-700');
} else {
elements.weatherFog.classList.add('bg-gray-800');
}
if (gameState.weather === 'rain') {
elements.weatherRain.classList.add('bg-indigo-700');
} else {
elements.weatherRain.classList.add('bg-indigo-800');
}
renderScene();
}
function updateTimeDisplay() {
const hours = Math.floor(gameState.time / 60);
const minutes = gameState.time % 60;
const ampm = hours >= 12 ? 'PM' : 'AM';
const displayHours = hours % 12 || 12;
elements.timeDisplay.textContent =
`${displayHours}:${minutes.toString().padStart(2, '0')} ${ampm}`;
}
function playHornSound() {
// In a real implementation, we would play an actual sound
console.log("Horn sound played!");
}
function cycleAnnouncements() {
elements.announcementText.textContent = gameState.announcements[gameState.currentAnnouncement];
gameState.currentAnnouncement = (gameState.currentAnnouncement + 1) % gameState.announcements.length;
// Random interval between announcements (15-45 seconds)
setTimeout(cycleAnnouncements, 15000 + Math.random() * 30000);
}
// Render the 3D scene (simplified 2D representation)
function renderScene() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Background based on time of day
const hour = gameState.time / 60;
let bgColor;
if (hour < 5 || hour >= 19) {
// Night
bgColor = '#0f172a';
} else if (hour < 6 || hour >= 18) {
// Dawn/Dusk
bgColor = '#1e40af';
} else {
// Day
bgColor = '#38bdf8';
}
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
// Draw horizon
ctx.fillStyle = hour < 6 || hour >= 18 ? '#1e293b' : '#475569';
ctx.fillRect(0, canvas.height * 0.7, canvas.width, canvas.height * 0.3);
// Draw tracks
ctx.fillStyle = '#4b5563';
ctx.fillRect(0, canvas.height * 0.8, canvas.width, 10);
// Draw sleepers
ctx.fillStyle = '#6b7280';
for (let x = 0; x < canvas.width; x += 40) {
ctx.fillRect(x, canvas.height * 0.8 - 5, 30, 5);
}
// Draw platform if at station
if (gameState.speed === 0) {
ctx.fillStyle = '#9ca3af';
ctx.fillRect(0, canvas.height * 0.7 - 20, canvas.width, 20);
// Platform tiles
ctx.fillStyle = '#d1d5db';
for (let x = 0; x < canvas.width; x += 40) {
ctx.fillRect(x, canvas.height * 0.7 - 20, 20, 20);
}
// Draw passengers
for (let i = 0; i < 5; i++) {
const x = Math.random() * canvas.width;
const y = canvas.height * 0.7 - 25;
drawPassenger(x, y);
}
}
// Draw train
drawTrain();
// Draw signals
drawSignal(canvas.width * 0.8, canvas.height * 0.6);
// Draw scenery elements
if (gameState.speed > 0) {
// Moving scenery
for (let i = 0; i < 3; i++) {
const x = Math.random() * canvas.width;
const y = canvas.height * 0.6;
drawSceneryElement(x, y);
}
}
}
function drawTrain() {
const trainLength = 200 + (gameState.speed / 10);
const trainX = canvas.width * 0.2;
const trainY = canvas.height * 0.7 - 50;
// Locomotive
ctx.fillStyle = '#d10a11';
ctx.fillRect(trainX, trainY, 80, 50);
ctx.fillStyle = 'white';
ctx.fillRect(trainX + 48, trainY, 32, 50);
// Windows
ctx.fillStyle = '#1e293b';
for (let i = 0; i < 3; i++) {
ctx.fillRect(trainX + 10 + i * 20, trainY + 10, 15, 15);
}
// Headlight if on
if (gameState.headlights) {
ctx.fillStyle = 'rgba(255, 255, 255, 0.7)';
ctx.beginPath();
ctx.moveTo(trainX + 80, trainY + 25);
ctx.lineTo(trainX + 120, trainY + 10);
ctx.lineTo(trainX + 120, trainY + 40);
ctx.closePath();
ctx.fill();
}
// Coaches
for (let i = 0; i < 5; i++) {
ctx.fillStyle = '#003580';
ctx.fillRect(trainX + 80 + i * 40, trainY, 40, 50);
ctx.fillStyle = 'white';
ctx.fillRect(trainX + 80 + i * 40 + 24, trainY, 16, 50);
// Windows
ctx.fillStyle = '#1e293b';
for (let j = 0; j < 2; j++) {
ctx.fillRect(trainX + 80 + i * 40 + 5 + j * 15, trainY + 10, 10, 15);
}
// Coach number
ctx.fillStyle = 'white';
ctx.font = '10px Arial';
ctx.fillText(`S${i+1}`, trainX + 80 + i * 40 + 15, trainY + 40);
}
}
function drawSignal(x, y) {
// Post
ctx.fillStyle = '#57534e';
ctx.fillRect(x, y, 10, 100);
// Housing
ctx.fillStyle = '#1e293b';
ctx.fillRect(x - 15, y - 30, 40, 30);
// Lights
const colors = {
red: gameState.signal === 'red' ? '#ef4444' : '#450a0a',
yellow: gameState.signal === 'yellow' ? '#eab308' : '#422006',
green: gameState.signal === 'green' ? '#22c55e' : '#052e16'
};
ctx.beginPath();
ctx.arc(x + 5, y - 20, 5, 0, Math.PI * 2);
ctx.fillStyle = colors.red;
ctx.fill();
ctx.beginPath();
ctx.arc(x + 5, y - 10, 5, 0, Math.PI * 2);
ctx.fillStyle = colors.yellow;
ctx.fill();
ctx.beginPath();
ctx.arc(x + 5, y, 5, 0, Math.PI * 2);
ctx.fillStyle = colors.green;
ctx.fill();
}
function drawPassenger(x, y) {
// Head
ctx.beginPath();
ctx.arc(x, y, 5, 0, Math.PI * 2);
ctx.fillStyle = '#f59e0b';
ctx.fill();
// Body
ctx.fillStyle = '#4b5563';
ctx.fillRect(x - 5, y + 5, 10, 15);
// Legs
ctx.fillRect(x - 5, y + 20, 4, 10);
ctx.fillRect(x + 1, y + 20, 4, 10);
}
function drawSceneryElement(x, y) {
const types = ['tree', 'building', 'cow'];
const type = types[Math.floor(Math.random() * types.length)];
switch (type) {
case 'tree':
// Trunk
ctx.fillStyle = '#78350f';
ctx.fillRect(x, y, 5, 20);
// Leaves
ctx.beginPath();
ctx.arc(x + 2, y - 10, 15, 0, Math.PI * 2);
ctx.fillStyle = '#166534';
ctx.fill();
break;
case 'building':
ctx.fillStyle = '#475569';
const height = 30 + Math.random() * 30;
const width = 20 + Math.random() * 20;
ctx.fillRect(x, y - height, width, height);
// Windows
ctx.fillStyle = '#fef08a';
for (let i = 0; i < 2; i++) {
for (let j = 0; j < 2; j++) {
if (Math.random() > 0.3) {
ctx.fillRect(x + 5 + i * 8, y - height + 5 + j * 8, 5, 5);
}
}
}
break;
case 'cow':
// Body
ctx.beginPath();
ctx.ellipse(x, y, 10, 5, 0, 0, Math.PI * 2);
ctx.fillStyle = '#6b7280';
ctx.fill();
// Head
ctx.beginPath();
ctx.arc(x - 12, y - 3, 4, 0, Math.PI * 2);
ctx.fillStyle = '#6b7280';
ctx.fill();
// Spots
ctx.beginPath();
ctx.arc(x + 2, y - 2, 3, 0, Math.PI * 2);
ctx.fillStyle = '#9ca3af';
ctx.fill();
break;
}
}
// Game loop
function gameLoop() {
updateSpeed();
renderScene();
// Random signal changes
if (Math.random() < 0.005) {
const signals = ['red', 'yellow', 'green'];
gameState.signal = signals[Math.floor(Math.random() * signals.length)];
}
requestAnimationFrame(gameLoop);
}
// Initialize game
updateWeather();
updateTimeDisplay();
cycleAnnouncements();
gameLoop();
// Simulate random AI train horns
setInterval(() => {
if (Math.random() > 0.7) {
playHornSound();
}
}, 10000 + Math.random() * 20000);
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=div988/train" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |