Rename map array to mapWalls
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
+32
-32
@@ -27,7 +27,7 @@
|
||||
int mapX = 8, mapY = 8, mapSize = 32;
|
||||
|
||||
// clang-format off
|
||||
int map[] =
|
||||
int mapWalls[] =
|
||||
{
|
||||
1,1,1,1,1,1,1,1,
|
||||
1,0,0,0,0,0,0,1,
|
||||
@@ -358,21 +358,21 @@ void drawRays2D()
|
||||
while (dof < 8)
|
||||
{
|
||||
// We know the coordinates where the ray will hit the wall, but we need
|
||||
// to know where that is in the map array.
|
||||
// to know where that is in the mapWalls array.
|
||||
// Let's take the ray hit position (rx,ry) and divide it by 64 (bit-shift
|
||||
// 6 places), and use that to find the position in the map's array.
|
||||
// 6 places), and use that to find the position in the mapWalls's array.
|
||||
mx = (int)(rayX) >> shiftSize;
|
||||
my = (int)(rayY) >> shiftSize;
|
||||
mapPoint = my * mapX + mx;
|
||||
|
||||
// If the map position is less than the array's size, then we can check it
|
||||
// inside the map. If the value is 1, there's a wall. If we hit a wall,
|
||||
// If the mapWalls position is less than the array's size, then we can check it
|
||||
// inside the mapWalls. If the value is 1, there's a wall. If we hit a wall,
|
||||
// we're done!
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && map[mapPoint] > 0)
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && mapWalls[mapPoint] > 0)
|
||||
{
|
||||
// We hit a wall!
|
||||
|
||||
mh = map[mapPoint];
|
||||
mh = mapWalls[mapPoint];
|
||||
|
||||
// Save the values and calculate the distance from the player
|
||||
hx = rayX;
|
||||
@@ -426,21 +426,21 @@ void drawRays2D()
|
||||
while (dof < 8)
|
||||
{
|
||||
// We know the coordinates where the ray will hit the wall, but we need
|
||||
// to know where that is in the map array.
|
||||
// to know where that is in the mapWalls array.
|
||||
// Let's take the ray hit position (rx,ry) and divide it by 64 (bit-shift
|
||||
// 6 places), and use that to find the position in the map's array.
|
||||
// 6 places), and use that to find the position in the mapWalls's array.
|
||||
mx = (int)(rayX) >> shiftSize;
|
||||
my = (int)(rayY) >> shiftSize;
|
||||
mapPoint = my * mapX + mx;
|
||||
|
||||
// If the map position is less than the array's size, then we can check it
|
||||
// inside the map. If the value is 1, there's a wall. If we hit a wall,
|
||||
// If the mapWalls position is less than the array's size, then we can check it
|
||||
// inside the mapWalls. If the value is 1, there's a wall. If we hit a wall,
|
||||
// we're done!
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && map[mapPoint] > 0)
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && mapWalls[mapPoint] > 0)
|
||||
{
|
||||
// We hit a wall!
|
||||
|
||||
mv = map[mapPoint];
|
||||
mv = mapWalls[mapPoint];
|
||||
|
||||
// Save the values and calculate the distance from the player
|
||||
vx = rayX;
|
||||
@@ -525,7 +525,7 @@ void drawMap2D()
|
||||
for (x = 0; x < mapX; x++)
|
||||
{
|
||||
// Check if it's a wall
|
||||
if (map[y * mapX + x] > 0)
|
||||
if (mapWalls[y * mapX + x] > 0)
|
||||
{
|
||||
// Color walls (white)
|
||||
glColor3f(1, 1, 1);
|
||||
@@ -657,28 +657,28 @@ void drawRays3D()
|
||||
while (dof < 8)
|
||||
{
|
||||
// We know the coordinates where the ray will hit the wall, but we need
|
||||
// to know where that is in the map array.
|
||||
// to know where that is in the mapWalls array.
|
||||
// Let's take the ray hit position (rx,ry) and divide it by 64 (bit-shift
|
||||
// 6 places), and use that to find the position in the map's array.
|
||||
// 6 places), and use that to find the position in the mapWalls's array.
|
||||
mx = (int)(rayX) >> shiftSize;
|
||||
my = (int)(rayY) >> shiftSize;
|
||||
mapPoint = my * mapX + mx;
|
||||
|
||||
// If the map position is less than the array's size, then we can check it
|
||||
// inside the map. If the value is 1, there's a wall. If we hit a wall,
|
||||
// If the mapWalls position is less than the array's size, then we can check it
|
||||
// inside the mapWalls. If the value is 1, there's a wall. If we hit a wall,
|
||||
// we're done!
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && map[mapPoint] > 0)
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && mapWalls[mapPoint] > 0)
|
||||
{
|
||||
// We hit a wall!
|
||||
|
||||
mh = map[mapPoint];
|
||||
mh = mapWalls[mapPoint];
|
||||
|
||||
// Save the values and calculate the distance from the player
|
||||
hx = rayX;
|
||||
hy = rayY;
|
||||
distanceHor = distance(playerX, playerY, hx, hy, rayAngle);
|
||||
|
||||
verticalMapTexture = map[mapPoint] - 1;
|
||||
verticalMapTexture = mapWalls[mapPoint] - 1;
|
||||
|
||||
dof = 8; // Break the loop - no need to calculate more.
|
||||
}
|
||||
@@ -727,28 +727,28 @@ void drawRays3D()
|
||||
while (dof < 8)
|
||||
{
|
||||
// We know the coordinates where the ray will hit the wall, but we need
|
||||
// to know where that is in the map array.
|
||||
// to know where that is in the mapWalls array.
|
||||
// Let's take the ray hit position (rx,ry) and divide it by 64 (bit-shift
|
||||
// 6 places), and use that to find the position in the map's array.
|
||||
// 6 places), and use that to find the position in the mapWalls's array.
|
||||
mx = (int)(rayX) >> shiftSize;
|
||||
my = (int)(rayY) >> shiftSize;
|
||||
mapPoint = my * mapX + mx;
|
||||
|
||||
// If the map position is less than the array's size, then we can check it
|
||||
// inside the map. If the value is 1, there's a wall. If we hit a wall,
|
||||
// If the mapWalls position is less than the array's size, then we can check it
|
||||
// inside the mapWalls. If the value is 1, there's a wall. If we hit a wall,
|
||||
// we're done!
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && map[mapPoint] > 0)
|
||||
if (mapPoint > 0 && mapPoint < mapX * mapY && mapWalls[mapPoint] > 0)
|
||||
{
|
||||
// We hit a wall!
|
||||
|
||||
mv = map[mapPoint];
|
||||
mv = mapWalls[mapPoint];
|
||||
|
||||
// Save the values and calculate the distance from the player
|
||||
vx = rayX;
|
||||
vy = rayY;
|
||||
distanceVert = distance(playerX, playerY, vx, vy, rayAngle);
|
||||
|
||||
verticalMapTexture = map[mapPoint] - 1;
|
||||
verticalMapTexture = mapWalls[mapPoint] - 1;
|
||||
|
||||
dof = 8; // Break the loop - no need to calculate more.
|
||||
}
|
||||
@@ -1041,13 +1041,13 @@ void display()
|
||||
{
|
||||
// We change the X and Y values based on our delta, which is calculated
|
||||
// during our rotation.
|
||||
if (map[iPlayerY * mapX + iPlayerX_add_xOffset] == 0)
|
||||
if (mapWalls[iPlayerY * mapX + iPlayerX_add_xOffset] == 0)
|
||||
{
|
||||
|
||||
playerX += playerDeltaX * movementMultiplier;
|
||||
}
|
||||
|
||||
if (map[iPlayerY_add_yOffset * mapX + iPlayerX] == 0)
|
||||
if (mapWalls[iPlayerY_add_yOffset * mapX + iPlayerX] == 0)
|
||||
{
|
||||
|
||||
playerY += playerDeltaY * movementMultiplier;
|
||||
@@ -1057,12 +1057,12 @@ void display()
|
||||
// ? Move backwards
|
||||
if (Keys.s == 1)
|
||||
{
|
||||
if (map[iPlayerY * mapX + iPlayerX_sub_xOffset] == 0)
|
||||
if (mapWalls[iPlayerY * mapX + iPlayerX_sub_xOffset] == 0)
|
||||
{
|
||||
playerX -= playerDeltaX * movementMultiplier;
|
||||
}
|
||||
|
||||
if (map[iPlayerY_sub_yOffset * mapX + iPlayerX] == 0)
|
||||
if (mapWalls[iPlayerY_sub_yOffset * mapX + iPlayerX] == 0)
|
||||
{
|
||||
playerY -= playerDeltaY * movementMultiplier;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user