Compare commits

..

2 Commits

2 changed files with 31 additions and 3 deletions

View File

@ -19,7 +19,7 @@ namespace SemiColinGames {
// The number of total triangles drawn is one less than the number of edge points.
readonly int[] indices = new int[(NUM_EDGE_VERTICES - 1) * 3];
Color color = Color.FromNonPremultiplied(new Vector4(1, 0, 0, 0.5f));
Color color = Color.FromNonPremultiplied(new Vector4(1, 0, 0, 0.25f));
public LinesOfSight(GraphicsDevice graphics) {
for (int i = 0; i < MAX_NPCS; i++) {
@ -88,11 +88,13 @@ namespace SemiColinGames {
}
}
coneVertices[index][i + 1] = new VertexPositionColor(new Vector3(closestHit, 0), color);
coneVertices[index][i + 1] = new VertexPositionColor(
new Vector3((int) closestHit.X, (int) closestHit.Y, 0), color);
}
}
public void Draw(GraphicsDevice graphics, BasicEffect lightingEffect) {
// Draw the cones themselves.
for (int i = 0; i < NUM_EDGE_VERTICES - 1; i++) {
indices[i * 3] = 0;
indices[i * 3 + 1] = i + 1;
@ -113,6 +115,31 @@ namespace SemiColinGames {
graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indices.Length / 3);
}
}
// Draw the outlines of the cones.
for (int i = 0; i <= NUM_EDGE_VERTICES; i++) {
indices[i] = i;
}
indices[NUM_EDGE_VERTICES + 1] = 0;
for (int npcIndex = 0; npcIndex < MAX_NPCS; npcIndex++) {
if (!coneEnabled[npcIndex]) {
continue;
}
vertexBuffer.SetData(coneVertices[npcIndex]);
indexBuffer.SetData(indices);
graphics.SetVertexBuffer(vertexBuffer);
graphics.Indices = indexBuffer;
foreach (EffectPass pass in lightingEffect.CurrentTechnique.Passes) {
pass.Apply();
// TODO: just draw a single opaque outline.
for (int i = 0; i < 4; i++) {
graphics.DrawIndexedPrimitives(
PrimitiveType.LineStrip, 0, 0, NUM_EDGE_VERTICES + 1);
}
}
}
}
}
}

View File

@ -26,8 +26,9 @@ namespace SemiColinGames {
public string Update(NPC npc, float modelTime, World world) {
int moveSpeed = 120;
int desiredX = npc.Position.X + (int) (moveSpeed * npc.Facing * modelTime);
int testPoint = desiredX + 12 * npc.Facing;
// TODO: define the box modularly & correctly.
AABB npcBox = new AABB(new Vector2(desiredX, npc.Position.Y), new Vector2(1, 33));
AABB npcBox = new AABB(new Vector2(testPoint, npc.Position.Y), new Vector2(1, 33));
Debug.AddRect(npcBox, Color.Cyan);
bool foundBox = false;
foreach (AABB box in world.CollisionTargets) {