Skip to content

Commit 8814a9c

Browse files
authored
Minor improvements to documentation (#11)
* docs: update setup instructions * docs: fix highlighted line and wrong name file
1 parent e61499b commit 8814a9c

File tree

2 files changed

+62
-55
lines changed

2 files changed

+62
-55
lines changed

docs/tutorials/world/index.md

+52-52
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
An introduction to working with the luxe world APIs.
66

77
!!! example "outcome"
8-
In this tutorial we'll **use the World api** to put something on screen.
8+
In this tutorial we'll **use the World api** to put something on screen.
99
We'll also use a module, called **Arcade** for handling physics + collision.
1010
We'll load scenes and create prototype instances to populate a world,
11-
and create a custom **Modifier**.
11+
and create a custom **Modifier**.
1212

1313
We'll make a game where you play as a bee, and have to bounce on flowers.
1414

1515
## Play it
1616

17-
Click first, then press ++left-button++, ++up++, ++w++, ++x++ or ++space++ to jump.
17+
Click first, then press ++left-button++, ++up++, ++w++, ++x++ or ++space++ to jump.
1818
Press ++r++ key to reset.
1919

2020
<iframe src="live/index.html" width="100%" height="405px" style="overflow:hidden; display:block; position: relative; border:none;">
2121
</iframe>
2222

2323
## Creating the project
2424

25-
For this tutorial, create a new project using the launcher,
25+
For this tutorial, create a new project using the launcher,
2626
and when choosing an outline, **select the tutorial project outline**.
2727
This project is pre-configured so we can dive right in.
2828

@@ -33,7 +33,7 @@ This project is pre-configured so we can dive right in.
3333
In order to run our project, we first need to install a module. If you don't, you'll get errors!
3434

3535
You can use the launcher to install modules. Head over to the module page, and search for the arcade module.
36-
Once you find it, you can click through, and click the download arrow.
36+
Once you find it, you can click through, and click the download arrow.
3737

3838
The project is configured to use version `0.0.23`, install that version.
3939

@@ -45,7 +45,7 @@ The project is configured to use version `0.0.23`, install that version.
4545

4646
## Using the module in a project
4747

48-
If you look inside of the `luxe.project/modules.lx` file you'll find the `luxe` and `arcade` modules referenced by version.
48+
If you look inside of the `luxe.project/modules.lx` file you'll find the `luxe` and `arcade` modules referenced by version.
4949
You can use the launcher to add a module to the project using the `+` icon, or you can manually add it to this file.
5050

5151
In this case, it's already there from the outline, so let's move on!
@@ -61,13 +61,13 @@ An Entity in the world can also have modifiers attached that perform logic, and
6161

6262
To create an entity, we do `Entity.create(world)` - this gives us a blank entity, and is ready to be modified to give it meaning.
6363

64-
The first thing we'll do, is attach a `Transform` modifier. Modifiers use the same `create` pattern,
64+
The first thing we'll do, is attach a `Transform` modifier. Modifiers use the same `create` pattern,
6565
and some modifiers add `create` methods with convenience arguments, like we'll see below from `Sprite.create`.
6666

6767
Let's create a new `player` variable in our game, and then inside ready we'll create an entity, attach a transform and a sprite to it.
6868

6969
??? note "`world_width/world_height` ?"
70-
Since our tutorial outline is based on the pixel outline, we have a fixed world size that will auto scale. This size is set in `outline/settings.settings.lx` and the size of the world is available in `world_width` and `world_height`. This is different from `width`/`height`, which is the window size.
70+
Since our tutorial outline is based on the pixel outline, we have a fixed world size that will auto scale. This size is set in `outline/settings.settings.lx` and the size of the world is available in `world_width` and `world_height`. This is different from `width`/`height`, which is the window size.
7171

7272
!!! tip "add the highlighted code to `ready`"
7373

@@ -98,11 +98,11 @@ And just like that, we have our player in the middle of the screen.
9898
9999
## Arcade physics
100100
101-
The `arcade` module provides collision + physics for a wide range of games, and comes with a bunch of ready to use tools.
101+
The `arcade` module provides collision + physics for a wide range of games, and comes with a bunch of ready to use tools.
102102
103-
The first important one is the Arcade modifier, which gives an entity a collider shape, and allows you to choose flags like whether it's solid or a trigger, what shape it is, change the velocity and more. It also gives us a callback for when we collide with something, so we can implement a response to overlapping or colliding with something.
103+
The first important one is the Arcade modifier, which gives an entity a collider shape, and allows you to choose flags like whether it's solid or a trigger, what shape it is, change the velocity and more. It also gives us a callback for when we collide with something, so we can implement a response to overlapping or colliding with something.
104104
105-
### Arcade import
105+
### Arcade import
106106
107107
We're gonna use the `Arcade` modifier from the `arcade` module to make our bee interact with the world. We'll import that module into the top of our `game.wren` code like this:
108108
@@ -139,12 +139,12 @@ create_player() {
139139
Arcade.create(player)
140140
Arcade.set_shape_type(player, ShapeType.circle)
141141
Arcade.set_radius(player, 32)
142-
142+
143143
}
144144
```
145145
146-
If we run this, it will look identical to before! That's because there's no gravity or anything on our entity.
147-
So how do we know it's working? How do we know the radius matches? We can ask `Arcade` to debug draw the physics state.
146+
If we run this, it will look identical to before! That's because there's no gravity or anything on our entity.
147+
So how do we know it's working? How do we know the radius matches? We can ask `Arcade` to debug draw the physics state.
148148
149149
!!! tip "add the highlighted line to `create_player`"
150150
@@ -156,7 +156,7 @@ Arcade.set_debug_draw_enabled(world, true)
156156
157157
![](../../images/tutorial/world/arcade.1.png)
158158
159-
Gravity is a constant acceleration, so we can use the `Arcade.set_acc` tool to add a downward acceleration.
159+
Gravity is a constant acceleration, so we can use the `Arcade.set_acc` tool to add a downward acceleration.
160160
The value is relative to your world size, and is game specific. For this game, we'll pick `-200` as that feels good.
161161
You can make it whatever you want!
162162
@@ -171,15 +171,15 @@ Arcade.set_debug_draw_enabled(world, true)
171171
172172
If you run this now, you should see the bee falling off the bottom of the world!
173173
174-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
174+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
175175
<source src="../../images/tutorial/world/arcade.2.mp4" type="video/mp4"></source>
176176
</video>
177177
178-
## Loading a scene
178+
## Loading a scene
179179
180180
Our outline includes a scene that has been created for us. This scene includes some background details, and a floor collider which will keep our bee on screen.
181181
182-
A scene is a kind of data based asset, a container for pre-configured entities with their modifiers already attached.
182+
A scene is a kind of data based asset, a container for pre-configured entities with their modifiers already attached.
183183
184184
A particular scene can only be loaded once into the same world, but you can load multiple scenes into the same world.
185185
This makes them useful as a tool to layer or keep things loaded in the world, and much more. Scenes are typically what you would use for stuff like a Menu, or Level based games.
@@ -215,17 +215,17 @@ construct ready() {
215215
216216
With that, we'll see the clouds, some buildings, a gradient and we'll see the floor collider. The bee will bounce off the floor, and we're ready for the next step.
217217
218-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
218+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
219219
<source src="../../images/tutorial/world/arcade.3.mp4" type="video/mp4"></source>
220220
</video>
221221
222222
## Named input events
223223
224-
In the first tutorial, we used `Input.key_state_released` to directly query a key.
224+
In the first tutorial, we used `Input.key_state_released` to directly query a key.
225225
This is great for quick prototypes but doesn't allow multiple keys, gamepads, or mouse inputs easily.
226226
227-
For that we'll need to use **named input events**. A named input event is what it sounds like, a name assigned to one or more inputs!
228-
We have a few of these already defined by our project, if you look inside of `outline/input.inputs.lx` you'll see this:
227+
For that we'll need to use **named input events**. A named input event is what it sounds like, a name assigned to one or more inputs!
228+
We have a few of these already defined by our project, if you look inside of `outline/inputs.input.lx` you'll see this:
229229
230230
```js
231231
jump = {
@@ -235,7 +235,7 @@ jump = {
235235
}
236236
```
237237
238-
If we query this instead of the individual key, any of those inputs will trigger the event.
238+
If we query this instead of the individual key, any of those inputs will trigger the event.
239239
Since these are named events we refer to them by a string value, "jump", but using strings all over
240240
our project can lead to code that can be difficult to change.
241241
@@ -273,21 +273,21 @@ tick(delta: Num) {
273273
if(Input.event_began(In.jump)) {
274274
jump()
275275
}
276-
276+
277277
...
278278
```
279279
280280
Now when we run the game and press ++up++, ++w++, ++x++ or ++space++ the bee will jump upward.
281281
282-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
282+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
283283
<source src="../../images/tutorial/world/arcade.4.mp4" type="video/mp4"></source>
284284
</video>
285285
286286
## Player position and speed
287287
288288
The bee jump is a little easy to go off screen, so we'll make a minor change to `create_player()` to give them a max speed, and we'll also enforce that the bee is always in the same position on screen, about a quarter of the way in.
289289
290-
```js hl_lines="4"
290+
```js hl_lines="6"
291291
create_player() {
292292

293293
...
@@ -312,16 +312,16 @@ tick(delta: Num) {
312312
313313
Now when we play, we have a couple jumps before we leave the screen, and our bee is in a nice place for the game.
314314
315-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
315+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
316316
<source src="../../images/tutorial/world/arcade.5.mp4" type="video/mp4"></source>
317317
</video>
318318
319319
## Create a Prototype instance
320320
321-
Prototypes are similar to a `Scene`, they are pre-configured entities with their modifiers ready to create.
321+
Prototypes are similar to a `Scene`, they are pre-configured entities with their modifiers ready to create.
322322
323323
!!! info "Prototype vs Scene"
324-
Prototypes are not limited to one per world like scenes. You can create an **instance** as many times as you need.
324+
Prototypes are not limited to one per world like scenes. You can create an **instance** as many times as you need.
325325
326326
They can be created dynamically like we will below, and they can be placed inside a scene, and inside of other prototypes. Each instance can have the values from the prototype overridden when placed that way.
327327
@@ -356,7 +356,7 @@ The next step is to move the pillars across the screen, so the player will have
356356
357357
!!! note "There's a more detailed guide on [custom modifiers](../../learn/modifiers/custom-modifiers.md) here"
358358
359-
To do that, we want to make a modifier that will move any pillar that it is attached to, and when the pillar moves off the left of the screen, clean itself up.
359+
To do that, we want to make a modifier that will move any pillar that it is attached to, and when the pillar moves off the left of the screen, clean itself up.
360360
361361
!!! tip "Create a folder called system/ in the project"
362362
@@ -404,7 +404,7 @@ class System is Modifier {
404404
tick(delta: Num) {
405405
each {|entity: Entity, pillar: Data|
406406

407-
}
407+
}
408408
}
409409
}
410410
```
@@ -474,13 +474,13 @@ tick(delta: Num) {
474474
} //tick
475475
```
476476
477-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
477+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
478478
<source src="../../images/tutorial/world/modifier.1.mp4" type="video/mp4"></source>
479479
</video>
480480
481481
## More pillars
482482
483-
We probably want more than one pillar to come across the level, so we'll use a tool called `World.schedule(world, time, fn)`. This calls a function every `time` seconds, but the important part is that it is affected by the world rate.
483+
We probably want more than one pillar to come across the level, so we'll use a tool called `World.schedule(world, time, fn)`. This calls a function every `time` seconds, but the important part is that it is affected by the world rate.
484484
485485
!!! note "If we used `Frame.schedule(time, fn)` it would be global, and not world specific. With `World.schedule` we can pause by setting the world rate to 0."
486486
@@ -489,7 +489,7 @@ We probably want more than one pillar to come across the level, so we'll use a t
489489
...
490490

491491
create_player()
492-
492+
493493
create_pillar()
494494
World.schedule(world, 6, 9999) {
495495
create_pillar()
@@ -504,11 +504,11 @@ And with that change, we now get a constant stream of pillars to jump over! We h
504504
505505
## Handling collision
506506
507-
Our last step for this game is handling what happens when you hit something.
507+
Our last step for this game is handling what happens when you hit something.
508508
509509
If you saw the moving pillar video above, the player goes through the walls and keeps jumping forward because of our code to keep it in the same spot.
510510
511-
Instead what we'll do is check the direction of the hit, and if you hit a wall (sideways), pause the game world.
511+
Instead what we'll do is check the direction of the hit, and if you hit a wall (sideways), pause the game world.
512512
513513
```js hl_lines="3 7"
514514
...
@@ -518,7 +518,7 @@ Instead what we'll do is check the direction of the hit, and if you hit a wall (
518518
} //ready
519519

520520
handle_collision() {
521-
521+
522522
Arcade.add_collision_callback(player) {|entity_a, entity_b, state, normal, overlap_dist|
523523
if(state != CollisionEvent.begin) return
524524

@@ -535,21 +535,21 @@ handle_collision() {
535535
536536
You can see here we bounce off the top of things, but when we hit the side wall, we stop.
537537
538-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
538+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
539539
<source src="../../images/tutorial/world/collision.1.mp4" type="video/mp4"></source>
540540
</video>
541541
542542
## Polishing
543543
544-
The check is a little abrupt, and isn't very fun because it's super precise and you can fail easily.
544+
The check is a little abrupt, and isn't very fun because it's super precise and you can fail easily.
545545
546546
To make the game a bit more fun, we'll add some squishy behaviour. When we hit a collider, we get the height and check the distance. If the distance is less than 32 (half the radius of our bee), we've just hit the edge of the collider with the bottom of the bee and we can ignore it.
547547
548548
Another tweak, we'll **play a bounce animation** when we hit a flower. This also uses the `Tags` modifier, which allows us to tag entities with specific tags and check for them. In this case, our flower entity inside the pillar prototype already has a tag.
549549
550550
```js hl_lines="8 9 10 11 12 13 17 18 19"
551551
handle_collision() {
552-
552+
553553
Arcade.add_collision_callback(player) {|entity_a, entity_b, state, normal, overlap_dist|
554554
if(state != CollisionEvent.begin) return
555555

@@ -573,15 +573,15 @@ handle_collision() {
573573
} //handle_collision
574574
```
575575
576-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
576+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
577577
<source src="../../images/tutorial/world/collision.2.mp4" type="video/mp4"></source>
578578
</video>
579579
580580
## Reset
581581
582582
One final task is to make it so you can reset the state so you can try again.
583583
584-
We'll add a `reset()` method, first we reset the player position, and unpause the world.
584+
We'll add a `reset()` method, first we reset the player position, and unpause the world.
585585
This is called from tick using a simple key check.
586586
587587
```js hl_lines="1 2 3 4 8 9 10"
@@ -600,18 +600,18 @@ tick(delta: Num) {
600600
```
601601
602602
Now, our pillars will still be there, so we'll need to clear them up.
603-
We could keep an array of pillars we create, and then clean them up like we did in the draw tutorial?
603+
We could keep an array of pillars we create, and then clean them up like we did in the draw tutorial?
604604
The modifer system we created already knows about all of our pillars though!
605605
606-
We can add a public API to our pillar modifier, e.g `Pillar.reset(world)`.
606+
We can add a public API to our pillar modifier, e.g `Pillar.reset(world)`.
607607
To do this, we'll add a method to the `API` class in our modifier. This method has access to a method called `system_in`, which gives us our system to call into.
608608
609609
```js hl_lines="3 4 5 6"
610610
class Pillar is API {
611611

612612
static reset(world: World) {
613613
var system: System = system_in(world)
614-
system.reset()
614+
system.reset()
615615
}
616616

617617
}
@@ -623,7 +623,7 @@ Now inside of our system, we can add the reset method. This method will simply l
623623
class System is Modifier {
624624

625625
...
626-
626+
627627
reset() {
628628
each {|entity: Entity, pillar: Data|
629629
Frame.end { Entity.destroy(entity) }
@@ -650,14 +650,14 @@ One more tweak, now that we know it is working: turn off the debug drawer!
650650
// Arcade.set_debug_draw_enabled(world, true)
651651
```
652652
653-
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
653+
<video preload="auto" autoplay controls muted playinsline loop="loop" style="max-width:100%; width:auto; margin:auto; display:block;">
654654
<source src="../../images/tutorial/world/final.mp4" type="video/mp4"></source>
655655
</video>
656656
657657
## Try this
658658
659659
!!! tip "Add score"
660-
Add a `score` variable to the game class, add `1` to it each time a flower is collected.
660+
Add a `score` variable to the game class, add `1` to it each time a flower is collected.
661661
662662
!!! tip "Add Game Over and a Win condition"
663663
Like before, make the experience more complete.
@@ -708,7 +708,7 @@ class Game is Ready {
708708

709709
Scene.create(world, Asset.scene("scene/level"))
710710
create_player()
711-
711+
712712
create_pillar()
713713
World.schedule(world, 6, 9999) {
714714
create_pillar()
@@ -719,7 +719,7 @@ class Game is Ready {
719719
} //ready
720720

721721
handle_collision() {
722-
722+
723723
Arcade.add_collision_callback(player) {|entity_a, entity_b, state, normal, overlap_dist|
724724
if(state != CollisionEvent.begin) return
725725

@@ -827,7 +827,7 @@ class Pillar is API {
827827

828828
static reset(world: World) {
829829
var system: System = system_in(world)
830-
system.reset()
830+
system.reset()
831831
}
832832

833833
}
@@ -868,4 +868,4 @@ class System is Modifier {
868868
} //tick
869869

870870
}
871-
```
871+
```

0 commit comments

Comments
 (0)