engine decorator references

pull/1/head
Evan Hemsley 2019-06-12 11:16:10 -07:00
parent 69a6a8d2bf
commit d9c9008cf4
4 changed files with 7 additions and 15 deletions

View File

@ -40,8 +40,6 @@ import { World } from "lua-lib/bump";
@Reads(BallSpawnMessage)
export class BallSpawner extends Spawner {
public spawn_message_type = BallSpawnMessage;
public collision_world: World;
public initialize(collision_world: World) {
@ -110,8 +108,6 @@ import { World } from "lua-lib/bump";
@Reads(GameBoundarySpawnMessage)
export class GameBoundarySpawner extends Spawner {
public spawn_message_type = GameBoundarySpawnMessage;
private collision_world: World;
public initialize(collision_world: World) {
@ -174,8 +170,6 @@ import { World } from "lua-lib/bump";
@Reads(PaddleSpawnMessage)
export class PaddleSpawner extends Spawner {
public spawn_message_type = PaddleSpawnMessage;
private collision_world: World;
public initialize(collision_world: World) {

View File

@ -36,9 +36,8 @@ import { VelocityComponent } from "game/components/velocity";
import { MotionMessage } from "game/messages/component/motion";
@Emits(MotionMessage)
@Detects(PositionComponent, VelocityComponent)
export class VelocityEngine extends Detector {
public component_types = [ PositionComponent, VelocityComponent ];
protected detect(entity: Entity) {
const position_component = entity.get_component(PositionComponent);
const velocity_component = entity.get_component(VelocityComponent);
@ -50,9 +49,9 @@ export class VelocityEngine extends Detector {
}
```
A Detector, like a Spawner, is an engine with one required property and method: *component_types* and *detect*.
A Detector, like a Spawner, is an engine with one required method: *detect*.
When an Entity has all of the components specified in *component_types*, it begins to track the Entity. Each frame, it calls its *detect* method on that Entity.
When an Entity has all of the components specified in **@Detects**, it begins to track the Entity. Each frame, it calls its *detect* method on that Entity.
So, our VelocityEngine will track everything with a PositionComponent and VelocityComponent and create a MotionMessage every frame.

View File

@ -41,8 +41,6 @@ import { BallSpawnMessage } from "game/messages/ball_spawn";
@Reads(BallSpawnMessage)
export class BallSpawner extends Spawner {
public spawn_message_type = BallSpawnMessage;
public spawn(message: BallSpawnMessage) {
const ball_entity = this.create_entity();
@ -65,9 +63,10 @@ export class BallSpawner extends Spawner {
}
```
Spawners aren't very complicated. They have one required property and method: *spawn_message_type* and *spawn*.
Spawners aren't very complicated. They have one required method: *spawn*.
The first Message type given to **@Reads** is assumed to be the spawn message type.
When the Spawner reads a message of *spawn_message_type*, it runs its spawn method once. Simple as that.
When the Spawner reads a message of the spawn message type, it runs its spawn method once. Simple as that.
Now let's actually send out the BallSpawnMessage.

View File

@ -77,7 +77,7 @@ It's also very expensive to create a new LOVE Font every frame. Like the Text ob
Let's add our ScoreRenderer to the WorldBuilder.
```ts
world_builder.add_renderer(ScoreRenderer);
world_builder.add_renderer(ScoreRenderer).initialize(play_area_width * 0.5);
```
<video width="75%" autoplay="autoplay" muted="muted" loop="loop" style="display: block; margin: 0 auto;">