Spaces:
Running
Running
Download index.html from Ronak778/anycoder-37a02ed1: direct link, hf CLI and curl.
- Browser
- Download file 36.5 kB
-
https://huggingface.co/spaces/Ronak778/anycoder-37a02ed1/resolve/main/index.html
- Command line
-
hf download hf://spaces/Ronak778/anycoder-37a02ed1/index.html
-
curl -L -o index.html https://huggingface.co/spaces/Ronak778/anycoder-37a02ed1/resolve/main/index.html
36.5 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ronak Mario - 3D First Person Adventure</title>
<!-- Three.js for 3D Graphics -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
overflow: hidden;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: relative;
}
#gameCanvas {
width: 100vw;
height: 100vh;
display: block;
image-rendering: crisp-edges;
image-rendering: -webkit-crisp-edges;
image-rendering: pixelated;
image-rendering: -moz-crisp-edges;
image-rendering: high-quality;
}
.ui-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 10;
}
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 20px;
background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
display: flex;
justify-content: space-between;
align-items: center;
animation: slideDown 0.5s ease-out;
}
@keyframes slideDown {
from {
transform: translateY(-100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.game-title {
font-size: clamp(1.5rem, 4vw, 3rem);
font-weight: bold;
background: linear-gradient(45deg, #FFD700, #FFA500, #FF6347);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
from {
filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.5));
}
to {
filter: drop-shadow(0 0 30px rgba(255, 165, 0, 0.8));
}
}
.game-title a {
text-decoration: none;
color: inherit;
}
.stats {
display: flex;
gap: 30px;
align-items: center;
}
.stat-item {
display: flex;
align-items: center;
gap: 10px;
background: rgba(0, 0, 0, 0.6);
padding: 10px 20px;
border-radius: 50px;
backdrop-filter: blur(10px);
border: 2px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
}
.stat-item:hover {
transform: scale(1.05);
background: rgba(0, 0, 0, 0.8);
border-color: rgba(255, 215, 0, 0.5);
}
.stat-icon {
font-size: 1.5rem;
color: #FFD700;
}
.stat-value {
font-size: 1.2rem;
font-weight: bold;
color: white;
min-width: 50px;
text-align: center;
}
.controls {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 20px;
pointer-events: all;
}
.control-btn {
width: 60px;
height: 60px;
border-radius: 50%;
background: linear-gradient(145deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.1));
backdrop-filter: blur(10px);
border: 2px solid rgba(255, 255, 255, 0.3);
color: white;
font-size: 1.5rem;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}
.control-btn:hover {
transform: scale(1.1);
background: linear-gradient(145deg, rgba(255, 215, 0, 0.3), rgba(255, 165, 0, 0.2));
border-color: #FFD700;
box-shadow: 0 8px 30px rgba(255, 215, 0, 0.4);
}
.control-btn:active {
transform: scale(0.95);
}
.mobile-controls {
position: absolute;
bottom: 30px;
left: 30px;
display: none;
flex-direction: column;
gap: 10px;
pointer-events: all;
}
.joystick-base {
width: 120px;
height: 120px;
background: radial-gradient(circle, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
position: relative;
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(10px);
}
.joystick-handle {
width: 50px;
height: 50px;
background: linear-gradient(145deg, #FFD700, #FFA500);
border-radius: 50%;
position: absolute;
transition: none;
box-shadow: 0 5px 20px rgba(255, 215, 0, 0.5);
}
.jump-btn {
position: absolute;
bottom: 60px;
right: 30px;
width: 80px;
height: 80px;
background: linear-gradient(145deg, #FF6B6B, #FF4757);
border: 3px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
color: white;
font-size: 2rem;
font-weight: bold;
display: none;
align-items: center;
justify-content: center;
cursor: pointer;
backdrop-filter: blur(10px);
box-shadow: 0 5px 20px rgba(255, 75, 75, 0.5);
pointer-events: all;
transition: all 0.2s ease;
}
.jump-btn:active {
transform: scale(0.9);
}
.message {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: linear-gradient(145deg, rgba(0, 0, 0, 0.9), rgba(50, 50, 50, 0.9));
color: white;
padding: 30px 50px;
border-radius: 20px;
font-size: 1.5rem;
font-weight: bold;
text-align: center;
backdrop-filter: blur(20px);
border: 3px solid rgba(255, 215, 0, 0.5);
box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
display: none;
animation: messagePopup 0.5s ease-out;
}
@keyframes messagePopup {
from {
transform: translate(-50%, -50%) scale(0);
opacity: 0;
}
to {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
}
}
.loading-screen {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 100;
transition: opacity 1s ease-out;
}
.loading-screen h1 {
font-size: 4rem;
color: white;
margin-bottom: 30px;
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
}
.loader {
width: 100px;
height: 100px;
border: 10px solid rgba(255, 255, 255, 0.3);
border-top: 10px solid #FFD700;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@media (max-width: 768px) {
.mobile-controls {
display: flex;
}
.jump-btn {
display: flex;
}
.controls {
display: none;
}
.header {
padding: 10px;
}
.game-title {
font-size: 1.5rem;
}
.stats {
gap: 10px;
}
.stat-item {
padding: 5px 10px;
}
.stat-value {
font-size: 1rem;
}
}
.power-up-indicator {
position: absolute;
top: 150px;
right: 30px;
background: linear-gradient(145deg, rgba(255, 215, 0, 0.8), rgba(255, 165, 0, 0.8));
padding: 15px 25px;
border-radius: 50px;
color: white;
font-weight: bold;
display: none;
animation: powerUpPulse 0.5s ease-in-out infinite;
}
@keyframes powerUpPulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.05);
}
}
.crosshair {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 30px;
height: 30px;
pointer-events: none;
}
.crosshair::before,
.crosshair::after {
content: '';
position: absolute;
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}
.crosshair::before {
width: 100%;
height: 2px;
top: 50%;
transform: translateY(-50%);
}
.crosshair::after {
height: 100%;
width: 2px;
left: 50%;
transform: translateX(-50%);
}
</style>
</head>
<body>
<!-- Loading Screen -->
<div class="loading-screen" id="loadingScreen">
<h1><i class="fas fa-gamepad"></i> Ronak Mario</h1>
<div class="loader"></div>
</div>
<!-- Game Canvas -->
<canvas id="gameCanvas"></canvas>
<!-- UI Container -->
<div class="ui-container">
<!-- Header -->
<div class="header">
<div class="game-title">
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">
<i class="fas fa-crown"></i> Ronak Mario
</a>
</div>
<div class="stats">
<div class="stat-item">
<i class="fas fa-coins stat-icon"></i>
<span class="stat-value" id="coins">0</span>
</div>
<div class="stat-item">
<i class="fas fa-heart stat-icon"></i>
<span class="stat-value" id="lives">3</span>
</div>
<div class="stat-item">
<i class="fas fa-trophy stat-icon"></i>
<span class="stat-value" id="score">0</span>
</div>
</div>
</div>
<!-- Crosshair -->
<div class="crosshair"></div>
<!-- Power-up Indicator -->
<div class="power-up-indicator" id="powerUpIndicator">
<i class="fas fa-star"></i> Super Mario Active!
</div>
<!-- Desktop Controls -->
<div class="controls">
<button class="control-btn" id="pauseBtn">
<i class="fas fa-pause"></i>
</button>
<button class="control-btn" id="restartBtn">
<i class="fas fa-redo"></i>
</button>
<button class="control-btn" id="fullscreenBtn">
<i class="fas fa-expand"></i>
</button>
</div>
<!-- Mobile Controls -->
<div class="mobile-controls">
<div class="joystick-base" id="joystick">
<div class="joystick-handle" id="joystickHandle"></div>
</div>
</div>
<!-- Jump Button for Mobile -->
<button class="jump-btn" id="jumpBtn">
<i class="fas fa-arrow-up"></i>
</button>
<!-- Message Display -->
<div class="message" id="message"></div>
</div>
<script>
// Game Variables
let scene, camera, renderer;
let player, velocity, isGrounded, isJumping;
let coins = [], platforms = [], powerUps = [];
let score = 0, lives = 3, coinsCollected = 0;
let keys = {};
let isPaused = false;
let isPowerUpActive = false;
let powerUpTimer = null;
let joystickActive = false;
let joystickVector = { x: 0, z: 0 };
// Initialize Game
function init() {
// Scene Setup
scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x87CEEB, 10, 100);
scene.background = new THREE.Color(0x87CEEB);
// Camera Setup
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 5, 10);
// Renderer Setup with High DPI Support
renderer = new THREE.WebGLRenderer({
canvas: document.getElementById('gameCanvas'),
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 4)); // Support up to 4K
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.2;
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(10, 20, 5);
directionalLight.castShadow = true;
directionalLight.shadow.camera.left = -50;
directionalLight.shadow.camera.right = 50;
directionalLight.shadow.camera.top = 50;
directionalLight.shadow.camera.bottom = -50;
directionalLight.shadow.mapSize.width = 4096;
directionalLight.shadow.mapSize.height = 4096;
scene.add(directionalLight);
// Player Setup
player = new THREE.Group();
player.position.set(0, 5, 0);
scene.add(player);
// Add player body (invisible in first person, but for collision)
const playerGeometry = new THREE.CapsuleGeometry(0.5, 1.5, 4, 8);
const playerMaterial = new THREE.MeshBasicMaterial({ visible: false });
const playerMesh = new THREE.Mesh(playerGeometry, playerMaterial);
player.add(playerMesh);
// Initialize Physics
velocity = new THREE.Vector3(0, 0, 0);
isGrounded = false;
isJumping = false;
// Create World
createGround();
createPlatforms();
createCoins();
createPowerUps();
createEnvironment();
// Event Listeners
setupEventListeners();
// Hide Loading Screen
setTimeout(() => {
const loadingScreen = document.getElementById('loadingScreen');
loadingScreen.style.opacity = '0';
setTimeout(() => {
loadingScreen.style.display = 'none';
}, 1000);
}, 2000);
// Start Game Loop
animate();
}
function createGround() {
const groundGeometry = new THREE.PlaneGeometry(200, 200);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x90EE90,
roughness: 0.8,
metalness: 0.2
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
// Add grid pattern
const gridHelper = new THREE.GridHelper(200, 50, 0x228B22, 0x228B22);
scene.add(gridHelper);
}
function createPlatforms() {
const platformPositions = [
{ x: 5, y: 3, z: -10, width: 4, height: 0.5, depth: 4 },
{ x: -7, y: 5, z: -15, width: 5, height: 0.5, depth: 5 },
{ x: 0, y: 7, z: -20, width: 6, height: 0.5, depth: 6 },
{ x: 10, y: 4, z: -25, width: 4, height: 0.5, depth: 4 },
{ x: -10, y: 6, z: -30, width: 5, height: 0.5, depth: 5 },
{ x: 15, y: 8, z: -35, width: 4, height: 0.5, depth: 4 }
];
platformPositions.forEach(pos => {
const geometry = new THREE.BoxGeometry(pos.width, pos.height, pos.depth);
const material = new THREE.MeshStandardMaterial({
color: 0x8B4513,
roughness: 0.7,
metalness: 0.1
});
const platform = new THREE.Mesh(geometry, material);
platform.position.set(pos.x, pos.y, pos.z);
platform.castShadow = true;
platform.receiveShadow = true;
platform.userData.isPlatform = true;
platforms.push(platform);
scene.add(platform);
// Add decorative border
const borderGeometry = new THREE.EdgesGeometry(geometry);
const borderMaterial = new THREE.LineBasicMaterial({ color: 0xFFD700 });
const border = new THREE.LineSegments(borderGeometry, borderMaterial);
platform.add(border);
});
}
function createCoins() {
const coinPositions = [
{ x: 5, y: 5, z: -10 },
{ x: -7, y: 7, z: -15 },
{ x: 0, y: 9, z: -20 },
{ x: 10, y: 6, z: -25 },
{ x: -10, y: 8, z: -30 },
{ x: 15, y: 10, z: -35 },
{ x: 3, y: 2, z: -5 },
{ x: -3, y: 3, z: -8 },
{ x: 8, y: 4, z: -12 },
{ x: -8, y: 5, z: -18 }
];
coinPositions.forEach(pos => {
const geometry = new THREE.CylinderGeometry(0.5, 0.5, 0.1, 32);
const material = new THREE.MeshStandardMaterial({
color: 0xFFD700,
metalness: 1,
roughness: 0.1,
emissive: 0xFFD700,
emissiveIntensity: 0.2
});
const coin = new THREE.Mesh(geometry, material);
coin.position.set(pos.x, pos.y, pos.z);
coin.userData.isCoin = true;
coin.userData.collected = false;
coins.push(coin);
scene.add(coin);
});
}
function createPowerUps() {
const powerUpPositions = [
{ x: 0, y: 10, z: -20 },
{ x: 15, y: 11, z: -35 }
];
powerUpPositions.forEach(pos => {
const geometry = new THREE.OctahedronGeometry(0.5);
const material = new THREE.MeshStandardMaterial({
color: 0xFF1493,
metalness: 0.5,
roughness: 0.2,
emissive: 0xFF1493,
emissiveIntensity: 0.3
});
const powerUp = new THREE.Mesh(geometry, material);
powerUp.position.set(pos.x, pos.y, pos.z);
powerUp.userData.isPowerUp = true;
powerUp.userData.collected = false;
powerUps.push(powerUp);
scene.add(powerUp);
});
}
function createEnvironment() {
// Add floating clouds
for (let i = 0; i < 5; i++) {
const cloudGeometry = new THREE.SphereGeometry(Math.random() * 3 + 2, 16, 16);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
transparent: true,
opacity: 0.8
});
const cloud = new THREE.Mesh(cloudGeometry, cloudMaterial);
cloud.position.set(
Math.random() * 40 - 20,
Math.random() * 10 + 15,
Math.random() * -50 - 10
);
cloud.scale.set(1, 0.5, 1);
scene.add(cloud);
}
// Add decorative trees
for (let i = 0; i < 10; i++) {
const trunkGeometry = new THREE.CylinderGeometry(0.5, 0.7, 3);
const trunkMaterial = new THREE.MeshStandardMaterial({ color: 0x8B4513 });
const trunk = new THREE.Mesh(trunkGeometry, trunkMaterial);
const leavesGeometry = new THREE.ConeGeometry(2, 4, 8);
const leavesMaterial = new THREE.MeshStandardMaterial({ color: 0x228B22 });
const leaves = new THREE.Mesh(leavesGeometry, leavesMaterial);
leaves.position.y = 2.5;
const tree = new THREE.Group();
tree.add(trunk);
tree.add(leaves);
tree.position.set(
Math.random() * 50 - 25,
1.5,
Math.random() * 30 + 20
);
tree.castShadow = true;
scene.add(tree);
}
}
function setupEventListeners() {
// Keyboard Controls
document.addEventListener('keydown', (e) => {
keys[e.key.toLowerCase()] = true;
if (e.key === ' ' || e.key === 'w' || e.key === 'ArrowUp') {
jump();
}
});
document.addEventListener('keyup', (e) => {
keys[e.key.toLowerCase()] = false;
});
// Mouse Controls for Look
let mouseX = 0, mouseY = 0;
let isPointerLocked = false;
document.addEventListener('click', () => {
if (!isPointerLocked && !isMobileDevice()) {
document.body.requestPointerLock();
}
});
document.addEventListener('pointerlockchange', () => {
isPointerLocked = document.pointerLockElement === document.body;
});
document.addEventListener('mousemove', (e) => {
if (isPointerLocked) {
player.rotation.y -= e.movementX * 0.002;
camera.rotation.x -= e.movementY * 0.002;
camera.rotation.x = Math.max(-Math.PI / 3, Math.min(Math.PI / 3, camera.rotation.x));
}
});
// Touch Controls for Mobile
setupMobileControls();
// UI Controls
document.getElementById('pauseBtn').addEventListener('click', togglePause);
document.getElementById('restartBtn').addEventListener('click', restartGame);
document.getElementById('fullscreenBtn').addEventListener('click', toggleFullscreen);
}
function setupMobileControls() {
const joystick = document.getElementById('joystick');
const joystickHandle = document.getElementById('joystickHandle');
const jumpBtn = document.getElementById('jumpBtn');
// Joystick
joystick.addEventListener('touchstart', (e) => {
joystickActive = true;
e.preventDefault();
});
joystick.addEventListener('touchmove', (e) => {
if (joystickActive) {
const touch = e.touches[0];
const rect = joystick.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
let x = touch.clientX - centerX;
let y = touch.clientY - centerY;
const distance = Math.sqrt(x * x + y * y);
const maxDistance = rect.width / 2 - 25;
if (distance > maxDistance) {
x = x / distance * maxDistance;
y = y / distance * maxDistance;
}
joystickHandle.style.transform = `translate(${x}px, ${y}px)`;
joystickVector.x = x / maxDistance;
joystickVector.z = y / maxDistance;
}
e.preventDefault();
});
joystick.addEventListener('touchend', () => {
joystickActive = false;
joystickHandle.style.transform = 'translate(0, 0)';
joystickVector = { x: 0, z: 0 };
});
// Jump Button
jumpBtn.addEventListener('touchstart', (e) => {
jump();
e.preventDefault();
});
}
function jump() {
if (isGrounded && !isJumping) {
velocity.y = isPowerUpActive ? 15 : 10;
isJumping = true;
isGrounded = false;
}
}
function updatePlayer() {
if (isPaused) return;
const speed = isPowerUpActive ? 0.3 : 0.2;
const moveVector = new THREE.Vector3();
// Keyboard Movement
if (keys['a'] || keys['arrowleft']) moveVector.x -= speed;
if (keys['d'] || keys['arrowright']) moveVector.x += speed;
if (keys['w'] || keys['arrowup']) moveVector.z -= speed;
if (keys['s'] || keys['arrowdown']) moveVector.z += speed;
// Mobile Joystick Movement
if (isMobileDevice()) {
moveVector.x += joystickVector.x * speed;
moveVector.z += joystickVector.z * speed;
}
// Apply movement relative to player rotation
moveVector.applyAxisAngle(new THREE.Vector3(0, 1, 0), player.rotation.y);
// Gravity
if (!isGrounded) {
velocity.y -= 0.5;
}
// Update position
player.position.add(moveVector);
player.position.y += velocity.y * 0.1;
// Ground collision
if (player.position.y <= 1.5) {
player.position.y = 1.5;
velocity.y = 0;
isGrounded = true;
isJumping = false;
}
// Platform collision
checkPlatformCollision();
// Update camera to follow player
camera.position.copy(player.position);
camera.position.y += 1.5;
camera.rotation.y = player.rotation.y;
// Collect coins
checkCoinCollection();
// Collect power-ups
checkPowerUpCollection();
}
function checkPlatformCollision() {
const playerBox = new THREE.Box3().setFromObject(player);
platforms.forEach(platform => {
const platformBox = new THREE.Box3().setFromObject(platform);
if (playerBox.intersectsBox(platformBox)) {
const playerTop = player.position.y + 1.5;
const platformBottom = platform.position.y - platform.geometry.parameters.height / 2;
if (playerTop > platformBottom && velocity.y <= 0) {
player.position.y = platformBottom + 1.5 + platform.geometry.parameters.height / 2;
velocity.y = 0;
isGrounded = true;
isJumping = false;
}
}
});
}
function checkCoinCollection() {
coins.forEach(coin => {
if (!coin.userData.collected) {
const distance = player.position.distanceTo(coin.position);
if (distance < 2) {
coin.userData.collected = true;
coin.visible = false;
coinsCollected++;
score += 100;
updateUI();
// Play collection effect
createCollectionEffect(coin.position, 0xFFD700);
// Check win condition
if (coinsCollected === coins.length) {
showMessage('๐ Level Complete! ๐');
setTimeout(() => {
restartGame();
}, 3000);
}
}
}
});
}
function checkPowerUpCollection() {
powerUps.forEach(powerUp => {
if (!powerUp.userData.collected) {
const distance = player.position.distanceTo(powerUp.position);
if (distance < 2) {
powerUp.userData.collected = true;
powerUp.visible = false;
activatePowerUp();
// Play collection effect
createCollectionEffect(powerUp.position, 0xFF1493);
}
}
});
}
function activatePowerUp() {
isPowerUpActive = true;
document.getElementById('powerUpIndicator').style.display = 'block';
if (powerUpTimer) clearTimeout(powerUpTimer);
powerUpTimer = setTimeout(() => {
isPowerUpActive = false;
document.getElementById('powerUpIndicator').style.display = 'none';
}, 10000);
}
function createCollectionEffect(position, color) {
const particleCount = 20;
const particles = [];
for (let i = 0; i < particleCount; i++) {
const geometry = new THREE.SphereGeometry(0.1, 8, 8);
const material = new THREE.MeshBasicMaterial({ color });
const particle = new THREE.Mesh(geometry, material);
particle.position.copy(position);
particle.velocity = new THREE.Vector3(
(Math.random() - 0.5) * 0.5,
Math.random() * 0.5,
(Math.random() - 0.5) * 0.5
);
particles.push(particle);
scene.add(particle);
}
// Animate particles
const animateParticles = () => {
particles.forEach((particle, index) => {
particle.position.add(particle.velocity);
particle.velocity.y -= 0.02;
particle.material.opacity -= 0.02;
if (particle.material.opacity <= 0) {
scene.remove(particle);
particles.splice(index, 1);
}
});
if (particles.length > 0) {
requestAnimationFrame(animateParticles);
}
};
animateParticles();
}
function animate() {
requestAnimationFrame(animate);
if (!isPaused) {
updatePlayer();
// Animate coins
coins.forEach(coin => {
if (!coin.userData.collected) {
coin.rotation.y += 0.05;
coin.position.y += Math.sin(Date.now() * 0.003) * 0.01;
}
});
// Animate power-ups
powerUps.forEach(powerUp => {
if (!powerUp.userData.collected) {
powerUp.rotation.x += 0.02;
powerUp.rotation.y += 0.03;
powerUp.position.y += Math.sin(Date.now() * 0.002) * 0.02;
}
});
}
renderer.render(scene, camera);
}
function updateUI() {
document.getElementById('coins').textContent = coinsCollected;
document.getElementById('lives').textContent = lives;
document.getElementById('score').textContent = score;
}
function showMessage(text) {
const messageEl = document.getElementById('message');
messageEl.textContent = text;
messageEl.style.display = 'block';
setTimeout(() => {
messageEl.style.display = 'none';
}, 3000);
}
function togglePause() {
isPaused = !isPaused;
showMessage(isPaused ? 'Game Paused' : 'Game Resumed');
}
function restartGame() {
// Reset player position
player.position.set(0, 5, 0);
camera.position.set(0, 6.5, 10);
velocity.set(0, 0, 0);
// Reset game state
score = 0;
coinsCollected = 0;
isPowerUpActive = false;
// Reset coins
coins.forEach(coin => {
coin.userData.collected = false;
coin.visible = true;
});
// Reset power-ups
powerUps.forEach(powerUp => {
powerUp.userData.collected = false;
powerUp.visible = true;
});
// Update UI
updateUI();
document.getElementById('powerUpIndicator').style.display = 'none';
showMessage('Game Restarted!');
}
function toggleFullscreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
document.exitFullscreen();
}
}
function isMobileDevice() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Initialize game when page loads
window.addEventListener('load', init);
</script>
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ronak Mario - 3D First Person Adventure</title>
<!-- Three.js for 3D Graphics -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<!-- Font Awesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
overflow: hidden;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
position: relative;
}
#gameCanvas {
width: 100vw;
height: 100vh;
display: block;
image-rendering: crisp-edges;
image-rendering: -webkit-crisp-edges;
image-rendering: pixelated;
image-rendering: -moz-crisp-edges;
image-rendering: high-quality;
}
.ui-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 10;
}
.header {
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 20px;
background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
display: flex;
justify-content: space-between;
align-items: center;
animation: slideDown 0.5s ease-out;
}
@keyframes slideDown {
from {
transform: translateY(-100%);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.game-title {
font-size: clamp(1.5rem, 4vw, 3rem);
font-weight: bold;
background: linear-gradient(45deg, #FFD700, #FFA500, #FF6347);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
from {
filter: drop-shadow(0 0 20px rgba(255, 215, 0, 0.5));
}
to {
filter: drop-shadow(0 0 30px rgba(255, 165, 0, 0.8));
}
}
.game-title a {
text-decoration: none;
color: inherit;
}
.stats {
display: flex;
gap: 30px;