Skip to content

Commit 23ead80

Browse files
committed
format
1 parent 569777c commit 23ead80

23 files changed

Lines changed: 579 additions & 639 deletions
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
21
# Bullet System
32

4-
5-
63
## How to use
74

8-
After importing the project
5+
After importing the project

docs/building-blocks/enemy.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
21
# Enemy
32

4-
This importable building block is a basic enemy which chases the nearest player. The enemy uses the [Health](./health.mdx) behavior and if the player has one it will damage it.
3+
This importable building block is a basic enemy which chases the nearest player. The enemy uses the
4+
[Health](./health.mdx) behavior and if the player has one it will damage it.
55

66
## How to use
77

8-
After importing this building block, simply drag the enemy into your project and hit play.
8+
After importing this building block, simply drag the enemy into your project and hit play.

docs/building-blocks/health.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
21
# Health and Health Bars
32

4-
53
## How to use
64

75
After importing the building block, simply attach the Health behavior to any entity and it will get a health bar!
@@ -12,4 +10,4 @@ Health has the following methods:
1210
- `setHealth(number)` - Set the health value
1311
- `setShield(number)` - Set the shield value
1412
- `showHealthbar()` - Show the health bar
15-
- `hideHealthbar()` - Hide the health bar
13+
- `hideHealthbar()` - Hide the health bar

docs/building-blocks/hud.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
# Heads-up Display
1+
# Heads-up Display

docs/building-blocks/lighting.mdx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
This page shows how to create dynamic lighting effects in Dreamlab using raycasting and PIXI graphics.
99

10-
There is no built-in lighting system in Dreamlab. Instead, you can create lighting effects by combining raycasting for line-of-sight calculations with PIXI graphics for rendering shadows and illuminated areas.
10+
There is no built-in lighting system in Dreamlab. Instead, you can create lighting effects by combining raycasting for
11+
line-of-sight calculations with PIXI graphics for rendering shadows and illuminated areas.
1112

1213
## Light Overlay Example
1314

14-
Here's an example implementation of a lighting system using the `LightOverlay` behavior, which creates a dynamic shadow overlay that responds to the cursor position and world geometry.
15+
Here's an example implementation of a lighting system using the `LightOverlay` behavior, which creates a dynamic shadow
16+
overlay that responds to the cursor position and world geometry.
1517

1618
```ts
1719
import { Behavior, BehaviorDestroyed, Collider, RawPixi, value } from "@dreamlab/engine";
@@ -29,9 +31,7 @@ export default class LightOverlay extends Behavior {
2931
#overlay!: PIXI.Graphics;
3032
#mask!: PIXI.Graphics;
3133

32-
#overlayCtx = new PIXI.GraphicsContext()
33-
.rect(-100, -100, 200, 200)
34-
.fill({ color: "black", alpha: 0.8 });
34+
#overlayCtx = new PIXI.GraphicsContext().rect(-100, -100, 200, 200).fill({ color: "black", alpha: 0.8 });
3535

3636
onInitialize(): void {
3737
if (!this.game.isClient()) return;
@@ -61,9 +61,7 @@ export default class LightOverlay extends Behavior {
6161
const { world } = this.game.inputs.cursor;
6262
if (!world) return;
6363

64-
const colliders = this.game.entities
65-
.lookupByPosition(world)
66-
.filter(entity => entity instanceof Collider);
64+
const colliders = this.game.entities.lookupByPosition(world).filter((entity) => entity instanceof Collider);
6765

6866
if (colliders.length > 0) return;
6967

@@ -146,4 +144,4 @@ Lighting effects can integrate with Dreamlab's physics system:
146144

147145
- Uses `Ray` from the Rapier physics engine for collision detection
148146
- Respects all solid colliders in the scene
149-
- Can be combined with dynamic obstacles for moving shadows
147+
- Can be combined with dynamic obstacles for moving shadows

docs/building-blocks/platformer-controller.mdx

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ title: Platform Player Controller
44

55
# Platform Player Controllers
66

7-
These two example controllers give you everything from a simple jump-and-gravity player to a full-featured platformer with animation control and moving platform support.
8-
This follows the [standard player spawning model](/guide/network-authority/#standard-player-spawning-model).
7+
These two example controllers give you everything from a simple jump-and-gravity player to a full-featured platformer
8+
with animation control and moving platform support. This follows the
9+
[standard player spawning model](/guide/network-authority/#standard-player-spawning-model).
910

1011
---
1112

@@ -38,19 +39,13 @@ Move and jump with keyboard controls! Fully multiplayer!
3839
</div>
3940

4041
### Code
42+
4143
```typescript
42-
import {
43-
Behavior,
44-
CharacterController,
45-
RichText,
46-
Vector2,
47-
syncedValue,
48-
} from "@dreamlab/engine";
44+
import { Behavior, CharacterController, RichText, Vector2, syncedValue } from "@dreamlab/engine";
4945

5046
// A very simple platformer controller, attach to a PlayerController Entity.
5147
// This follows the https://docs.dreamlab.gg/guide/network-authority/#standard-player-spawning-model
5248

53-
5449
export default class PlayerController extends Behavior {
5550
#controller = this.entity.cast(CharacterController);
5651

@@ -100,17 +95,13 @@ export default class PlayerController extends Behavior {
10095
}
10196

10297
// Create movement vector
103-
const movement = new Vector2(
104-
horizontalVelocity * deltaTime,
105-
this.#verticalVelocity * deltaTime,
106-
);
98+
const movement = new Vector2(horizontalVelocity * deltaTime, this.#verticalVelocity * deltaTime);
10799

108100
if (!this.#controller.isGrounded) this.#verticalVelocity -= this.gravity * deltaTime;
109101

110102
this.entity.pos = this.entity.pos.add(movement);
111103
}
112104
}
113-
114105
```
115106

116107
---
@@ -149,12 +140,15 @@ This demo is multiplayer! Try opening another browser tab to this page!
149140
:::
150141

151142
### Overview
152-
A complete 2D character controller for platformer games.
153-
Includes variable jump height, coyote time, head collision checks, and sticking to moving platforms.
154143

155-
It uses Dreamlab's built-in `CharacterController` for physics and `Rapier` raycasts for grounded detection, plus animation references for idle/run/jump/fall states.
144+
A complete 2D character controller for platformer games. Includes variable jump height, coyote time, head collision
145+
checks, and sticking to moving platforms.
146+
147+
It uses Dreamlab's built-in `CharacterController` for physics and `Rapier` raycasts for grounded detection, plus
148+
animation references for idle/run/jump/fall states.
156149

157150
### Code
151+
158152
```typescript
159153
// This follows the https://docs.dreamlab.gg/guide/network-authority/#standard-player-spawning-model
160154

@@ -231,13 +225,10 @@ export default class PlatformPlayer extends Behavior {
231225
this.horizontalVelocity = horizontalInput * this.speed;
232226

233227
if (horizontalInput > 0) {
234-
this.animationsContainer.transform.scale.x = Math.abs(
235-
this.animationsContainer.transform.scale.x,
236-
);
228+
this.animationsContainer.transform.scale.x = Math.abs(this.animationsContainer.transform.scale.x);
237229
this.runAnim.enabled = true;
238230
} else if (horizontalInput < 0) {
239-
this.animationsContainer.transform.scale.x =
240-
Math.abs(this.animationsContainer.transform.scale.x) * -1;
231+
this.animationsContainer.transform.scale.x = Math.abs(this.animationsContainer.transform.scale.x) * -1;
241232
this.runAnim.enabled = true;
242233
} else {
243234
this.idleAnim.enabled = true;
@@ -257,10 +248,7 @@ export default class PlatformPlayer extends Behavior {
257248
this.#jumpTimeCounter = 0;
258249
this.coyoteTime = 0;
259250

260-
const jumpMovement = new Vector2(
261-
this.horizontalVelocity * deltaTime,
262-
this.verticalVelocity * deltaTime,
263-
);
251+
const jumpMovement = new Vector2(this.horizontalVelocity * deltaTime, this.verticalVelocity * deltaTime);
264252
this.entity.pos = this.entity.pos.add(jumpMovement);
265253
return;
266254
}
@@ -327,10 +315,7 @@ export default class PlatformPlayer extends Behavior {
327315
}
328316

329317
// Apply final movement
330-
const movement = new Vector2(
331-
this.horizontalVelocity * deltaTime,
332-
this.verticalVelocity * deltaTime,
333-
);
318+
const movement = new Vector2(this.horizontalVelocity * deltaTime, this.verticalVelocity * deltaTime);
334319

335320
if (this.#isJumping) {
336321
this.jumpAnim.enabled = true;
@@ -358,14 +343,7 @@ export default class PlatformPlayer extends Behavior {
358343
let foundPlatform: Entity | undefined;
359344

360345
// Left foot check
361-
const leftHit = this.game.physics.world.castRay(
362-
leftRay,
363-
1,
364-
true,
365-
undefined,
366-
undefined,
367-
this.#character.collider,
368-
);
346+
const leftHit = this.game.physics.world.castRay(leftRay, 1, true, undefined, undefined, this.#character.collider);
369347
if (leftHit && this.grounded) {
370348
const body = this.game.physics.world.colliders.get(leftHit.collider.handle) as any;
371349
if (body) {
@@ -430,40 +408,16 @@ export default class PlatformPlayer extends Behavior {
430408
{ x: this.entity.pos.x - halfExtents.x, y: this.entity.pos.y },
431409
{ x: 0, y: halfExtents.y + 0.1 },
432410
);
433-
const midHeadRay = new RAPIER.Ray(
434-
{ x: this.entity.pos.x, y: this.entity.pos.y },
435-
{ x: 0, y: halfExtents.y + 0.1 },
436-
);
411+
const midHeadRay = new RAPIER.Ray({ x: this.entity.pos.x, y: this.entity.pos.y }, { x: 0, y: halfExtents.y + 0.1 });
437412
const rightHeadRay = new RAPIER.Ray(
438413
{ x: this.entity.pos.x + halfExtents.x, y: this.entity.pos.y },
439414
{ x: 0, y: halfExtents.y + 0.1 },
440415
);
441416

442417
// Cast each ray. If any hit, we clamp upward velocity.
443-
const leftHit = world.castRay(
444-
leftHeadRay,
445-
1,
446-
true,
447-
undefined,
448-
undefined,
449-
this.#character.collider,
450-
);
451-
const midHit = world.castRay(
452-
midHeadRay,
453-
1,
454-
true,
455-
undefined,
456-
undefined,
457-
this.#character.collider,
458-
);
459-
const rightHit = world.castRay(
460-
rightHeadRay,
461-
1,
462-
true,
463-
undefined,
464-
undefined,
465-
this.#character.collider,
466-
);
418+
const leftHit = world.castRay(leftHeadRay, 1, true, undefined, undefined, this.#character.collider);
419+
const midHit = world.castRay(midHeadRay, 1, true, undefined, undefined, this.#character.collider);
420+
const rightHit = world.castRay(rightHeadRay, 1, true, undefined, undefined, this.#character.collider);
467421

468422
if (leftHit || midHit || rightHit) {
469423
// Stop upward movement
@@ -504,14 +458,7 @@ export default class PlatformPlayer extends Behavior {
504458
);
505459

506460
// Check left foot
507-
const leftHit = this.game.physics.world.castRay(
508-
leftRay,
509-
1,
510-
true,
511-
undefined,
512-
undefined,
513-
this.#character.collider,
514-
);
461+
const leftHit = this.game.physics.world.castRay(leftRay, 1, true, undefined, undefined, this.#character.collider);
515462
if (leftHit) {
516463
const leftBody = this.game.physics.world.colliders.get(leftHit.collider.handle) as any;
517464
if (leftBody) {
@@ -523,14 +470,7 @@ export default class PlatformPlayer extends Behavior {
523470
}
524471

525472
// Check right foot
526-
const rightHit = this.game.physics.world.castRay(
527-
rightRay,
528-
1,
529-
true,
530-
undefined,
531-
undefined,
532-
this.#character.collider,
533-
);
473+
const rightHit = this.game.physics.world.castRay(rightRay, 1, true, undefined, undefined, this.#character.collider);
534474
if (rightHit) {
535475
const rightBody = this.game.physics.world.colliders.get(rightHit.collider.handle) as any;
536476
if (rightBody) {
@@ -545,4 +485,4 @@ export default class PlatformPlayer extends Behavior {
545485
return false;
546486
}
547487
}
548-
```
488+
```

docs/building-blocks/top-down-character-controller.mdx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ This follows the [standard player spawning model](/guide/network-authority/#stan
1515
Move in 8 directions with WASD controls and animation state handling.
1616

1717
### Overview
18-
A straightforward top-down character controller with movement and idle animations.
19-
Supports directional sprites and smooth 8-directional movement.
18+
19+
A straightforward top-down character controller with movement and idle animations. Supports directional sprites and
20+
smooth 8-directional movement.
2021

2122
### Code
23+
2224
```typescript
2325
import { AnimatedSprite, Behavior, syncedValue, Vector2 } from "@dreamlab/engine";
2426

@@ -58,9 +60,7 @@ export default class Player extends Behavior {
5860
let movement = new Vector2(dx, dy);
5961

6062
// Normalize diagonal movement for consistent speed
61-
this.entity.pos = this.entity.pos.add(
62-
movement.normalize().mul(this.speed * dt)
63-
);
63+
this.entity.pos = this.entity.pos.add(movement.normalize().mul(this.speed * dt));
6464
} else {
6565
this.state = "idle";
6666
}
@@ -110,23 +110,16 @@ export default class Player extends Behavior {
110110
</div>
111111

112112
### Overview
113+
113114
This demo includes mobile joystick support for touch controls in addition to keyboard movement.
114115

115116
### Player Code
117+
116118
```typescript
117119
import { AnimatedSprite, Behavior, syncedValue, Vector2 } from "@dreamlab/engine";
118120
import Joystick from "./joystick.tsx";
119121

120-
export const ACTION_TYPES = [
121-
"punch",
122-
"attack",
123-
"kick",
124-
"stomp",
125-
"grab",
126-
"hit",
127-
"entrance",
128-
"leaving",
129-
] as const;
122+
export const ACTION_TYPES = ["punch", "attack", "kick", "stomp", "grab", "hit", "entrance", "leaving"] as const;
130123

131124
export type ActionType = (typeof ACTION_TYPES)[number];
132125

@@ -179,7 +172,10 @@ export default class Player extends Behavior {
179172
let movement = new Vector2(dx, dy);
180173

181174
this.entity.pos = this.entity.pos.add(
182-
movement.normalize().mul(this.speed * dt).mul(joystickSpeedMultiplier),
175+
movement
176+
.normalize()
177+
.mul(this.speed * dt)
178+
.mul(joystickSpeedMultiplier),
183179
);
184180
} else {
185181
this.state = "idle";
@@ -294,4 +290,4 @@ export default class Joystick extends UIBehavior {
294290
return <div style={{ width: "100%", height: "100%", position: "relative" }}></div>;
295291
}
296292
}
297-
```
293+
```

0 commit comments

Comments
 (0)