mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-21 20:29:59 +01:00
Update terminal demo
This commit is contained in:
parent
759c525962
commit
8def7d7868
1 changed files with 61 additions and 27 deletions
|
@ -1,49 +1,51 @@
|
|||
#include <stdio.h>
|
||||
#include "raycastlib.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LEVEL_W 20
|
||||
#define LEVEL_H 15
|
||||
|
||||
#define SCREEN_W 60
|
||||
#define SCREEN_H 20
|
||||
#define SCREEN_W 80
|
||||
#define SCREEN_H 40
|
||||
|
||||
char pixels[SCREEN_W * SCREEN_H];
|
||||
Camera camera;
|
||||
|
||||
int8_t level[LEVEL_W * LEVEL_H] =
|
||||
const int8_t level[LEVEL_W * LEVEL_H] =
|
||||
{
|
||||
/* 11 13 15 17 19
|
||||
0 1 2 3 4 5 6 7 8 9 10 12 14 16 18 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, // 0
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, // 1
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, // 2
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, // 3
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0, // 4
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 5
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 6
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 7
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 8
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 9
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 10
|
||||
0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0, // 11
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, // 0
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0, // 1
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0, // 2
|
||||
1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0, // 3
|
||||
0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,0,0,1,0,0, // 4
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0, // 5
|
||||
1,1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0, // 6
|
||||
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0, // 7
|
||||
0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,1, // 8
|
||||
0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, // 9
|
||||
0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1, // 10
|
||||
0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,1,1,0,0,1, // 11
|
||||
0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0, // 12
|
||||
0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0, // 13
|
||||
0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0 // 14
|
||||
0,0,0,0,0,1,0,0,0,1,1,1,0,0,1,0,0,0,0,0, // 13
|
||||
0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0 // 14
|
||||
};
|
||||
|
||||
Unit heightAt(int16_t x, int16_t y)
|
||||
{
|
||||
if (x < 0 || x >= SCREEN_W || y < 0 || y >= SCREEN_H)
|
||||
int32_t index = y * LEVEL_W + x;
|
||||
|
||||
if (index < 0 || (index >= LEVEL_W * LEVEL_H))
|
||||
return UNITS_PER_SQUARE * 2;
|
||||
|
||||
return 0;
|
||||
// return level[y * LEVEL_W + x] * UNITS_PER_SQUARE * 2;
|
||||
return level[y * LEVEL_W + x] * UNITS_PER_SQUARE * 2;
|
||||
}
|
||||
|
||||
void pixelFunc(PixelInfo *p)
|
||||
{
|
||||
char c = '.';
|
||||
char c = ' ';
|
||||
|
||||
if (p->isWall)
|
||||
{
|
||||
|
@ -51,9 +53,9 @@ void pixelFunc(PixelInfo *p)
|
|||
{
|
||||
case 0: c = 'X'; break;
|
||||
case 1: c = '#'; break;
|
||||
case 2: c = 'p'; break;
|
||||
case 2: c = 'o'; break;
|
||||
case 3:
|
||||
default: c = 'o'; break;
|
||||
default: c = '.'; break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +75,9 @@ void draw()
|
|||
c.maxSteps = 40;
|
||||
c.computeTextureCoords = 0;
|
||||
|
||||
renderSimple(camera,heightAt,0,pixelFunc,0,c);
|
||||
|
||||
//renderSimple(camera,heightAt,0,pixelFunc,0,c);
|
||||
render(camera,heightAt,0,0,pixelFunc,c);
|
||||
|
||||
for (int j = 0; j < SCREEN_H; ++j)
|
||||
{
|
||||
|
@ -84,20 +88,50 @@ void draw()
|
|||
}
|
||||
}
|
||||
|
||||
int dx = 1;
|
||||
int dy = 0;
|
||||
int dr = 1;
|
||||
int frame = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
initCamera(&camera);
|
||||
camera.position.x = 2 * UNITS_PER_SQUARE;
|
||||
camera.position.y = 2 * UNITS_PER_SQUARE;
|
||||
camera.direction = -UNITS_PER_SQUARE / 3; //0;//(3 * UNITS_PER_SQUARE) / 4;
|
||||
camera.direction = 0;
|
||||
camera.resolution.x = SCREEN_W;
|
||||
camera.resolution.y = SCREEN_H;
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
for (int i = 0; i < 10000; ++i)
|
||||
{
|
||||
draw();
|
||||
camera.position.x += 100;
|
||||
|
||||
int squareX = divRoundDown(camera.position.x,UNITS_PER_SQUARE);
|
||||
int squareY = divRoundDown(camera.position.y,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 = UNITS_PER_SQUARE + sinInt(frame * 16) / 2;
|
||||
|
||||
usleep(100000);
|
||||
|
||||
frame++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue