summaryrefslogtreecommitdiffstats
path: root/src/pixelfunc.cpp
blob: 08bbee69d177bc55b65e9d3546b310fead1c83d5 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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++;
	}
}