75 lines
1.4 KiB
C++
75 lines
1.4 KiB
C++
//
|
|
// Created by trotfunky on 27/05/19.
|
|
//
|
|
|
|
#include "World.h"
|
|
|
|
|
|
World::World(int w, int h, std::vector<BlockType> worldMap) : w(w), h(h), map(std::move(worldMap))
|
|
{
|
|
map.resize(w*h,BlockType::WALL);
|
|
}
|
|
|
|
int World::getW() const
|
|
{
|
|
return w;
|
|
}
|
|
|
|
int World::getH() const
|
|
{
|
|
return h;
|
|
}
|
|
|
|
BlockType World::getBlock(float x, float y) const
|
|
{
|
|
return(map.at(static_cast<int>(x)+w* static_cast<int>(y)));
|
|
}
|
|
|
|
void World::setBlock(BlockType block, int x, int y, int width, int height)
|
|
{
|
|
for(int i = 0;i<height;i++)
|
|
{
|
|
for(int j = 0;j<width;j++)
|
|
{
|
|
if(x+j<w && y+i < h)
|
|
{
|
|
map.at((y+i)*w+x+j) = block;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& ostream, World const& world)
|
|
{
|
|
for(int i = 0;i<world.w*world.h;i++)
|
|
{
|
|
if(i%world.w == 0)
|
|
{
|
|
ostream << std::endl;
|
|
}
|
|
switch(world.getBlock(i%world.w,i/world.w))
|
|
{
|
|
case BlockType::AIR:
|
|
{
|
|
ostream << " ";
|
|
break;
|
|
}
|
|
case BlockType::WALL:
|
|
{
|
|
ostream << "W";
|
|
break;
|
|
}
|
|
case BlockType::DOOR:
|
|
{
|
|
ostream << "D";
|
|
break;
|
|
}
|
|
case BlockType::WINDOW:
|
|
{
|
|
ostream << "W";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return(ostream);
|
|
}
|