Add textures
This commit is contained in:
parent
7eecabd620
commit
c41e9a8fd9
1 changed files with 109 additions and 34 deletions
143
game.cpp
143
game.cpp
|
@ -14,7 +14,95 @@
|
|||
#include "Pokitto.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SUBSAMPLE 3
|
||||
#define SUBSAMPLE 2
|
||||
|
||||
const unsigned char image[] =
|
||||
{ 32, 32 // width, height
|
||||
,0x12,0x12,0x12,0x12,0x12,0x12,0x00,0x09,0x00,0x12,0x12,0x12,0x12,0x12
|
||||
,0x09,0x00,0x12,0x12,0x12,0x00,0x12,0x00,0x12,0x12,0x12,0x00,0x12,0x00
|
||||
,0x12,0x12,0x09,0x00,0x65,0x5b,0x24,0x24,0x64,0x65,0x64,0x5b,0x09,0x64
|
||||
,0x64,0x6d,0x6d,0x63,0x5b,0x00,0x24,0x64,0x64,0x64,0x64,0x64,0x6d,0x63
|
||||
,0x64,0x65,0x6d,0x64,0x64,0x64,0x5b,0x00,0x65,0x5b,0x5b,0x5b,0x5b,0x5c
|
||||
,0x52,0x09,0x00,0x64,0x5b,0x5b,0x5b,0x5b,0x11,0x00,0x64,0x64,0x52,0x64
|
||||
,0x5b,0x63,0x5b,0x5b,0x5a,0x52,0x5b,0x5b,0x52,0x5b,0x12,0x09,0x6d,0x5b
|
||||
,0x5b,0x5b,0x52,0x52,0x52,0x09,0x00,0x6d,0x64,0x52,0x5b,0x5a,0x08,0x00
|
||||
,0x65,0x5b,0x5c,0x5b,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x52
|
||||
,0x52,0x09,0x24,0x52,0x5b,0x52,0x09,0x5a,0x52,0x09,0x00,0x24,0x12,0x5a
|
||||
,0x12,0x09,0x09,0x00,0x24,0x5b,0x5b,0x52,0x52,0x5b,0x5b,0x5b,0x52,0x5b
|
||||
,0x5b,0x52,0x5b,0x5b,0x52,0x12,0x64,0x5b,0x5b,0x5a,0x11,0x5b,0x52,0x09
|
||||
,0x00,0x5b,0x12,0x12,0x11,0x5b,0x09,0x00,0x64,0x5b,0x64,0x5b,0x5b,0x52
|
||||
,0x5b,0x5b,0x5b,0x52,0x5b,0x5a,0x5b,0x5b,0x09,0x00,0x5b,0x5b,0x09,0x12
|
||||
,0x12,0x51,0x5b,0x09,0x00,0x5b,0x12,0x09,0x12,0x11,0x09,0x12,0x64,0x64
|
||||
,0x5b,0x5b,0x52,0x52,0x5b,0x52,0x5b,0x11,0x5a,0x5b,0x5b,0x52,0x09,0x12
|
||||
,0x12,0x52,0x11,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x08,0x09,0x09,0x08
|
||||
,0x08,0x00,0x5b,0x52,0x51,0x09,0x49,0x09,0x09,0x08,0x08,0x09,0x11,0x09
|
||||
,0x09,0x09,0x09,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00
|
||||
,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x12,0x00,0x12,0x00,0x00
|
||||
,0x00,0x09,0x00,0x12,0x12,0x00,0x00,0x00,0x64,0x64,0x64,0x5b,0x12,0x64
|
||||
,0x6d,0x65,0x5b,0x5b,0x00,0x65,0x65,0x65,0x64,0x5b,0x5b,0x6d,0x6d,0x65
|
||||
,0x64,0x64,0x64,0x5c,0x5b,0x00,0x6d,0x6d,0x6d,0x5b,0x6d,0x64,0x5b,0x64
|
||||
,0x5b,0x52,0x00,0x6d,0x5b,0x5b,0x64,0x5a,0x00,0x64,0x5b,0x5b,0x64,0x5b
|
||||
,0x5b,0x5b,0x5b,0x64,0x5b,0x5b,0x11,0x52,0x52,0x00,0x6d,0x64,0x12,0x5b
|
||||
,0x5b,0x52,0x5b,0x52,0x5b,0x09,0x12,0x6d,0x5b,0x5b,0x5b,0x52,0x12,0x6d
|
||||
,0x64,0x5b,0x5b,0x5b,0x52,0x52,0x52,0x5b,0x52,0x5b,0x5a,0x5b,0x09,0x00
|
||||
,0x24,0x5a,0x5b,0x52,0x52,0x5b,0x12,0x52,0x5a,0x12,0x00,0x5c,0x52,0x5b
|
||||
,0x09,0x52,0x09,0x6d,0x5b,0x52,0x5b,0x52,0x5b,0x5b,0x5b,0x52,0x52,0x52
|
||||
,0x52,0x5b,0x09,0x00,0x64,0x5b,0x12,0x11,0x52,0x52,0x51,0x52,0x09,0x09
|
||||
,0x00,0x65,0x5b,0x52,0x5b,0x09,0x00,0x64,0x5b,0x5b,0x5b,0x52,0x5b,0x52
|
||||
,0x52,0x5b,0x5b,0x11,0x5b,0x52,0x09,0x12,0x64,0x5b,0x52,0x5b,0x12,0x5b
|
||||
,0x12,0x5b,0x09,0x09,0x00,0x64,0x51,0x5b,0x52,0x08,0x09,0x64,0x5b,0x52
|
||||
,0x5b,0x5b,0x52,0x52,0x11,0x52,0x51,0x5b,0x52,0x52,0x09,0x00,0x5b,0x5b
|
||||
,0x5b,0x12,0x12,0x52,0x09,0x00,0x08,0x09,0x08,0x09,0x09,0x09,0x09,0x09
|
||||
,0x00,0x5b,0x52,0x52,0x09,0x09,0x09,0x08,0x09,0x09,0x09,0x09,0x09,0x08
|
||||
,0x09,0x08,0x5b,0x5b,0x52,0x09,0x09,0x09,0x00,0x09,0x00,0x00,0x09,0x00
|
||||
,0x00,0x00,0x09,0x12,0x12,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x12
|
||||
,0x09,0x00,0x00,0x08,0x09,0x00,0x00,0x00,0x09,0x08,0x08,0x09,0x6d,0x6d
|
||||
,0x5b,0x24,0x64,0x24,0x1b,0x64,0x5b,0x5b,0x24,0x5a,0x00,0x65,0x5b,0x65
|
||||
,0x64,0x5b,0x64,0x64,0x5b,0x00,0x5b,0x5b,0x24,0x5b,0x5a,0x5a,0x5a,0x5b
|
||||
,0x11,0x00,0x6d,0x5b,0x5b,0x5a,0x5b,0x64,0x5b,0x12,0x11,0x52,0x5a,0x08
|
||||
,0x12,0x6d,0x5b,0x5b,0x5b,0x5b,0x5a,0x64,0x09,0x00,0x5a,0x52,0x52,0x52
|
||||
,0x12,0x11,0x09,0x5a,0x00,0x00,0x6d,0x5a,0x5b,0x5a,0x51,0x5b,0x12,0x63
|
||||
,0x52,0x11,0x52,0x08,0x12,0x64,0x5b,0x5b,0x5b,0x52,0x64,0x64,0x09,0x00
|
||||
,0x63,0x51,0x09,0x51,0x52,0x52,0x51,0x09,0x49,0x00,0x24,0x5b,0x5a,0x5b
|
||||
,0x12,0x09,0x12,0x5b,0x09,0x5a,0x12,0x09,0x12,0x65,0x5b,0x5b,0x12,0x52
|
||||
,0x5b,0x52,0x09,0x00,0x5a,0x09,0x12,0x09,0x12,0x09,0x09,0x51,0x09,0x00
|
||||
,0x5b,0x5b,0x64,0x51,0x11,0x12,0x12,0x12,0x12,0x11,0x12,0x09,0x09,0x64
|
||||
,0x5b,0x52,0x52,0x5b,0x52,0x09,0x08,0x00,0x23,0x52,0x09,0x09,0x09,0x12
|
||||
,0x09,0x52,0x00,0x09,0x5b,0x5a,0x12,0x12,0x12,0x11,0x12,0x5b,0x09,0x12
|
||||
,0x12,0x08,0x00,0x64,0x52,0x5b,0x5a,0x52,0x5b,0x5c,0x09,0x00,0x12,0x5a
|
||||
,0x52,0x09,0x12,0x09,0x09,0x12,0x09,0x00,0x52,0x51,0x51,0x08,0x08,0x00
|
||||
,0x09,0x09,0x08,0x08,0x08,0x09,0x00,0x5b,0x52,0x09,0x09,0x09,0x08,0x08
|
||||
,0x12,0x09,0x00,0x09,0x08,0x09,0x08,0x09,0x09,0x08,0x00,0x00,0x12,0x12
|
||||
,0x00,0x09,0x09,0x09,0x12,0x00,0x00,0x08,0x12,0x00,0x00,0x00,0x00,0x00
|
||||
,0x12,0x00,0x00,0x00,0x00,0x12,0x12,0x00,0x00,0x00,0x00,0x09,0x09,0x00
|
||||
,0x00,0x00,0x5b,0x64,0x64,0x25,0x64,0x64,0x5b,0x00,0x1b,0x1b,0x1b,0x5b
|
||||
,0x5a,0x5b,0x64,0x63,0x24,0x1b,0x11,0x00,0x6d,0x6d,0x6d,0x6d,0x5b,0x64
|
||||
,0x5b,0x00,0x5c,0x5b,0x6d,0x64,0x52,0x5b,0x5b,0x5b,0x5a,0x5b,0x11,0x00
|
||||
,0x1b,0x52,0x12,0x5a,0x52,0x12,0x51,0x5a,0x52,0x52,0x09,0x00,0x24,0x64
|
||||
,0x5b,0x52,0x5a,0x5b,0x12,0x00,0x64,0x5b,0x12,0x52,0x5b,0x52,0x52,0x52
|
||||
,0x5b,0x52,0x09,0x00,0x23,0x52,0x5a,0x11,0x52,0x09,0x52,0x51,0x52,0x51
|
||||
,0x49,0x00,0x6d,0x5b,0x11,0x11,0x52,0x52,0x09,0x00,0x6d,0x11,0x5b,0x5b
|
||||
,0x12,0x5b,0x52,0x5b,0x12,0x52,0x11,0x00,0x1b,0x5b,0x49,0x51,0x09,0x11
|
||||
,0x52,0x51,0x09,0x5a,0x08,0x00,0x24,0x52,0x5b,0x52,0x12,0x52,0x09,0x00
|
||||
,0x1b,0x5b,0x52,0x5b,0x5b,0x52,0x11,0x52,0x12,0x12,0x09,0x09,0x5a,0x5a
|
||||
,0x5a,0x51,0x52,0x09,0x52,0x51,0x52,0x52,0x09,0x00,0x64,0x64,0x64,0x5b
|
||||
,0x5b,0x09,0x09,0x12,0x24,0x5b,0x5b,0x52,0x52,0x5b,0x09,0x11,0x09,0x12
|
||||
,0x09,0x00,0x5b,0x09,0x52,0x5a,0x09,0x09,0x09,0x5a,0x52,0x09,0x00,0x00
|
||||
,0x64,0x5b,0x64,0x52,0x5b,0x5b,0x08,0x12,0x64,0x5b,0x52,0x52,0x09,0x08
|
||||
,0x09,0x09,0x09,0x08,0x09,0x00,0x11,0x09,0x09,0x09,0x09,0x09,0x00,0x08
|
||||
,0x08,0x09,0x09,0x00,0x5b,0x52,0x52,0x09,0x09,0x09,0x09,0x12,0x08,0x08
|
||||
,0x09,0x09
|
||||
};
|
||||
|
||||
uint8_t sampleImage(const unsigned char *image, Unit x, Unit y)
|
||||
{
|
||||
int32_t index = clamp(
|
||||
image[1] * ((image[1] * y) / UNITS_PER_SQUARE) +
|
||||
(image[0] * x) / UNITS_PER_SQUARE,
|
||||
0, image[0] * image[1] - 1);
|
||||
|
||||
return image[2 + index];
|
||||
}
|
||||
|
||||
// r: 3 bits, g: 3 bits, b: 2 bits
|
||||
inline uint8_t rgbToIndex(uint8_t r, uint8_t g, uint8_t b)
|
||||
|
@ -46,9 +134,9 @@ public:
|
|||
|
||||
Character()
|
||||
{
|
||||
mCamera.position.x = 7695; // UNITS_PER_SQUARE * 4;
|
||||
mCamera.position.y = 7697; //UNITS_PER_SQUARE * 5;
|
||||
mCamera.direction = -500; //0;
|
||||
mCamera.position.x = 14337; // UNITS_PER_SQUARE * 4;
|
||||
mCamera.position.y = 7963; //UNITS_PER_SQUARE * 5;
|
||||
mCamera.direction = -340; //0;
|
||||
mCamera.fovAngle = UNITS_PER_SQUARE / 4;
|
||||
mCamera.height = 2756; //UNITS_PER_SQUARE / 2;
|
||||
mCamera.resolution.x = 110 / SUBSAMPLE;
|
||||
|
@ -80,25 +168,15 @@ 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));
|
||||
uint8_t c;
|
||||
|
||||
Unit depth = pixel.depth - UNITS_PER_SQUARE;
|
||||
#if 0
|
||||
c = pixel.isWall ? pixel.hit.direction + 4 : 1;
|
||||
|
||||
if (depth < 0)
|
||||
depth = 0;
|
||||
|
||||
int16_t d = depth / (UNITS_PER_SQUARE * 2);
|
||||
|
||||
if (d < 0)
|
||||
d = 0;
|
||||
|
||||
if (d <= 2)
|
||||
c -= d;
|
||||
else
|
||||
c = 0;
|
||||
*/
|
||||
for (uint8_t i = 0; i < SUBSAMPLE; ++i)
|
||||
p.display.drawPixel(pixel.position.x * SUBSAMPLE + i,pixel.position.y,c);
|
||||
|
||||
#else
|
||||
Unit depth = pixel.depth - UNITS_PER_SQUARE;
|
||||
|
||||
if (depth < 0)
|
||||
|
@ -109,23 +187,22 @@ 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;
|
||||
}
|
||||
if ((pixel.hit.direction == 0 || pixel.hit.direction == 2))
|
||||
intensity -= 2;
|
||||
|
||||
if (intensity < 0)
|
||||
intensity = 0;
|
||||
}
|
||||
|
||||
if (pixel.isWall)
|
||||
c = sampleImage(image,pixel.hit.textureCoord,pixel.textureCoordY);
|
||||
else
|
||||
c = rgbToIndex(intensity,intensity,intensity / 2);
|
||||
|
||||
|
||||
uint8_t *buf = p.display.screenbuffer;
|
||||
|
||||
buf += pixel.position.x * SUBSAMPLE;
|
||||
|
@ -135,10 +212,8 @@ else
|
|||
*buf++ = c;
|
||||
|
||||
*buf = c;
|
||||
#endif
|
||||
|
||||
|
||||
//for (uint8_t i = 0; i < SUBSAMPLE; ++i)
|
||||
//p.display.drawPixel(pixel.position.x * SUBSAMPLE + i,pixel.position.y,c);
|
||||
}
|
||||
|
||||
unsigned short pal[256];
|
||||
|
@ -151,7 +226,7 @@ uint8_t a = 0;
|
|||
for (uint8_t j = 0; j < 88; ++j)
|
||||
for (uint8_t i = 0; i < 110; ++i)
|
||||
{
|
||||
p.display.drawPixel(i,j,a);
|
||||
p.display.drawPixel(i,j,sampleImage(image,i * 10,j * 9));
|
||||
++a;
|
||||
}
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue