🎮ArcadeLab

2D Racer - Version 1

by ChromeMeteor64
209 lines3.0 KB
▶ Play
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2D Racer - Version 1</title>

<style>
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: #222;
    font-family: Arial, sans-serif;
    text-align: center;
    overflow: hidden;
}

#game {
    width: 360px;
    height: 640px;
    margin: auto;
    position: relative;
    overflow: hidden;
    background: #555;
}

/* Home screen */
#home {
    position: absolute;
    inset: 0;
    background: #111;
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

#home h1 {
    font-size: 42px;
    margin-bottom: 15px;
}

#home p {
    margin-bottom: 30px;
}

button {
    border: none;
    border-radius: 12px;
    padding: 15px 40px;
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
}

#playBtn {
    background: #00c853;
    color: white;
}

/* Road */
#road {
    position: absolute;
    left: 35px;
    right: 35px;
    top: 0;
    bottom: 0;
    background: #333;
    border-left: 6px solid white;
    border-right: 6px solid white;
}

.lane {
    position: absolute;
    width: 6px;
    height: 80px;
    background: white;
    left: 50%;
    transform: translateX(-50%);
}

/* Player car */
#player {
    position: absolute;
    width: 45px;
    height: 75px;
    background: red;
    border-radius: 10px;
    bottom: 35px;
    left: 158px;
    z-index: 5;
}

#player::before,
#player::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 18px;
    background: #111;
    top: 12px;
    border-radius: 3px;
}

#player::before {
    left: 6px;
}

#player::after {
    right: 6px;
}

.window {
    position: absolute;
    width: 28px;
    height: 22px;
    background: #87ceeb;
    left: 8px;
    top: 8px;
    border-radius: 5px;
}

/* Traffic cars */
.enemy {
    position: absolute;
    width: 45px;
    height: 75px;
    border-radius: 10px;
    z-index: 4;
}

.enemy::before,
.enemy::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 18px;
    background: #111;
    top: 12px;
    border-radius: 3px;
}

.enemy::before {
    left: 6px;
}

.enemy::after {
    right: 6px;
}

.enemyWindow {
    position: absolute;
    width: 28px;
    height: 22px;
    background: #87ceeb;
    left: 8px;
    top: 8px;
    border-radius: 5px;
}

/* Score */
#score {
    position: absolute;
    top: 10px;
    left: 10px;
    color: white;
    font-size: 22px;
    font-weight: bold;
    z-index: 8;
}

/* Game over */
#gameOver {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.85);
    color: white;
    z-index: 20;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#gameOver h2 {
    font-size: 40px;
    margin-bottom: 15px;
}

#restartBtn {
    margin-top: 25px;
    background: #ff1744;
    color: white;
}
</style>
</head>

<body>

<div id="game">

    <div id="home">
        <h1>🏎

Game Source: 2D Racer - Version 1

Creator: ChromeMeteor64

Libraries: none

Complexity: complex (209 lines, 3.0 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: 2d-racer-version-1-chromemeteor64" to link back to the original. Then publish at arcadelab.ai/publish.