Skip to content

Commit cc01909

Browse files
committed
Imporve obsticle collision detection, increase max speed, place CSS in separate file
Add comments, code cleanup
1 parent 132a12a commit cc01909

File tree

6 files changed

+401
-213
lines changed

6 files changed

+401
-213
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 2Cars Game
2+
3+
A retro-style racing game where players control two cars simultaneously, built with Svelte. This game leverages modern web technologies to create a smooth, responsive gaming experience.
4+
5+
[Play the demo](https://bpk-endless.s3.amazonaws.com/2Cars.html)
6+
7+
![2Cars Game Screenshot](./screenshot.webp)
8+
9+
## How to Play
10+
11+
- Control two cars simultaneously
12+
- Left car: Press 'S' key or tap left side of screen
13+
- Right car: Press 'K' key or tap right side of screen
14+
- Collect circles for points
15+
- Avoid squares
16+
- Press 'P' to pause
17+
18+
## Technical Overview
19+
20+
- **SVG-Based Rendering**: Uses SVG for declarative rendering that automatically scales. All game objects (cars, obstacles, lanes) are SVG primitives composed together.
21+
22+
- **Reactive Game State**: Built with Svelte's reactivity to automatically update visual elements when game state changes. Car positions, obstacle locations, and scrolling road effects are all driven by reactive statements.
23+
24+
- **Game Loop Architecture**: Uses requestAnimationFrame for the main game loop to handle physics, collision detection, scoring, and obstacle spawning. The loop updates game state which triggers reactive UI updates.
25+
26+
- **Cross-Platform Controls**: Playable via both keyboard and touch controls, with transparent touch zones overlaying each side of the screen for mobile play.
27+
28+
## Development
29+
30+
### Installation
31+
32+
```bash
33+
npm install
34+
npm run dev
35+
npm run build # produces a single-file HTML of the game
36+
```

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "2-cars",
2+
"name": "2cars",
33
"private": true,
44
"version": "0.0.1",
55
"type": "module",

screenshot.webp

4.05 KB
Loading

0 commit comments

Comments
 (0)