Skip to content

Commit 74448a9

Browse files
committed
fixed trigger collision bug
1 parent 0cf09e6 commit 74448a9

5 files changed

Lines changed: 75 additions & 8 deletions

File tree

backend/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import postgres from "postgres";
22
import { authenticate, type authResponse, getCookies } from "./auth.ts";
33

4-
const STATIC_DIR = "frontend";
4+
const STATIC_DIR = "dist";
55

66
async function serveFile(req: Request, filePath: string) {
77
let theme = "cream";
@@ -687,7 +687,7 @@ const server = Bun.serve({
687687
);
688688
} else {
689689
return new Response(
690-
"Not signed in"
690+
"Not signed in",
691691
withCors(
692692
{ status: 401, headers: { "Content-Type": "application/json" } },
693693
CORS,

docs/level-data.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Level Data
2+
3+
This file details the level data storage scheme.
4+
5+
## Metadata
6+
7+
This is the information that the level share uses to display levels:
8+
9+
- `id:` - the id of the level
10+
- `public`- the visibility of the level, Boolean
11+
- `data` - the level data described below
12+
- `name` - the name of the level
13+
- `description` - a description of the level
14+
- `width` - the level width
15+
- `height` - the level height
16+
- `owner` - the id of the level owner
17+
- `tags` - a list of tags
18+
- `image_url` - currently doesn't do anything
19+
- `approvals` - how many people have rated this level thumbs up
20+
- `disapprovals` - how many people have rated this level thumbs down
21+
- `approval_percentage` - the percentage of people who have rated it thumbs up versus thumbs down
22+
- `total_plays` - how many times the level has been played
23+
- `finished_plays` - how many times the level has been finished
24+
- `owned` - is the user who requested this level the owner
25+
- `username` - the username of the owner
26+
27+
## Level Data
28+
29+
- `width` - the level width, max: 200, min: 10
30+
- `height` - the level height, max: 100, min: 10
31+
- `jumpHeight` - how far the player should jump in tiles
32+
- `wallJump` - what type of walljump the level should have, either `"none"`, `"off"`, or `"up"`
33+
- `bouncePadHeight` - the height in tiles the bounce pads should propel you
34+
- `zoom` - how many pixels should be used to display a block
35+
- `tilesetPath` - the path to the tileset
36+
- `layers` - an array of the different layers of the level
37+
- `spawn` an object with x and y properties showing where the player should spawn
38+
- `triggers` - a list of triggers in the level
39+
40+
## Layers
41+
42+
Each layer has a `"type"` property that determines what type of layer it is. There can only be one type of each layer. They also have a `data` property that stores the actual data of that layer in an array.
43+
44+
## **RLE Encoding**
45+
46+
RLE, or run length encoding compresses data by storing runs of numbers instead of each number individually. For example, instead of storing
47+
48+
`[0, 0, 0, 0, 0, 5, 6, 1, 1, 1, 0]`
49+
50+
RLE would encode that as:
51+
52+
`[[0, 5], 5, 6, [1, 3], 0]`
53+
54+
This takes a level down to about 4KB.
55+
56+
**Layer Types**
57+
58+
`"tileLayer"` - stores the tileIds of every single block in the level
59+
60+
This uses RLE to store each
61+
62+
`"rotation"` - stores rotation of the blocks in the level

frontend/javascript/platformer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,12 @@ function checkCollision(dt, x, y, w, h, simulate = false) {
664664

665665
if (player.x !== oldX || player.y !== oldY) return false;
666666
if (tileId !== 0) {
667-
if (mechanicsHas(tileId, "noCollision")) {
668-
continue;
669-
}
670667
if (mechanicsHas(tileId, "trigger")) {
671668
touchingTrigger = true;
672669
}
670+
if (mechanicsHas(tileId, "noCollision")) {
671+
continue;
672+
}
673673
if (mechanicsHas(tileId, "killOnTouch")) {
674674
continue;
675675
}

frontend/javascript/ui.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ export function needsSmallerLevel() {
209209
function updateCoinsDisplay() {
210210
const coinDisplay = document.querySelector(".collected-coins")
211211

212-
coinDisplay.innerText = `${player.collectedCoins}/${player.coinsInLevel}`
212+
if (coinDisplay) {
213+
coinDisplay.innerText = `${player.collectedCoins}/${player.coinsInLevel}`
214+
}
213215
}
214216

215217
export function updateDisplay() {

todo.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- add trigger limit
55
- pixel collision not working for dissipation block
66
- triggers rapidly alternate
7+
- trigger delays are stored as strings
78

89
**Platformer**
910

@@ -19,6 +20,8 @@
1920

2021
- options page
2122
- sign out button
23+
- you can still request levels from the server that are private
24+
- opening a page of a level you've rated should show your rating
2225

2326
**Editor**
2427

@@ -27,7 +30,7 @@
2730
- drag trigger steps around
2831
- drag minimap around
2932

30-
**Documenation**
33+
**Documentation**
3134

32-
- tileset
3335
- level data
36+
- trigger storage

0 commit comments

Comments
 (0)