glerminal/examples/towers.cpp

79 lines
1.3 KiB
C++
Raw Normal View History

#include <glerminal.h>
#include <cstdlib>
#include <cmath>
namespace
{
void init()
{
for (int i = 1; i < 256; i++)
{
2024-05-16 18:48:24 +00:00
constexpr unsigned char c = 16;
const unsigned char v = (255 - c) * powf((i - 1) / 256.0f, 4.0f) + c;
2024-05-16 18:48:24 +00:00
const unsigned int j = (0xFF << 24) | (v << 16) | (v << 8) | v;
glerminal_update_sprite(i,
{
j,j,j,j,j,j,j,j,
j,j,j,j,j,j,j,j,
2024-05-16 18:48:24 +00:00
j,j,j,j,j,j,j,j,
j,j,j,j,j,j,j,j,
j,j,j,j,j,j,j,j,
j,j,j,j,j,j,j,j,
j,j,j,j,j,j,j,j,
j,j,j,j,j,j,j,j,
});
}
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 25; j++)
{
2024-05-16 18:48:24 +00:00
const int c = rand() % 224 + 32;
for (int k = 0; k < c; k++)
{
glerminal_set(i, j, k, k);
}
}
}
}
void mainloop(float dt)
{
static float time = 1;
time += dt;
if (time < 1.0f)
{
return;
}
else
{
time = 0;
}
const int cx = rand() % 40;
const int cy = rand() % 25;
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 25; j++)
{
for (int k = 0; k < 256; k++)
{
2024-05-16 18:48:24 +00:00
const float ox = 0.025f * powf(k, 0.8f) * (i - cx);
const float oy = 0.025f * powf(k, 0.8f) * (j - cy);
glerminal_offset(i, j, k, ox, oy);
}
}
}
glerminal_flush();
}
}
int main(int argc, char** argv)
{
glerminal_run(init, mainloop);
}