diff --git a/game.cpp b/game.cpp index bbfcf8e..5fe5846 100644 --- a/game.cpp +++ b/game.cpp @@ -5,6 +5,8 @@ license: CC0 */ +//#define RAYCAST_TINY + #include #include "raycastlib.h" #include "Pokitto.h" @@ -18,10 +20,12 @@ public: if (x > 12 || y > 12) return max(x,y) - 10; - if (x < 5 && x > 2 && y < 5 && y > 2) - return 1; + if (y < 5 && y > 0) + { + return y > 2 ? x : -x; + } - return (x < 0 || y < 0 || x > 9 || y > 9) ? 1 : 0; + return (x < 0 || y < 0 || x > 9 || y > 9) ? 4 : 0; } }; @@ -32,11 +36,11 @@ public: Character() { - mCamera.position.x = 400; - mCamera.position.y = 6811; - mCamera.direction = 660; + mCamera.position.x = UNITS_PER_SQUARE * 4; + mCamera.position.y = UNITS_PER_SQUARE * 5; + mCamera.direction = 0; mCamera.fovAngle = UNITS_PER_SQUARE / 4; - mCamera.height = 0; + mCamera.height = UNITS_PER_SQUARE / 2; mCamera.resolution.x = 36; mCamera.resolution.y = 88; } @@ -48,7 +52,7 @@ Level level; Unit heightFunc(int16_t x, int16_t y) { - return level.getHeight(x,y) * UNITS_PER_SQUARE; + return level.getHeight(x,y) * UNITS_PER_SQUARE / 4; } bool dither(uint8_t intensity, uint32_t x, uint32_t y) @@ -63,34 +67,45 @@ bool dither(uint8_t intensity, uint32_t x, uint32_t y) } } -void pixelFunc(PixelInfo pixel) +inline void pixelFunc(PixelInfo pixel) { - uint8_t c = pixel.isWall ? pixel.hit.direction + 4 : 3; + uint8_t c = 3 + (pixel.isWall == 0 ? 12 : (pixel.hit.direction * 3)); - uint16_t x = pixel.position.x * 3; - uint16_t y = pixel.position.y; + uint8_t d = pixel.depth / (UNITS_PER_SQUARE * 3); - uint8_t d = pixel.depth / (UNITS_PER_SQUARE * 2); + if (d <= 2) + c-= d; + else + c = 0; - p.display.color = dither(d,x,y) ? 0 : c; - p.display.drawPixel(x,pixel.position.y); + //c -= min(2,pixel.depth / UNITS_PER_SQUARE); - x++; + uint8_t *buf = p.display.screenbuffer; - p.display.color = dither(d,x,y) ? 0 : c; - p.display.drawPixel(x,pixel.position.y); - - x++; - - p.display.color = dither(d,x,y) ? 0 : c; - p.display.drawPixel(x,pixel.position.y); + buf += pixel.position.x * 3; + buf += pixel.position.y * p.display.width; + *buf++ = c; + *buf++ = c; + *buf = c; } +unsigned short pal[256]; + void draw() { +/* +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); +++a; +} +return; +*/ RayConstraints c; - c.maxHits = 3; + c.maxHits = 8; c.maxSteps = 10; render(player.mCamera,heightFunc,pixelFunc,c); @@ -99,6 +114,40 @@ void draw() int main() { p.begin(); + + + int a,s,r,g,b; + for(a=0; a<=63; a++){ + s = 0; r = a; g = 63-a; b = 0; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4); + s = 64; r = 63-a; g = 0; b = a; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4); + 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 (int i = 0; i < 16; ++i) +pal[i] = p.display.RGBto565(i*16,i*16,i*16); +*/ + +pal[0] = p.display.RGBto565(0,0,0); +pal[1] = p.display.RGBto565(64,0,0); +pal[2] = p.display.RGBto565(128,0,0); +pal[3] = p.display.RGBto565(192,0,0); +pal[4] = p.display.RGBto565(0,64,0); +pal[5] = p.display.RGBto565(0,128,0); +pal[6] = p.display.RGBto565(0,192,0); +pal[7] = p.display.RGBto565(0,0,64); +pal[8] = p.display.RGBto565(0,0,128); +pal[9] = p.display.RGBto565(0,0,192); +pal[10] = p.display.RGBto565(64,64,0); +pal[11] = p.display.RGBto565(128,128,0); +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.setFrameRate(30); p.display.setFont(fontTiny); @@ -109,14 +158,20 @@ int main() { draw(); - const int16_t step = 50; - const int16_t step2 = 10; + const int16_t step = max(UNITS_PER_SQUARE / 10,1); + const int16_t step2 = max(UNITS_PER_SQUARE / 50,1); Vector2D d = angleToDirection(player.mCamera.direction); d.x = (d.x * step) / UNITS_PER_SQUARE; d.y = (d.y * step) / UNITS_PER_SQUARE; + if (d.x == 0 && d.y == 0) + { + d.x = d.x > 0 ? step : -step; + d.y = d.y > 0 ? step : -step; + } + if (p.upBtn()) { player.mCamera.position.x += d.x; @@ -133,13 +188,13 @@ int main() else if (p.leftBtn()) player.mCamera.direction -= step2; - if (p.bBtn()) + if (p.aBtn()) player.mCamera.height += step; - else if (p.cBtn()) + else if (p.bBtn()) player.mCamera.height -= step; - player.mCamera.position.x = clamp(player.mCamera.position.x,UNITS_PER_SQUARE / 2,10 * UNITS_PER_SQUARE - UNITS_PER_SQUARE / 2); - player.mCamera.position.y = clamp(player.mCamera.position.y,UNITS_PER_SQUARE / 2,10 * UNITS_PER_SQUARE - UNITS_PER_SQUARE / 2); + player.mCamera.height = + max(heightFunc(player.mCamera.position.x / UNITS_PER_SQUARE,player.mCamera.position.y / UNITS_PER_SQUARE) + UNITS_PER_SQUARE / 2,player.mCamera.height); } }