Skip to content

Commit 957d0a4

Browse files
committed
update tutorial.
1 parent e337d83 commit 957d0a4

14 files changed

+195
-6
lines changed

components/under-construction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Callout } from 'nextra/components'
22

33
export const UnderConstruction = () => (
4-
<Callout type='info'>Our docs are always improving. Expect more information coming to this page soon!<br></br>
4+
<Callout type='info'>This docs page is under construction. Expect more information coming to this page soon!<br></br>
55
If you have questions, please ask them in our <u><a href="https://discord.gg/nwXFvtJ92g">Discord server</a></u> and we'll answer them promptly! 😊</Callout>
66
)

pages/tutorial/01-start.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ As a prize for completing it, you'll get the following:
1414
- **Early access to all upcoming beta features.**
1515
- $50 in AI credits to use for image or code generation!
1616

17-
Click the link below to continue to the _Project Overview_
17+
This tutorial will only take about ten minutes to complete.
18+
19+
Click the link below to continue to the _Project Overview_ ↘️

pages/tutorial/01.1-project-overview.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: 'Project Overview'
33
---
44

55
import { UnderConstruction } from '~/components/under-construction'
6-
import TutScreenshot from '~/assets/images/tut_screenshot.png'
6+
import TutScreenshot from './tut_screenshot.png'
77
import { Image } from '~/components/image'
88

99
# Project Overview
@@ -14,6 +14,9 @@ The sample project only has a few entities:
1414
2. Enemy. This is an enemy that runs at the player.
1515
3. Xp. This entity is dropped by enemies when they die.
1616

17-
In addition, it has a UI layer written using React displaying the player's health and current XP.
17+
It has a UI layer written using React displaying the player's health and current XP.
18+
**Because it was made using Dreamlab, it has seamless multiplayer support. Players can fight together against an endless stream of monsters!**
1819

1920
<Image src={TutScreenshot} />
21+
22+
To create a new project with this game as the template, continue to the next step!
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: 'Create a New Project'
3+
---
4+
5+
import { UnderConstruction } from '~/components/under-construction'
6+
import NewProj from './newproj.png'
7+
import postcreate from './post-create.png'
8+
import { Image } from '~/components/image'
9+
10+
# Create a New Project
11+
12+
After registering for Dreamlab, click the "Create" tab then select "Create a Project".
13+
You will see a dialogue that looks like this:
14+
15+
<Image src={NewProj} />
16+
17+
Select the "Dreamlab Tutorial" project, then click "Create Project". After clicking that, you will be redirected to the project's page.
18+
19+
<Image src={postcreate} />
20+
21+
Click on the big orange "Edit World" button and the Dreamlab editor will launch!

pages/tutorial/02-add-powerup.mdx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,158 @@ title: 'Add a Power-Up'
33
---
44

55
import { UnderConstruction } from '~/components/under-construction'
6+
import assetcreator from './assetcreator.png'
7+
import gennewasset from './gennewasset.png'
8+
import speedpill from './speedpill.png'
9+
import { Image } from '~/components/image'
610

711
# Add a Super-Speed Power-Up
812

913
We're going to be implementing a new entity that when your player collides with it, it increases their speed for ten seconds when they collide with it.
14+
15+
## Creating Art
16+
17+
You can use the Dreamlab asset creator to create art for your powerup. You can access it from the editor menu (openable with backtick \`)
18+
19+
<Image src={gennewasset} />
20+
21+
On this page, you can make a sketch and type a prompt to generate an image using AI.
22+
I made a pill with a lightning bolt but you can do whatever you want!
23+
24+
<Image src={assetcreator} />
25+
26+
After you've created it, it will appear in your "Assets" tab in the Dreamlab sidebar.
27+
28+
<Image src={speedpill} />
29+
30+
## Writing the Scripts
31+
32+
### Create a New Entity
33+
34+
```typescript filename="SpeedBoost.ts"
35+
import type { SpawnableContext, Time } from '@dreamlab.gg/core'
36+
import { game } from '@dreamlab.gg/core/labs'
37+
import { z } from '@dreamlab.gg/core/sdk'
38+
import { Solid, SolidArgs } from '@dreamlab.gg/core/entities'
39+
40+
export const SpeedBoostArgs = SolidArgs.extend({
41+
amount: z.number().default(4),
42+
duration: z.number().default(10),
43+
})
44+
45+
export class SpeedBoost extends Solid<typeof SpeedBoostArgs> {
46+
private lifeTime = 1000
47+
public constructor(ctx: SpawnableContext<typeof SpeedBoostArgs>) {
48+
super(ctx)
49+
this.transform.zIndex = -10
50+
if (this.body) {
51+
this.body.isSensor = true
52+
}
53+
54+
if (!this.tags.includes('net/replicated')) {
55+
this.tags.push('net/replicated')
56+
}
57+
if (!this.tags.includes('editor/doNotSave'))
58+
this.tags.push('editor/doNotSave')
59+
60+
// replace this with the URL you copied when creating your own art
61+
this.args.spriteSource = {
62+
url: 'https://s3-assets.dreamlab.gg/uploaded-from-editor/speed-pill-1717034434636.png',
63+
}
64+
}
65+
66+
public die(): void {
67+
const $game = game('server')
68+
if (!$game) return
69+
$game.destroy(this)
70+
return
71+
}
72+
73+
public expire() {
74+
this.lifeTime -= 1
75+
if (this.lifeTime <= 0) {
76+
this.die()
77+
return
78+
}
79+
}
80+
override onPhysicsStep(_: Time) {
81+
this.expire()
82+
}
83+
}
84+
```
85+
86+
### Register Your Entity
87+
88+
```typescript filename="shared.ts"
89+
import { SpeedBoost, SpeedBoostArgs } from './entities/SpeedBoost.ts'
90+
91+
// this gets run on both the client and the server
92+
export const sharedInit: InitShared = game => {
93+
// disable gravity since this game is top-down
94+
game.physics.engine.gravity.scale = 0
95+
96+
// other entities being registered ...
97+
98+
// register our speedboost powerup entity
99+
game.register('SpeedBoost', SpeedBoost, SpeedBoostArgs)
100+
}
101+
```
102+
103+
### Add Ability For Player to Pick Up Speedboost
104+
105+
Inside the `onCollide` function in the `BulletHeavenPlayer` class, we can add the following snippet
106+
107+
```typescript filename="BulletHeavenPlayer.ts"
108+
onCollide([a, b]: readonly [SpawnableEntity, SpawnableEntity]) {
109+
// ...
110+
111+
if (other instanceof SpeedBoost) {
112+
// only run pick-up code on client.
113+
const $game = game('client')
114+
if (!$game) return
115+
116+
// destroy picked up SpeedBoost on server to make it disappear for other players
117+
network('client')?.sendCustomMessage('DESTROY_BY_ID', { uid: other.uid })
118+
// destroy on client
119+
$game.destroy(other)
120+
121+
// add our speed buff
122+
this.args.speed += other.args.amount
123+
124+
// if we have a timer running down, cancel it
125+
if (this.speedBuffTimer) {
126+
clearTimeout(this.speedBuffTimer)
127+
}
128+
129+
// clear the speed buff after the specified duration.
130+
this.speedBuffTimer = setTimeout(() => {
131+
this.args.speed = this.baseSpeed;
132+
}, other.args.duration * 1000)
133+
}
134+
135+
}
136+
137+
```
138+
139+
You'll also need to add a `speedBuffTimer` property to the class to store the timer.
140+
141+
### Making Enemies Drop Speed Buffs
142+
143+
In the `die` function, we can give our enemies a 20% chance of dropping our new SpeedBoost item.
144+
145+
```typescript filename="Enemy.ts"
146+
public die(): void {
147+
// ...
148+
if (Math.random() < 0.2) {
149+
$game?.spawn({
150+
entity: "SpeedBoost",
151+
args: {
152+
spriteSource: { url: "world://assets/symboo.png" },
153+
amount: 4,
154+
duration: 10
155+
},
156+
transform: { position: this.transform.position }
157+
})
158+
}
159+
}
160+
```

pages/tutorial/03-modify-entity.mdx renamed to pages/tutorial/03-modify-entity.mdx.disabled

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { UnderConstruction } from '~/components/under-construction'
66

77
# Modify an Entity
88

9-
Finally, we're going to be adding a new custom enemy
9+
<UnderConstruction />
10+
11+
Finally, we're going to be adding a new custom enemy.
1012

1113
## Generate Art
1214

pages/tutorial/04-save-changes.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
---
2-
title: 'Commit your changes to version control'
2+
title: 'Commit Your Changes'
33
---
44

55
import { UnderConstruction } from '~/components/under-construction'
6+
import commit from './commit.png'
7+
import { Image } from '~/components/image'
68

79
# Commit your changes
10+
11+
Once you're done, go over to the source control tab.
12+
13+
<Image src={commit} />
14+
15+
Then, press "Stage All" to stage all your files, enter a commit message, and press "Commit"!
16+
17+
P.S. You will find something on this source control page to help you get credit for completing this tutorial.

pages/tutorial/assetcreator.png

410 KB
Loading

pages/tutorial/commit.png

5.62 KB
Loading

pages/tutorial/gennewasset.png

75.2 KB
Loading

pages/tutorial/newproj.png

91.4 KB
Loading

pages/tutorial/post-create.png

372 KB
Loading

pages/tutorial/speedpill.png

46.3 KB
Loading
File renamed without changes.

0 commit comments

Comments
 (0)