glerminal/examples/towers.cpp

63 lines
1.3 KiB
C++
Raw Normal View History

#include <glerminal.h>
#include <cstdlib>
#include <cmath>
namespace
{
void init()
{
2024-05-20 02:46:56 +00:00
glerminal_load_sprites_file("resources/towers.png");
2024-05-17 04:51:45 +00:00
for (int i = 0; i < 256; i++)
{
2024-05-20 02:46:56 +00:00
constexpr unsigned char c = 0;
2024-05-17 04:51:45 +00:00
const unsigned char v = (255 - c) * powf((i - 1) / 256.0f, 2.0f) + c;
2024-05-20 02:46:56 +00:00
const unsigned int j = (0x7F << 24) | (v << 16) | (v << 8) | v;
2024-05-17 04:51:45 +00:00
glerminal_layer_color(i, j);
glerminal_layer_scale(i, i / 256.0f + 1);
}
2024-05-20 02:46:56 +00:00
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 25; j++)
{
const int c = rand() % 224 + 32;
for (int k = 0; k < c; k++)
{
glerminal_set(i, j, k, 1);
}
}
}
}
void mainloop(float dt)
{
2024-05-20 02:46:56 +00:00
static float time = 0;
time += dt;
2024-05-20 02:46:56 +00:00
const float cx = 20.0f * cosf(time / 3.1415f) + 20.0f;
const float cy = 12.5f * sinf(time / 3.1415f) + 12.5f;
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 25; j++)
{
for (int k = 0; k < 256; k++)
{
2024-05-20 02:46:56 +00:00
const float ox = 0.01f * k * (i - cx);
const float oy = 0.01f * k * (j - cy);
glerminal_offset(i, j, k, ox + (1 + 0.004f * k) * cosf(i + k * 6.2832f / 128.0f + 3.1415f * time), oy + (1 + 0.004f * k) * sinf(j + k * 6.2832f / 128.0f + 3.1415f * time));
}
}
}
glerminal_flush();
}
}
int main(int argc, char** argv)
{
glerminal_run(init, mainloop);
}