Skip to content

Commit 803d9ba

Browse files
committed
feat: more roads
also improves jump and bounce
1 parent 13bc0d9 commit 803d9ba

9 files changed

Lines changed: 445 additions & 409 deletions

File tree

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"tasks": {
44
"test": "deno test",
55
"dev": "deno run -A npm:concurrently 'deno task build:main --watch' 'deno task build:worker --watch' 'deno task build:style --watch' 'deno task build:static --watch' 'deno task serve'",
6-
"build": "deno task build:main && deno task build:worker && deno task build:style && deno task build:static",
6+
"build": "deno task build:main && deno task build:worker && deno task build:style && deno task build:static && deno -A npm:replace BUILD_DATE `deno -A npm:date-now-cli --format=yyyy.MM.dd` out/index.html",
77
"build:main": "deno bundle --platform browser -o out/main.js player/main.ts",
88
"build:worker": "deno bundle --platform browser -o out/canvas-worker.js player/canvas-worker.ts",
99
"build:style": "deno run -A npm:tailwindcss@3 -o ./out/style.css",

model/character.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,23 @@ export abstract class Character implements IChar {
277277
this.onMoveEndWrap(fieldTester, itemContainer, moveType)
278278
}
279279
} else if (this.#moveType === "jump") {
280-
this.#movePhase += this.#speed * 2
281-
if (this.#movePhase < 8) {
282-
this.#d += this.#speed * 2
280+
this.#movePhase += 2
281+
if (this.#movePhase === 2) {
282+
this.#d += 4
283+
} else if (this.#movePhase === 4) {
284+
this.#d += 3
285+
} else if (this.#movePhase === 6) {
286+
this.#d += 1
287+
} else if (this.#movePhase === 8) {
288+
this.#d += 0
289+
} else if (this.#movePhase === 10) {
290+
this.#d -= 0
291+
} else if (this.#movePhase === 12) {
292+
this.#d -= 1
293+
} else if (this.#movePhase === 14) {
294+
this.#d -= 3
283295
} else {
284-
this.#d -= this.#speed * 2
296+
this.#d -= 4
285297
}
286298
if (this.#movePhase == 16) {
287299
this.#movePhase = 0
@@ -343,6 +355,11 @@ export abstract class Character implements IChar {
343355

344356
/** Gets the center x of the world coordinates. This is used for setting the center of ViewScope. */
345357
get centerX(): number {
358+
if (this.#moveType === "jump" || this.#moveType === "bounce") {
359+
// We don't use #d in jump and bounce state to prevent screen shake
360+
return this.#i * CELL_SIZE + CELL_SIZE / 2
361+
}
362+
346363
return this.x + CELL_SIZE / 2
347364
}
348365

@@ -376,8 +393,8 @@ export abstract class Character implements IChar {
376393

377394
/** Gets the center y of the world coordinates. This is used for setting the center of ViewScope. */
378395
get centerY(): number {
379-
if (this.#moveType === "jump") {
380-
// We don't use #d in jump state. Otherwise the screen shakes for each jump.
396+
if (this.#moveType === "jump" || this.#moveType === "bounce") {
397+
// We don't use #d in jump and bounce state to prevent screen shake
381398
return this.#j * CELL_SIZE + CELL_SIZE / 2
382399
}
383400

player/game-screen.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ class Field implements IFieldTester {
437437

438438
const newItemSpawns = chunks.flatMap((c) => c.getItemSpawnInfo())
439439
.filter((spawn) => !items.isCollected(spawn.id)) // isn't collected yet
440-
.filter((spawn) => !items.get(spawn.i, spawn.j)) // the place isn't occupied by other item
441440
.filter((spawn) => initialLoad || !viewScope.overlaps(spawn)) // not in view
442441
.filter((spawn) => this.#activateScope.overlaps(spawn)) // in activate scope
443442

@@ -464,6 +463,10 @@ class Field implements IFieldTester {
464463
if (newItemSpawns.length > 0) {
465464
console.log(`Spawning ${newItemSpawns.length} items`)
466465
for (const spawn of newItemSpawns) {
466+
if (items.get(spawn.i, spawn.j)) {
467+
// The space is already occupied by some other item
468+
continue
469+
}
467470
items.add(
468471
new Item(
469472
spawn.id,

static/cell/floor3.png

152 Bytes
Loading

static/cell/floor4.png

100 Bytes
Loading

static/cell/floor5.png

117 Bytes
Loading

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<span class="px-0.5">ITEMS
7070
<span class="js-items-counter">-</span>
7171
</span>
72+
<span>BUILD DATE BUILD_DATE</span>
7273
</div>
7374
<span class="js-loading-indicator hidden">
7475
<svg

static/map/block_0.0.json

Lines changed: 215 additions & 200 deletions
Large diffs are not rendered by default.

static/map/block_not_found.json

Lines changed: 201 additions & 201 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)