Sure! Below is a simple implementation of Doodle Jump optimized for iPhone (mobile) with touchscreen support. It uses the device's tilt (gyroscope) controls to move the player left/right, like the original Doodle Jump mobile control. It also supports basic touch controls (tap left/right side of screen) if device orientation is not available or for extra control.
Features:
- Player automatically jumps upward on platforms.
- Platforms scroll down as player goes up, giving an endless feel.
- Player moves by tilting the device left/right.
- Tap left/right side screen as alternative controls.
- The game ends when the player falls below the screen.
- Simple score display (height reached).
- Canvas resizes to fit device width for iPhone screens.
- Smooth 60 FPS animation.
How to run:
- Open on iPhone or any mobile device with orientation support.
- Tilt device left/right to move the doodler.
- Tap left/right screen halves to move if needed.
- The doodler jumps automatically on platforms.
- Try not to fall off the bottom.
Here is the full HTML + CSS + JavaScript code:
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<title>Doodle Jump (iPhone)</title>
<style>
html, body {
margin: 0; padding: 0;
height: 100%;
background: linear-gradient(180deg, #a0d8f7 0%, #fff 100%);
overflow: hidden;
-webkit-user-select: none;
user-select: none;
touch-action: manipulation;
font-family: 'Arial', sans-serif;
}
#game-container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
background: linear-gradient(180deg, #a0d8f7 0%, #fff 100%);
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
-webkit-tap-highlight-color: transparent;
}
canvas {
display: block;
background: transparent;
touch-action: none;
margin: 0 auto;
}
#score {
position: absolute;
top: 10px;
left: 50%;
transform: translateX(-50%);
font-size: 24px;
color: #2c3e50;
font-weight: bold;
text-shadow: 0 2px 3px rgba(255,255,255,0.7);
z-index: 10;
user-select: none;
}
#game-over-overlay {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
background: rgba(255,255,255,0.95);
border-radius: 12px;
padding: 30px 40px;
font-size: 22px;
font-weight: bold;
color: #34495e;
box-shadow: 0 8px 20px rgba(0,0,0,0.15);
display: none;
text-align: center;
user-select: none;
z-index: 20;
}
#game-over-overlay button {
margin-top: 20px;
background: #3498db;
color: white;
font-weight: bold;
border: none;
border-radius: 8px;
padding: 12px 30px;
font-size: 18px;
cursor: pointer;
user-select: none;
box-shadow: 0 4px 8px rgba(52,152,219,0.6);
transition: background-color 0.3s ease;
}
#game-over-overlay button:hover {
background: #2980b9;
}
</style>
</head>
<body>
<div id="game-container">
<canvas id="game-canvas" width="360" height="600" aria-label="Doodle Jump game"></canvas>
<div id="score" aria-live="polite">Score: 0</div>
<div id="game-over-overlay" role="alert" aria-hidden="true">
Game Over!<br />
<button id="restart-btn" aria-label="Restart Game">Play Again</button>
</div>
</div>
<script>
(() => {
const canvas = document.getElementById('game-canvas');
const ctx = canvas.getContext('2d');
const scoreElem = document.getElementById('score');
const gameOverOverlay = document.getElementById('game-over-overlay');
const restartBtn = document.getElementById('restart-btn');
// Fit canvas for iPhone screen width (max 375px wide)
function resizeCanvas() {
const maxWidth = window.innerWidth;
const maxHeight = window.innerHeight;
// Keep aspect ratio 3:5 (360x600)
const width = Math.min(maxWidth, 360);
const height = width * (600/360);
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Game constants
const GRAVITY = 0.15;
const JUMP_VELOCITY = -6.8;
const PLAYER_WIDTH = 50;
const PLAYER_HEIGHT = 50;
const PLATFORM_WIDTH = 70;
const PLATFORM_HEIGHT = 15;
const PLATFORM_COUNT = 10;
const MAX_PLATFORM_Y_GAP = 70;
const MOVE_ACCEL = 0.4;
const MAX_MOVE_SPEED = 5;
// Game state:
let player, platforms, scrollOffset, score, velocityX;
let isGameOver = false;
// Player initialization
function createPlayer() {
return {
x: canvas.width / 2 - PLAYER_WIDTH /2,
y: canvas.height - PLAYER_HEIGHT - 100,
width: PLAYER_WIDTH,
height: PLAYER_HEIGHT,
vy: 0,
vx: 0
};
}
// Platform initialization - random platforms
function createPlatforms() {
const plats = [];
const spacing = canvas.height / PLATFORM_COUNT;
for(let i=0; i < PLATFORM_COUNT; i++) {
plats.push({
x: Math.random() * (canvas.width - PLATFORM_WIDTH),
y: canvas.height - i*spacing,
width: PLATFORM_WIDTH,
height: PLATFORM_HEIGHT
});
}
return plats;
}
// Draw the 'doodler' - simplified as a green rectangle with eyes
function drawPlayer() {
const p = player;
ctx.save();
// Body
ctx.fillStyle = "#2ecc71";
ctx.strokeStyle = "#27ae60";
ctx.lineWidth = 2;
ctx.fillRect(p.x, p.y, p.width, p.height);
ctx.strokeRect(p.x, p.y, p.width, p.height);
// Face (eyes)
const eyeRadius = 5;
const eyeOffsetX = 12;
const eyeOffsetY = 15;
ctx.fillStyle = "#fff";
ctx.beginPath();
ctx.arc(p.x + eyeOffsetX, p.y + eyeOffsetY, eyeRadius, 0, Math.PI*2);
ctx.arc(p.x + p.width - eyeOffsetX, p.y + eyeOffsetY, eyeRadius, 0, Math.PI*2);
ctx.fill();
ctx.fillStyle = "#34495e";
ctx.beginPath();
const pupilRadius = 2;
ctx.arc(p.x + eyeOffsetX, p.y + eyeOffsetY, pupilRadius, 0, Math.PI*2);
ctx.arc(p.x + p.width - eyeOffsetX, p.y + eyeOffsetY, pupilRadius, 0, Math.PI*2);
ctx.fill();
// Mouth
ctx.strokeStyle = "#27ae60";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(p.x + 10, p.y + p.height - 10);
ctx.lineTo(p.x + p.width - 10, p.y + p.height - 10);
ctx.stroke();
ctx.restore();
}
// Draw platforms -- simple rectangle with texture lines
function drawPlatform(plat) {
ctx.save();
// Platform base
ctx.fillStyle = "#8e44ad";
ctx.fillRect(plat.x, plat.y, plat.width, plat.height);
ctx.strokeStyle = "#732d91";
ctx.lineWidth = 2;
ctx.strokeRect(plat.x, plat.y, plat.width, plat.height);
// Texture lines
ctx.strokeStyle = "rgba(255,255,255,0.3)";
for(let i=5; i < plat.width; i += 15) {
ctx.beginPath();
ctx.moveTo(plat.x + i, plat.y + 3);
ctx.lineTo(plat.x + i, plat.y + plat.height - 3);
ctx.stroke();
}
ctx.restore();
}
function drawScore() {
scoreElem.textContent = `Score: ${Math.floor(score)}`;
}
// Reset game state
function resetGame() {
player = createPlayer();
platforms = createPlatforms();
scrollOffset = 0;
score = 0;
velocityX = 0;
isGameOver = false;
gameOverOverlay.style.display = "none";
}
// Game over handler
function gameOver() {
isGameOver = true;
gameOverOverlay.style.display = 'block';
gameOverOverlay.setAttribute('aria-hidden', 'false');
scoreElem.textContent = `Final Score: ${Math.floor(score)}`;
}
// Input control management
let moveLeft = false;
let moveRight = false;
// Device orientation support for tilt controls
let hasGyro = false;
let tiltGamma = 0; // left-right tilt in degrees
function onDeviceOrientation(event) {
if(event.gamma !== null) {
hasGyro = true;
tiltGamma = event.gamma; // Between approx -90 and +90 degrees
}
}
window.addEventListener('deviceorientation', onDeviceOrientation);
// Touch controls on screen left/right halves
function setupTouchControls() {
// Touchstart and touchend set moveLeft/moveRight flags accordingly
function onTouchStart(e) {
if (e.touches.length > 0) {
const x = e.touches[0].clientX;
if (x < window.innerWidth/2) {
moveLeft = true;
moveRight = false;
} else {
moveRight = true;
moveLeft = false;
}
}
}
function onTouchEnd(e) {
// Remove all move flags on touch end
moveLeft = false;
moveRight = false;
}
// Add listeners to entire game container
const container = document.getElementById('game-container');
container.addEventListener('touchstart', onTouchStart, {passive:true});
container.addEventListener('touchend', onTouchEnd);
container.addEventListener('touchcancel', onTouchEnd);
}
setupTouchControls();
// Main game loop
function gameLoop() {
if (isGameOver) return;
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Handle horizontal movement from input
if (hasGyro) {
// Map gamma from approx -30...+30 degrees to -maxSpeed...+maxSpeed
let maxTilt = 30;
let tiltX = Math.min(Math.max(tiltGamma, -maxTilt), maxTilt);
velocityX += (tiltX / maxTilt) * MAX_MOVE_SPEED * 0.1 - velocityX * 0.1;
} else {
// No gyro: move based on moveLeft and moveRight touch buttons
if (moveLeft) {
velocityX -= MOVE_ACCEL;
} else if (moveRight) {
velocityX += MOVE_ACCEL;
} else {
velocityX *= 0.85; // friction
}
}
// Clamp horizontal velocity
velocityX = Math.max(Math.min(velocityX, MAX_MOVE_SPEED), -MAX_MOVE_SPEED);
player.vx = velocityX;
// Update player position
player.x += player.vx;
player.y += player.vy;
// Keep player in horizontal bounds
if (player.x < 0) {
player.x = 0;
velocityX = 0;
} else if (player.x + player.width > canvas.width) {
player.x = canvas.width - player.width;
velocityX = 0;
}
// Apply gravity
player.vy += GRAVITY;
// Collision with platforms (only when falling)
if (player.vy > 0) {
platforms.forEach(platform => {
if (
player.x + player.width > platform.x &&
player.x < platform.x + platform.width &&
player.y + player.height > platform.y &&
player.y + player.height < platform.y + platform.height + player.vy &&
player.vy > 0
) {
player.vy = JUMP_VELOCITY;
// You land on the platform, don’t fall through it
}
});
}
// Scroll platforms and player up when player is above middle of screen (say 40% from top)
let threshold = canvas.height * 0.4;
if (player.y < threshold) {
let diff = threshold - player.y;
player.y = threshold;
scrollOffset += diff;
platforms.forEach(platform => {
platform.y += diff;
});
score += diff;
}
// Remove platforms that went off bottom and add new platforms at top
platforms = platforms.filter(p => p.y < canvas.height);
while (platforms.length < PLATFORM_COUNT) {
let lastPlatY = platforms.reduce((min, p) => p.y < min ? p.y : min, canvas.height);
let newY = lastPlatY - (Math.random() * MAX_PLATFORM_Y_GAP * 1.5 + MAX_PLATFORM_Y_GAP * 0.5);
platforms.push({
x: Math.random() * (canvas.width - PLATFORM_WIDTH),
y: newY,
width: PLATFORM_WIDTH,
height: PLATFORM_HEIGHT
});
}
// Check if player fell off bottom - game over
if (player.y > canvas.height) {
gameOver();
}
// Draw everything
drawScore();
platforms.forEach(drawPlatform);
drawPlayer();
requestAnimationFrame(gameLoop);
}
// Start the game
resetGame();
requestAnimationFrame(gameLoop);
restartBtn.addEventListener('click', () => {
resetGame();
requestAnimationFrame(gameLoop);
});
})();
</script>
</body>
</html>
How it works for iPhone users:
- The canvas is sized responsively to the device width.
- The player (doodler) is drawn simply — a green rectangle with eyes and a mouth.
- Platforms move downward as the doodler advances upward.
- Use tilt controls (hold device flat, then tilt left/right) to move the doodler horizontally.
- Alternatively, tap on the left or right half of the screen to move the doodler.
- Jumping happens automatically on platform contact.
- When the player falls below the bottom edge, game over screen shows with score and Play Again.
- "Play Again" restarts the game.
Feel free to open this on an iPhone or Safari mobile simulator, tilt your device and enjoy!
If you want me to add boost platforms, monsters, sounds, or polish animations, just let me know!