10 Games You Can Build
Play them. Read the tiny game blocks. Learn what each block means. Then copy, change and combine them to invent your own game.
🚀 How to Make Your Own Copy
1. Coin Collector
Move around and collect 10 coins.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("player", 7, "game");
collect("player", "coin", "scoreText", 1, "game");
winAtScore("scoreText", 10, "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>1. Coin Collector</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>1. Coin Collector</h1>
<p>Move around and collect 10 coins.</p>
<div class="hud">
<span>Coins: <span id="scoreText">0</span></span>
<span>Goal: 10</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:40px;top:160px">😀</div>
<div id="coin" class="sprite" style="left:540px;top:90px">🪙</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("player", 7, "game");
collect("player", "coin", "scoreText", 1, "game");
winAtScore("scoreText", 10, "message");
</script>
</body>
</html>
2. Treasure Rush
Collect treasure, but a monster chases you.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("player", 7, "game");
collect("player", "treasure", "scoreText", 1, "game");
chase("monster", "player", 1.2);
loseOnTouch("player", "monster", "message");
winAtScore("scoreText", 7, "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>2. Treasure Rush</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>2. Treasure Rush</h1>
<p>Collect treasure, but a monster chases you.</p>
<div class="hud">
<span>Treasure: <span id="scoreText">0</span></span>
<span>Goal: 7</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:40px;top:160px">🏃</div>
<div id="treasure" class="sprite" style="left:560px;top:80px">💎</div>
<div id="monster" class="sprite" style="left:560px;top:300px">👾</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("player", 7, "game");
collect("player", "treasure", "scoreText", 1, "game");
chase("monster", "player", 1.2);
loseOnTouch("player", "monster", "message");
winAtScore("scoreText", 7, "message");
</script>
</body>
</html>
3. Key Escape
Find the key, avoid the guard, then reach the locked door.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("player", 7, "game");
keyOpensDoor("player", "key", "door", "message");
patrol("guard", 3, 0, "game");
loseOnTouch("player", "guard", "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>3. Key Escape</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>3. Key Escape</h1>
<p>Find the key, avoid the guard, then reach the locked door.</p>
<div class="hud">
<span>Mission: get 🔑</span>
<span>Then reach 🚪</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:35px;top:300px">🧑</div>
<div id="key" class="sprite" style="left:300px;top:70px">🔑</div>
<div id="door" class="sprite big" style="left:585px;top:20px">🚪</div>
<div id="guard" class="sprite" style="left:250px;top:245px">🤖</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("player", 7, "game");
keyOpensDoor("player", "key", "door", "message");
patrol("guard", 3, 0, "game");
loseOnTouch("player", "guard", "message");
</script>
</body>
</html>
4. Dodge to the Door
Reach the exit while two hazards patrol the arena.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("player", 7, "game");
patrol("danger1", 4, 0, "game");
patrol("danger2", 0, 3, "game");
loseOnTouch("player", "danger1", "message");
loseOnTouch("player", "danger2", "message");
winOnTouch("player", "door", "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>4. Dodge to the Door</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>4. Dodge to the Door</h1>
<p>Reach the exit while two hazards patrol the arena.</p>
<div class="hud">
<span>Mission: survive</span>
<span>Goal: 🚪</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:35px;top:300px">🏃</div>
<div id="danger1" class="sprite" style="left:200px;top:90px">💥</div>
<div id="danger2" class="sprite" style="left:440px;top:250px">☄️</div>
<div id="door" class="sprite big" style="left:580px;top:25px">🚪</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("player", 7, "game");
patrol("danger1", 4, 0, "game");
patrol("danger2", 0, 3, "game");
loseOnTouch("player", "danger1", "message");
loseOnTouch("player", "danger2", "message");
winOnTouch("player", "door", "message");
</script>
</body>
</html>
5. Timed Gem Rush
Collect 8 gems before the countdown reaches zero.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("player", 8, "game");
collect("player", "gem", "scoreText", 1, "game");
winAtScore("scoreText", 8, "message");
countdown(20, "timeText", "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>5. Timed Gem Rush</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>5. Timed Gem Rush</h1>
<p>Collect 8 gems before the countdown reaches zero.</p>
<div class="hud">
<span>Gems: <span id="scoreText">0</span></span>
<span>Time: <span id="timeText">20</span></span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:40px;top:160px">🛸</div>
<div id="gem" class="sprite" style="left:550px;top:100px">💠</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("player", 8, "game");
collect("player", "gem", "scoreText", 1, "game");
winAtScore("scoreText", 8, "message");
countdown(20, "timeText", "message");
</script>
</body>
</html>
6. Two-Player Tag
Blue uses WASD. Red uses arrows. Blue wins by catching Red.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("blue", 7, "game", "w", "s", "a", "d");
moveWithKeys("red", 7, "game");
winOnTouch("blue", "red", "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>6. Two-Player Tag</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>6. Two-Player Tag</h1>
<p>Blue uses WASD. Red uses arrows. Blue wins by catching Red.</p>
<div class="hud">
<span>Blue: W A S D</span>
<span>Red: arrows</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="blue" class="sprite" style="left:60px;top:170px">🔵</div>
<div id="red" class="sprite" style="left:560px;top:170px">🔴</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("blue", 7, "game", "w", "s", "a", "d");
moveWithKeys("red", 7, "game");
winOnTouch("blue", "red", "message");
</script>
</body>
</html>
7. Monster Survival
Stay alive for 15 seconds while two monsters chase you.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithKeys("player", 7, "game");
chase("monster1", "player", 1.0);
chase("monster2", "player", 0.8);
loseOnTouch("player", "monster1", "message");
loseOnTouch("player", "monster2", "message");
survive(15, "timeText", "message", "player");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>7. Monster Survival</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<h1>7. Monster Survival</h1>
<p>Stay alive for 15 seconds while two monsters chase you.</p>
<div class="hud">
<span>Survive!</span>
<span>Time: <span id="timeText">15</span></span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:320px;top:170px">😎</div>
<div id="monster1" class="sprite" style="left:30px;top:30px">👹</div>
<div id="monster2" class="sprite" style="left:590px;top:300px">👾</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithKeys("player", 7, "game");
chase("monster1", "player", 1.0);
chase("monster2", "player", 0.8);
loseOnTouch("player", "monster1", "message");
loseOnTouch("player", "monster2", "message");
survive(15, "timeText", "message", "player");
</script>
</body>
</html>
8. Gamepad Treasure Hunt
Use the LEFT STICK to collect 10 gems.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithGamepad("player", 8, "game");
collect("player", "gem", "scoreText", 1, "game");
winAtScore("scoreText", 10, "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>8. Gamepad Treasure Hunt</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<div style="background:#fff7ed;border-left:5px solid #f59e0b;padding:10px 12px;border-radius:9px;margin-bottom:12px"><b>🎮 Gamepad:</b> Plug it in, press a button once, then play.</div>
<h1>8. Gamepad Treasure Hunt</h1>
<p>Use the LEFT STICK to collect 10 gems.</p>
<div class="hud">
<span>Gems: <span id="scoreText">0</span></span>
<span>LEFT STICK</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:40px;top:160px">🎮</div>
<div id="gem" class="sprite" style="left:550px;top:90px">💎</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<script src="rbs-gamepad-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithGamepad("player", 8, "game");
collect("player", "gem", "scoreText", 1, "game");
winAtScore("scoreText", 10, "message");
</script>
</body>
</html>
9. Gamepad Racer
LEFT STICK steers. RT accelerates. LT reverses/brakes. Reach the flag.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
driveWithGamepad("car", 5, 7, "game");
patrol("block2", 2.5, 0, "game");
loseOnTouch("car", "block1", "message");
loseOnTouch("car", "block2", "message");
winOnTouch("car", "flag", "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>9. Gamepad Racer</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
.game{background:linear-gradient(90deg,#4b5563 0 15%,#d1d5db 15% 17%,#374151 17% 83%,#d1d5db 83% 85%,#4b5563 85%);}
</style>
</head>
<body>
<div class="wrap">
<div style="background:#fff7ed;border-left:5px solid #f59e0b;padding:10px 12px;border-radius:9px;margin-bottom:12px"><b>🎮 Gamepad:</b> Plug it in, press a button once, then play.</div>
<h1>9. Gamepad Racer</h1>
<p>LEFT STICK steers. RT accelerates. LT reverses/brakes. Reach the flag.</p>
<div class="hud">
<span>Steer: LEFT STICK</span>
<span>Gas: RT · Brake: LT</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="car" class="sprite" style="left:310px;top:310px">🏎️</div>
<div id="block1" class="sprite" style="left:130px;top:150px">🚧</div>
<div id="block2" class="sprite" style="left:500px;top:210px">🚙</div>
<div id="flag" class="sprite big" style="left:315px;top:15px">🏁</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<script src="rbs-gamepad-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
driveWithGamepad("car", 5, 7, "game");
patrol("block2", 2.5, 0, "game");
loseOnTouch("car", "block1", "message");
loseOnTouch("car", "block2", "message");
winOnTouch("car", "flag", "message");
</script>
</body>
</html>
10. Gamepad Key Mission
LEFT STICK moves. Get the key, avoid the moving drone and escape.
1 · PLAY IT
Click inside the game, then use the controls.
2 · READ THE GAME BLOCKS
These few lines are the main rules of this game.
moveWithGamepad("player", 8, "game");
keyOpensDoor("player", "key", "door", "message");
patrol("drone", 3, 0, "game");
rumbleOnTouch("player", "drone", 1, 0.5, 250);
loseOnTouch("player", "drone", "message");
3 · WHAT DO THE BLOCKS MEAN?
4 · MAKE YOUR OWN COPY
index.html, paste, and save. Keep the library file(s) in the same folder.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>10. Gamepad Key Mission</title>
<style>
body {
margin: 0;
font-family: Arial, sans-serif;
background: #eef2f7;
color: #172033;
}
.wrap {
width: 700px;
max-width: calc(100% - 24px);
margin: 24px auto;
}
h1 {
margin: 0 0 8px;
}
.hud {
background: white;
padding: 12px 16px;
border-radius: 12px 12px 0 0;
font-size: 18px;
font-weight: bold;
display: flex;
justify-content: space-between;
}
.message {
background: #172033;
color: white;
padding: 10px 16px;
font-weight: bold;
text-align: center;
}
.game {
position: relative;
width: 100%;
height: 390px;
overflow: hidden;
border: 4px solid #172033;
box-sizing: border-box;
background: linear-gradient(#dff4ff, #c9f1d2);
}
.sprite {
position: absolute;
width: 52px;
height: 52px;
font-size: 42px;
line-height: 52px;
text-align: center;
user-select: none;
}
.big {
width: 68px;
height: 68px;
font-size: 54px;
line-height: 68px;
}
button {
margin-top: 12px;
padding: 10px 15px;
border: 0;
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<div class="wrap">
<div style="background:#fff7ed;border-left:5px solid #f59e0b;padding:10px 12px;border-radius:9px;margin-bottom:12px"><b>🎮 Gamepad:</b> Plug it in, press a button once, then play.</div>
<h1>10. Gamepad Key Mission</h1>
<p>LEFT STICK moves. Get the key, avoid the moving drone and escape.</p>
<div class="hud">
<span>LEFT STICK</span>
<span>Mission: 🔑 → 🚪</span>
</div>
<div id="message" class="message">GO!</div>
<div id="game" class="game">
<div id="player" class="sprite" style="left:35px;top:300px">👨🚀</div>
<div id="key" class="sprite" style="left:300px;top:80px">🔑</div>
<div id="door" class="sprite big" style="left:580px;top:25px">🚪</div>
<div id="drone" class="sprite" style="left:220px;top:230px">🛸</div>
</div>
<button onclick="restartGame()">RESTART</button>
</div>
<!-- LIBRARIES FIRST -->
<script src="rbs-game-library.js"></script>
<script src="rbs-gamepad-library.js"></script>
<!-- YOUR GAME CODE -->
<script>
moveWithGamepad("player", 8, "game");
keyOpensDoor("player", "key", "door", "message");
patrol("drone", 3, 0, "game");
rumbleOnTouch("player", "drone", 1, 0.5, 250);
loseOnTouch("player", "drone", "message");
</script>
</body>
</html>