From d9c9008cf4af454ebfe51232ac53aa30865056b6 Mon Sep 17 00:00:00 2001 From: Evan Hemsley <2342303+ehemsley@users.noreply.github.com> Date: Wed, 12 Jun 2019 11:16:10 -0700 Subject: [PATCH] engine decorator references --- content/pong/ball/bouncing/spawners.md | 6 ------ content/pong/ball/moving.md | 7 +++---- content/pong/ball/spawning.md | 7 +++---- content/pong/scoring/drawing_score.md | 2 +- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/content/pong/ball/bouncing/spawners.md b/content/pong/ball/bouncing/spawners.md index 9c76c6f..66570c4 100644 --- a/content/pong/ball/bouncing/spawners.md +++ b/content/pong/ball/bouncing/spawners.md @@ -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) { diff --git a/content/pong/ball/moving.md b/content/pong/ball/moving.md index 116f795..44abda0 100644 --- a/content/pong/ball/moving.md +++ b/content/pong/ball/moving.md @@ -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. diff --git a/content/pong/ball/spawning.md b/content/pong/ball/spawning.md index 0fc83bc..eb14da2 100644 --- a/content/pong/ball/spawning.md +++ b/content/pong/ball/spawning.md @@ -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. diff --git a/content/pong/scoring/drawing_score.md b/content/pong/scoring/drawing_score.md index b78aa2b..4295139 100644 --- a/content/pong/scoring/drawing_score.md +++ b/content/pong/scoring/drawing_score.md @@ -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); ```