Use mode 13
This commit is contained in:
parent
2fa261cbc9
commit
f46946036b
1 changed files with 72 additions and 13 deletions
83
game.cpp
83
game.cpp
|
@ -1,6 +1,8 @@
|
|||
/**
|
||||
WIP raycasting demo for Pokitto.
|
||||
|
||||
Don't forget to compile with -O3!
|
||||
|
||||
author: Miloslav "drummyfish" Ciz
|
||||
license: CC0
|
||||
*/
|
||||
|
@ -12,6 +14,14 @@
|
|||
#include "Pokitto.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SUBSAMPLE 3
|
||||
|
||||
// r: 3 bits, g: 3 bits, b: 2 bits
|
||||
inline uint8_t rgbToIndex(uint8_t r, uint8_t g, uint8_t b)
|
||||
{
|
||||
return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6);
|
||||
}
|
||||
|
||||
class Level
|
||||
{
|
||||
public:
|
||||
|
@ -36,12 +46,12 @@ public:
|
|||
|
||||
Character()
|
||||
{
|
||||
mCamera.position.x = UNITS_PER_SQUARE * 4;
|
||||
mCamera.position.y = UNITS_PER_SQUARE * 5;
|
||||
mCamera.direction = 0;
|
||||
mCamera.position.x = 7695; // UNITS_PER_SQUARE * 4;
|
||||
mCamera.position.y = 7697; //UNITS_PER_SQUARE * 5;
|
||||
mCamera.direction = -500; //0;
|
||||
mCamera.fovAngle = UNITS_PER_SQUARE / 4;
|
||||
mCamera.height = UNITS_PER_SQUARE / 2;
|
||||
mCamera.resolution.x = 36;
|
||||
mCamera.height = 2756; //UNITS_PER_SQUARE / 2;
|
||||
mCamera.resolution.x = 110 / SUBSAMPLE;
|
||||
mCamera.resolution.y = 88;
|
||||
}
|
||||
};
|
||||
|
@ -69,6 +79,8 @@ bool dither(uint8_t intensity, uint32_t x, uint32_t y)
|
|||
|
||||
inline void pixelFunc(PixelInfo pixel)
|
||||
{
|
||||
|
||||
/*
|
||||
uint8_t c = 3 + (pixel.isWall == 0 ? 12 : (pixel.hit.direction * 3));
|
||||
|
||||
Unit depth = pixel.depth - UNITS_PER_SQUARE;
|
||||
|
@ -76,7 +88,7 @@ inline void pixelFunc(PixelInfo pixel)
|
|||
if (depth < 0)
|
||||
depth = 0;
|
||||
|
||||
int16_t d = depth / (UNITS_PER_SQUARE * 4);
|
||||
int16_t d = depth / (UNITS_PER_SQUARE * 2);
|
||||
|
||||
if (d < 0)
|
||||
d = 0;
|
||||
|
@ -85,22 +97,55 @@ inline void pixelFunc(PixelInfo pixel)
|
|||
c -= d;
|
||||
else
|
||||
c = 0;
|
||||
*/
|
||||
|
||||
Unit depth = pixel.depth - UNITS_PER_SQUARE;
|
||||
|
||||
if (depth < 0)
|
||||
depth = 0;
|
||||
|
||||
int intensity = 7 - (depth * 7) / (UNITS_PER_SQUARE * 5);
|
||||
|
||||
if (intensity < 0)
|
||||
intensity = 0;
|
||||
|
||||
uint8_t c;
|
||||
|
||||
if (pixel.isWall)
|
||||
{
|
||||
switch (pixel.hit.direction)
|
||||
{
|
||||
case 0: c = rgbToIndex(intensity,0,0); break;
|
||||
case 1: c = rgbToIndex(0,intensity,0); break;
|
||||
case 2: c = rgbToIndex(0,0,intensity / 2); break;
|
||||
case 3: c = rgbToIndex(intensity,intensity,0); break;
|
||||
default: c = 0; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
c = rgbToIndex(intensity,intensity,intensity / 2);
|
||||
|
||||
//c -= min(2,pixel.depth / UNITS_PER_SQUARE);
|
||||
|
||||
uint8_t *buf = p.display.screenbuffer;
|
||||
|
||||
buf += pixel.position.x * 3;
|
||||
buf += pixel.position.x * SUBSAMPLE;
|
||||
buf += pixel.position.y * p.display.width;
|
||||
|
||||
for (uint8_t i = 0; i < SUBSAMPLE - 1; ++i)
|
||||
*buf++ = c;
|
||||
*buf++ = c;
|
||||
|
||||
*buf = c;
|
||||
|
||||
|
||||
//for (uint8_t i = 0; i < SUBSAMPLE; ++i)
|
||||
//p.display.drawPixel(pixel.position.x * SUBSAMPLE + i,pixel.position.y,c);
|
||||
}
|
||||
|
||||
unsigned short pal[256];
|
||||
|
||||
void draw()
|
||||
{
|
||||
|
||||
/*
|
||||
uint8_t a = 0;
|
||||
for (uint8_t j = 0; j < 88; ++j)
|
||||
|
@ -111,6 +156,7 @@ p.display.drawPixel(i,j,a);
|
|||
}
|
||||
return;
|
||||
*/
|
||||
|
||||
RayConstraints c;
|
||||
|
||||
c.maxHits = 16;
|
||||
|
@ -118,12 +164,16 @@ return;
|
|||
|
||||
render(player.mCamera,heightFunc,pixelFunc,c);
|
||||
|
||||
/*
|
||||
p.display.setCursor(1,1);
|
||||
p.display.print(player.mCamera.position.x);
|
||||
p.display.print(' ');
|
||||
p.display.print(player.mCamera.position.x);
|
||||
p.display.print(player.mCamera.position.y);
|
||||
p.display.print(' ');
|
||||
p.display.print(player.mCamera.height);
|
||||
p.display.print(' ');
|
||||
p.display.print(player.mCamera.direction);
|
||||
*/
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -138,11 +188,18 @@ int main()
|
|||
s = 128; r = 0; g = 0; b = 63-a; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4);
|
||||
s = 192; r = 0; g = a; b = 0; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4);
|
||||
}
|
||||
*/
|
||||
|
||||
for (uint8_t r = 0; r < 8; ++r)
|
||||
for (uint8_t g = 0; g < 8; ++g)
|
||||
for (uint8_t b = 0; b < 4; ++b)
|
||||
{
|
||||
pal[rgbToIndex(r,g,b)] = p.display.RGBto565(36 * r, 36 * g, 85 * b);
|
||||
}
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 16; ++i)
|
||||
pal[i] = p.display.RGBto565(255-i,255-i,255-i);
|
||||
*/
|
||||
|
||||
pal[0] = p.display.RGBto565(0,0,0);
|
||||
pal[1] = p.display.RGBto565(64,0,0);
|
||||
|
@ -160,10 +217,12 @@ pal[12] = p.display.RGBto565(192,192,0);
|
|||
pal[13] = p.display.RGBto565(64,64,64);
|
||||
pal[14] = p.display.RGBto565(128,128,128);
|
||||
pal[15] = p.display.RGBto565(192,192,192);
|
||||
|
||||
*/
|
||||
|
||||
p.display.load565Palette(&pal[0]); // load a palette the same way as any other palette in any other screen mode
|
||||
|
||||
p.display.persistence = 1;
|
||||
|
||||
p.setFrameRate(60);
|
||||
|
||||
p.display.setFont(fontTiny);
|
||||
|
|
Loading…
Reference in a new issue