smooth snake
This commit is contained in:
parent
59c0d5ee4d
commit
a59110067e
1 changed files with 17 additions and 4 deletions
21
src/Arts.cs
21
src/Arts.cs
|
@ -76,6 +76,7 @@ static class Arts
|
||||||
}
|
}
|
||||||
|
|
||||||
// snake
|
// snake
|
||||||
|
float snake_t = Maths.smooth_stop((float)Mono.step_t);
|
||||||
bool food_next = (Mono.snake[0] + Mono.snake_dir) == Mono.food;
|
bool food_next = (Mono.snake[0] + Mono.snake_dir) == Mono.food;
|
||||||
if (!food_next)
|
if (!food_next)
|
||||||
{
|
{
|
||||||
|
@ -93,13 +94,13 @@ static class Arts
|
||||||
meshes[face].Draw(
|
meshes[face].Draw(
|
||||||
mat_mono,
|
mat_mono,
|
||||||
Matrix.TRS(
|
Matrix.TRS(
|
||||||
Mono.snake[0].ToVec3 + fall,
|
Mono.snake[0].ToVec3 - (Mono.snake_dir.ToVec3 * (float)(1.0 - snake_t) * 0.3f),
|
||||||
Quat.LookDir(Mono.snake_dir.ToVec3),
|
Quat.LookDir(Mono.snake_dir.ToVec3),
|
||||||
V.XYZ(1, 1, 1)// * (float)(Mono.step_t))
|
V.XYZ(1, 1, (float)(snake_t))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
for (int i = 1; i < Mono.snake_len; i++)
|
for (int i = 1; i < Mono.snake_len - 1; i++)
|
||||||
{
|
{
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
if ((int)((Time.Total - Mono.eat_timestamp) * Mono.snake_len / Mono.step_step) == i)
|
if ((int)((Time.Total - Mono.eat_timestamp) * Mono.snake_len / Mono.step_step) == i)
|
||||||
|
@ -109,12 +110,24 @@ static class Arts
|
||||||
meshes["Segment"].Draw(
|
meshes["Segment"].Draw(
|
||||||
mat_mono,
|
mat_mono,
|
||||||
Matrix.TRS(
|
Matrix.TRS(
|
||||||
Mono.snake[i].ToVec3 + fall,
|
Mono.snake[i].ToVec3,
|
||||||
Quat.LookAt(Mono.snake[i].ToVec3, Mono.snake[i - 1].ToVec3),
|
Quat.LookAt(Mono.snake[i].ToVec3, Mono.snake[i - 1].ToVec3),
|
||||||
scale
|
scale
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// tail
|
||||||
|
if (Mono.grow_buffer > 0) { snake_t = 0.0f; }
|
||||||
|
int i_tail = Mono.snake_len - 1;
|
||||||
|
Vec3 tail_dir = Vec3.Direction(Mono.snake[i_tail - 1].ToVec3, Mono.snake[i_tail].ToVec3);
|
||||||
|
meshes["Segment"].Draw(
|
||||||
|
mat_mono,
|
||||||
|
Matrix.TRS(
|
||||||
|
Mono.snake[i_tail].ToVec3 + (tail_dir * (float)(snake_t) * 0.7f),
|
||||||
|
Quat.LookDir(tail_dir),
|
||||||
|
V.XYZ(1, 1, (float)(1.0 - snake_t))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// holes
|
// holes
|
||||||
foreach (KeyValuePair<XYZi, XYZi> hole in Mono.holes)
|
foreach (KeyValuePair<XYZi, XYZi> hole in Mono.holes)
|
||||||
|
|
Loading…
Add table
Reference in a new issue