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;
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 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.

View File

@ -30,15 +30,12 @@ public class PauseEngine : Engine
{
foreach (ref readonly var pauseMessage in ReadMessages<PauseMessage>())
{
SetComponent(pauseMessage.entity, new PauseComponent
{
timer = pauseMessage.time
});
SetComponent(pauseMessage.entity, new PauseComponent(pauseMessage.time));
}
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;
timer -= dt;
@ -49,7 +46,7 @@ public class PauseEngine : Engine
}
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;
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();
SetComponent(entity, new PositionComponent
{
x = 0,
y = 0
});
SetComponent(entity, new PositionComponent(0, 0));
SetComponent(entity, new VelocityComponent(20, 0));
SetComponent(entity, new VelocityComponent
{
x = 20,
y = 0
});
SetComponent(entity, new TextureComponent
{
texture = TextureHelper.LoadTexture("assets/sprites/ball.png")
});
SetComponent(entity, new TextureComponent(
TextureHelper.LoadTexture("Sprites/ball.png");
);
world = worldBuilder.Build();
}