void Field::UpdateSight(void)
{
int x, y;
- this->SightPass.resize((this->width * 2 + 1) * (this->height * 2 + 1));
- this->PhysicalPass.resize((this->width * 2 + 1) * (this->height * 2 + 1));
+ int updateSizeX = this->width * 2 + 1;
+ int updateSizeY = this->height * 2 + 1;
+ this->SightPass.resize(updateSizeX * updateSizeY);
+ this->PhysicalPass.resize(updateSizeX * updateSizeY);
- for(x = 0; x < this->height * this->width; x++)
+ for(x = 0; x < updateSizeX * updateSizeY; x++)
{
- this->SightPass[x] = true;
- this->PhysicalPass[x] = true;
+ this->SightPass[x] = false;
+ this->PhysicalPass[x] = false;
}
- for(y = 1; y < this->height * 2 + 1; y += 2)
+ for(y = 1; y < updateSizeY; y += 2)
{
- for(x = 1; x < this->width * 2 + 1; x += 2)
+ for(x = 1; x < updateSizeX; x += 2)
{
- this->SightPass[y * this->width + x] = !this->GetSquare(x / 2, y / 2)->IsWall();
- this->PhysicalPass[y * this->width + x] = !this->GetSquare(x / 2, y / 2)->IsWall();
+ this->SightPass[y * updateSizeX + x] = !this->GetSquare(x / 2, y / 2)->IsWall();
+ this->PhysicalPass[y * updateSizeX + x] = !this->GetSquare(x / 2, y / 2)->IsWall();
}
}
+
for(y = 0; y < this->height * 2 + 1; y += 2)
{
for(x = 0; x < this->width * 2 + 1; x += 2)
{
if(!this->GetSquare(x / 2 - 1, y / 2 - 1) || !this->GetSquare(x / 2 - 1, y / 2) || !this->GetSquare(x / 2, y / 2 - 1) || !this->GetSquare(x / 2, y / 2))
{
- this->SightPass[y * this->width + x] = false;
- this->PhysicalPass[y * this->width + x] = false;
+ this->SightPass[y * updateSizeX + x] = false;
+ this->PhysicalPass[y * updateSizeX + x] = false;
}
else if((!this->GetSquare(x / 2 - 1, y / 2 - 1)->IsWall() && !this->GetSquare(x / 2, y / 2 )->IsWall()) || (!this->GetSquare(x / 2, y / 2 - 1)->IsWall() && !this->GetSquare(x / 2 - 1, y / 2)->IsWall()))
{
- this->SightPass[y * this->width + x] = true;
- this->PhysicalPass[y * this->width + x] = true;
+ this->SightPass[y * updateSizeX + x] = true;
+ this->PhysicalPass[y * updateSizeX + x] = true;
}
else
{
- this->SightPass[y * this->width + x] = false;
- this->PhysicalPass[y * this->width + x] = false;
+ this->SightPass[y * updateSizeX + x] = false;
+ this->PhysicalPass[y * updateSizeX + x] = false;
}
}
}
-
- /*
for(y = 0; y < this->height * 2 + 1; y += 2)
{
for(x = 1; x < this->width * 2 + 1; x += 2)
{
if(!this->GetSquare(x / 2, y / 2 - 1) || !this->GetSquare(x / 2, y / 2))
{
- this->SightPass[y * this->width + x] = false;
- this->PhysicalPass[y * this->width + x] = false;
+ this->SightPass[y * updateSizeX + x] = false;
+ this->PhysicalPass[y * updateSizeX + x] = false;
}
else if(this->GetSquare(x / 2, y / 2 - 1)->IsWall() || this->GetSquare(x / 2, y / 2)->IsWall())
{
- this->SightPass[y * this->width + x] = false;
- this->PhysicalPass[y * this->width + x] = false;
+ this->SightPass[y * updateSizeX + x] = false;
+ this->PhysicalPass[y * updateSizeX + x] = false;
}
else
{
- this->SightPass[y * this->width + x] = true;
- this->PhysicalPass[y * this->width + x] = true;
+ this->SightPass[y * updateSizeX + x] = true;
+ this->PhysicalPass[y * updateSizeX + x] = true;
}
}
}
-
- for(y = 1; y < this->height * 2 + 1; y += 2)
+ for(y = 1; y < updateSizeY; y += 2)
{
- for(x = 0; x < this->width * 2 + 1; x += 2)
+ for(x = 0; x < updateSizeX; x += 2)
{
if(!this->GetSquare(x / 2 - 1, y / 2) || !this->GetSquare(x / 2, y / 2))
{
- this->SightPass[y * this->width + x] = false;
- this->PhysicalPass[y * this->width + x] = false;
+ this->SightPass[y * updateSizeX + x] = false;
+ this->PhysicalPass[y * updateSizeX + x] = false;
}
else if(this->GetSquare(x / 2 - 1, y / 2)->IsWall() || this->GetSquare(x / 2, y / 2)->IsWall())
{
- this->SightPass[y * this->width + x] = false;
- this->PhysicalPass[y * this->width + x] = false;
+ this->SightPass[y * updateSizeX + x] = false;
+ this->PhysicalPass[y * updateSizeX+ x] = false;
}
else
{
- this->SightPass[y * this->width + x] = true;
- this->PhysicalPass[y * this->width + x] = true;
+ this->SightPass[y * updateSizeX + x] = true;
+ this->PhysicalPass[y * updateSizeX + x] = true;
}
}
}
- */
}
bool Field::GetSightPass(int x, int y)
{
- return SightPass[y * width + x];
+ return SightPass[y * (this->width * 2 + 1) + x];
}
}
\ No newline at end of file