Separate floor/ceil
This commit is contained in:
parent
864a83182f
commit
eba49eb12a
1 changed files with 33 additions and 26 deletions
59
game.cpp
59
game.cpp
|
@ -422,23 +422,6 @@ inline uint8_t addIntensity(uint8_t color, int intensity)
|
||||||
return rgbToIndex(r,g,b);
|
return rgbToIndex(r,g,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Level
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
int16_t getHeight(int16_t x, int16_t y)
|
|
||||||
{
|
|
||||||
if (x > 12 || y > 12)
|
|
||||||
return max(x,y) - 10;
|
|
||||||
|
|
||||||
if (y < 5 && y > 0)
|
|
||||||
{
|
|
||||||
return y > 2 ? x : -x;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (x < 0 || y < 0 || x > 9 || y > 9) ? 4 : 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Sprite
|
class Sprite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -453,9 +436,9 @@ public:
|
||||||
|
|
||||||
Character()
|
Character()
|
||||||
{
|
{
|
||||||
mCamera.position.x = 2468;//UNITS_PER_SQUARE * 1;
|
mCamera.position.x = 961;//UNITS_PER_SQUARE * 1;
|
||||||
mCamera.position.y = 6736;//UNITS_PER_SQUARE * 5;
|
mCamera.position.y = 7381;//UNITS_PER_SQUARE * 5;
|
||||||
mCamera.direction = -100;//200;
|
mCamera.direction = -575;//200;
|
||||||
mCamera.fovAngle = UNITS_PER_SQUARE / 4;
|
mCamera.fovAngle = UNITS_PER_SQUARE / 4;
|
||||||
mCamera.height = UNITS_PER_SQUARE / 2;
|
mCamera.height = UNITS_PER_SQUARE / 2;
|
||||||
mCamera.resolution.x = 110 / SUBSAMPLE;
|
mCamera.resolution.x = 110 / SUBSAMPLE;
|
||||||
|
@ -464,12 +447,27 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
Character player;
|
Character player;
|
||||||
Level level;
|
|
||||||
Sprite sprites[SPRITES];
|
Sprite sprites[SPRITES];
|
||||||
|
|
||||||
Unit heightFunc(int16_t x, int16_t y)
|
Unit floorHeight(int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
return level.getHeight(x,y) * UNITS_PER_SQUARE / 4;
|
if (x > 12 || y > 12)
|
||||||
|
return (max(x,y) - 10) * UNITS_PER_SQUARE / 2;
|
||||||
|
|
||||||
|
if (y < 5 && y > 0)
|
||||||
|
{
|
||||||
|
return (y > 2 ? x : -x) * UNITS_PER_SQUARE / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((x < 0 || y < 0 || x > 9 || y > 9) ? 4 : 0) * UNITS_PER_SQUARE / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unit ceilingHeight(int16_t x, int16_t y)
|
||||||
|
{
|
||||||
|
if (x > 12 || y > 12)
|
||||||
|
return (10 + (11 - max(x,y))) * UNITS_PER_SQUARE / 2;
|
||||||
|
|
||||||
|
return 10 * UNITS_PER_SQUARE;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void pixelFunc(PixelInfo pixel)
|
inline void pixelFunc(PixelInfo pixel)
|
||||||
|
@ -497,7 +495,7 @@ inline void pixelFunc(PixelInfo pixel)
|
||||||
if (intensity < 0)
|
if (intensity < 0)
|
||||||
intensity = 0;
|
intensity = 0;
|
||||||
|
|
||||||
c = sampleImage(image,pixel.hit.textureCoord,pixel.textureCoordY);
|
c = sampleImage(image2,pixel.hit.textureCoord,pixel.textureCoordY);
|
||||||
c = addIntensity(c,intensity - 3);
|
c = addIntensity(c,intensity - 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -523,7 +521,7 @@ void draw()
|
||||||
c.maxHits = 16;
|
c.maxHits = 16;
|
||||||
c.maxSteps = 16;
|
c.maxSteps = 16;
|
||||||
|
|
||||||
render(player.mCamera,heightFunc,pixelFunc,c);
|
render(player.mCamera,floorHeight,ceilingHeight,pixelFunc,c);
|
||||||
|
|
||||||
Unit previousDepth;
|
Unit previousDepth;
|
||||||
|
|
||||||
|
@ -544,6 +542,15 @@ void draw()
|
||||||
|
|
||||||
previousDepth = pos.depth;
|
previousDepth = pos.depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.display.setColor(rgbToIndex(7,7,3));
|
||||||
|
p.display.setCursor(1,1);
|
||||||
|
p.display.print(player.mCamera.position.x);
|
||||||
|
p.display.print(" ");
|
||||||
|
p.display.print(player.mCamera.position.y);
|
||||||
|
p.display.print(" ");
|
||||||
|
p.display.print(player.mCamera.direction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -641,7 +648,7 @@ int main()
|
||||||
player.mCamera.direction += addition * step2;
|
player.mCamera.direction += addition * step2;
|
||||||
|
|
||||||
player.mCamera.height =
|
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);
|
max(floorHeight(player.mCamera.position.x / UNITS_PER_SQUARE,player.mCamera.position.y / UNITS_PER_SQUARE) + UNITS_PER_SQUARE / 2,player.mCamera.height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue