diff options
Diffstat (limited to 'src/pixelfunc.cpp')
-rw-r--r-- | src/pixelfunc.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/pixelfunc.cpp b/src/pixelfunc.cpp new file mode 100644 index 0000000..08bbee6 --- /dev/null +++ b/src/pixelfunc.cpp @@ -0,0 +1,82 @@ +#include "pixelfunc.h" + +RCL_Camera camera; +static int dx = 1; +static int dy = 0; +static int dr = 1; +static int frame = 0; + +void pixelFunc(RCL_PixelInfo *p) +{ + int c = GxEPD_WHITE; + if (p->isWall) + { + c = GxEPD_BLACK; + } + if (displayPtr != nullptr) + { + displayPtr->drawPixel(p->position.x, p->position.y, c); + } +} + +RCL_Unit heightAt(int16_t x, int16_t y) +{ + int32_t index = y * LEVEL_W + x; + + if (index < 0 || (index >= LEVEL_W * LEVEL_H)) + return RCL_UNITS_PER_SQUARE * 2; + + return level[y * LEVEL_W + x] * RCL_UNITS_PER_SQUARE * 2; +} + +void draw() +{ + RCL_RayConstraints c; + + RCL_initRayConstraints(&c); + + c.maxHits = 1; + c.maxSteps = 100; + + RCL_renderSimple(camera,heightAt,0,0,c); +} + +void draw_doom() +{ + RCL_initCamera(&camera); + camera.position.x = 2 * RCL_UNITS_PER_SQUARE; + camera.position.y = 2 * RCL_UNITS_PER_SQUARE; + camera.direction = 0; + camera.resolution.x = SCREEN_W; + camera.resolution.y = SCREEN_H; + + for (int i = 0; i < 10000; ++i) + { + draw(); + + int squareX = RCL_divRoundDown(camera.position.x,RCL_UNITS_PER_SQUARE); + int squareY = RCL_divRoundDown(camera.position.y,RCL_UNITS_PER_SQUARE); + + if (rand() % 100 == 0) + { + dx = 1 - rand() % 3; + dy = 1 - rand() % 3; + dr = 1 - rand() % 3; + } + + while (heightAt(squareX + dx,squareY + dy) > 0) + { + dx = 1 - rand() % 3; + dy = 1 - rand() % 3; + dr = 1 - rand() % 3; + } + + camera.position.x += dx * 200; + camera.position.y += dy * 200; + camera.direction += dr * 10; + + camera.height = RCL_UNITS_PER_SQUARE + RCL_sin(frame * 16) / 2; + + frame++; + } +} |