2 #include "raycastlib.h"
12 char pixels
[SCREEN_W
* SCREEN_H
];
15 const int8_t level
[LEVEL_W
* LEVEL_H
] =
18 0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 */
19 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, // 0
20 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, // 1
21 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0, // 2
22 1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0, // 3
23 0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,0, // 4
24 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, // 5
25 1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0, // 6
26 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0, // 7
27 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,1, // 8
28 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, // 9
29 0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1, // 10
30 0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,0,1, // 11
31 0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0, // 12
32 0,0,0,0,0,1,0,0,0,1,1,1,0,0,1,0,0,0,0,0, // 13
33 0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0 // 14
36 Unit
heightAt(int16_t x
, int16_t y
)
38 int32_t index
= y
* LEVEL_W
+ x
;
40 if (index
< 0 || (index
>= LEVEL_W
* LEVEL_H
))
41 return UNITS_PER_SQUARE
* 2;
43 return level
[y
* LEVEL_W
+ x
] * UNITS_PER_SQUARE
* 2;
46 void pixelFunc(PixelInfo
*p
)
52 switch (p
->hit
.direction
)
54 case 0: c
= 'X'; break;
55 case 1: c
= '#'; break;
56 case 2: c
= 'o'; break;
58 default: c
= '.'; break;
62 pixels
[p
->position
.y
* SCREEN_W
+ p
->position
.x
] = c
;
67 for (int i
= 0; i
< 10; ++i
)
72 initRayConstraints(&c
);
76 c
.computeTextureCoords
= 0;
79 //renderSimple(camera,heightAt,0,pixelFunc,0,c);
80 render(camera
,heightAt
,0,0,pixelFunc
,c
);
82 for (int j
= 0; j
< SCREEN_H
; ++j
)
84 for (int i
= 0; i
< SCREEN_W
; ++i
)
85 printf("%c",pixels
[j
* SCREEN_W
+ i
]);
99 camera
.position
.x
= 2 * UNITS_PER_SQUARE
;
100 camera
.position
.y
= 2 * UNITS_PER_SQUARE
;
101 camera
.direction
= 0;
102 camera
.resolution
.x
= SCREEN_W
;
103 camera
.resolution
.y
= SCREEN_H
;
105 for (int i
= 0; i
< 10000; ++i
)
109 int squareX
= divRoundDown(camera
.position
.x
,UNITS_PER_SQUARE
);
110 int squareY
= divRoundDown(camera
.position
.y
,UNITS_PER_SQUARE
);
112 if (rand() % 100 == 0)
119 while (heightAt(squareX
+ dx
,squareY
+ dy
) > 0)
126 camera
.position
.x
+= dx
* 200;
127 camera
.position
.y
+= dy
* 200;
128 camera
.direction
+= dr
* 10;
130 camera
.height
= UNITS_PER_SQUARE
+ sinInt(frame
* 16) / 2;