update formatting on concepts chapter
continuous-integration/drone/push Build is passing Details

main
Evan Hemsley 2020-07-12 12:09:27 -07:00
parent 3ee7328b7e
commit 84ecc93076
4 changed files with 20 additions and 27 deletions

View File

@ -13,7 +13,13 @@ using Encompass;
using System.Numerics; using System.Numerics;
public struct VelocityComponent : IComponent { public struct VelocityComponent : IComponent {
public Vector2 velocity;
public Vector2 Velocity { get; }
public VelocityComponent(Vector2 velocity)
{
Velocity = velocity;
}
} }
``` ```
@ -26,7 +32,7 @@ using Encompass;
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
worldBuilder.SetComponent(entity, new VelocityComponent { velocity = Vector2.Zero }); worldBuilder.SetComponent(entity, new VelocityComponent(Vector2.One));
``` ```
**SetComponent** can also be used from within an **Engine**. We will talk more about this later. **SetComponent** can also be used from within an **Engine**. We will talk more about this later.

View File

@ -30,15 +30,12 @@ public class PauseEngine : Engine
{ {
foreach (ref readonly var pauseMessage in ReadMessages<PauseMessage>()) foreach (ref readonly var pauseMessage in ReadMessages<PauseMessage>())
{ {
SetComponent(pauseMessage.entity, new PauseComponent SetComponent(pauseMessage.entity, new PauseComponent(pauseMessage.time));
{
timer = pauseMessage.time
});
} }
foreach (ref readonly var entity in ReadEntities<PauseComponent>()) foreach (ref readonly var entity in ReadEntities<PauseComponent>())
{ {
ref readonly var pauseComponent = GetComponent<PauseComponent>(entity); ref readonly var pauseComponent = ref GetComponent<PauseComponent>(entity);
var timer = pauseComponent.timer; var timer = pauseComponent.timer;
timer -= dt; timer -= dt;
@ -49,7 +46,7 @@ public class PauseEngine : Engine
} }
else else
{ {
SetComponent(entity, new PauseComponent { timer = timer }); SetComponent(entity, new PauseComponent(timer));
} }
} }
} }

View File

@ -14,7 +14,7 @@ To define a message, declare a struct which implements the IMessage interface.
using Encompass; using Encompass;
public struct MotionMessage : IMessage { public struct MotionMessage : IMessage {
public Vector2 motion; public Vector2 Motion { get; }
} }
``` ```

View File

@ -31,22 +31,12 @@ public class MyGame : Game
var entity = worldBuilder.CreateEntity(); var entity = worldBuilder.CreateEntity();
SetComponent(entity, new PositionComponent SetComponent(entity, new PositionComponent(0, 0));
{ SetComponent(entity, new VelocityComponent(20, 0));
x = 0,
y = 0
});
SetComponent(entity, new VelocityComponent SetComponent(entity, new TextureComponent(
{ TextureHelper.LoadTexture("Sprites/ball.png");
x = 20, );
y = 0
});
SetComponent(entity, new TextureComponent
{
texture = TextureHelper.LoadTexture("assets/sprites/ball.png")
});
world = worldBuilder.Build(); world = worldBuilder.Build();
} }