Add square type
This commit is contained in:
parent
ec72771e8a
commit
442d0af6a8
1 changed files with 38 additions and 5 deletions
43
game.cpp
43
game.cpp
|
@ -34,6 +34,31 @@ Unit zBuffer[SUBSAMPLED_WIDTH];
|
||||||
#define LEVEL_X_RES 29
|
#define LEVEL_X_RES 29
|
||||||
#define LEVEL_Y_RES 21
|
#define LEVEL_Y_RES 21
|
||||||
|
|
||||||
|
const unsigned char levelTexture[] =
|
||||||
|
{
|
||||||
|
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, 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, 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, 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, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
const signed char levelFloor[] =
|
const signed char levelFloor[] =
|
||||||
{
|
{
|
||||||
40,40,40,40,40,40,40,40,48,40,48,40,40,40,40,40,40,48,40,48,40,48,40,48,48,24,24,26,28,
|
40,40,40,40,40,40,40,40,48,40,48,40,40,40,40,40,40,48,40,48,40,48,40,48,48,24,24,26,28,
|
||||||
|
@ -503,7 +528,15 @@ public:
|
||||||
Character player;
|
Character player;
|
||||||
Sprite sprites[SPRITES];
|
Sprite sprites[SPRITES];
|
||||||
|
|
||||||
Unit floorHeight(int16_t x, int16_t y)
|
Unit textureAt(int16_t x, int16_t y)
|
||||||
|
{
|
||||||
|
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
||||||
|
return levelTexture[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Unit floorHeightAt(int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
if (x >= 0 && x < LEVEL_X_RES && y >= 0 && y < LEVEL_Y_RES)
|
||||||
return (levelFloor[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x] * UNITS_PER_SQUARE) / 8;
|
return (levelFloor[(LEVEL_Y_RES - y -1) * LEVEL_X_RES + x] * UNITS_PER_SQUARE) / 8;
|
||||||
|
@ -511,7 +544,7 @@ Unit floorHeight(int16_t x, int16_t y)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit ceilingHeight(int16_t x, int16_t y)
|
Unit ceilingHeightAt(int16_t x, int16_t y)
|
||||||
{
|
{
|
||||||
signed char v = 99;
|
signed char v = 99;
|
||||||
|
|
||||||
|
@ -546,7 +579,7 @@ inline void pixelFunc(PixelInfo pixel)
|
||||||
if (intensity < 0)
|
if (intensity < 0)
|
||||||
intensity = 0;
|
intensity = 0;
|
||||||
|
|
||||||
c = sampleImage(image2,pixel.hit.textureCoord,pixel.textureCoordY);
|
c = sampleImage(pixel.hit.type == 0 ? image2 : image,pixel.hit.textureCoord,pixel.textureCoordY);
|
||||||
c = addIntensity(c,intensity - 3);
|
c = addIntensity(c,intensity - 3);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -573,7 +606,7 @@ void draw()
|
||||||
c.maxSteps = 16;
|
c.maxSteps = 16;
|
||||||
c.computeTextureCoords = 1;
|
c.computeTextureCoords = 1;
|
||||||
|
|
||||||
render(player.mCamera,floorHeight,ceilingHeight,pixelFunc,c);
|
render(player.mCamera,floorHeightAt,ceilingHeightAt,textureAt,pixelFunc,c);
|
||||||
|
|
||||||
Unit previousDepth;
|
Unit previousDepth;
|
||||||
|
|
||||||
|
@ -700,7 +733,7 @@ int main()
|
||||||
player.mCamera.direction += addition * step2;
|
player.mCamera.direction += addition * step2;
|
||||||
|
|
||||||
player.mCamera.height =
|
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);
|
max(floorHeightAt(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