💨
What's New
Version 1.0
First release
What it does
3 actions-
Text
-
Set Name
-
Show Web Page
View as code
Every action of this Shortcut written out as Cherri, a programming language for Shortcuts. Great for learning how it works.
#include 'actions/web'
#define color gray
const Text = "<!DOCTYPE html>\n<html lang=\\"en\\">\n<head>\n <meta charset=\\"UTF-8\\">\n <meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\\">\n <title>Mario Runner</title>\n <style>\n body { margin:0; overflow:hidden; background:#5C94FC; font-family:sans-serif; }\n canvas { display:block; margin:0 auto; image-rendering:pixelated; }\n #ui { position:absolute; top:10px; left:10px; color:white; font-size:18px; text-shadow:2px 2px 2px #000; }\n </style>\n</head>\n<body>\n <div id=\\"ui\\">Score: <span id=\\"score\\">0</span></div>\n <canvas id=\\"c\\" width=\\"800\\" height=\\"400\\"></canvas>\n\n <script>\n const canvas = document.getElementById('c');\n const ctx = canvas.getContext('2d');\n let score = 0;\n document.getElementById('score').textContent = score;\n\n // Player (Mario-like)\n let player = { x: 50, y: 200, w: 30, h: 40, vx: 0, vy: 0, jumping: false };\n\n // Simple platforms\n let platforms = [\n {x:0, y:350, w:800, h:50}, // ground\n {x:200, y:280, w:150, h:20},\n {x:450, y:220, w:120, h:20},\n {x:650, y:280, w:180, h:20}\n ];\n\n // Coin\n let coin = {x:300, y:200, w:20, h:20, collected:false};\n\n // Enemy (Goomba-like)\n let enemy = {x:600, y:310, w:30, h:30, vx:-1.5};\n\n let keys = {};\n window.addEventListener('keydown', e => keys[e.key] = true);\n window.addEventListener('keyup', e => keys[e.key] = false);\n\n // Touch support for mobile / Shortcuts\n canvas.addEventListener('touchstart', e => {\n if (e.touches[0].clientX > canvas.width/2) player.vx = 5; // right\n else if (!player.jumping) { player.vy = -15; player.jumping = true; } // jump\n });\n\n function update() {\n // Controls\n player.vx = 0;\n if (keys['ArrowLeft'] || keys['a']) player.vx = -5;\n if (keys['ArrowRight'] || keys['d']) player.vx = 5;\n if ((keys['ArrowUp'] || keys['w'] || keys[' ']) && !player.jumping) {\n player.vy = -15;\n player.jumping = true;\n }\n\n // Physics\n player.vy += 0.8; // gravity\n player.x += player.vx;\n player.y += player.vy;\n\n // Ground / platform collision\n player.jumping = true;\n for (let p of platforms) {\n if (player.x + player.w > p.x && player.x < p.x + p.w &&\n player.y + player.h > p.y && player.y + player.h - player.vy <= p.y) {\n player.y = p.y - player.h;\n player.vy = 0;\n player.jumping = false;\n }\n }\n\n // Boundaries\n if (player.y > 350) { player.y = 350; player.vy = 0; player.jumping = false; }\n if (player.x < 0) player.x = 0;\n if (player.x > 770) player.x = 770;\n\n // Coin\n if (!coin.collected &&\n Math.abs(player.x + player.w/2 - coin.x) < 25 &&\n Math.abs(player.y + player.h/2 - coin.y) < 25) {\n coin.collected = true;\n score += 100;\n document.getElementById('score').textContent = score;\n }\n\n // Enemy\n enemy.x += enemy.vx;\n if (enemy.x < 100 || enemy.x > 700) enemy.vx *= -1;\n\n // Collision with enemy\n if (player.x + player.w > enemy.x && player.x < enemy.x + enemy.w &&\n player.y + player.h > enemy.y && player.y < enemy.y + enemy.h) {\n alert(\\"Game Over! Score: \\" + score);\n resetGame();\n }\n\n // Simple win condition\n if (player.x > 750 && score >= 100) {\n alert(\\"You Win! 🎉 Final Score: \\" + score);\n resetGame();\n }\n }\n\n function draw() {\n ctx.clearRect(0, 0, canvas.width, canvas.height);\n\n // Sky background\n ctx.fillStyle = '#5C94FC';\n ctx.fillRect(0, 0, canvas.width, canvas.height);\n\n // Platforms\n ctx.fillStyle = '#0A0';\n for (let p of platforms) ctx.fillRect(p.x, p.y, p.w, p.h);\n\n // Player (red rectangle + hat simulation)\n ctx.fillStyle = '#E00';\n ctx.fillRect(player.x, player.y, player.w, player.h);\n ctx.fillStyle = '#000';\n ctx.fillRect(player.x + 5, player.y + 5, 20, 10); // hat\n\n // Coin\n if (!coin.collected) {\n ctx.fillStyle = '#FF0';\n ctx.fillRect(coin.x, coin.y, coin.w, coin.h);\n }\n\n // Enemy\n ctx.fillStyle = '#840';\n ctx.fillRect(enemy.x, enemy.y, enemy.w, enemy.h);\n }\n\n function resetGame() {\n player.x = 50; player.y = 200;\n coin.collected = false;\n score = 0;\n document.getElementById('score').textContent = score;\n }\n\n function loop() {\n update();\n draw();\n requestAnimationFrame(loop);\n }\n\n resetGame();\n loop();\n </script>\n</body>\n</html>"
setName(Text, "mario.html")
showWebpage(, true)
Open in Cherri Playground
Decompiled with cherri 2.3.0 (GPL-2.0). May need small fixes before it compiles.
Ratings & Reviews
Write a Review–
out of 5
★★★★★
★★★★
★★★
★★
★
0 ratings
No reviews yet. Be the first to share what you think!
Advertisement
More by jamesjhb
You Might Also Like
Advertisement