summaryrefslogtreecommitdiffstats
path: root/src/pixelfunc.cpp
blob: f2fd81f7aeaa4800bdd8397e51924a7fe3695e2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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 drawDoom()
{
	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 < 100; ++i)
	{
		draw();

		if (rand() % 100 == 0)
		{
			dr = 1 - rand() % 3;
		}

		camera.height = RCL_UNITS_PER_SQUARE + RCL_sin(frame * 16) / 2;
		frame++;
	}
}